/*__attribute__((naked)) 很关键 不加调度 *使用naked属性可以告诉编译器不生成函数的prologue和epilogue代码, *这样任务切换函数可以自行管理寄存器的入栈和恢复,从而简化上下文管理*/ void vFreeRTOS_ISR(void) __attribute__((naked)); void vFreeRTOS_ISR(void) { extern void irq_handler(void); /* Save the context of the interrupted task. */ portSAVE_CONTEXT(); /* irq all*/ irq_handler(); /* Restore the context of the new task. */ portRESTORE_CONTEXT(); }
portISR.c 系统嘀嗒中断
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef write32 #define write32(x, y) (*((volatile uint32_t *)(x)) = y) #endif #include "task.h" void vTickISR(void) { /* Increment the RTOS tick count, then look for the highest priority * task that is ready to run. */ if (xTaskIncrementTick() != pdFALSE) { vTaskSwitchContext(); } /* Ready for the next interrupt. */ write32((0x01C20C00) + 0x04, (1 << 0)); }