RT-Thread学习笔记(6)- RT-Thread中断服务程序的书写注意

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37697335/article/details/83242641

在RT-Thread中,中断服务程序的书写和在裸机开发的写法差不多,区别是加入一组API函数,如下:

    rt_interrupt_enter(); //通知操作系统此时进入中断状态
    rt_interrupt_leave();//通知操作系统此时离开中断状态

对于使用方法,我们以系统滴答定时器中断为例,在中断服务程序的开始后和最后分别加上这两个API函数,如下:

/**
 * This is the timer interrupt service routine.
 *
 */
void SysTick_Handler(void)
{
    /* enter interrupt */
    rt_interrupt_enter(); //通知操作系统此时进入中断状态
    HAL_IncTick();
    rt_tick_increase();
    /* leave interrupt */
    rt_interrupt_leave();//通知操作系统此时离开中断状态
}

值得注意的是,这两组API不是必须要加的,只有在中断服务程序中使用到操作系统(此处指的是RT-Thread)的函数时,这两组API才是必须添加的,否则可加可不加,如果不吝啬那一点点内存和CPU消耗时间的话,为了使整个系统规范,还是都加上的好。

当然,和裸机开发一样,中断尽量短小精悍。。

猜你喜欢

转载自blog.csdn.net/m0_37697335/article/details/83242641