Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
CPU
线程上下文调度切换_context
中断
10
中断里进行线程上下文切换如何做到的?
发布于 2023-05-23 09:47:50 浏览:293
订阅该版
``` rt_hw_context_switch_interrupt EXPORT rt_hw_context_switch_interrupt rt_hw_context_switch PROC EXPORT rt_hw_context_switch ; set rt_thread_switch_interrupt_flag to 1 LDR r2, =rt_thread_switch_interrupt_flag LDR r3, [r2] CMP r3, #1 BEQ _reswitch MOV r3, #1 STR r3, [r2] LDR r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread STR r0, [r2] _reswitch LDR r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread STR r1, [r2] LDR r0, =NVIC_INT_CTRL ; trigger the PendSV exception (causes context switch) LDR r1, =NVIC_PENDSVSET STR r1, [r0] BX LR ENDP ``` ------------ 上面是context-m 这个中断时线程上下文切换也是通过触发PendSV进行的,但是一些其他的CPU架构在中断环境下不触发类似PendSV,那么是如何进行真正切换呢?例如下面 ``` rt_hw_context_switch: /* compare rt_thread_switch_interrupt_flag and set it */ lis r5,rt_thread_switch_interrput_flag@h ori r5,r5,rt_thread_switch_interrput_flag@l lwz r6,0(r5) cmpi cr0,0,r6,0x1 /* whether is 1 */ beq _reswitch /* set already, goto _reswitch */ li r6,0x1 /* set rt_thread_switch_interrput_flag to 1*/ stw r6,0(r5) /* set rt_interrupt_from_thread to 'from' */ lis r5,rt_interrupt_from_thread@h ori r5,r5,rt_interrupt_from_thread@l stw r3,0(r5) _reswitch: /* set rt_interrupt_to_thread to 'to' */ lis r6,rt_interrupt_to_thread@h ori r6,r6,rt_interrupt_to_thread@l stw r4,0(r6) /* trigger a system call */ sc blr rt_hw_context_switch_interrupt: /* compare rt_thread_switch_interrupt_flag and set it */ lis r5,rt_thread_switch_interrput_flag@h ori r5,r5,rt_thread_switch_interrput_flag@l lwz r6,0(r5) cmpi cr0,0,r6,0x1 /* whether is 1 */ beq _int_reswitch /* set already, goto _int_reswitch */ li r6,0x1 /* set rt_thread_switch_interrput_flag to 1*/ stw r6,0(r5) /* set rt_interrupt_from_thread to 'from' */ lis r5,rt_interrupt_from_thread@h ori r5,r5,rt_interrupt_from_thread@l stw r3,0(r5) _int_reswitch: /* set rt_interrupt_to_thread to 'to' */ lis r6,rt_interrupt_to_thread@h ori r6,r6,rt_interrupt_to_thread@l stw r4,0(r6) blr ``` 目前的情况就是当我两个优先级相同的线程以时间片轮转时会在定时器中断tick增加时产生线程切换,并且调试模式打印是进了 `rt_hw_context_switch_interrupt`,现象就是没有进行切换。从这个汇编来看确实只是获取了from和to线程,真正的切换寄存器压栈进栈并没有进行。 所以我想问问不和context-m一样在里面触发,那么是怎么做到在中断下上下文切换呢?
查看更多
2
个回答
默认排序
按发布时间排序
靖哥哥我滴神
2023-05-24
这家伙很懒,什么也没写!
看这代码我猜应该和m核的类似吧,应该靠陷阱中断或者软中断的方式,`rt_hw_context_switch_interrupt`完成后在scheduler那开中断然后才进中断切?我猜的
323LJH12
2023-05-24
这家伙很懒,什么也没写!
```c void thread1_entry(void* parameter) { int i = 0; while(i < 20){ rt_kprintf("THREAD TICK:0X%x \r\n",rt_tick_get()); i++; } } void thread2_entry(void* parameter) { int j = 0; while(j < 20){ rt_kprintf("thread tick:0x%x \r\n",rt_tick_get()); j++; } } int main() { rt_thread_t tid1; rt_thread_t tid2; rt_err_t result; rt_kprintf("00tick:0x%x \n",rt_tick_get()); tid1 = &LED_Thread; result = rt_thread_init(tid1,"THREAD1",thread1_entry, RT_NULL,rt_led_thread_stack, sizeof(rt_led_thread_stack), 12,10); rt_thread_startup(tid1); rt_kprintf("11tick:0x%x \n",rt_tick_get()); tid2 = rt_thread_create("thread2", thread2_entry, (void*)1, THREAD_STACK_SIZE, 12, 10); if (tid2 != RT_NULL) rt_thread_startup(tid2); rt_kprintf("main_thread is ending \n"); return 0; } ```
撰写答案
登录
注册新账号
关注者
0
被浏览
293
关于作者
323LJH12
这家伙很懒,什么也没写!
提问
4
回答
2
被采纳
0
关注TA
发私信
相关问题
1
使用CmBacktrace定位错误异常,请教分析原因
2
ARM9、raspberry-pi中断问题
3
内联函数不压栈,会因为中断导致栈内现场被破坏吗
4
rt_hw_context_switch_interrupt的逻辑
5
中断的入口程序在哪个文件里?
6
我想实现一个定时器中断,发现rt_hw_interrupt_install未定义
7
临界区和关中断,是否需要同时使用?
8
gpio 引脚一直进中断,请问怎么办呢?
9
RT-Thread那些API可以在中断程序中调用?
10
spi dma 中断接收的问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
ulog组件多端绑定的demo案例
2
记录rt-thread消息队列的调试方法
3
AT32的ADC使用
4
aht10 终端:The aht10 is under an abnormal status
5
github高阶加速,速度可达带宽峰值,测试到146Mbit/s
热门标签
RT-Thread Studio
串口
LWIP
Env
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
RT-Thread
DMA
SCons
线程
MQTT
RT-Thread Nano
STM32
RTC
rt-smart
ESP8266
flash
ota在线升级
WIZnet_W5500
FAL
I2C
packages_软件包
UART
cubemx
freemodbus
潘多拉开发板_Pandora
定时器
BSP
PWM
ADC
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
SDIO
Debug
AB32VG1
MicroPython
C++_cpp
编译报错
msh
ulog
QEMU
本月问答贡献
出出啊
1500
个答案
338
次被采纳
小小李sunny
1390
个答案
276
次被采纳
张世争
715
个答案
157
次被采纳
crystal266
522
个答案
153
次被采纳
whj467467222
1216
个答案
146
次被采纳
本月文章贡献
出出啊
1
篇文章
12
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
2
篇文章
2
次点赞
crystal266
2
篇文章
5
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部