Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

//****************************************************************************
// Copyright (C) 2000-2004  ARW Elektronik Germany
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// This product is not authorized for use as critical component in
// life support systems without the express written approval of
// ARW Elektronik Germany.
//  
// Please announce changes and hints to ARW Elektronik
//
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
//
//****************************************************************************

//****************************************************************************
//
// pcicc32_test.c -- a program to test some features of the PCICC32 PCI to
//                   CAMAC Interface
//
// $Log: pcicc32_test.c,v $
// Revision 1.6  2004/08/12 20:00:09  klaus
// conversion to kernel-version 2.6, released version 6.0
//
// Revision 1.5  2002/04/17 18:57:33  klaus
// last changes to release 4.4
//
// Revision 1.4  2002/04/14 18:25:38  klaus
// added interrupt handling, driver 4.4. ...3.5.tar.gz
//
// Revision 1.3  2001/11/20 20:12:50  klaus
// included new header and CVS log
//
//
// first steps                                                 AR   26.02.2000
// default device changed to number 1                          AR   14.04.2000
//
//****************************************************************************

#define DEVICE_NAME "/dev/cc32_1"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <ctype.h>

#include "../lib/libcc32.h" /* the header of the shared library */

char *cszPrgName;
CC32_HANDLE handle;

void hlpMsg(void)
{
    printf("pcicc32_test - a program to test some features of the PCICC32 interface of ARW Elektronik Germany.\n");
    printf("Copyright see the GPL of the free software foundation. K.Hitschler, %s.\n", __DATE__);
    printf("usage: pcicc32_test [-d=device_name] [-?]\n");
    printf("                     -d - choose a device to use. (Default: %s)\n", DEVICE_NAME);
    printf("                     -? - this help.\n");  
}

int main(int argc, char **argv)
{
    char *fname = DEVICE_NAME;
    char *ptr;
    char ch;
    int i;
    int error;
    int nTimeout, nLam;
    int k, j;

   
    cszPrgName = argv[0];
    for (i = 1; i < argc; i++)
    {
        ptr = argv[i];
            if (*ptr == '-') ptr++;
            ch = *ptr;
            ptr++;
            if (*ptr == '=') ptr++;
            switch (tolower(ch))
            {
                    case '?': hlpMsg(); exit(0);
                    case 'd': fname = ptr; break;
                    default:  printf("%s : Unknown command ?%c?!\n", cszPrgName, ch); exit(0); 
            }
       
            if (!fname) printf("%s : Must have devicename!\n", cszPrgName);
    }
   
   
    if ((error = cc32_open(fname, &handle)))
    {
        fprintf(stderr, "%s: %s: %s\n", cszPrgName, fname, strerror(error));
        exit(1);
    }
    else
        printf("%s: open done.\n", cszPrgName);
 
    for (k = 0; k < 1; k++)
    {
            for (j = 0; j < 0x00FFFFFF; j++)
            {    
                    cc32_write_long(handle, 1 + (j % 23), (j % 15), 16 + (j % 15), j);
            }
    }
   
    // poll the event
    error = cc32_poll_event(handle, &nTimeout, &nLam);
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);

    // enable all LAM mask bits for this test    
    cc32_write_long(handle, 28, 1, 16, 0x00FFFFFF);
    // enable interrupts
    error = cc32_interrupt_enable(handle);
   
    // generate a LAM interrupt with help of the test mode bits
    cc32_write_long(handle, 24, 0, 16, 5);
             
    // wait for a event
    error = cc32_wait_event(handle, &nTimeout, &nLam);
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
   
    if (nLam)
    {
      // clear LAM
      cc32_write_word(handle, 28, 0, 16, 0);
    }
   
    // wait again for a event (which never comes)
    error = cc32_wait_event(handle, &nTimeout, &nLam);
    printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
   
         
    cc32_close(handle);;

    printf("%s: close done.\n", cszPrgName);
   
    return 0;
}