Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. //****************************************************************************
  2. // Copyright (C) 2000-2004  ARW Elektronik Germany
  3. //
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. //
  19. // This product is not authorized for use as critical component in
  20. // life support systems without the express written approval of
  21. // ARW Elektronik Germany.
  22. //  
  23. // Please announce changes and hints to ARW Elektronik
  24. //
  25. // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
  26. //
  27. //****************************************************************************
  28.  
  29. //****************************************************************************
  30. //
  31. // pcicc32_test++.cpp -- a program to test some features of the PCICC32 PCI to
  32. //                       CAMAC Interface, C++ variant
  33. //
  34. // $Log: pcicc32_test++.cpp,v $
  35. // Revision 1.1  2004/10/09 21:05:03  klaus
  36. // Added C++ examples to test programs
  37. //
  38. //
  39. //****************************************************************************
  40.  
  41. #define DEVICE_NAME "/dev/cc32_1"
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <unistd.h>
  47. #include <sys/mman.h>
  48. #include <errno.h>
  49. #include <ctype.h>
  50.  
  51. #include <cpcicc32.h> /* the header of the cc32 representing class */
  52.  
  53. char *cszPrgName;
  54.  
  55. void hlpMsg(void)
  56. {
  57.     printf("pcicc32_test++ - a program to test some features of the PCICC32 interface of ARW Elektronik Germany.\n");
  58.     printf("Copyright see the GPL of the free software foundation. K.Hitschler, %s.\n", __DATE__);
  59.     printf("usage: pcicc32_test++ [-d=device_name] [-?]\n");
  60.     printf("                       -d - choose a device to use. (Default: %s)\n", DEVICE_NAME);
  61.     printf("                       -? - this help.\n");
  62. }
  63.  
  64. int main(int argc, char **argv)
  65. {
  66.     char *fname = DEVICE_NAME;
  67.     char *ptr;
  68.     char ch;
  69.     int i;
  70.     int error;
  71.     int nTimeout, nLam;
  72.     unsigned int k, j;
  73.     cpcicc32 theCC32;
  74.  
  75.    
  76.     cszPrgName = argv[0];
  77.     for (i = 1; i < argc; i++)
  78.     {
  79.         ptr = argv[i];
  80.             if (*ptr == '-') ptr++;
  81.             ch = *ptr;
  82.             ptr++;
  83.             if (*ptr == '=') ptr++;
  84.             switch (tolower(ch))
  85.             {
  86.                     case '?': hlpMsg(); exit(0);
  87.                     case 'd': fname = ptr; break;
  88.                     default:  printf("%s : Unknown command ?%c?!\n", cszPrgName, ch); exit(0); 
  89.         }
  90.     }
  91.    
  92.     // open path to device    
  93.     if ((error = theCC32.open(fname)))
  94.     {
  95.         fprintf(stderr, "%s: %s: %s\n", cszPrgName, fname, strerror(error));
  96.         exit(theCC32.getLastError());
  97.     }
  98.     else
  99.         printf("%s: open done.\n", cszPrgName);
  100.  
  101.     // do some senseless writes to senseless locations
  102.     for (k = 0; k < 1; k++)
  103.     {
  104.             for (j = 0; j < 0x00FFFFFF; j++)
  105.             {    
  106.                     theCC32.write(1 + (j % 23), (j % 15), 16 + (j % 15), static_cast<__u32>(j));
  107.             }
  108.     }
  109.    
  110.     // poll the event
  111.     error = theCC32.poll_event(nTimeout, nLam);
  112.     printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
  113.  
  114.     // enable all LAM mask bits for this test    
  115.     theCC32.write(28, 1, 16, static_cast<__u32>(0x00FFFFFF));
  116.     // enable interrupts
  117.     error = theCC32.interrupt_enable();
  118.    
  119.     // generate a LAM interrupt with help of the test mode bits
  120.     theCC32.write(24, 0, 16, static_cast<__u32>(5));
  121.              
  122.     // wait for a event
  123.     error = theCC32.wait_event(nTimeout, nLam);
  124.     printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
  125.    
  126.     if (nLam)
  127.     {
  128.       // clear LAM
  129.       theCC32.write(28, 0, 16, static_cast<__u32>(0));
  130.     }
  131.    
  132.     printf("%s: This event should never raise. Please press Ctrl-C to abort.\n", cszPrgName);
  133.    
  134.     // wait again for a event (which never comes)
  135.     error = theCC32.wait_event(nTimeout, nLam);
  136.     printf("%s : bConnected = %d, bFail = %d, bIrq = %d\n", cszPrgName, error, nTimeout, nLam);
  137.    
  138.          
  139.     theCC32.close();
  140.  
  141.     printf("%s: close done.\n", cszPrgName);
  142.    
  143.     return 0;
  144. }
  145.