sysexc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //*****************************************************************************
  2. //
  3. // sysexc.c - Routines for the System Exception Module.
  4. //
  5. // Copyright (c) 2011-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup sysexc_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_sysctl.h"
  49. #include "inc/hw_sysexc.h"
  50. #include "inc/hw_types.h"
  51. #include "driverlib/debug.h"
  52. #include "driverlib/interrupt.h"
  53. //*****************************************************************************
  54. //
  55. //! Returns the interrupt number for a system exception.
  56. //!
  57. //! This function returns the interrupt number for a system exception.
  58. //!
  59. //! \return Returns the system exception interrupt number.
  60. //
  61. //*****************************************************************************
  62. static uint32_t
  63. _SysExcIntNumberGet(void)
  64. {
  65. uint32_t ui32Int;
  66. //
  67. // Get the interrupt number based on the class.
  68. //
  69. if(CLASS_IS_TM4C123)
  70. {
  71. ui32Int = INT_SYSEXC_TM4C123;
  72. }
  73. else if(CLASS_IS_TM4C129)
  74. {
  75. ui32Int = INT_SYSEXC_TM4C129;
  76. }
  77. else
  78. {
  79. ui32Int = 0;
  80. }
  81. return(ui32Int);
  82. }
  83. //*****************************************************************************
  84. //
  85. //! Registers an interrupt handler for the system exception interrupt.
  86. //!
  87. //! \param pfnHandler is a pointer to the function to be called when the system
  88. //! exception interrupt occurs.
  89. //!
  90. //! This function places the address of the system exception interrupt handler
  91. //! into the interrupt vector table in SRAM. This function also enables the
  92. //! global interrupt in the interrupt controller; specific system exception
  93. //! interrupts must be enabled via SysExcIntEnable(). It is the interrupt
  94. //! handler's responsibility to clear the interrupt source.
  95. //!
  96. //! \sa IntRegister() for important information about registering interrupt
  97. //! handlers.
  98. //!
  99. //! \return None.
  100. //
  101. //*****************************************************************************
  102. void
  103. SysExcIntRegister(void (*pfnHandler)(void))
  104. {
  105. uint32_t ui32Int;
  106. //
  107. // Get the system exception interrupt number.
  108. //
  109. ui32Int = _SysExcIntNumberGet();
  110. ASSERT(ui32Int != 0);
  111. //
  112. // Register the interrupt handler.
  113. //
  114. IntRegister(ui32Int, pfnHandler);
  115. //
  116. // Enable the system exception interrupt.
  117. //
  118. IntEnable(ui32Int);
  119. }
  120. //*****************************************************************************
  121. //
  122. //! Unregisters the system exception interrupt handler.
  123. //!
  124. //! This function removes the system exception interrupt handler from the
  125. //! vector table in SRAM. This function also masks off the system exception
  126. //! interrupt in the interrupt controller so that the interrupt handler is no
  127. //! longer called.
  128. //!
  129. //! \sa IntRegister() for important information about registering interrupt
  130. //! handlers.
  131. //!
  132. //! \return None.
  133. //
  134. //*****************************************************************************
  135. void
  136. SysExcIntUnregister(void)
  137. {
  138. uint32_t ui32Int;
  139. //
  140. // Get the system exception interrupt number.
  141. //
  142. ui32Int = _SysExcIntNumberGet();
  143. ASSERT(ui32Int != 0);
  144. //
  145. // Disable the system exception interrupt.
  146. //
  147. IntDisable(ui32Int);
  148. //
  149. // Unregister the system exception interrupt handler.
  150. //
  151. IntUnregister(ui32Int);
  152. }
  153. //*****************************************************************************
  154. //
  155. //! Enables individual system exception interrupt sources.
  156. //!
  157. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  158. //!
  159. //! This function enables the indicated system exception interrupt sources.
  160. //! Only the sources that are enabled can be reflected to the processor
  161. //! interrupt; disabled sources have no effect on the processor.
  162. //!
  163. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  164. //!
  165. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  166. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  167. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  168. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  169. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  170. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  171. //!
  172. //! \return None.
  173. //
  174. //*****************************************************************************
  175. void
  176. SysExcIntEnable(uint32_t ui32IntFlags)
  177. {
  178. //
  179. // Enable the specified interrupts.
  180. //
  181. HWREG(SYSEXC_IM) |= ui32IntFlags;
  182. }
  183. //*****************************************************************************
  184. //
  185. //! Disables individual system exception interrupt sources.
  186. //!
  187. //! \param ui32IntFlags is the bit mask of the interrupt sources to be
  188. //! disabled.
  189. //!
  190. //! This function disables the indicated system exception interrupt sources.
  191. //! Only sources that are enabled can be reflected to the processor interrupt;
  192. //! disabled sources have no effect on the processor.
  193. //!
  194. //! The \e ui32IntFlags 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. //! \return None.
  204. //
  205. //*****************************************************************************
  206. void
  207. SysExcIntDisable(uint32_t ui32IntFlags)
  208. {
  209. //
  210. // Disable the specified interrupts.
  211. //
  212. HWREG(SYSEXC_IM) &= ~(ui32IntFlags);
  213. }
  214. //*****************************************************************************
  215. //
  216. //! Gets the current system exception interrupt status.
  217. //!
  218. //! \param bMasked is \b false if the raw interrupt status is required and
  219. //! \b true if the masked interrupt status is required.
  220. //!
  221. //! This function returns the system exception interrupt status. Either the
  222. //! raw interrupt status or the status of interrupts that are allowed to
  223. //! reflect to the processor can be returned.
  224. //!
  225. //! \return Returns the current system exception interrupt status, enumerated
  226. //! as the logical OR of \b SYSEXC_INT_FP_IXC, \b SYSEXC_INT_FP_OFC,
  227. //! \b SYSEXC_INT_FP_UFC, \b SYSEXC_INT_FP_IOC, \b SYSEXC_INT_FP_DZC, and
  228. //! \b SYSEXC_INT_FP_IDC.
  229. //
  230. //*****************************************************************************
  231. uint32_t
  232. SysExcIntStatus(bool bMasked)
  233. {
  234. //
  235. // Return either the interrupt status or the raw interrupt status as
  236. // requested.
  237. //
  238. if(bMasked)
  239. {
  240. return(HWREG(SYSEXC_MIS));
  241. }
  242. else
  243. {
  244. return(HWREG(SYSEXC_RIS));
  245. }
  246. }
  247. //*****************************************************************************
  248. //
  249. //! Clears system exception interrupt sources.
  250. //!
  251. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  252. //!
  253. //! This function clears the specified system exception interrupt sources, so
  254. //! that they no longer assert. This function must be called in the interrupt
  255. //! handler to keep the interrupt from being recognized again immediately upon
  256. //! exit.
  257. //!
  258. //! The \e ui32IntFlags parameter is the logical OR of any of the following:
  259. //!
  260. //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
  261. //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
  262. //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
  263. //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
  264. //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
  265. //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
  266. //!
  267. //! \note Because there is a write buffer in the Cortex-M processor, it may
  268. //! take several clock cycles before the interrupt source is actually cleared.
  269. //! Therefore, it is recommended that the interrupt source be cleared early in
  270. //! the interrupt handler (as opposed to the very last action) to avoid
  271. //! returning from the interrupt handler before the interrupt source is
  272. //! actually cleared. Failure to do so may result in the interrupt handler
  273. //! being immediately reentered (because the interrupt controller still sees
  274. //! the interrupt source asserted).
  275. //!
  276. //! \return None.
  277. //
  278. //*****************************************************************************
  279. void
  280. SysExcIntClear(uint32_t ui32IntFlags)
  281. {
  282. //
  283. // Clear the requested interrupt sources.
  284. //
  285. HWREG(SYSEXC_IC) = ui32IntFlags;
  286. }
  287. //*****************************************************************************
  288. //
  289. // Close the Doxygen group.
  290. //! @}
  291. //
  292. //*****************************************************************************