高级会员

- 积分
- 907
- 金钱
- 907
- 注册时间
- 2011-10-19
- 在线时间
- 196 小时
|

楼主 |
发表于 2021-1-1 13:04:50
|
显示全部楼层
本帖最后由 ufbycd 于 2021-1-1 16:08 编辑
更新:添加Module的中断服务处理
Module的中断处理函数的进入
为了在Module内灵活使用(APP未占用的)外设资源,需要处理Module的中断服务。而Module的中断向量表并不是芯片的入口而由APP调用,那么就需要从APP的中断向量表跳转到Module的中断向量表。
在APP的中断向量表内,未使用的中断服务其实都是Default_Handler的别名(并且都是弱(weak)符号)。而APP未使用的中断有可能会被Module使用;所以只要修改APP的Default_Handler,使其跳转到Module那边就行了。本项目的APP的Default_Handler实现如下:
- void __attribute__ ((weak)) Default_Handler(void)
- {
- typedef void (* IrqHandler_t)(void);
- extern unsigned int _eflash; // 来自链接脚本,指向Flash末尾
- uint32_t isrNum;
- IrqHandler_t *moduleIsrVector;
- IrqHandler_t handler;
- if(Main_IsModuleLoaded())
- {
- moduleIsrVector = (IrqHandler_t *) & _eflash;
- isrNum = __get_IPSR();
- handler = moduleIsrVector[isrNum];
- handler();
- }
- else
- {
- __DEBUG_BKPT();
- while(1);
- }
- }
复制代码- 其中_eflash定义于链接脚本,其值指向APP的Flash空间的末尾即Module的Flash的起始亦即Module的中断向量表。
- Default_Handler的主要工作为:当Module已经载入时,获取当前的中断号并直接跳转到Module的中断服务函数;当Module未载入时,则进行常规处理,进入死循环。
目前测试了在Module使用硬件定时器6,中断频率为10Hz、每计时2秒打印一条信息,运行时的调试串口输出如下:- MStdio Init
- Software Reset
- APP:
- Version: 5d31203-202101011115
- Build : 2021-01-01 11:15:34
- Config : Debug
- shell>Static module loading...
- Module:
- Version: 5d31203-202101011106
- Build : 2021-01-01 11:06:11
- Config : Debug
- .data test: 123
- Module: Stimer Tick: 20
- Module: Stimer Tick: 40
- Module: Stimer Tick: 60
复制代码
|
|