LPC_Vic.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*************************************************************************
  2. *
  3. * Used with ICCARM and AARM.
  4. *
  5. * (c) Copyright IAR Systems 2003
  6. *
  7. * File name : LPC_Vic.h
  8. * Description : Define API for VIC
  9. *
  10. * History :
  11. * 1. Data: July 8th, 2004
  12. * Author: Wilson Liu
  13. * Description: Create the basic function
  14. *
  15. * 2. Data: August 4th, 2004
  16. * Author: Shawn Zhang
  17. * Description: Clean up the functions. Support nonvector interrupt at first.
  18. *
  19. * 3. Data : Oct 11, 2004
  20. * Author : Stanimir Bonev
  21. * Description : Modify some function and interface
  22. *
  23. * $Revision: 1.1 $
  24. **************************************************************************/
  25. #include "LPC_Vic.h"
  26. /*************************************************************************
  27. * Function Name: VIC_SetProtectionMode
  28. * Parameters: LPC_Vic_ProtectionMode_t ProtectionType
  29. * Return: void
  30. *
  31. * Description: According to the parameter:- ProtectionType to decide the VIC
  32. * access mode (previledged mode | user or previledged mode).
  33. *
  34. *************************************************************************/
  35. void VIC_SetProtectionMode(LPC_Vic_ProtectionMode_t ProtectionType)
  36. {
  37. VICProtection_bit.PROTECT = ProtectionType;
  38. return ;
  39. }
  40. /*************************************************************************
  41. * Function Name: VIC_GetProtectionMode
  42. * Parameters: void
  43. * Return: LPC_Vic_ProtectionMode_t
  44. *
  45. * Description: Get the VIC access mode (previledged mode | user or previledged mode).
  46. *
  47. *************************************************************************/
  48. LPC_Vic_ProtectionMode_t VIC_GetProtectionMode(void)
  49. {
  50. LPC_Vic_ProtectionMode_t ProtectionType;
  51. if (VICProtection & 0x1)
  52. ProtectionType = PrivilegedMode;
  53. else
  54. ProtectionType = UserandPrivilegedMode;
  55. return ProtectionType;
  56. }
  57. /*************************************************************************
  58. * Function Name: VIC_Init
  59. * Parameters: void
  60. * Return: void
  61. *
  62. * Description: Initialize VIC
  63. *
  64. *************************************************************************/
  65. void VIC_Init(void)
  66. {
  67. // Assign all interrupt chanels to IRQ
  68. VICIntSelect = 0;
  69. // Diasable all interrupts
  70. VICIntEnClear = 0xFFFFFFFF;
  71. // Clear all software interrutps
  72. VICSoftIntClear = 0xFFFFFFFF;
  73. // VIC registers can be accessed in User or privileged mode
  74. VICProtection = 0;
  75. // Clear interrupt
  76. VICVectAddr = 0;
  77. // Clear address of the Interrupt Service routine (ISR) for non-vectored IRQs.
  78. VICDefVectAddr = 0;
  79. // Clear address of the Interrupt Service routine (ISR) for vectored IRQs.
  80. VICVectAddr0 = \
  81. VICVectAddr1 = \
  82. VICVectAddr2 = \
  83. VICVectAddr3 = \
  84. VICVectAddr4 = \
  85. VICVectAddr5 = \
  86. VICVectAddr6 = \
  87. VICVectAddr7 = \
  88. VICVectAddr8 = \
  89. VICVectAddr9 = \
  90. VICVectAddr10 = \
  91. VICVectAddr11 = \
  92. VICVectAddr12 = \
  93. VICVectAddr13 = \
  94. VICVectAddr14 = \
  95. VICVectAddr15 = 0;
  96. // Disable all vectored IRQ slots
  97. VICVectCntl0 = \
  98. VICVectCntl1 = \
  99. VICVectCntl2 = \
  100. VICVectCntl3 = \
  101. VICVectCntl4 = \
  102. VICVectCntl5 = \
  103. VICVectCntl6 = \
  104. VICVectCntl7 = \
  105. VICVectCntl8 = \
  106. VICVectCntl9 = \
  107. VICVectCntl10 = \
  108. VICVectCntl11 = \
  109. VICVectCntl12 = \
  110. VICVectCntl13 = \
  111. VICVectCntl14 = \
  112. VICVectCntl15 = 0;
  113. }
  114. /*************************************************************************
  115. * Function Name: VIC_GetIRQStatus
  116. * Parameters: void
  117. * Return: unsigned int
  118. *
  119. * Description: Get IRQ Status of VIC. Return register VICIRQSTATUS's value.
  120. * If some IRQ interrupt request is enabled, then the corresponding
  121. * bit of VICIRQSTATUS is set.
  122. *
  123. *************************************************************************/
  124. unsigned int VIC_GetIRQStatus(void)
  125. {
  126. return (VICIRQStatus);
  127. }
  128. /*************************************************************************
  129. * Function Name: VIC_GetFIQStatus
  130. * Parameters: void
  131. * Return: unsigned int
  132. *
  133. * Description: Get FIQ Status of VIC. Return register VICFIQSTATUS's value.
  134. * If some FIQ interrupt request is enabled, then the corresponding
  135. * bit of VICFIQSTATUS is set. If more that one interrupt request
  136. * is assigned as FIQ, then invoking this function can decide which
  137. * one or ones is/are the request source(s).
  138. *
  139. *************************************************************************/
  140. unsigned int VIC_GetFIQStatus(void)
  141. {
  142. return (VICFIQStatus);
  143. }
  144. /*************************************************************************
  145. * Function Name: VIC_EnableInt
  146. * Parameters: lpc_uint32 IntType
  147. * Return: void
  148. *
  149. * Description: Enable specific interrupt
  150. *
  151. *************************************************************************/
  152. void VIC_EnableInt(unsigned int IntType)
  153. {
  154. VICIntEnable |= IntType;
  155. }
  156. /*************************************************************************
  157. * Function Name: VIC_DisableInt
  158. * Parameters: unsigned int IntType
  159. * Return: void
  160. *
  161. * Description: Disable specific interrupt
  162. *
  163. *************************************************************************/
  164. void VIC_DisableInt(unsigned int IntType)
  165. {
  166. VICIntEnClear |= IntType;
  167. }
  168. /*************************************************************************
  169. * Function Name: VIC_EnableNonVectoredIRQ
  170. * Parameters: pIRQSub - Non Vectored IRQ Sub address
  171. * Return: void
  172. *
  173. * Description: Set VICDefVectAddr to be the IRQ Sub address.
  174. *
  175. *************************************************************************/
  176. void VIC_EnableNonVectoredIRQ(void(*pIRQSub)())
  177. {
  178. VICDefVectAddr = (unsigned int)pIRQSub;
  179. }
  180. /*************************************************************************
  181. * Function Name: VIC_DisableNonVectoredIRQ
  182. * Parameters: void
  183. * Return: void
  184. *
  185. * Description: set VICDefVectAddr to be reset value (NULL).
  186. *
  187. *************************************************************************/
  188. void VIC_DisableNonVectoredIRQ(void)
  189. {
  190. VICDefVectAddr = NULL;
  191. }
  192. /*************************************************************************
  193. * Function Name: VIC_SetVectoredIRQ
  194. * Parameters: void(*pIRQSub)()
  195. * LPC_VicIrqSlots_t VicIrqSlot
  196. * unsigned int VicIntSouce
  197. *
  198. * Return: void
  199. *
  200. * Description: Init vectored inerrutps
  201. *
  202. *************************************************************************/
  203. void VIC_SetVectoredIRQ(void(*pIRQSub)(), LPC_VicIrqSlots_t VicIrqSlot, unsigned int VicIntSource)
  204. {
  205. unsigned long volatile *pReg;
  206. // load base address of vectored address registers
  207. pReg = &VICVectAddr0;
  208. // Set Address of callback function to corresponding Slot
  209. *(pReg+VicIrqSlot) = (unsigned long)pIRQSub;
  210. // load base address of ctrl registers
  211. pReg = &VICVectCntl0;
  212. // Set source chanel and enable the slot
  213. *(pReg+VicIrqSlot) = VicIntSource | 0x20;
  214. // Clear FIQ select bit
  215. VICIntSelect &= ~(1<<VicIntSource);
  216. }