Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1482303
  • 博文数量: 204
  • 博客积分: 4013
  • 博客等级: 中校
  • 技术积分: 4030
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-29 06:34
文章分类

全部博文(204)

文章存档

2012年(204)

分类: C/C++

2012-08-01 21:00:12

点击(此处)折叠或打开

  1. /*******************************************************************************
  2. * Function Name : SysTickHandler
  3. * Description : This function handles SysTick Handler.
  4. * Input : None
  5. * Output : None
  6. * Return : None
  7. *******************************************************************************/
  8. void SysTickHandler(void)
  9. {
  10. __SVC();
  11. /* Toggle PC.04 pin */ LED4
  12. GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_4)));
  13. }
  14. /*******************************************************************************
  15. * Function Name : SVCHandler
  16. * Description : This function handles SVCall exception.
  17. * Input : None
  18. * Output : None
  19. * Return : None
  20. *******************************************************************************/
  21. void SVCHandler(void)
  22. {
  23. /* Set the PSV system handler pending bit */
  24. NVIC_SetSystemHandlerPendingBit(SystemHandler_PSV);
  25. /* Toggle PC.05 pin */ LED3
  26. GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_5)));
  27. }
  28. /*******************************************************************************
  29. * Function Name : PendSVC
  30. * Description : This function handles PendSVC exception.
  31. * Input : None
  32. * Output : None
  33. * Return : None
  34. *******************************************************************************/
  35. void PendSVC(void)
  36. {
  37. /* Set the NMI system handler pending bit */
  38. NVIC_SetSystemHandlerPendingBit(SystemHandler_NMI);
  39. /* Toggle PC.06 pin */ LED2
  40. GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6)));
  41. }
  42. /*******************************************************************************
  43. * Function Name : NMIException
  44. * Description : This function handles NMI exception.
  45. * Input : None
  46. * Output : None
  47. * Return : None
  48. *******************************************************************************/
  49. void NMIException(void)
  50. {
  51. /* Toggle PC.07 pin */  LED1
  52. GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7)));
  53. }
本例展示了如何运用NVIC和系统Handler(system handler):
各个system handlers拥有如下的强制优先级(preemption priority):
   - NMI preemption priority    -2   固定优先级
   - PSV preemption priority     0   可设置
   - SVCall preemption priority  1   可设置
   - SysTick preemption priority 2   可设置

首先把Systick定时器设定为每当其计数器为零,这里是1s产生一个Systick中断。

点击(此处)折叠或打开

  1. /* SysTick interrupt each 1 Hz with Counter clock equal to 72MHz/8 = 9MHz */
  2. SysTick_SetReload(9000000);
  3. /* Enable the SysTick Interrupt */
  4. SysTick_ITConfig(ENABLE);
  5. /* Enable the SysTick Counter */
  6. SysTick_CounterCmd(SysTick_Counter_Enable);
Systick handler routine中,设置与PC.04相连的LED4以1秒为周期闪耀。随后执行_SVC(System Service Call)指令。这个指令在cortexm3_macro.h中
执行_SVC()会激活SVCall handler来打断当前的指令流。在SVCall handler routine中,设置与PC.05相连的LED3闪耀,同时设置PSV handler的pending比特。由于PSV(Pendable request for system service)的优先级更高,因此他又会打断SVCall handler。在PSV handler routine中,设置与PC.06相连的LED2闪耀,并设置NMI(Non maskable interrupt)pending比特,进一步由NMI handler打断当前handler。
最后,在NMI handler中设置与PC.07相连的LED1闪耀。

阅读(12846) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~