Autosar平台集成测试测试OS的执行周期和执行时间

首先设置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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值