interrupt.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. //*****************************************************************************
  2. //
  3. // interrupt.c
  4. //
  5. // Driver for the NVIC Interrupt Controller.
  6. //
  7. // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  8. //
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions
  12. // are met:
  13. //
  14. // Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. //
  17. // Redistributions in binary form must reproduce the above copyright
  18. // notice, this list of conditions and the following disclaimer in the
  19. // documentation and/or other materials provided with the
  20. // distribution.
  21. //
  22. // Neither the name of Texas Instruments Incorporated nor the names of
  23. // its contributors may be used to endorse or promote products derived
  24. // from this software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup interrupt_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include "inc/hw_ints.h"
  46. #include "inc/hw_nvic.h"
  47. #include "inc/hw_types.h"
  48. #include "cpu.h"
  49. #include "debug.h"
  50. #include "interrupt.h"
  51. //*****************************************************************************
  52. //
  53. // This is a mapping between priority grouping encodings and the number of
  54. // preemption priority bits.
  55. //
  56. //*****************************************************************************
  57. static const unsigned long g_pulPriority[] =
  58. {
  59. NVIC_APINT_PRIGROUP_0_8, NVIC_APINT_PRIGROUP_1_7, NVIC_APINT_PRIGROUP_2_6,
  60. NVIC_APINT_PRIGROUP_3_5, NVIC_APINT_PRIGROUP_4_4, NVIC_APINT_PRIGROUP_5_3,
  61. NVIC_APINT_PRIGROUP_6_2, NVIC_APINT_PRIGROUP_7_1
  62. };
  63. //*****************************************************************************
  64. //
  65. // This is a mapping between interrupt number and the register that contains
  66. // the priority encoding for that interrupt.
  67. //
  68. //*****************************************************************************
  69. static const unsigned long g_pulRegs[] =
  70. {
  71. 0, NVIC_SYS_PRI1, NVIC_SYS_PRI2, NVIC_SYS_PRI3, NVIC_PRI0, NVIC_PRI1,
  72. NVIC_PRI2, NVIC_PRI3, NVIC_PRI4, NVIC_PRI5, NVIC_PRI6, NVIC_PRI7,
  73. NVIC_PRI8, NVIC_PRI9, NVIC_PRI10, NVIC_PRI11, NVIC_PRI12, NVIC_PRI13,
  74. NVIC_PRI14, NVIC_PRI15, NVIC_PRI16, NVIC_PRI17, NVIC_PRI18, NVIC_PRI19,
  75. NVIC_PRI20, NVIC_PRI21, NVIC_PRI22, NVIC_PRI23, NVIC_PRI24, NVIC_PRI25,
  76. NVIC_PRI26, NVIC_PRI27, NVIC_PRI28, NVIC_PRI29, NVIC_PRI30, NVIC_PRI31,
  77. NVIC_PRI32, NVIC_PRI33, NVIC_PRI34, NVIC_PRI35, NVIC_PRI36, NVIC_PRI37,
  78. NVIC_PRI38, NVIC_PRI39, NVIC_PRI40, NVIC_PRI41, NVIC_PRI42, NVIC_PRI43,
  79. NVIC_PRI44, NVIC_PRI45, NVIC_PRI46, NVIC_PRI47, NVIC_PRI48
  80. };
  81. //*****************************************************************************
  82. //
  83. // This is a mapping between interrupt number (for the peripheral interrupts
  84. // only) and the register that contains the interrupt enable for that
  85. // interrupt.
  86. //
  87. //*****************************************************************************
  88. static const unsigned long g_pulEnRegs[] =
  89. {
  90. NVIC_EN0, NVIC_EN1, NVIC_EN2, NVIC_EN3, NVIC_EN4, NVIC_EN5
  91. };
  92. //*****************************************************************************
  93. //
  94. // This is a mapping between interrupt number (for the peripheral interrupts
  95. // only) and the register that contains the interrupt disable for that
  96. // interrupt.
  97. //
  98. //*****************************************************************************
  99. static const unsigned long g_pulDisRegs[] =
  100. {
  101. NVIC_DIS0, NVIC_DIS1, NVIC_DIS2, NVIC_DIS3, NVIC_DIS4, NVIC_DIS5
  102. };
  103. //*****************************************************************************
  104. //
  105. // This is a mapping between interrupt number (for the peripheral interrupts
  106. // only) and the register that contains the interrupt pend for that interrupt.
  107. //
  108. //*****************************************************************************
  109. static const unsigned long g_pulPendRegs[] =
  110. {
  111. NVIC_PEND0, NVIC_PEND1, NVIC_PEND2, NVIC_PEND3, NVIC_PEND4, NVIC_PEND5
  112. };
  113. //*****************************************************************************
  114. //
  115. // This is a mapping between interrupt number (for the peripheral interrupts
  116. // only) and the register that contains the interrupt unpend for that
  117. // interrupt.
  118. //
  119. //*****************************************************************************
  120. static const unsigned long g_pulUnpendRegs[] =
  121. {
  122. NVIC_UNPEND0, NVIC_UNPEND1, NVIC_UNPEND2, NVIC_UNPEND3, NVIC_UNPEND4,
  123. NVIC_UNPEND5
  124. };
  125. //*****************************************************************************
  126. //
  127. //! \internal
  128. //! The default interrupt handler.
  129. //!
  130. //! This is the default interrupt handler for all interrupts. It simply loops
  131. //! forever so that the system state is preserved for observation by a
  132. //! debugger. Since interrupts should be disabled before unregistering the
  133. //! corresponding handler, this should never be called.
  134. //!
  135. //! \return None.
  136. //
  137. //*****************************************************************************
  138. static void
  139. IntDefaultHandler(void)
  140. {
  141. //
  142. // Go into an infinite loop.
  143. //
  144. while(1)
  145. {
  146. }
  147. }
  148. //*****************************************************************************
  149. //
  150. //! Enables the processor interrupt.
  151. //!
  152. //! Allows the processor to respond to interrupts. This does not affect the
  153. //! set of interrupts enabled in the interrupt controller; it just gates the
  154. //! single interrupt from the controller to the processor.
  155. //!
  156. //! \note Previously, this function had no return value. As such, it was
  157. //! possible to include <tt>interrupt.h</tt> and call this function without
  158. //! having included <tt>hw_types.h</tt>. Now that the return is a
  159. //! <tt>tBoolean</tt>, a compiler error will occur in this case. The solution
  160. //! is to include <tt>hw_types.h</tt> before including <tt>interrupt.h</tt>.
  161. //!
  162. //! \return Returns \b true if interrupts were disabled when the function was
  163. //! called or \b false if they were initially enabled.
  164. //
  165. //*****************************************************************************
  166. tBoolean
  167. IntMasterEnable(void)
  168. {
  169. //
  170. // Enable processor interrupts.
  171. //
  172. return(CPUcpsie());
  173. }
  174. //*****************************************************************************
  175. //
  176. //! Disables the processor interrupt.
  177. //!
  178. //! Prevents the processor from receiving interrupts. This does not affect the
  179. //! set of interrupts enabled in the interrupt controller; it just gates the
  180. //! single interrupt from the controller to the processor.
  181. //!
  182. //! \note Previously, this function had no return value. As such, it was
  183. //! possible to include <tt>interrupt.h</tt> and call this function without
  184. //! having included <tt>hw_types.h</tt>. Now that the return is a
  185. //! <tt>tBoolean</tt>, a compiler error will occur in this case. The solution
  186. //! is to include <tt>hw_types.h</tt> before including <tt>interrupt.h</tt>.
  187. //!
  188. //! \return Returns \b true if interrupts were already disabled when the
  189. //! function was called or \b false if they were initially enabled.
  190. //
  191. //*****************************************************************************
  192. tBoolean
  193. IntMasterDisable(void)
  194. {
  195. //
  196. // Disable processor interrupts.
  197. //
  198. return(CPUcpsid());
  199. }
  200. //*****************************************************************************
  201. //
  202. //! Sets the NVIC VTable base.
  203. //!
  204. //! \param ulVtableBase specifies the new base address of VTable
  205. //!
  206. //! This function is used to specify a new base address for the VTable.
  207. //! This function must be called before using IntRegister() for registering
  208. //! any interrupt handler.
  209. //!
  210. //!
  211. //! \return None.
  212. //
  213. //*****************************************************************************
  214. void
  215. IntVTableBaseSet(unsigned long ulVtableBase)
  216. {
  217. HWREG(NVIC_VTABLE) = ulVtableBase;
  218. }
  219. //*****************************************************************************
  220. //
  221. //! Registers a function to be called when an interrupt occurs.
  222. //!
  223. //! \param ulInterrupt specifies the interrupt in question.
  224. //! \param pfnHandler is a pointer to the function to be called.
  225. //!
  226. //! This function is used to specify the handler function to be called when the
  227. //! given interrupt is asserted to the processor. When the interrupt occurs,
  228. //! if it is enabled (via IntEnable()), the handler function will be called in
  229. //! interrupt context. Since the handler function can preempt other code, care
  230. //! must be taken to protect memory or peripherals that are accessed by the
  231. //! handler and other non-handler code.
  232. //!
  233. //!
  234. //! \return None.
  235. //
  236. //*****************************************************************************
  237. void
  238. IntRegister(unsigned long ulInterrupt, void (*pfnHandler)(void))
  239. {
  240. unsigned long *ulNvicTbl;
  241. //
  242. // Check the arguments.
  243. //
  244. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  245. ulNvicTbl = (unsigned long *)HWREG(NVIC_VTABLE);
  246. ulNvicTbl[ulInterrupt]= (unsigned long)pfnHandler;
  247. }
  248. //*****************************************************************************
  249. //
  250. //! Unregisters the function to be called when an interrupt occurs.
  251. //!
  252. //! \param ulInterrupt specifies the interrupt in question.
  253. //!
  254. //! This function is used to indicate that no handler should be called when the
  255. //! given interrupt is asserted to the processor. The interrupt source will be
  256. //! automatically disabled (via IntDisable()) if necessary.
  257. //!
  258. //! \sa IntRegister() for important information about registering interrupt
  259. //! handlers.
  260. //!
  261. //! \return None.
  262. //
  263. //*****************************************************************************
  264. void
  265. IntUnregister(unsigned long ulInterrupt)
  266. {
  267. unsigned long *ulNvicTbl;
  268. //
  269. // Check the arguments.
  270. //
  271. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  272. ulNvicTbl = (unsigned long *)HWREG(NVIC_VTABLE);
  273. ulNvicTbl[ulInterrupt]= (unsigned long)IntDefaultHandler;
  274. }
  275. //*****************************************************************************
  276. //
  277. //! Sets the priority grouping of the interrupt controller.
  278. //!
  279. //! \param ulBits specifies the number of bits of preemptable priority.
  280. //!
  281. //! This function specifies the split between preemptable priority levels and
  282. //! subpriority levels in the interrupt priority specification. The range of
  283. //! the grouping values are dependent upon the hardware implementation; on
  284. //! the CC3200 , three bits are available for hardware interrupt
  285. //! prioritization and therefore priority grouping values of three through
  286. //! seven have the same effect.
  287. //!
  288. //! \return None.
  289. //
  290. //*****************************************************************************
  291. void
  292. IntPriorityGroupingSet(unsigned long ulBits)
  293. {
  294. //
  295. // Check the arguments.
  296. //
  297. ASSERT(ulBits < NUM_PRIORITY);
  298. //
  299. // Set the priority grouping.
  300. //
  301. HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | g_pulPriority[ulBits];
  302. }
  303. //*****************************************************************************
  304. //
  305. //! Gets the priority grouping of the interrupt controller.
  306. //!
  307. //! This function returns the split between preemptable priority levels and
  308. //! subpriority levels in the interrupt priority specification.
  309. //!
  310. //! \return The number of bits of preemptable priority.
  311. //
  312. //*****************************************************************************
  313. unsigned long
  314. IntPriorityGroupingGet(void)
  315. {
  316. unsigned long ulLoop, ulValue;
  317. //
  318. // Read the priority grouping.
  319. //
  320. ulValue = HWREG(NVIC_APINT) & NVIC_APINT_PRIGROUP_M;
  321. //
  322. // Loop through the priority grouping values.
  323. //
  324. for(ulLoop = 0; ulLoop < NUM_PRIORITY; ulLoop++)
  325. {
  326. //
  327. // Stop looping if this value matches.
  328. //
  329. if(ulValue == g_pulPriority[ulLoop])
  330. {
  331. break;
  332. }
  333. }
  334. //
  335. // Return the number of priority bits.
  336. //
  337. return(ulLoop);
  338. }
  339. //*****************************************************************************
  340. //
  341. //! Sets the priority of an interrupt.
  342. //!
  343. //! \param ulInterrupt specifies the interrupt in question.
  344. //! \param ucPriority specifies the priority of the interrupt.
  345. //!
  346. //! This function is used to set the priority of an interrupt. When multiple
  347. //! interrupts are asserted simultaneously, the ones with the highest priority
  348. //! are processed before the lower priority interrupts. Smaller numbers
  349. //! correspond to higher interrupt priorities; priority 0 is the highest
  350. //! interrupt priority.
  351. //!
  352. //! The hardware priority mechanism will only look at the upper N bits of the
  353. //! priority level (where N is 3), so any prioritization must be performed in
  354. //! those bits. The remaining bits can be used to sub-prioritize the interrupt
  355. //! sources, and may be used by the hardware priority mechanism on a future
  356. //! part. This arrangement allows priorities to migrate to different NVIC
  357. //! implementations without changing the gross prioritization of the
  358. //! interrupts.
  359. //!
  360. //! The parameter \e ucPriority can be any one of the following
  361. //! -\b INT_PRIORITY_LVL_0
  362. //! -\b INT_PRIORITY_LVL_1
  363. //! -\b INT_PRIORITY_LVL_2
  364. //! -\b INT_PRIORITY_LVL_3
  365. //! -\b INT_PRIORITY_LVL_4
  366. //! -\b INT_PRIORITY_LVL_5
  367. //! -\b INT_PRIORITY_LVL_6
  368. //! -\b INT_PRIORITY_LVL_7
  369. //!
  370. //! \return None.
  371. //
  372. //*****************************************************************************
  373. void
  374. IntPrioritySet(unsigned long ulInterrupt, unsigned char ucPriority)
  375. {
  376. unsigned long ulTemp;
  377. //
  378. // Check the arguments.
  379. //
  380. ASSERT((ulInterrupt >= 4) && (ulInterrupt < NUM_INTERRUPTS));
  381. //
  382. // Set the interrupt priority.
  383. //
  384. ulTemp = HWREG(g_pulRegs[ulInterrupt >> 2]);
  385. ulTemp &= ~(0xFF << (8 * (ulInterrupt & 3)));
  386. ulTemp |= ucPriority << (8 * (ulInterrupt & 3));
  387. HWREG(g_pulRegs[ulInterrupt >> 2]) = ulTemp;
  388. }
  389. //*****************************************************************************
  390. //
  391. //! Gets the priority of an interrupt.
  392. //!
  393. //! \param ulInterrupt specifies the interrupt in question.
  394. //!
  395. //! This function gets the priority of an interrupt. See IntPrioritySet() for
  396. //! a definition of the priority value.
  397. //!
  398. //! \return Returns the interrupt priority, or -1 if an invalid interrupt was
  399. //! specified.
  400. //
  401. //*****************************************************************************
  402. long
  403. IntPriorityGet(unsigned long ulInterrupt)
  404. {
  405. //
  406. // Check the arguments.
  407. //
  408. ASSERT((ulInterrupt >= 4) && (ulInterrupt < NUM_INTERRUPTS));
  409. //
  410. // Return the interrupt priority.
  411. //
  412. return((HWREG(g_pulRegs[ulInterrupt >> 2]) >> (8 * (ulInterrupt & 3))) &
  413. 0xFF);
  414. }
  415. //*****************************************************************************
  416. //
  417. //! Enables an interrupt.
  418. //!
  419. //! \param ulInterrupt specifies the interrupt to be enabled.
  420. //!
  421. //! The specified interrupt is enabled in the interrupt controller. Other
  422. //! enables for the interrupt (such as at the peripheral level) are unaffected
  423. //! by this function.
  424. //!
  425. //! \return None.
  426. //
  427. //*****************************************************************************
  428. void
  429. IntEnable(unsigned long ulInterrupt)
  430. {
  431. //
  432. // Check the arguments.
  433. //
  434. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  435. //
  436. // Determine the interrupt to enable.
  437. //
  438. if(ulInterrupt == FAULT_MPU)
  439. {
  440. //
  441. // Enable the MemManage interrupt.
  442. //
  443. HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_MEM;
  444. __asm(" dsb ");
  445. __asm(" isb ");
  446. }
  447. else if(ulInterrupt == FAULT_BUS)
  448. {
  449. //
  450. // Enable the bus fault interrupt.
  451. //
  452. HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_BUS;
  453. __asm(" dsb ");
  454. __asm(" isb ");
  455. }
  456. else if(ulInterrupt == FAULT_USAGE)
  457. {
  458. //
  459. // Enable the usage fault interrupt.
  460. //
  461. HWREG(NVIC_SYS_HND_CTRL) |= NVIC_SYS_HND_CTRL_USAGE;
  462. __asm(" dsb ");
  463. __asm(" isb ");
  464. }
  465. else if(ulInterrupt == FAULT_SYSTICK)
  466. {
  467. //
  468. // Enable the System Tick interrupt.
  469. //
  470. HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
  471. __asm(" dsb ");
  472. __asm(" isb ");
  473. }
  474. else if(ulInterrupt >= 16)
  475. {
  476. //
  477. // Enable the general interrupt.
  478. //
  479. HWREG(g_pulEnRegs[(ulInterrupt - 16) / 32]) =
  480. 1 << ((ulInterrupt - 16) & 31);
  481. __asm(" dsb ");
  482. __asm(" isb ");
  483. }
  484. }
  485. //*****************************************************************************
  486. //
  487. //! Disables an interrupt.
  488. //!
  489. //! \param ulInterrupt specifies the interrupt to be disabled.
  490. //!
  491. //! The specified interrupt is disabled in the interrupt controller. Other
  492. //! enables for the interrupt (such as at the peripheral level) are unaffected
  493. //! by this function.
  494. //!
  495. //! \return None.
  496. //
  497. //*****************************************************************************
  498. void
  499. IntDisable(unsigned long ulInterrupt)
  500. {
  501. //
  502. // Check the arguments.
  503. //
  504. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  505. //
  506. // Determine the interrupt to disable.
  507. //
  508. if(ulInterrupt == FAULT_MPU)
  509. {
  510. //
  511. // Disable the MemManage interrupt.
  512. //
  513. HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_MEM);
  514. __asm(" dsb ");
  515. __asm(" isb ");
  516. }
  517. else if(ulInterrupt == FAULT_BUS)
  518. {
  519. //
  520. // Disable the bus fault interrupt.
  521. //
  522. HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_BUS);
  523. __asm(" dsb ");
  524. __asm(" isb ");
  525. }
  526. else if(ulInterrupt == FAULT_USAGE)
  527. {
  528. //
  529. // Disable the usage fault interrupt.
  530. //
  531. HWREG(NVIC_SYS_HND_CTRL) &= ~(NVIC_SYS_HND_CTRL_USAGE);
  532. __asm(" dsb ");
  533. __asm(" isb ");
  534. }
  535. else if(ulInterrupt == FAULT_SYSTICK)
  536. {
  537. //
  538. // Disable the System Tick interrupt.
  539. //
  540. HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
  541. __asm(" dsb ");
  542. __asm(" isb ");
  543. }
  544. else if(ulInterrupt >= 16)
  545. {
  546. //
  547. // Disable the general interrupt.
  548. //
  549. HWREG(g_pulDisRegs[(ulInterrupt - 16) / 32]) =
  550. 1 << ((ulInterrupt - 16) & 31);
  551. __asm(" dsb ");
  552. __asm(" isb ");
  553. }
  554. }
  555. //*****************************************************************************
  556. //
  557. //! Pends an interrupt.
  558. //!
  559. //! \param ulInterrupt specifies the interrupt to be pended.
  560. //!
  561. //! The specified interrupt is pended in the interrupt controller. This will
  562. //! cause the interrupt controller to execute the corresponding interrupt
  563. //! handler at the next available time, based on the current interrupt state
  564. //! priorities. For example, if called by a higher priority interrupt handler,
  565. //! the specified interrupt handler will not be called until after the current
  566. //! interrupt handler has completed execution. The interrupt must have been
  567. //! enabled for it to be called.
  568. //!
  569. //! \return None.
  570. //
  571. //*****************************************************************************
  572. void
  573. IntPendSet(unsigned long ulInterrupt)
  574. {
  575. //
  576. // Check the arguments.
  577. //
  578. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  579. //
  580. // Determine the interrupt to pend.
  581. //
  582. if(ulInterrupt == FAULT_NMI)
  583. {
  584. //
  585. // Pend the NMI interrupt.
  586. //
  587. HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_NMI_SET;
  588. __asm(" dsb ");
  589. __asm(" isb ");
  590. }
  591. else if(ulInterrupt == FAULT_PENDSV)
  592. {
  593. //
  594. // Pend the PendSV interrupt.
  595. //
  596. HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PEND_SV;
  597. __asm(" dsb ");
  598. __asm(" isb ");
  599. }
  600. else if(ulInterrupt == FAULT_SYSTICK)
  601. {
  602. //
  603. // Pend the SysTick interrupt.
  604. //
  605. HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PENDSTSET;
  606. __asm(" dsb ");
  607. __asm(" isb ");
  608. }
  609. else if(ulInterrupt >= 16)
  610. {
  611. //
  612. // Pend the general interrupt.
  613. //
  614. HWREG(g_pulPendRegs[(ulInterrupt - 16) / 32]) =
  615. 1 << ((ulInterrupt - 16) & 31);
  616. __asm(" dsb ");
  617. __asm(" isb ");
  618. }
  619. }
  620. //*****************************************************************************
  621. //
  622. //! Unpends an interrupt.
  623. //!
  624. //! \param ulInterrupt specifies the interrupt to be unpended.
  625. //!
  626. //! The specified interrupt is unpended in the interrupt controller. This will
  627. //! cause any previously generated interrupts that have not been handled yet
  628. //! (due to higher priority interrupts or the interrupt no having been enabled
  629. //! yet) to be discarded.
  630. //!
  631. //! \return None.
  632. //
  633. //*****************************************************************************
  634. void
  635. IntPendClear(unsigned long ulInterrupt)
  636. {
  637. //
  638. // Check the arguments.
  639. //
  640. ASSERT(ulInterrupt < NUM_INTERRUPTS);
  641. //
  642. // Determine the interrupt to unpend.
  643. //
  644. if(ulInterrupt == FAULT_PENDSV)
  645. {
  646. //
  647. // Unpend the PendSV interrupt.
  648. //
  649. HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_UNPEND_SV;
  650. }
  651. else if(ulInterrupt == FAULT_SYSTICK)
  652. {
  653. //
  654. // Unpend the SysTick interrupt.
  655. //
  656. HWREG(NVIC_INT_CTRL) |= NVIC_INT_CTRL_PENDSTCLR;
  657. }
  658. else if(ulInterrupt >= 16)
  659. {
  660. //
  661. // Unpend the general interrupt.
  662. //
  663. HWREG(g_pulUnpendRegs[(ulInterrupt - 16) / 32]) =
  664. 1 << ((ulInterrupt - 16) & 31);
  665. }
  666. }
  667. //*****************************************************************************
  668. //
  669. //! Sets the priority masking level
  670. //!
  671. //! \param ulPriorityMask is the priority level that will be masked.
  672. //!
  673. //! This function sets the interrupt priority masking level so that all
  674. //! interrupts at the specified or lesser priority level is masked. This
  675. //! can be used to globally disable a set of interrupts with priority below
  676. //! a predetermined threshold. A value of 0 disables priority
  677. //! masking.
  678. //!
  679. //! Smaller numbers correspond to higher interrupt priorities. So for example
  680. //! a priority level mask of 4 will allow interrupts of priority level 0-3,
  681. //! and interrupts with a numerical priority of 4 and greater will be blocked.
  682. //!
  683. //! The hardware priority mechanism will only look at the upper N bits of the
  684. //! priority level (where N is 3), so any
  685. //! prioritization must be performed in those bits.
  686. //!
  687. //! \return None.
  688. //
  689. //*****************************************************************************
  690. void
  691. IntPriorityMaskSet(unsigned long ulPriorityMask)
  692. {
  693. CPUbasepriSet(ulPriorityMask);
  694. }
  695. //*****************************************************************************
  696. //
  697. //! Gets the priority masking level
  698. //!
  699. //! This function gets the current setting of the interrupt priority masking
  700. //! level. The value returned is the priority level such that all interrupts
  701. //! of that and lesser priority are masked. A value of 0 means that priority
  702. //! masking is disabled.
  703. //!
  704. //! Smaller numbers correspond to higher interrupt priorities. So for example
  705. //! a priority level mask of 4 will allow interrupts of priority level 0-3,
  706. //! and interrupts with a numerical priority of 4 and greater will be blocked.
  707. //!
  708. //! The hardware priority mechanism will only look at the upper N bits of the
  709. //! priority level (where N is 3), so any
  710. //! prioritization must be performed in those bits.
  711. //!
  712. //! \return Returns the value of the interrupt priority level mask.
  713. //
  714. //*****************************************************************************
  715. unsigned long
  716. IntPriorityMaskGet(void)
  717. {
  718. return(CPUbasepriGet());
  719. }
  720. //*****************************************************************************
  721. //
  722. // Close the Doxygen group.
  723. //! @}
  724. //
  725. //*****************************************************************************