高级会员
- 积分
- 657
- 威望
- 411
- 贡献
- 184
- 兑换币
- 138
- 注册时间
- 2016-11-1
- 在线时间
- 31 小时
- 毕业学校
- 曲阜师范大学
|
#include "gpio.h"
#include "common.h"
#include "uart.h"
#include "pit.h"
/* 每1秒触发一次 */
static void PIT0_ISR(void)
{
printf("PIT0 IT enter!\r\n");
DelayMs(500);
printf("PIT0 IT exit!\r\n");
}
/* 每200MS 触发一次 */
static void PIT1_ISR(void)
{
printf("PIT1 IT!\r\n");
}
int main(void)
{
DelayInit();
GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP);
UART_QuickInit(UART4_RX_PE25_TX_PE24, 115200);
//设置优先级分组
NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2);
NVIC_SetPriority(PIT0_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 2, 2)); /* PIT0中断,抢占2 子优先级1 */
NVIC_SetPriority(PIT1_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 2, 1)); /* PIT1中断,抢占2 子优先级2 */
//中断优先级修改完毕
PIT_QuickInit(HW_PIT_CH0, 1000*1000);
PIT_CallbackInstall(HW_PIT_CH0, PIT0_ISR);
PIT_ITDMAConfig(HW_PIT_CH0, kPIT_IT_TOF, true);
PIT_QuickInit(HW_PIT_CH1, 200*1000);
PIT_CallbackInstall(HW_PIT_CH1, PIT1_ISR);
PIT_ITDMAConfig(HW_PIT_CH1, kPIT_IT_TOF, true);
/* 打印优先级 */
uint32_t PreemptPriority, SubPriority;
NVIC_DecodePriority(NVIC_GetPriority(PIT0_IRQn), NVIC_PriorityGroup_2, &PreemptPriority, &SubPriority);
printf("NVIC PIT0_IRQn PreemptPriority:%d SubPriority:%d\r\n", PreemptPriority, SubPriority);
NVIC_DecodePriority(NVIC_GetPriority(PIT1_IRQn), NVIC_PriorityGroup_2, &PreemptPriority, &SubPriority);
printf("NVIC PIT1_IRQn PreemptPriority:%d SubPriority:%d\r\n", PreemptPriority, SubPriority);
while(1)
{
GPIO_ToggleBit(HW_GPIOE, 6);
DelayMs(500);
}
}
|
|