home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / c / samples / misc / vmedev.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  1.3 KB  |  58 lines

  1. /* vmedev.c
  2.    This example program opens a VXI interface session and sets
  3.    up an interrupt handler.  When the specified interrupt occurs,
  4.    the procedure defined in the interrupt handler is called. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <sicl.h>
  8.  
  9. #define ADDR "vxi"
  10.  
  11. void handler (INST id, long reason, long secval){
  12.   printf ("Got the interrupt\n");
  13. }
  14.  
  15. void main ()
  16. {
  17.   unsigned short reg;
  18.   unsigned long a24map;
  19.   INST id;
  20.  
  21.   /* install error handler */
  22.   ionerror (I_ERROR_EXIT);
  23.  
  24.   /* open an interface communications session */
  25.   id = iopen (ADDR);
  26.  
  27.   /* install interrupt handler */
  28.   ionintr (id, handler);
  29.   isetintr (id, I_INTR_VXI_VME, 1);
  30.  
  31.   /* turn off interrupt notification */
  32.   iintroff ();
  33.  
  34.   /* map into user memory space */
  35.   a24map = imapx (id, I_MAP_A24, 0x40, 1);
  36.  
  37.   /* read a register */
  38.   ipeekx16(id, a24map, 0x00, ®);
  39.  
  40.   /* print contents */
  41.   printf ("The registers contents were as follows:  0x%04X\n", reg);
  42.  
  43.   /* write to a register causing interrupt */
  44.   ipokex16 (id, a24map, 0x00, reg);
  45.  
  46.   /* wait for interrupt */
  47.   iwaithdlr (10000);
  48.  
  49.   /* turn on interrupt notification */
  50.   iintron ();
  51.  
  52.   /* unmap memory space */
  53.   iunmapx (id, a24map, I_MAP_A24, 0x40, 1);
  54.  
  55.   /* close session */
  56.   iclose (id);
  57. }
  58.