gd32 timer优先级
时间: 2023-12-22 19:05:11 浏览: 116
根据引用[1]所述,GD32或者ST32使用4个bit来表示中断优先级,优先级又被分为抢占优先级和子优先级。数值越小,优先级越高。如果抢占优先级相同的话,就比较子优先级,如果抢占优先级和子优先级都相同的话,就比较硬件中断编号,编号越小,优先级越高。因此,在GD32中,timer的优先级也是由抢占优先级和子优先级组成的。可以通过设置抢占优先级和子优先级来设置timer的优先级。
以下是一个设置GD32 timer优先级的例子:
```c
#include "gd32f10x.h"
void timer_init(void)
{
nvic_irq_enable(TIMER0_IRQn, 1, 0); // 设置TIMER0的抢占优先级为1,子优先级为0
timer_parameter_struct timer_initpara;
timer_deinit(TIMER0);
timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 7199;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_init(TIMER0, &timer_initpara);
timer_interrupt_enable(TIMER0, TIMER_INT_UP);
timer_enable(TIMER0);
}
void TIMER0_IRQHandler(void)
{
if (timer_interrupt_flag_get(TIMER0, TIMER_INT_UP) != RESET)
{
timer_interrupt_flag_clear(TIMER0, TIMER_INT_UP);
// do something
}
}
int main(void)
{
timer_init();
while (1);
}
```
阅读全文