首先设置PCC模块


重点是上述PCS寄存器选择SPLL时钟源;
PCD寄存器选择100b - Divide by 5;

可以使用EB来配置PCC模块
LPTMR寄存器配置
寄存器地址0x40040000
LPTMR寄存器配置如下图:

周期时间计算
SPLL2时钟频率是 40M
经过两次分频 寄存器PCD (5)和 PSR(128) 调节后的频率: 40M/5/128 = 62500
所以时间每过10ms, LPTMR的计时值增加 625;
LPTMR初始化和获取定时器值
#define LPTMR_CNR_COUNTER(x) (((uint32)(((uint32)(x))<<0u))&(0xFFFFu))
#define LPTMR_CSR *((volatile unsigned int *)0x40040000u)
#define LPTMR_PSR *((volatile unsigned int *)0x40040004u)
#define LPTMR_CMR *((volatile unsigned int *)0x40040008u)
#define LPTMR_CNR *((volatile unsigned int *)0x4004000Cu)
static uint16 s_usCnr;
void BswTest_Lptmr_Init(void)
{
LPTMR_CSR = (uint32)0x0;
LPTMR_PSR = (uint32)0x33;
LPTMR_CMR = (uint32)0xFFFF;
LPTMR_CSR = (uint32)0x1;
}
uint16 BswTest_Lptmr_GetCounterValue(void)
{
/* Write dummy value before reading register */
LPTMR_CNR = LPTMR_CNR_COUNTER(0u);
s_usCnr = (uint16)LPTMR_CNR;
return s_usCnr;
}
测试OS模块的结构体
typedef struct
{
boolean Ord_Flag; // Flag of task Execution Order
uint8 Order; // Task Execution Order
uint32 Counter; // Task Execution Counter
uint32 Start_tick;
uint32 Stop_tick;
uint32 PreStart_tick;
uint32 Current_Period;
uint32 Max_Period;
uint32 Min_Period;
uint32 Average_Period;
uint64 Sum_Period;
uint32 Current_Execution;
uint32 Max_Execution;
uint32 Min_Execution;
uint32 Average_Execution;
uint64 Sum_Execution;
}BT_TASK_INFO_ST;
测试OS模块执行时间和周期的函数
static void BswTest_OS_Timer_Calculate(const uint8 taskIndex)
{
if(s_stBswTestPara[taskIndex].Counter >=TASK_RUN_NORMAL)
{
//Current_Period
if(s_stBswTestPara[taskIndex].PreStart_tick)
{
if(s_stBswTestPara[taskIndex].Start_tick >= s_stBswTestPara[taskIndex].PreStart_tick)
{
s_stBswTestPara[taskIndex].Current_Period =s_stBswTestPara[taskIndex].Start_tick
- s_stBswTestPara[taskIndex].PreStart_tick;
}
else
{
s_stBswTestPara[taskIndex].Current_Period =s_stBswTestPara[taskIndex].Start_tick
+ (TIMER2_OVER_FLOW_VAL - s_stBswTestPara[taskIndex].PreStart_tick);
}
}
//Sum_Period
s_stBswTestPara[taskIndex].Sum_Period += s_stBswTestPara[taskIndex].Current_Period;
//Average_Period
if(s_stBswTestPara[taskIndex].Counter-TASK_RUN_NORMAL)
{
s_stBswTestPara[taskIndex].Average_Period = s_stBswTestPara[taskIndex].Sum_Period
/(s_stBswTestPara[taskIndex].Counter-TASK_RUN_NORMAL);
}
//Current_Execution
if(s_stBswTestPara[taskIndex].Stop_tick >= s_stBswTestPara[taskIndex].Start_tick)
{
s_stBswTestPara[taskIndex].Current_Execution =s_stBswTestPara[taskIndex].Stop_tick
- s_stBswTestPara[taskIndex].Start_tick;
}
else
{
s_stBswTestPara[taskIndex].Current_Execution =s_stBswTestPara[taskIndex].Stop_tick
+ (TIMER2_OVER_FLOW_VAL - s_stBswTestPara[taskIndex].Start_tick);
}
//Sum_Execution
s_stBswTestPara[taskIndex].Sum_Execution += s_stBswTestPara[taskIndex].Current_Execution;
//Average_Execution
if(s_stBswTestPara[taskIndex].Counter-TASK_RUN_NORMAL)
{
s_stBswTestPara[taskIndex].Average_Execution = s_stBswTestPara[taskIndex].Sum_Execution
/(s_stBswTestPara[taskIndex].Counter -TASK_RUN_NORMAL + 1u);
}
else
{
s_stBswTestPara[taskIndex].Average_Execution = s_stBswTestPara[taskIndex].Current_Execution;
}
//Max_Period
if(s_stBswTestPara[taskIndex].Current_Period > s_stBswTestPara[taskIndex].Max_Period)
{
s_stBswTestPara[taskIndex].Max_Period = s_stBswTestPara[taskIndex].Current_Period;
}
//Max_Execution
if(s_stBswTestPara[taskIndex].Current_Execution > s_stBswTestPara[taskIndex].Max_Execution)
{
s_stBswTestPara[taskIndex].Max_Execution = s_stBswTestPara[taskIndex].Current_Execution;
}
//Min_Period
if((s_stBswTestPara[taskIndex].Current_Period < s_stBswTestPara[taskIndex].Min_Period)||
(s_stBswTestPara[taskIndex].Min_Period == 0u))
{
s_stBswTestPara[taskIndex].Min_Period = s_stBswTestPara[taskIndex].Current_Period;
}
//Min_Execution
if((s_stBswTestPara[taskIndex].Current_Execution < s_stBswTestPara[taskIndex].Min_Execution)||
(s_stBswTestPara[taskIndex].Min_Execution == 0u))
{
s_stBswTestPara[taskIndex].Min_Execution = s_stBswTestPara[taskIndex].Current_Execution;
}
//PreStart_tick
s_stBswTestPara[taskIndex].PreStart_tick = s_stBswTestPara[taskIndex].Start_tick;
}
}
测试过程和结果
1、注释掉看门狗功能
2、注释掉ECC初始化相关代码
3、利用DavinciCFG工具,将所有的OS Application设置为特权模式,避免MPU功能执行报错;
结果:

结果见 IAR调试工具窗口 Watch1;
7041

被折叠的 条评论
为什么被折叠?



