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

VxWorks

开发平台:

C/C++

  1. /* ppc403Intr.c - 403 specific interrupt handling library */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /* modification history
  5. -----------------------
  6. 01a,08sep97,dat  adapted from ES release of evb401 BSP 
  7. */
  8. /*
  9. This library provides various interface routines to manipulate and connect 
  10. to external hardware interrupts for 403GA.  
  11. */
  12. #include "vxWorks.h"
  13. #include "logLib.h"
  14. #include "stdio.h"
  15. /* defines */
  16. #define INT_LEVEL_MAX 31
  17. #define INT_LEVEL_MIN 0
  18. /* externals */
  19. IMPORT STATUS (*_func_intConnectRtn) (VOIDFUNCPTR *, VOIDFUNCPTR, int);
  20. IMPORT int (*_func_intEnableRtn) (int);
  21. IMPORT int (*_func_intDisableRtn) (int);
  22. /* globals */
  23. void            sysPpc403IntHandler (void);
  24. /* locals */
  25. LOCAL VOIDFUNCPTR  sysIntBlTbl [32] = {(VOIDFUNCPTR) NULL};
  26. LOCAL int      sysIntArg [32]   = {0};
  27. /* forward LOCAL functions declarations */
  28. LOCAL STATUS    sysPpc403IntConnect (VOIDFUNCPTR * vector, VOIDFUNCPTR routine,
  29.                                      int parameter);
  30. LOCAL int       sysPpc403IntEnable (int intLevel);
  31. LOCAL int       sysPpc403IntDisable (int intLevel);
  32. /*******************************************************************************
  33. *
  34. * sysPpc403IntrInit - initialize the interrupt facility 
  35. *
  36. * This routine initializes the interrupt facility 
  37. *
  38. * RETURNS: OK
  39. */
  40. STATUS sysPpc403IntrInit (void)
  41.     {
  42.     /* set the BSP driver specific Interrupt Handler and intConnect routines */
  43.     _func_intConnectRtn = sysPpc403IntConnect;
  44.     _func_intEnableRtn = sysPpc403IntEnable;
  45.     _func_intDisableRtn = sysPpc403IntDisable;
  46.     return (OK);
  47.     }
  48. /*******************************************************************************
  49. *
  50. * sysPpc403IntConnect - connect a C routine to a hardware interrupt
  51. *
  52. * This routine is called by intConnect () to connect a routine to a specified
  53. * interrupt vector.  403GA does not provide vector for external interrupts.
  54. * We just simply assign vectors according to the bits in the External Interrupt
  55. * Enable Register (EXIER).
  56. *
  57. * RETURNS: OK, or ERROR if <vector> is out of range.
  58. */
  59. STATUS sysPpc403IntConnect 
  60.     (
  61.     VOIDFUNCPTR * vector, /* interrupt vector to attach to     */
  62.     VOIDFUNCPTR   routine, /* routine to be called              */
  63.     int           parameter /* parameter to be passed to routine */
  64.     )
  65.     {
  66.     if (((int)vector > INT_LEVEL_MAX) || ((int)vector < INT_LEVEL_MIN))
  67. return (ERROR);
  68.     else
  69. {
  70.         sysIntBlTbl[(int)vector] = routine;
  71.         sysIntArg[(int)vector]   = parameter;
  72.         return (OK);
  73. }
  74.     }
  75. /*******************************************************************************
  76. *
  77. * sysPpc403IntHandler - PPC403 interrupt handler for external interrupts. 
  78. */
  79. void sysPpc403IntHandler (void)
  80.     {
  81.     int vector;
  82.     UCHAR intLevel;
  83.     intLevel = sysInByte (PIC_IACK_ADR);      /* ignore the first one */
  84.     intLevel = sysInByte (PIC_IACK_ADR);      /* interrupt level 0-15 */
  85.     if (intLevel == 13)                       /* serial port 1 */
  86. vector = SERIAL2_INT_LVL;
  87.     else if (intLevel == 12)                  /* ethernet NIC */
  88. vector = INT_LVL_NIC;
  89.     else 
  90. vector = SERIAL2_INT_LVL;
  91.     if (sysIntBlTbl [vector] != (VOIDFUNCPTR) NULL)
  92. (*sysIntBlTbl [vector]) (sysIntArg[vector]);
  93.     else
  94. logMsg ("uninitialized interrupt vector %dn", vector, 0,0,0,0,0);
  95.     if (intLevel < 8)
  96. sysOutByte (PIC1_BASE_ADR, 0X60 | (1 << intLevel)); 
  97.     else
  98. {
  99. sysOutByte (PIC2_BASE_ADR, 0X60 | (intLevel - 8)); 
  100. sysOutByte (PIC1_BASE_ADR, 0X20); 
  101. }
  102.     }
  103. /*******************************************************************************
  104. *
  105. * sysPpc403IntDisable - disable an external interrupt level
  106. *
  107. * This routine disables a specified external interrupt.
  108. *
  109. * RETURNS: OK, or ERROR if <intLevel> is not in the range 0 - 31.
  110. *
  111. * SEE ALSO: sysPpc403IntEnable()
  112. */
  113. int sysPpc403IntDisable
  114.     (
  115.     int intLevel        /* interrupt level to disable */
  116.     )
  117.     {
  118.     if (intLevel > INT_LEVEL_MAX || intLevel < INT_LEVEL_MIN)
  119.         return (ERROR);
  120.     /* disable the interrupt level */
  121.     return (OK);
  122.     }
  123. /*******************************************************************************
  124. *
  125. * sysPpc403IntEnable - enable an external interrupt level
  126. *
  127. * This routine enables a specified external interrupt.
  128. *
  129. * RETURNS: OK, or ERROR if <intLevel> is not in the range 0 - 31.
  130. *
  131. * SEE ALSO: sysPpc403IntDisable()
  132. */
  133. int sysPpc403IntEnable
  134.     (
  135.     int intLevel        /* interrupt level to enable */
  136.     )
  137.     {
  138.     if (intLevel > INT_LEVEL_MAX || intLevel < INT_LEVEL_MIN)
  139.         return (ERROR);
  140.     /* enable the interrupt level */
  141.     return (OK);
  142.     }