Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread一般讨论
关于renesas M16C分支的一点移植说明
发布于 2011-09-02 15:50:10 浏览:3322
订阅该版
在SVN r1687中context_iar.asm ```rt_hw_context_switch CMP.W #1,rt_thread_switch_interrput_flag JEQ jump1 MOV.W #1,rt_thread_switch_interrput_flag MOV.W R0, rt_interrupt_from_thread jump1 MOV.W R1, rt_interrupt_to_thread INT #0 RTS ``` rt_hw_context_switch()是任务级的上下文切换函数(通过非屏蔽的软件中断实现上下文切换) 而rt_thread_switch_interrput_flag是中断级上下文切换标志 显然在M16C的移植分支中,函数rt_hw_context_switch()里无需判断标志rt_thread_switch_interrput_flag(事实上此时该标志值为0) 因此可以简化函数rt_hw_context_switch(),提高效率 ```rt_hw_context_switch MOV.W R0, rt_interrupt_from_thread MOV.W R1, rt_interrupt_to_thread INT #0 RTS ``` 相应的非屏蔽软件中断0处理函数 ```os_context_switch: PUSHM R0,R1,R2,R3,A0,A1,SB,FB CMP.W #0,rt_thread_switch_interrput_flag JEQ exit MOV.W #0, rt_thread_switch_interrput_flag MOV.W rt_interrupt_from_thread, A0 STC ISP, [A0] MOV.W rt_interrupt_to_thread, A0 LDC [A0], ISP exit POPM R0,R1,R2,R3,A0,A1,SB,FB REIT ; Return from interrup``` 也可以去掉对rt_thread_switch_interrput_flag标志的判断语句,可简化为: ```os_context_switch: PUSHM R0,R1,R2,R3,A0,A1,SB,FB MOV.W rt_interrupt_from_thread, A0 STC ISP, [A0] MOV.W rt_interrupt_to_thread, A0 LDC [A0], ISP POPM R0,R1,R2,R3,A0,A1,SB,FB REIT ; Return from interrup``` 现在回头看任务级的上下文切换函数rt_hw_context_switch(), ```rt_hw_context_switch MOV.W R0, rt_interrupt_from_thread MOV.W R1, rt_interrupt_to_thread INT #0 RTS ``` 貌似比以前简洁很多,效率也提高了一点 但其实存在很严重的问题,问题就出在参数传递过程中,代码里默认为R0是参数1,R1是参数2 殊不知,M16C IAR编译器函数参数并非是如此传递的,在IAR的文档《IAR C/C++ Compiler Reference Guide》第97页有这样的说明: The normal calling convention The registers A0,R0, and R2 are used as much as possible to pass paramenters. The simple calling convention Only the first paramater may be passed in a register, either in R0L, R0, or R2R0, depending on the size of the first parameter. 由此可见不同的calling convention,函数参数使用的寄存器也是不一样的,有的还需要压栈 我想到的解决方法是:用C语言来实现任务级的上下文切换函数rt_hw_context_switch() ```void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to) { rt_interrupt_from_thread = from; rt_interrupt_to_thread = to; asm("INT #0"); }``` 同样道理,也应该用C语言来实现函数rt_hw_context_switch_interrupt() ```void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to) { if (rt_thread_switch_interrput_flag != 1) { rt_thread_switch_interrput_flag = 1; rt_interrupt_from_thread = from; } rt_interrupt_to_thread = to; }``` 如此一来,任何一种calling convention(normal/simple)或者任一优化级别(none, low, medium, high),都可以正确的执行上下文切换。
查看更多
2
个回答
默认排序
按发布时间排序
lgnq
2011-09-06
这家伙很懒,什么也没写!
有一处拼写错误 [s:179] rt_thread_switch_interrput_flag -> rt_thread_switch_interrupt_flag
撰写答案
登录
注册新账号
关注者
0
被浏览
3.3k
关于作者
lgnq
这家伙很懒,什么也没写!
提问
28
回答
57
被采纳
1
关注TA
发私信
相关问题
1
有关动态模块加载的一篇论文
2
最近的调程序总结
3
晕掉了,这么久都不见layer2的踪影啊
4
继续K9ii的历程
5
[GUI相关] FreeType 2
6
[GUI相关]嵌入式系统中文输入法的设计
7
20081101 RT-Thread开发者聚会总结
8
嵌入式系统基础
9
linux2.4.19在at91rm9200 上的寄存器设置
10
[转]基于嵌入式Linux的通用触摸屏校准程序
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RT-Thread 屏蔽在线软件包的方法
2
RT-Thread OS应用开发实战线上师资培训通知
3
【ci】【github】【bsp】RT-Thread仓库的CI自动编译测试
4
免费解锁MCU超能力!4月AIoT实战培训三城巡演
5
rt-thread主仓 BSP瘦身指南
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
cubemx
ESP8266
WIZnet_W5500
UART
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
GD32
定时器
ADC
flashDB
编译报错
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
Debug
SFUD
msh
ulog
C++_cpp
at_device
本月问答贡献
RTT_逍遥
4
个答案
2
次被采纳
聚散无由
4
个答案
2
次被采纳
踩姑娘的小蘑菇
5
个答案
1
次被采纳
a1012112796
4
个答案
1
次被采纳
winfeng
2
个答案
1
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
6
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部