vmeChip2Vme.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* vmeChip2Vme.c - VMEchip2 VMEbus interface library */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01e,05nov96,wlf  doc: cleanup.
  8. 01d,23sep96,mas  changed LM_SIG_LM3 to LM_SIG_SIG3 in sysMailboxInt().
  9. 01c,04jun96,wlf  doc: cleanup.
  10. 01b,07jan93,ccc  changed name to vmeChip2Vme.c.
  11. 01a,11jun92,ccc  created by copying routines from mv167 sysLib.c, ansified.
  12. */
  13. /*
  14. DESCRIPTION
  15. This library contains routines which relate to the VME Chip 2
  16. VMEbus interface.
  17. The functions addressed here include:
  18.     Bus interrupt functions:
  19. - enable/disable VMEbus interrupt levels
  20. - generate bus interrupts
  21.     Mailbox/locations monitor functions:
  22. - enable mailbox/location monitor interrupts
  23. */
  24. #include "drv/vme/vmechip2.h"
  25. LOCAL FUNCPTR sysMailboxRoutine  = NULL;
  26. LOCAL int sysMailboxArg          = NULL;
  27. /*******************************************************************************
  28. *
  29. * sysIntDisable - disable a bus interrupt level
  30. *
  31. * This routine disables a specified VMEbus interrupt level.
  32. *
  33. * RETURNS: OK, or ERROR if <intLevel> is not in the range 1 - 7.
  34. *
  35. * SEE ALSO: sysIntEnable()
  36. */
  37. STATUS sysIntDisable
  38.     (
  39.     int intLevel        /* interrupt level to disable (1-7) */
  40.     )
  41.     {
  42.     if (intLevel < 1 || intLevel > 7)
  43.         return (ERROR);
  44.     *VMECHIP2_LBIER &= ~(1 << (intLevel - 1));
  45.     return (OK);
  46.     }
  47. /*******************************************************************************
  48. *
  49. * sysIntEnable - enable a bus interrupt level
  50. *
  51. * This routine enables a specified VMEbus interrupt level.
  52. *
  53. * RETURNS: OK, or ERROR if <intLevel> is not in the range 1 - 7.
  54. *
  55. * SEE ALSO: sysIntDisable()
  56. */
  57. STATUS sysIntEnable
  58.     (
  59.     int intLevel        /* interrupt level to enable (1-7) */
  60.     )
  61.     {
  62.     if (intLevel < 1 || intLevel > 7)
  63.         return (ERROR);
  64.     *VMECHIP2_LBIER |= (1 << (intLevel - 1));
  65.     return (OK);
  66.     }
  67. /*******************************************************************************
  68. *
  69. * sysBusIntAck - acknowledge a bus interrupt
  70. *
  71. * This routine acknowledges a specified VMEbus interrupt level.
  72. *
  73. * NOTE: This routine has no effect, since VMEbus interrupts are
  74. * acknowledged automatically by hardware if the interrupt level is enabled.
  75. *
  76. * RETURNS: NULL.
  77. *
  78. * SEE ALSO: sysBusIntGen()
  79. */
  80. int sysBusIntAck
  81.     (
  82.     int intLevel        /* interrupt level to acknowledge */
  83.     )
  84.     {
  85.     return (NULL);
  86.     }
  87. /*******************************************************************************
  88. *
  89. * sysBusIntGen - generate a bus interrupt
  90. *
  91. * This routine generates a VMEbus interrupt for a specified level with a
  92. * specified vector.
  93. *
  94. * RETURNS: OK, or ERROR if <level> or <vector> are out of range.
  95. *
  96. * SEE ALSO: sysBusIntAck()
  97. */
  98.  
  99. STATUS sysBusIntGen
  100.     (
  101.     int level, /* interrupt level to generate (1-7)      */
  102.     int vector /* interrupt vector for interrupt (2-255) */
  103.     )
  104.     {
  105.     if (level < 1 || level > 7 || vector > 255 || vector < 2)
  106.         return (ERROR);
  107.  
  108.     *VMECHIP2_ICR       = (vector << 16 |
  109.                            level << 24);
  110.     return (OK);
  111.     }
  112. /*******************************************************************************
  113. *
  114. * sysMailboxInt - handle mailbox interrupt
  115. *
  116. * Mailbox interrupts must be acknowledged.
  117. */
  118. LOCAL void sysMailboxInt (void)
  119.     {
  120.     *VC2GCSR_LM_SIG = LM_SIG_SIG3;      /* clear signal */
  121.     *VMECHIP2_ICLR  = ICLR_CSIG3;       /* clear IRQ */
  122.     if (sysMailboxRoutine != NULL)
  123.         sysMailboxRoutine (sysMailboxArg);
  124.     }
  125. /*******************************************************************************
  126. *
  127. * sysMailboxConnect - connect a routine to the mailbox interrupt
  128. *
  129. * This routine specifies the interrupt service routine to be called at each
  130. * mailbox interrupt.
  131. *
  132. * NOTE: The mailbox interrupt is GCSR SIG3.
  133. *
  134. * RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.
  135. *
  136. * SEE ALSO: intConnect(), sysMailboxEnable()
  137. */
  138. STATUS sysMailboxConnect
  139.     (
  140.     FUNCPTR routine,    /* routine called at each mailbox interrupt */
  141.     int arg             /* argument with which to call routine      */
  142.     )
  143.     {
  144.     static BOOL sysMailboxConnected = FALSE;
  145.     if (!sysMailboxConnected &&
  146.         intConnect (INUM_TO_IVEC (UTIL_INT_VEC_BASE0 + LBIV_GCSR_SIG3),
  147.                         sysMailboxInt, NULL) == ERROR)
  148.         {
  149.         return (ERROR);
  150.         }
  151.     sysMailboxConnected = TRUE;
  152.     sysMailboxRoutine   = routine;
  153.     sysMailboxArg       = arg;
  154.     return (OK);
  155.     }
  156. /*******************************************************************************
  157. *
  158. * sysMailboxEnable - enable the mailbox interrupt
  159. *
  160. * This routine enables the mailbox interrupt.
  161. *
  162. * NOTE: The mailbox interrupt is GCSR SIG3.  The address of the register
  163. * used to set SIG3 is configured as a function of the processor number and
  164. * is set in sysProcNumSet(); thus <mailboxAdrs> is ignored.
  165. *
  166. * RETURNS: OK, always.
  167. *
  168. * SEE ALSO: sysMailboxConnect()
  169. */
  170. STATUS sysMailboxEnable
  171.     (
  172.     char *mailboxAdrs           /* address of mailbox (ignored) */
  173.     )
  174.     {
  175.     *VMECHIP2_LBTVCR |= (sysProcNumGet() << 20);
  176.     *VMECHIP2_ILR2  |= ILR2_SIG3_LEVEL3;        /* set to level 3 */
  177.     *VMECHIP2_LBIER |= LBIER_ESIG3;     /* enable GCSR SIG3 interrupt */
  178.     return (OK);
  179.     }