1
0

sysexc.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //*****************************************************************************
  2. //
  3. // sysexc.c - Routines for the System Exception Module.
  4. //
  5. // Copyright (c) 2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8049 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. //! \addtogroup sysexc_api
  27. //! @{
  28. //
  29. //*****************************************************************************
  30. #include "inc/hw_ints.h"
  31. #include "inc/hw_sysexc.h"
  32. #include "inc/hw_types.h"
  33. #include "interrupt.h"
  34. //*****************************************************************************
  35. //
  36. //! Registers an interrupt handler for the system exception interrupt.
  37. //!
  38. //! \param pfnHandler is a pointer to the function to be called when the system
  39. //! exception interrupt occurs.
  40. //!
  41. //! This function places the address of the system exception interrupt handler
  42. //! into the interrupt vector table in SRAM. It also enables the global
  43. //! interrupt in the interrupt controller; specific system exception interrupts
  44. //! must be enabled via SysExcIntEnable(). It is the interrupt handler's
  45. //! responsibility to clear the interrupt source.
  46. //!
  47. //! \sa IntRegister() for important information about registering interrupt
  48. //! handlers.
  49. //!
  50. //! \return None.
  51. //
  52. //*****************************************************************************
  53. void
  54. SysExcIntRegister(void (*pfnHandler)(void))
  55. {
  56. //
  57. // Register the interrupt handler.
  58. //
  59. IntRegister(INT_SYSEXC, pfnHandler);
  60. //
  61. // Enable the system exception interrupt.
  62. //
  63. IntEnable(INT_SYSEXC);
  64. }
  65. //*****************************************************************************
  66. //
  67. //! Unregisters the system exception interrupt handler.
  68. //!
  69. //! This function removes the system exception interrupt handler from the
  70. //! vector table in SRAM. It also masks off the system exception interrupt in
  71. //! the interrupt controller so that the interrupt handler is no longer called.
  72. //!
  73. //! \sa IntRegister() for important information about registering interrupt
  74. //! handlers.
  75. //!
  76. //! \return None.
  77. //
  78. //*****************************************************************************
  79. void
  80. SysExcIntUnregister(void)
  81. {
  82. //
  83. // Disable the system exception interrupt.
  84. //
  85. IntDisable(INT_SYSEXC);
  86. //
  87. // Unregister the system exception interrupt handler.
  88. //
  89. IntUnregister(INT_SYSEXC);
  90. }
  91. //*****************************************************************************
  92. //
  93. //! Enables individual system exception interrupt sources.
  94. //!
  95. //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
  96. //!
  97. //! This function enables the indicated system exception interrupt sources.
  98. //! Only the sources that are enabled can be reflected to the processor
  99. //! interrupt; disabled sources have no effect on the processor.
  100. //!
  101. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  102. //!
  103. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  104. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  105. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  106. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  107. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  108. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  109. //!
  110. //! \return None.
  111. //
  112. //*****************************************************************************
  113. void
  114. SysExcIntEnable(unsigned long ulIntFlags)
  115. {
  116. //
  117. // Enable the specified interrupts.
  118. //
  119. HWREG(SYSEXC_IM) |= ulIntFlags;
  120. }
  121. //*****************************************************************************
  122. //
  123. //! Disables individual system exception interrupt sources.
  124. //!
  125. //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
  126. //!
  127. //! This function disables the indicated system exception interrupt sources.
  128. //! Only sources that are enabled can be reflected to the processor interrupt;
  129. //! disabled sources have no effect on the processor.
  130. //!
  131. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  132. //!
  133. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  134. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  135. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  136. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  137. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  138. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  139. //!
  140. //! \return None.
  141. //
  142. //*****************************************************************************
  143. void
  144. SysExcIntDisable(unsigned long ulIntFlags)
  145. {
  146. //
  147. // Disable the specified interrupts.
  148. //
  149. HWREG(SYSEXC_IM) &= ~(ulIntFlags);
  150. }
  151. //*****************************************************************************
  152. //
  153. //! Gets the current system exception interrupt status.
  154. //!
  155. //! \param bMasked is \b false if the raw interrupt status is required and
  156. //! \b true if the masked interrupt status is required.
  157. //!
  158. //! This function returns the system exception interrupt status. Either the
  159. //! raw interrupt status or the status of interrupts that are allowed to
  160. //! reflect to the processor can be returned.
  161. //!
  162. //! \return Returns the current system exception interrupt status, enumerated
  163. //! as the logical OR of \b SYSEXC_INT_FP_IXC, \b SYSEXC_INT_FP_OFC,
  164. //! \b SYSEXC_INT_FP_UFC, \b SYSEXC_INT_FP_IOC, \b SYSEXC_INT_FP_DZC, and
  165. //! \b SYSEXC_INT_FP_IDC.
  166. //
  167. //*****************************************************************************
  168. unsigned long
  169. SysExcIntStatus(tBoolean bMasked)
  170. {
  171. //
  172. // Return either the interrupt status or the raw interrupt status as
  173. // requested.
  174. //
  175. if(bMasked)
  176. {
  177. return(HWREG(SYSEXC_MIS));
  178. }
  179. else
  180. {
  181. return(HWREG(SYSEXC_RIS));
  182. }
  183. }
  184. //*****************************************************************************
  185. //
  186. //! Clears system exception interrupt sources.
  187. //!
  188. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  189. //!
  190. //! The specified system exception interrupt sources are cleared, so that they
  191. //! no longer assert. This function must be called in the interrupt handler to
  192. //! keep the interrupt from being recognized again immediately upon exit.
  193. //!
  194. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  195. //!
  196. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  197. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  198. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  199. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  200. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  201. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  202. //!
  203. //! \note Because there is a write buffer in the Cortex-M processor, it may
  204. //! take several clock cycles before the interrupt source is actually cleared.
  205. //! Therefore, it is recommended that the interrupt source be cleared early in
  206. //! the interrupt handler (as opposed to the very last action) to avoid
  207. //! returning from the interrupt handler before the interrupt source is
  208. //! actually cleared. Failure to do so may result in the interrupt handler
  209. //! being immediately reentered (because the interrupt controller still sees
  210. //! the interrupt source asserted).
  211. //!
  212. //! \return None.
  213. //
  214. //*****************************************************************************
  215. void
  216. SysExcIntClear(unsigned long ulIntFlags)
  217. {
  218. //
  219. // Clear the requested interrupt sources.
  220. //
  221. HWREG(SYSEXC_IC) = ulIntFlags;
  222. }
  223. //*****************************************************************************
  224. //
  225. // Close the Doxygen group.
  226. //! @}
  227. //
  228. //*****************************************************************************