1. 问题:
在使用劳得巴赫调试TC397过程中,发现劳得巴赫break后,再次运行,task中的计数器不再增加,OS不再调度,并且会进入ERROR hook,error类型为OS_LIMITED
2. 排查
2.1 ErrorHook中的Error=4,错误类型是E_OS_LIMIT,原因:激活次数过大
2.2 造成激活次数过多的原因:
——激活task时机:
- 直接激活:调用ActivaTask()或者ChainTask();
- 间接激活:ALARM激活或者ScheduleTable激活;
每个ScheduleTable的counter使用的是STM的counter,如果STM的counter一直在增加,会导致ScheduleTable多次激活task。
2.3 查看STM counter,一直在变化
所以需要在劳德巴赫暂停时,STM的counter也暂停。
3. 解决
3.1 当核被暂停时,TriCore允许暂停外设。
3.2 调试器暂停时,STM模块暂停
寄存器STM0_OCS支持挂起STM counter,使用劳德巴赫修改STM0_OCS寄存器,STM0_TIM0计数器不再增加。同样操作,修改其他的STMOCS寄存器,暂停后重新运行程序,不会再进入ErrorHook;
4. 完善
4.1 使用cmm脚本修改STMx_OCS:
参考劳德巴赫提供的手册中:
实现如下:
缺点:每次DEBUG RESET后,寄存器恢复默认值;需要再次加载cmm脚本;
优点:只有在需要调试器会设置OCS寄存器,不接调试器不需要设置;
4.2 修改代码
注意!OCS相关寄存器只能在OCDS enable时才可以写入!否则会进TRAP。
实现如下:
/** \brief 80, OSCUStatus Register */
#define CBS_OSTATE /*lint --e(923, 9078)*/ (*(volatile Ifx_CBS_OSTATE*)0xF0000480u)/** \brief E8, OCDS Control and Status Register */
#define STM0_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00010E8u)/** \brief E8, OCDS Control and Status Register */
#define STM1_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00011E8u)/** \brief E8, OCDS Control and Status Register */
#define STM2_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00012E8u)/** \brief E8, OCDS Control and Status Register */
#define STM3_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00013E8u)/** \brief E8, OCDS Control and Status Register */
#define STM4_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00014E8u)/** \brief E8, OCDS Control and Status Register */
#define STM5_OCS /*lint --e(923, 9078)*/ (*(volatile Ifx_STM_OCS*)0xF00015E8u)if(CBS_OSTATE.B.OEN == 1u)
{
Ifx_STM_OCS ocs;
ocs = STM0_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM0_OCS = ocs;
STM0_OCS.B.SUS_P = 0u;ocs = STM1_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM1_OCS = ocs;
STM1_OCS.B.SUS_P = 0u;ocs = STM2_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM2_OCS = ocs;
STM2_OCS.B.SUS_P = 0u;ocs = STM3_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM3_OCS = ocs;
STM3_OCS.B.SUS_P = 0u;ocs = STM4_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM4_OCS = ocs;
STM4_OCS.B.SUS_P = 0u;ocs = STM5_OCS;
ocs.B.SUS_P = 1u;
ocs.B.SUS = 2u;
STM5_OCS = ocs;
STM5_OCS.B.SUS_P = 0u;
}