sysexc.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 8264 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. This function also enables the
  43. //! global interrupt in the interrupt controller; specific system exception
  44. //! interrupts must be enabled via SysExcIntEnable(). It is the interrupt
  45. //! handler's 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. This function also masks off the system exception
  71. //! interrupt in the interrupt controller so that the interrupt handler is no
  72. //! longer called.
  73. //!
  74. //! \sa IntRegister() for important information about registering interrupt
  75. //! handlers.
  76. //!
  77. //! \return None.
  78. //
  79. //*****************************************************************************
  80. void
  81. SysExcIntUnregister(void)
  82. {
  83. //
  84. // Disable the system exception interrupt.
  85. //
  86. IntDisable(INT_SYSEXC);
  87. //
  88. // Unregister the system exception interrupt handler.
  89. //
  90. IntUnregister(INT_SYSEXC);
  91. }
  92. //*****************************************************************************
  93. //
  94. //! Enables individual system exception interrupt sources.
  95. //!
  96. //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
  97. //!
  98. //! This function enables the indicated system exception interrupt sources.
  99. //! Only the sources that are enabled can be reflected to the processor
  100. //! interrupt; disabled sources have no effect on the processor.
  101. //!
  102. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  103. //!
  104. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  105. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  106. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  107. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  108. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  109. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  110. //!
  111. //! \return None.
  112. //
  113. //*****************************************************************************
  114. void
  115. SysExcIntEnable(unsigned long ulIntFlags)
  116. {
  117. //
  118. // Enable the specified interrupts.
  119. //
  120. HWREG(SYSEXC_IM) |= ulIntFlags;
  121. }
  122. //*****************************************************************************
  123. //
  124. //! Disables individual system exception interrupt sources.
  125. //!
  126. //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
  127. //!
  128. //! This function disables the indicated system exception interrupt sources.
  129. //! Only sources that are enabled can be reflected to the processor interrupt;
  130. //! disabled sources have no effect on the processor.
  131. //!
  132. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  133. //!
  134. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  135. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  136. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  137. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  138. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  139. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  140. //!
  141. //! \return None.
  142. //
  143. //*****************************************************************************
  144. void
  145. SysExcIntDisable(unsigned long ulIntFlags)
  146. {
  147. //
  148. // Disable the specified interrupts.
  149. //
  150. HWREG(SYSEXC_IM) &= ~(ulIntFlags);
  151. }
  152. //*****************************************************************************
  153. //
  154. //! Gets the current system exception interrupt status.
  155. //!
  156. //! \param bMasked is \b false if the raw interrupt status is required and
  157. //! \b true if the masked interrupt status is required.
  158. //!
  159. //! This function returns the system exception interrupt status. Either the
  160. //! raw interrupt status or the status of interrupts that are allowed to
  161. //! reflect to the processor can be returned.
  162. //!
  163. //! \return Returns the current system exception interrupt status, enumerated
  164. //! as the logical OR of \b SYSEXC_INT_FP_IXC, \b SYSEXC_INT_FP_OFC,
  165. //! \b SYSEXC_INT_FP_UFC, \b SYSEXC_INT_FP_IOC, \b SYSEXC_INT_FP_DZC, and
  166. //! \b SYSEXC_INT_FP_IDC.
  167. //
  168. //*****************************************************************************
  169. unsigned long
  170. SysExcIntStatus(tBoolean bMasked)
  171. {
  172. //
  173. // Return either the interrupt status or the raw interrupt status as
  174. // requested.
  175. //
  176. if(bMasked)
  177. {
  178. return(HWREG(SYSEXC_MIS));
  179. }
  180. else
  181. {
  182. return(HWREG(SYSEXC_RIS));
  183. }
  184. }
  185. //*****************************************************************************
  186. //
  187. //! Clears system exception interrupt sources.
  188. //!
  189. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
  190. //!
  191. //! This function clears the specified system exception interrupt sources, so
  192. //! that they no longer assert. This function must be called in the interrupt
  193. //! handler to keep the interrupt from being recognized again immediately upon
  194. //! exit.
  195. //!
  196. //! The \e ulIntFlags parameter is the logical OR of any of the following:
  197. //!
  198. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  199. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  200. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  201. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  202. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  203. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  204. //!
  205. //! \note Because there is a write buffer in the Cortex-M processor, it may
  206. //! take several clock cycles before the interrupt source is actually cleared.
  207. //! Therefore, it is recommended that the interrupt source be cleared early in
  208. //! the interrupt handler (as opposed to the very last action) to avoid
  209. //! returning from the interrupt handler before the interrupt source is
  210. //! actually cleared. Failure to do so may result in the interrupt handler
  211. //! being immediately reentered (because the interrupt controller still sees
  212. //! the interrupt source asserted).
  213. //!
  214. //! \return None.
  215. //
  216. //*****************************************************************************
  217. void
  218. SysExcIntClear(unsigned long ulIntFlags)
  219. {
  220. //
  221. // Clear the requested interrupt sources.
  222. //
  223. HWREG(SYSEXC_IC) = ulIntFlags;
  224. }
  225. //*****************************************************************************
  226. //
  227. // Close the Doxygen group.
  228. //! @}
  229. //
  230. //*****************************************************************************