Go to most recent revision |
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++.cpp -- a program to test some features of the PCICC32 PCI to
// CAMAC Interface, C++ variant
//
// $Log: pcicc32_test++.cpp,v $
// Revision 1.1 2004/10/09 21:05:03 klaus
// Added C++ examples to test programs
//
//
//****************************************************************************
#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 <cpcicc32.h> /* the header of the cc32 representing class */
char *cszPrgName;
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;
unsigned int k, j;
cpcicc32 theCC32;
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);
}
}
// open path to device
if ((error = theCC32.open(fname)))
{
fprintf(stderr, "%s: %s: %s\n", cszPrgName, fname, strerror(error));
exit(theCC32.getLastError());
}
else
printf("%s: open done.\n", cszPrgName);
// do some senseless writes to senseless locations
for (k = 0; k < 1; k++)
{
for (j = 0; j < 0x00FFFFFF; j++)
{
theCC32.write(1 + (j % 23), (j % 15), 16 + (j % 15), static_cast<__u32>(j));
}
}
// poll the event
error = theCC32.poll_event(nTimeout, nLam);
printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
// enable all LAM mask bits for this test
theCC32.write(28, 1, 16, static_cast<__u32>(0x00FFFFFF));
// enable interrupts
error = theCC32.interrupt_enable();
// generate a LAM interrupt with help of the test mode bits
theCC32.write(24, 0, 16, static_cast<__u32>(5));
// wait for a event
error = theCC32.wait_event(nTimeout, nLam);
printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
if (nLam)
{
// clear LAM
theCC32.write(28, 0, 16, static_cast<__u32>(0));
}
printf("%s: This event should never raise. Please press Ctrl-C to abort.\n", cszPrgName);
// wait again for a event (which never comes)
error = theCC32.wait_event(nTimeout, nLam);
printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
theCC32.close();
printf("%s: close done.\n", cszPrgName);
return 0;
}