stm32f10x_nvic.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name : stm32f10x_nvic.c
  3. * Author : MCD Application Team
  4. * Version : V2.0.3
  5. * Date : 09/22/2008
  6. * Description : This file provides all the NVIC firmware functions.
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/
  15. /* Includes ------------------------------------------------------------------*/
  16. #include "stm32f10x_nvic.h"
  17. /* Private typedef -----------------------------------------------------------*/
  18. /* Private define ------------------------------------------------------------*/
  19. #define AIRCR_VECTKEY_MASK ((u32)0x05FA0000)
  20. /* Private macro -------------------------------------------------------------*/
  21. /* Private variables ---------------------------------------------------------*/
  22. /* Private function prototypes -----------------------------------------------*/
  23. /* Private functions ---------------------------------------------------------*/
  24. /*******************************************************************************
  25. * Function Name : NVIC_DeInit
  26. * Description : Deinitializes the NVIC peripheral registers to their default
  27. * reset values.
  28. * Input : None
  29. * Output : None
  30. * Return : None
  31. *******************************************************************************/
  32. void NVIC_DeInit(void)
  33. {
  34. u32 index = 0;
  35. NVIC->ICER[0] = 0xFFFFFFFF;
  36. NVIC->ICER[1] = 0x0FFFFFFF;
  37. NVIC->ICPR[0] = 0xFFFFFFFF;
  38. NVIC->ICPR[1] = 0x0FFFFFFF;
  39. for(index = 0; index < 0x0F; index++)
  40. {
  41. NVIC->IPR[index] = 0x00000000;
  42. }
  43. }
  44. /*******************************************************************************
  45. * Function Name : NVIC_SCBDeInit
  46. * Description : Deinitializes the SCB peripheral registers to their default
  47. * reset values.
  48. * Input : None
  49. * Output : None
  50. * Return : None
  51. *******************************************************************************/
  52. void NVIC_SCBDeInit(void)
  53. {
  54. u32 index = 0x00;
  55. SCB->ICSR = 0x0A000000;
  56. SCB->VTOR = 0x00000000;
  57. SCB->AIRCR = AIRCR_VECTKEY_MASK;
  58. SCB->SCR = 0x00000000;
  59. SCB->CCR = 0x00000000;
  60. for(index = 0; index < 0x03; index++)
  61. {
  62. SCB->SHPR[index] = 0;
  63. }
  64. SCB->SHCSR = 0x00000000;
  65. SCB->CFSR = 0xFFFFFFFF;
  66. SCB->HFSR = 0xFFFFFFFF;
  67. SCB->DFSR = 0xFFFFFFFF;
  68. }
  69. /*******************************************************************************
  70. * Function Name : NVIC_PriorityGroupConfig
  71. * Description : Configures the priority grouping: pre-emption priority
  72. * and subpriority.
  73. * Input : - NVIC_PriorityGroup: specifies the priority grouping bits
  74. * length. This parameter can be one of the following values:
  75. * - NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  76. * 4 bits for subpriority
  77. * - NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  78. * 3 bits for subpriority
  79. * - NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  80. * 2 bits for subpriority
  81. * - NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  82. * 1 bits for subpriority
  83. * - NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  84. * 0 bits for subpriority
  85. * Output : None
  86. * Return : None
  87. *******************************************************************************/
  88. void NVIC_PriorityGroupConfig(u32 NVIC_PriorityGroup)
  89. {
  90. /* Check the parameters */
  91. assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
  92. /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  93. SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
  94. }
  95. /*******************************************************************************
  96. * Function Name : NVIC_Init
  97. * Description : Initializes the NVIC peripheral according to the specified
  98. * parameters in the NVIC_InitStruct.
  99. * Input : - NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure
  100. * that contains the configuration information for the
  101. * specified NVIC peripheral.
  102. * Output : None
  103. * Return : None
  104. *******************************************************************************/
  105. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  106. {
  107. u32 tmppriority = 0x00, tmpreg = 0x00, tmpmask = 0x00;
  108. u32 tmppre = 0, tmpsub = 0x0F;
  109. /* Check the parameters */
  110. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  111. assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_InitStruct->NVIC_IRQChannel));
  112. assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
  113. assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
  114. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  115. {
  116. /* Compute the Corresponding IRQ Priority --------------------------------*/
  117. tmppriority = (0x700 - (SCB->AIRCR & (u32)0x700))>> 0x08;
  118. tmppre = (0x4 - tmppriority);
  119. tmpsub = tmpsub >> tmppriority;
  120. tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
  121. tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
  122. tmppriority = tmppriority << 0x04;
  123. tmppriority = ((u32)tmppriority) << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
  124. tmpreg = NVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
  125. tmpmask = (u32)0xFF << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
  126. tmpreg &= ~tmpmask;
  127. tmppriority &= tmpmask;
  128. tmpreg |= tmppriority;
  129. NVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
  130. /* Enable the Selected IRQ Channels --------------------------------------*/
  131. NVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
  132. (u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
  133. }
  134. else
  135. {
  136. /* Disable the Selected IRQ Channels -------------------------------------*/
  137. NVIC->ICER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
  138. (u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
  139. }
  140. }
  141. /*******************************************************************************
  142. * Function Name : NVIC_StructInit
  143. * Description : Fills each NVIC_InitStruct member with its default value.
  144. * Input : - NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure which
  145. * will be initialized.
  146. * Output : None
  147. * Return : None
  148. *******************************************************************************/
  149. void NVIC_StructInit(NVIC_InitTypeDef* NVIC_InitStruct)
  150. {
  151. /* NVIC_InitStruct members default value */
  152. NVIC_InitStruct->NVIC_IRQChannel = 0x00;
  153. NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority = 0x00;
  154. NVIC_InitStruct->NVIC_IRQChannelSubPriority = 0x00;
  155. NVIC_InitStruct->NVIC_IRQChannelCmd = DISABLE;
  156. }
  157. /*******************************************************************************
  158. * Function Name : NVIC_SETPRIMASK
  159. * Description : Enables the PRIMASK priority: Raises the execution priority to 0.
  160. * Input : None
  161. * Output : None
  162. * Return : None
  163. *******************************************************************************/
  164. void NVIC_SETPRIMASK(void)
  165. {
  166. __SETPRIMASK();
  167. }
  168. /*******************************************************************************
  169. * Function Name : NVIC_RESETPRIMASK
  170. * Description : Disables the PRIMASK priority.
  171. * Input : None
  172. * Output : None
  173. * Return : None
  174. *******************************************************************************/
  175. void NVIC_RESETPRIMASK(void)
  176. {
  177. __RESETPRIMASK();
  178. }
  179. /*******************************************************************************
  180. * Function Name : NVIC_SETFAULTMASK
  181. * Description : Enables the FAULTMASK priority: Raises the execution priority to -1.
  182. * Input : None
  183. * Output : None
  184. * Return : None
  185. *******************************************************************************/
  186. void NVIC_SETFAULTMASK(void)
  187. {
  188. __SETFAULTMASK();
  189. }
  190. /*******************************************************************************
  191. * Function Name : NVIC_RESETFAULTMASK
  192. * Description : Disables the FAULTMASK priority.
  193. * Input : None
  194. * Output : None
  195. * Return : None
  196. *******************************************************************************/
  197. void NVIC_RESETFAULTMASK(void)
  198. {
  199. __RESETFAULTMASK();
  200. }
  201. /*******************************************************************************
  202. * Function Name : NVIC_BASEPRICONFIG
  203. * Description : The execution priority can be changed from 15 (lowest
  204. configurable priority) to 1. Writing a zero value will disable
  205. * the mask of execution priority.
  206. * Input : None
  207. * Output : None
  208. * Return : None
  209. *******************************************************************************/
  210. void NVIC_BASEPRICONFIG(u32 NewPriority)
  211. {
  212. /* Check the parameters */
  213. assert_param(IS_NVIC_BASE_PRI(NewPriority));
  214. __BASEPRICONFIG(NewPriority << 0x04);
  215. }
  216. /*******************************************************************************
  217. * Function Name : NVIC_GetBASEPRI
  218. * Description : Returns the BASEPRI mask value.
  219. * Input : None
  220. * Output : None
  221. * Return : BASEPRI register value
  222. *******************************************************************************/
  223. u32 NVIC_GetBASEPRI(void)
  224. {
  225. return (__GetBASEPRI());
  226. }
  227. /*******************************************************************************
  228. * Function Name : NVIC_GetCurrentPendingIRQChannel
  229. * Description : Returns the current pending IRQ channel identifier.
  230. * Input : None
  231. * Output : None
  232. * Return : Pending IRQ Channel Identifier.
  233. *******************************************************************************/
  234. u16 NVIC_GetCurrentPendingIRQChannel(void)
  235. {
  236. return ((u16)((SCB->ICSR & (u32)0x003FF000) >> 0x0C));
  237. }
  238. /*******************************************************************************
  239. * Function Name : NVIC_GetIRQChannelPendingBitStatus
  240. * Description : Checks whether the specified IRQ Channel pending bit is set
  241. * or not.
  242. * Input : - NVIC_IRQChannel: specifies the interrupt pending bit to check.
  243. * Output : None
  244. * Return : The new state of IRQ Channel pending bit(SET or RESET).
  245. *******************************************************************************/
  246. ITStatus NVIC_GetIRQChannelPendingBitStatus(u8 NVIC_IRQChannel)
  247. {
  248. ITStatus pendingirqstatus = RESET;
  249. u32 tmp = 0x00;
  250. /* Check the parameters */
  251. assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
  252. tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
  253. if (((NVIC->ISPR[(NVIC_IRQChannel >> 0x05)]) & tmp) == tmp)
  254. {
  255. pendingirqstatus = SET;
  256. }
  257. else
  258. {
  259. pendingirqstatus = RESET;
  260. }
  261. return pendingirqstatus;
  262. }
  263. /*******************************************************************************
  264. * Function Name : NVIC_SetIRQChannelPendingBit
  265. * Description : Sets the NVIC’s interrupt pending bit.
  266. * Input : - NVIC_IRQChannel: specifies the interrupt pending bit to Set.
  267. * Output : None
  268. * Return : None
  269. *******************************************************************************/
  270. void NVIC_SetIRQChannelPendingBit(u8 NVIC_IRQChannel)
  271. {
  272. /* Check the parameters */
  273. assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
  274. *(vu32*) 0xE000EF00 = (u32)NVIC_IRQChannel;
  275. }
  276. /*******************************************************************************
  277. * Function Name : NVIC_ClearIRQChannelPendingBit
  278. * Description : Clears the NVIC’s interrupt pending bit.
  279. * Input : - NVIC_IRQChannel: specifies the interrupt pending bit to clear.
  280. * Output : None
  281. * Return : None
  282. *******************************************************************************/
  283. void NVIC_ClearIRQChannelPendingBit(u8 NVIC_IRQChannel)
  284. {
  285. /* Check the parameters */
  286. assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
  287. NVIC->ICPR[(NVIC_IRQChannel >> 0x05)] = (u32)0x01 << (NVIC_IRQChannel & (u32)0x1F);
  288. }
  289. /*******************************************************************************
  290. * Function Name : NVIC_GetCurrentActiveHandler
  291. * Description : Returns the current active Handler (IRQ Channel and
  292. * SystemHandler) identifier.
  293. * Input : None
  294. * Output : None
  295. * Return : Active Handler Identifier.
  296. *******************************************************************************/
  297. u16 NVIC_GetCurrentActiveHandler(void)
  298. {
  299. return ((u16)(SCB->ICSR & (u32)0x3FF));
  300. }
  301. /*******************************************************************************
  302. * Function Name : NVIC_GetIRQChannelActiveBitStatus
  303. * Description : Checks whether the specified IRQ Channel active bit is set
  304. * or not.
  305. * Input : - NVIC_IRQChannel: specifies the interrupt active bit to check.
  306. * Output : None
  307. * Return : The new state of IRQ Channel active bit(SET or RESET).
  308. *******************************************************************************/
  309. ITStatus NVIC_GetIRQChannelActiveBitStatus(u8 NVIC_IRQChannel)
  310. {
  311. ITStatus activeirqstatus = RESET;
  312. u32 tmp = 0x00;
  313. /* Check the parameters */
  314. assert_param(IS_NVIC_IRQ_CHANNEL(NVIC_IRQChannel));
  315. tmp = ((u32)0x01 << (NVIC_IRQChannel & (u32)0x1F));
  316. if (((NVIC->IABR[(NVIC_IRQChannel >> 0x05)]) & tmp) == tmp )
  317. {
  318. activeirqstatus = SET;
  319. }
  320. else
  321. {
  322. activeirqstatus = RESET;
  323. }
  324. return activeirqstatus;
  325. }
  326. /*******************************************************************************
  327. * Function Name : NVIC_GetCPUID
  328. * Description : Returns the ID number, the version number and the implementation
  329. * details of the Cortex-M3 core.
  330. * Input : None
  331. * Output : None
  332. * Return : CPU ID.
  333. *******************************************************************************/
  334. u32 NVIC_GetCPUID(void)
  335. {
  336. return (SCB->CPUID);
  337. }
  338. /*******************************************************************************
  339. * Function Name : NVIC_SetVectorTable
  340. * Description : Sets the vector table location and Offset.
  341. * Input : - NVIC_VectTab: specifies if the vector table is in RAM or
  342. * FLASH memory.
  343. * This parameter can be one of the following values:
  344. * - NVIC_VectTab_RAM
  345. * - NVIC_VectTab_FLASH
  346. * - Offset: Vector Table base offset field.
  347. * This value must be a multiple of 0x100.
  348. * Output : None
  349. * Return : None
  350. *******************************************************************************/
  351. void NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset)
  352. {
  353. /* Check the parameters */
  354. assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
  355. assert_param(IS_NVIC_OFFSET(Offset));
  356. SCB->VTOR = NVIC_VectTab | (Offset & (u32)0x1FFFFF80);
  357. }
  358. /*******************************************************************************
  359. * Function Name : NVIC_GenerateSystemReset
  360. * Description : Generates a system reset.
  361. * Input : None
  362. * Output : None
  363. * Return : None
  364. *******************************************************************************/
  365. void NVIC_GenerateSystemReset(void)
  366. {
  367. SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x04;
  368. }
  369. /*******************************************************************************
  370. * Function Name : NVIC_GenerateCoreReset
  371. * Description : Generates a Core (Core + NVIC) reset.
  372. * Input : None
  373. * Output : None
  374. * Return : None
  375. *******************************************************************************/
  376. void NVIC_GenerateCoreReset(void)
  377. {
  378. SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x01;
  379. }
  380. /*******************************************************************************
  381. * Function Name : NVIC_SystemLPConfig
  382. * Description : Selects the condition for the system to enter low power mode.
  383. * Input : - LowPowerMode: Specifies the new mode for the system to enter
  384. * low power mode.
  385. * This parameter can be one of the following values:
  386. * - NVIC_LP_SEVONPEND
  387. * - NVIC_LP_SLEEPDEEP
  388. * - NVIC_LP_SLEEPONEXIT
  389. * - NewState: new state of LP condition.
  390. * This parameter can be: ENABLE or DISABLE.
  391. * Output : None
  392. * Return : None
  393. *******************************************************************************/
  394. void NVIC_SystemLPConfig(u8 LowPowerMode, FunctionalState NewState)
  395. {
  396. /* Check the parameters */
  397. assert_param(IS_NVIC_LP(LowPowerMode));
  398. assert_param(IS_FUNCTIONAL_STATE(NewState));
  399. if (NewState != DISABLE)
  400. {
  401. SCB->SCR |= LowPowerMode;
  402. }
  403. else
  404. {
  405. SCB->SCR &= (u32)(~(u32)LowPowerMode);
  406. }
  407. }
  408. /*******************************************************************************
  409. * Function Name : NVIC_SystemHandlerConfig
  410. * Description : Enables or disables the specified System Handlers.
  411. * Input : - SystemHandler: specifies the system handler to be enabled
  412. * or disabled.
  413. * This parameter can be one of the following values:
  414. * - SystemHandler_MemoryManage
  415. * - SystemHandler_BusFault
  416. * - SystemHandler_UsageFault
  417. * - NewState: new state of specified System Handlers.
  418. * This parameter can be: ENABLE or DISABLE.
  419. * Output : None
  420. * Return : None
  421. *******************************************************************************/
  422. void NVIC_SystemHandlerConfig(u32 SystemHandler, FunctionalState NewState)
  423. {
  424. u32 tmpreg = 0x00;
  425. /* Check the parameters */
  426. assert_param(IS_CONFIG_SYSTEM_HANDLER(SystemHandler));
  427. assert_param(IS_FUNCTIONAL_STATE(NewState));
  428. tmpreg = (u32)0x01 << (SystemHandler & (u32)0x1F);
  429. if (NewState != DISABLE)
  430. {
  431. SCB->SHCSR |= tmpreg;
  432. }
  433. else
  434. {
  435. SCB->SHCSR &= ~tmpreg;
  436. }
  437. }
  438. /*******************************************************************************
  439. * Function Name : NVIC_SystemHandlerPriorityConfig
  440. * Description : Configures the specified System Handlers priority.
  441. * Input : - SystemHandler: specifies the system handler to be
  442. * enabled or disabled.
  443. * This parameter can be one of the following values:
  444. * - SystemHandler_MemoryManage
  445. * - SystemHandler_BusFault
  446. * - SystemHandler_UsageFault
  447. * - SystemHandler_SVCall
  448. * - SystemHandler_DebugMonitor
  449. * - SystemHandler_PSV
  450. * - SystemHandler_SysTick
  451. * - SystemHandlerPreemptionPriority: new priority group of the
  452. * specified system handlers.
  453. * - SystemHandlerSubPriority: new sub priority of the specified
  454. * system handlers.
  455. * Output : None
  456. * Return : None
  457. *******************************************************************************/
  458. void NVIC_SystemHandlerPriorityConfig(u32 SystemHandler, u8 SystemHandlerPreemptionPriority,
  459. u8 SystemHandlerSubPriority)
  460. {
  461. u32 tmp1 = 0x00, tmp2 = 0xFF, handlermask = 0x00;
  462. u32 tmppriority = 0x00;
  463. /* Check the parameters */
  464. assert_param(IS_PRIORITY_SYSTEM_HANDLER(SystemHandler));
  465. assert_param(IS_NVIC_PREEMPTION_PRIORITY(SystemHandlerPreemptionPriority));
  466. assert_param(IS_NVIC_SUB_PRIORITY(SystemHandlerSubPriority));
  467. tmppriority = (0x700 - (SCB->AIRCR & (u32)0x700))>> 0x08;
  468. tmp1 = (0x4 - tmppriority);
  469. tmp2 = tmp2 >> tmppriority;
  470. tmppriority = (u32)SystemHandlerPreemptionPriority << tmp1;
  471. tmppriority |= SystemHandlerSubPriority & tmp2;
  472. tmppriority = tmppriority << 0x04;
  473. tmp1 = SystemHandler & (u32)0xC0;
  474. tmp1 = tmp1 >> 0x06;
  475. tmp2 = (SystemHandler >> 0x08) & (u32)0x03;
  476. tmppriority = tmppriority << (tmp2 * 0x08);
  477. handlermask = (u32)0xFF << (tmp2 * 0x08);
  478. SCB->SHPR[tmp1] &= ~handlermask;
  479. SCB->SHPR[tmp1] |= tmppriority;
  480. }
  481. /*******************************************************************************
  482. * Function Name : NVIC_GetSystemHandlerPendingBitStatus
  483. * Description : Checks whether the specified System handlers pending bit is
  484. * set or not.
  485. * Input : - SystemHandler: specifies the system handler pending bit to
  486. * check.
  487. * This parameter can be one of the following values:
  488. * - SystemHandler_MemoryManage
  489. * - SystemHandler_BusFault
  490. * - SystemHandler_SVCall
  491. * Output : None
  492. * Return : The new state of System Handler pending bit(SET or RESET).
  493. *******************************************************************************/
  494. ITStatus NVIC_GetSystemHandlerPendingBitStatus(u32 SystemHandler)
  495. {
  496. ITStatus bitstatus = RESET;
  497. u32 tmp = 0x00, tmppos = 0x00;
  498. /* Check the parameters */
  499. assert_param(IS_GET_PENDING_SYSTEM_HANDLER(SystemHandler));
  500. tmppos = (SystemHandler >> 0x0A);
  501. tmppos &= (u32)0x0F;
  502. tmppos = (u32)0x01 << tmppos;
  503. tmp = SCB->SHCSR & tmppos;
  504. if (tmp == tmppos)
  505. {
  506. bitstatus = SET;
  507. }
  508. else
  509. {
  510. bitstatus = RESET;
  511. }
  512. return bitstatus;
  513. }
  514. /*******************************************************************************
  515. * Function Name : NVIC_SetSystemHandlerPendingBit
  516. * Description : Sets System Handler pending bit.
  517. * Input : - SystemHandler: specifies the system handler pending bit
  518. * to be set.
  519. * This parameter can be one of the following values:
  520. * - SystemHandler_NMI
  521. * - SystemHandler_PSV
  522. * - SystemHandler_SysTick
  523. * Output : None
  524. * Return : None
  525. *******************************************************************************/
  526. void NVIC_SetSystemHandlerPendingBit(u32 SystemHandler)
  527. {
  528. u32 tmp = 0x00;
  529. /* Check the parameters */
  530. assert_param(IS_SET_PENDING_SYSTEM_HANDLER(SystemHandler));
  531. /* Get the System Handler pending bit position */
  532. tmp = SystemHandler & (u32)0x1F;
  533. /* Set the corresponding System Handler pending bit */
  534. SCB->ICSR |= ((u32)0x01 << tmp);
  535. }
  536. /*******************************************************************************
  537. * Function Name : NVIC_ClearSystemHandlerPendingBit
  538. * Description : Clears System Handler pending bit.
  539. * Input : - SystemHandler: specifies the system handler pending bit to
  540. * be clear.
  541. * This parameter can be one of the following values:
  542. * - SystemHandler_PSV
  543. * - SystemHandler_SysTick
  544. * Output : None
  545. * Return : None
  546. *******************************************************************************/
  547. void NVIC_ClearSystemHandlerPendingBit(u32 SystemHandler)
  548. {
  549. u32 tmp = 0x00;
  550. /* Check the parameters */
  551. assert_param(IS_CLEAR_SYSTEM_HANDLER(SystemHandler));
  552. /* Get the System Handler pending bit position */
  553. tmp = SystemHandler & (u32)0x1F;
  554. /* Clear the corresponding System Handler pending bit */
  555. SCB->ICSR |= ((u32)0x01 << (tmp - 0x01));
  556. }
  557. /*******************************************************************************
  558. * Function Name : NVIC_GetSystemHandlerActiveBitStatus
  559. * Description : Checks whether the specified System handlers active bit is
  560. * set or not.
  561. * Input : - SystemHandler: specifies the system handler active bit to
  562. * check.
  563. * This parameter can be one of the following values:
  564. * - SystemHandler_MemoryManage
  565. * - SystemHandler_BusFault
  566. * - SystemHandler_UsageFault
  567. * - SystemHandler_SVCall
  568. * - SystemHandler_DebugMonitor
  569. * - SystemHandler_PSV
  570. * - SystemHandler_SysTick
  571. * Output : None
  572. * Return : The new state of System Handler active bit(SET or RESET).
  573. *******************************************************************************/
  574. ITStatus NVIC_GetSystemHandlerActiveBitStatus(u32 SystemHandler)
  575. {
  576. ITStatus bitstatus = RESET;
  577. u32 tmp = 0x00, tmppos = 0x00;
  578. /* Check the parameters */
  579. assert_param(IS_GET_ACTIVE_SYSTEM_HANDLER(SystemHandler));
  580. tmppos = (SystemHandler >> 0x0E) & (u32)0x0F;
  581. tmppos = (u32)0x01 << tmppos;
  582. tmp = SCB->SHCSR & tmppos;
  583. if (tmp == tmppos)
  584. {
  585. bitstatus = SET;
  586. }
  587. else
  588. {
  589. bitstatus = RESET;
  590. }
  591. return bitstatus;
  592. }
  593. /*******************************************************************************
  594. * Function Name : NVIC_GetFaultHandlerSources
  595. * Description : Returns the system fault handlers sources.
  596. * Input : - SystemHandler: specifies the system handler to get its fault
  597. * sources.
  598. * This parameter can be one of the following values:
  599. * - SystemHandler_HardFault
  600. * - SystemHandler_MemoryManage
  601. * - SystemHandler_BusFault
  602. * - SystemHandler_UsageFault
  603. * - SystemHandler_DebugMonitor
  604. * Output : None
  605. * Return : Source of the fault handler.
  606. *******************************************************************************/
  607. u32 NVIC_GetFaultHandlerSources(u32 SystemHandler)
  608. {
  609. u32 faultsources = 0x00;
  610. u32 tmpreg = 0x00, tmppos = 0x00;
  611. /* Check the parameters */
  612. assert_param(IS_FAULT_SOURCE_SYSTEM_HANDLER(SystemHandler));
  613. tmpreg = (SystemHandler >> 0x12) & (u32)0x03;
  614. tmppos = (SystemHandler >> 0x14) & (u32)0x03;
  615. if (tmpreg == 0x00)
  616. {
  617. faultsources = SCB->HFSR;
  618. }
  619. else if (tmpreg == 0x01)
  620. {
  621. faultsources = SCB->CFSR >> (tmppos * 0x08);
  622. if (tmppos != 0x02)
  623. {
  624. faultsources &= (u32)0x0F;
  625. }
  626. else
  627. {
  628. faultsources &= (u32)0xFF;
  629. }
  630. }
  631. else
  632. {
  633. faultsources = SCB->DFSR;
  634. }
  635. return faultsources;
  636. }
  637. /*******************************************************************************
  638. * Function Name : NVIC_GetFaultAddress
  639. * Description : Returns the address of the location that generated a fault
  640. * handler.
  641. * Input : - SystemHandler: specifies the system handler to get its
  642. * fault address.
  643. * This parameter can be one of the following values:
  644. * - SystemHandler_MemoryManage
  645. * - SystemHandler_BusFault
  646. * Output : None
  647. * Return : Fault address.
  648. *******************************************************************************/
  649. u32 NVIC_GetFaultAddress(u32 SystemHandler)
  650. {
  651. u32 faultaddress = 0x00;
  652. u32 tmp = 0x00;
  653. /* Check the parameters */
  654. assert_param(IS_FAULT_ADDRESS_SYSTEM_HANDLER(SystemHandler));
  655. tmp = (SystemHandler >> 0x16) & (u32)0x01;
  656. if (tmp == 0x00)
  657. {
  658. faultaddress = SCB->MMFAR;
  659. }
  660. else
  661. {
  662. faultaddress = SCB->BFAR;
  663. }
  664. return faultaddress;
  665. }
  666. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/