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

VxWorks

开发平台:

C/C++

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