LDR r1, =rt_interrupt_to_thread STR r0, [r1] ; 设置 from 线程为空,表示不需要从保存 from 的上下文 LDR r1, =rt_interrupt_from_thread MOV r0, #0x0 STR r0, [r1] ; 设置标志为 1,表示需要切换,这个变量将在 PendSV 异常处理函数里切换的时被清零 LDR r1, =rt_thread_switch_interrupt_flag ...
; 设置 rt_thread_switch_interrupt_flag 变量为 1 MOV r3, #1 STR r3, [r2] ; 从参数 r0里更新 rt_interrupt_from_thread 变量 LDR r2, =rt_interrupt_from_thread STR r0, [r2] _reswitch ; 从参数r1里更新 rt_interrupt_to_thread 变量 LDR r2, =rt_interrupt_to_thread STR r1, [r2] ; 触...
99行-105行,rt_thread_switch_interrupt_flag清0,判断rt_interrupt_from_thread的值,为0表示OS第一次进行最高优先级就绪状态线程的运行,无需恢复psp,直接跳转到switch_to_thread;为1表示从from线程切换至to线程,需要恢复psp。Debug到此处,rt_interrupt_from_thread的值为0,是第一次进行线程运行。 此处直接分析127...
中断处理过程中并不执行线程切换,只是通过函数rt_hw_context_switch_interrupt设置相关的全局变量。当中断处理完毕后,检查rt_thread_switch_interrupt_flag变量,若值不为1则正常返回;若值为1,则进行线程切换,实际的切换工作由中断入口函数中rt_hw_context_switch_interrupt_do部分来完成。代码注释如下: rt_hw_context_...
在ARM9 等平台,rt_hw_context_switch() 和 rt_hw_context_switch_interrupt() 的实现并不一样。在中断处理程序里如果触发了线程的调度,调度函数里会调用 rt_hw_context_switch_interrupt() 触发上下文切换。中断处理程序里处理完中断事务之后,中断退出之前,检查 rt_thread_switch_interrupt_flag 变量,如果该变量的...
/** 如果rt_thread_switch_interrupt_flag值为1 */ beq_reswitch/** 如果rt_thread_switch_interrupt_flag值为1,跳转到标号_reswitch执行 */ mov r3, #1 /** 如果rt_thread_switch_interrupt_flag值为0,将其值设置为1 */ str r3, [r2]
rt_thread_switch_interrupt_flag 变量是指示 上下文切换动作 是否在PendSV中断中执行过,如果等于1,表示需要切换,需要在PendSV中断中执行,也就是还没有执行,那么也就不需要再更新rt_interrupt_from_thread变量,(在上一次调用过rt_hw_context_switch/rt_hw_context_switch_interrupt 函数之后还没来得及切换线程,即rt...
RT-Thread 为了解决临界区问题,提供了一系列的线程间同步和同步机制。这些机制内部实现都需要用到 libcpu 里提供的全局中断开关函数,他们分别是: /* 关闭全局中断 */ rt_base_t rt_hw_interrupt_disable(void); /* 打开全局中断 */ void rt_hw_interrupt_enable(rt_base_t level); ...
/* clear rt_thread_switch_interrupt_flag to 0 */MOV R1,#0STR R1,[R0] 设置被切换的线程栈地址,因为是开始,所以是0。也不用保存上文: 读出切入线程的栈指针,准备切换: 正式开始切换: 把线程的R4~R11装载进对应寄存器组,并且调整PSP指针:
(rt_flag1_thread_stack) ); /* 线程栈大小,单位为字节 */ /* 将线程插入到就绪列表 */ /* 初始化线程 */ rt_thread_init(&rt_flag2_thread, /* 线程控制块 */ flag2_thread_entry, /* 线程入口地址 */ RT_NULL, /* 线程形参 */ &rt_flag2_thread_stack[0], /* 线程栈起始地址 */ ...