本文主要是介绍[AutoSar]状态管理(四)单核BswM(二)流程、配置、 代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 关键词
- 平台说明
- 一、BswM的模式处理流程图
- 二、stand state handling
- 三、配置、代码、状态转移
- 3.1 initial -> wakeup
- 3.2 WakeUp -> Run
- 3.3 Run -> PostRun (first step)
- 3.4 Run -> PostRun (second step)
- 3.5 PostRun -> PreShutdown(first step)
- 3.6 PostRun -> PreShutdown(second step)
- 3.7 PostRun -> PreShutdown(third step)
- 3.8 PREP_SHUTDOWN-> WAIT_FOR_NVM
- 3.9 WAIT_FOR_NVM -> SHUTDOWN
- 3.10 WakeUp -> Run
- 3.11 WakeUp -> preshutdown
关键词
嵌入式、C语言、autosar、BswM
平台说明
项目 | Value |
---|---|
OS | autosar OS |
autosar厂商 | vector |
芯片厂商 | TI |
编程语言 | C,C++ |
编译器 | HighTec (GCC) |
一、BswM的模式处理流程图
蓝色箭头为SWC的上层交互,红色箭头为Bsw内部模块间的交互。
二、stand state handling
三、配置、代码、状态转移
3.1 initial -> wakeup
EcuM 初始化完毕后开始BswM初始化并调度mainfunction执行状态机。
rules:ESH_InitToWakeup
Expression:ESH_LE_InitToWakeup
Code:1.判定当前模式处于Init
if(BswM_GetGenericState(3, 0u) == BSWM_GENERICVALUE_ESH_State_ESH_INIT){/* Return conditional action list BswM_ActionList_ESH_AL_InitToWakeup. */retVal = BSWM_ID_AL_ESH_AL_InitToWakeup;}
Action list:
ESH_AL_InitToWakeup
{
ESH_Action_OnEnterWakeup
ESH_Action_SwitchWakeup
ESH_Action_ESH_Wakeup
}
Code: 1.请求模式切换到Wakeup。
BSWM_LOCAL FUNC(Std_ReturnType, BSWM_CODE) BswM_ActionList_ESH_AL_InitToWakeup(BswM_PCPartitionConfigIdxOfPartitionIdentifiersType partitionIdx)
{BswM_ESH_OnEnterWakeup();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_WAKEUP;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_WAKEUP);BSWM_DUMMY_STATEMENT(partitionIdx); /* PRQA S 1338, 2983, 3112 */ /* MD_MSR_DummyStmt */return E_OK;
}/* PRQA S 6010, 6030, 6050 */ /* MD_MSR_STPTH, MD_MSR_STCYC, MD_MSR_STCAL */
3.2 WakeUp -> Run
rules:ESH_WakeupToRun
Expression:ESH_LE_WakeupToRun
Code:
1.判定当前状态是否为wakeup;
2.判定是否有唤醒事件;
3.判定ComM request 是否为pending且上一次目标模式通知是否为wakeup。
if((BswM_GetGenericState(3, 0u) == BSWM_GENERICVALUE_ESH_State_ESH_WAKEUP) && ((EcuM_GetValidatedWakeupEvents() != 0u) || (BswM_GetGenericState(0, 0u) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_PENDING_REQUEST)) && ((BswM_GetNvMJobState(0, 0u) != NVM_REQ_PENDING) || (BswM_GetTimerState(0, 0u) != BSWM_TIMER_STARTED)) && (BswM_Mode_Notification_ESH_ModeNotification_BswM_MDGP_ESH_Mode == RTE_MODE_ESH_Mode_WAKEUP)){/* Return conditional action list BswM_ActionList_ESH_AL_WakeupToRun. */retVal = BSWM_ID_AL_ESH_AL_WakeupToRun;}
Action list:
1.在 ComM request pending 状态下允许通信;
2.更新BswM 计时器;
3.request 到 RUN 状态;
ESH_AL_WakeupToRun
{
ESH_Action_ComMAllow_CN_xxxxx
ESH_Action_SelfRunRequestTimer_Start
ESH_Action_OnEnterRun
ESH_Action_SwitchRun
ESH_Action_ESH_Run
}
Code:1.用户自定义实现代码
ComM_CommunicationAllowed(ComMConf_ComMChannel_CN_, TRUE);BswM_UpdateTimer(partitionIdx, BSWM_TMR_ESH_SelfRunRequestTimer, 10u);BswM_ESH_OnEnterRun();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_RUN;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_RUN);
3.3 Run -> PostRun (first step)
rules:ESH_RunToPostRun
Expression:ESH_LE_RunToPostRunTransition
Code:1.判定当前模式是否在RUN且上一次 request 为run;
2.判定ComM是否为NO_COMMUNICATION;
3.SWC没有模式请求;
4.判定BswM转换计时器超时(在mainfunction中调用BswM_DecreaseTimer(partitionIdx)–和转状态转换时update;);
if(((BswM_GetGenericState(1, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_State_ESH_RUN) && (BswM_Mode_Notification_ESH_ModeNotification_BswM_MDGP_ESH_Mode == RTE_MODE_ESH_Mode_RUN)) && (((BswM_GetComMChannelState(0, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == COMM_NO_COMMUNICATION) && (BswM_GetComMChannelState(4, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == COMM_NO_COMMUNICATION) && (BswM_GetComMChannelState(1, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == COMM_NO_COMMUNICATION) && (BswM_GetComMChannelState(3, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == COMM_NO_COMMUNICATION) && (BswM_GetComMChannelState(2, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == COMM_NO_COMMUNICATION)) && ((Request_ESH_RunRequest_0_requestedMode == RELEASED) && (Request_ESH_RunRequest_1_requestedMode == RELEASED)) && (BswM_GetTimerState(0, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_TIMER_EXPIRED))){/* Return conditional action list BswM_ActionList_ESH_AL_ExitRun. */retVal = BSWM_ID_AL_ESH_AL_ExitRun;}
**Action list:**1.进入ESH_RunToPostRunNested rules;
ESH_AL_ExitRun
{
ESH_Action_EnterExclusiveArea
ESH_RunToPostRunNested
ESH_Action_ComMCheckPendingRequests
ESH_Action_ExitExclusiveArea
}
Code:
SchM_Enter_BswM_BSWM_EXCLUSIVE_AREA_0();/*lint -restore */ESH_ComM_CheckPendingRequests();(void)BswM_Action_RuleHandler(BSWM_ID_RULE_ESH_RunToPostRunNested, partitionIdx);/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */SchM_Exit_BswM_BSWM_EXCLUSIVE_AREA_0();/*lint -restore */BSWM_DUMMY_STATEMENT(partitionIdx); /* PRQA S 1338, 2983, 3112 */ /* MD_MSR_DummyStmt */
3.4 Run -> PostRun (second step)
rules:ESH_RunToPostRunNested
Expression:ESH_LE_ComMNoPendingRequests
Code:1.判定当前ComM pending是否有请求。
if(BswM_GetGenericState(0, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_NO_REQUEST){/* Return conditional action list BswM_ActionList_ESH_AL_RunToPostRun. */retVal = BSWM_ID_AL_ESH_AL_RunToPostRun;}
Action list:
ESH_AL_RunToPostRun
{
ESH_Action_ComMDisallow_CN_XXX
ESH_Action_EcuMClearValidatedWakeupEvents
ESH_Action_OnEnterPostRun
ESH_Action_SwitchPostRun
ESH_Action_ESH_PostRun
}
Code:
1.禁止ComM通信;
2.清除唤醒事件;
3.请求模式转换到POSTRUN;
ComM_CommunicationAllowed(ComMConf_ComMChannel_CN_, FALSE);/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */EcuM_ClearValidatedWakeupEvent(ECUM_WKSOURCE_ALL_SOURCES);/*lint -restore */BswM_ESH_OnEnterPostRun();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_POSTRUN;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_POST_RUN);
3.5 PostRun -> PreShutdown(first step)
rules:ESH_PostRun
Expression:ESH_LE_PostRun
Code:1.判定当前模式是否为POSTRUN且上一次请求通知为POSTRUN;
if((Request_ESH_PostRunRequest_0_requestedMode == RELEASED) && (Request_ESH_PostRunRequest_1_requestedMode == RELEASED)){/* Return conditional action list BswM_ActionList_ESH_AL_PostRunToPrepShutdown. */retVal = BSWM_ID_AL_ESH_AL_PostRunToPrepShutdown;}
Action list:
ESH_AL_ExitPostRun
{
ESH_Action_EnterExclusiveArea
ESH_Action_ComMCheckPendingRequests
ESH_PostRunNested
ESH_Action_ExitExclusiveArea
}
Code:1.根据ComM状态是否为COMM_NO_COM_NO_PENDING_REQUEST 设置BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_PENDING_REQUEST还是BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_NO_REQUEST;
2.进入ruler ESH_PostRunNested;
SchM_Enter_BswM_BSWM_EXCLUSIVE_AREA_0();/*lint -restore */ESH_ComM_CheckPendingRequests();(void)BswM_Action_RuleHandler(BSWM_ID_RULE_ESH_PostRunNested, partitionIdx);/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */SchM_Exit_BswM_BSWM_EXCLUSIVE_AREA_0();
3.6 PostRun -> PreShutdown(second step)
这里为中间态,判定是回到RUN还是到preShutdown。
rules:ESH_PostRunNested
Expression:ESH_LE_PostRunToRun
Code:
1.判定SWC是否有模式请求;
2.判定是否有唤醒事件;
3.判定ComM 请求是否为 pengding;
/* Evaluate logical expression ESH_LE_PostRunToRun. */if(((Request_ESH_RunRequest_0_requestedMode == REQUESTED) || (Request_ESH_RunRequest_1_requestedMode == REQUESTED)) || ((EcuM_GetValidatedWakeupEvents() != 0u) || (BswM_GetGenericState(0, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_PENDING_REQUEST))){/* Return conditional action list BswM_ActionList_ESH_AL_PostRunToRun. */retVal = BSWM_ID_AL_ESH_AL_PostRunToRun;}else{/* Return conditional action list BswM_ActionList_ESH_AL_ESH_PostRunToPrepCheck. */retVal = BSWM_ID_AL_ESH_AL_ESH_PostRunToPrepCheck;}
Action list:
如果仲裁为TRUE;执行actionlist:ESH_AL_PostRunToRun;
如果仲裁为FALSE;执行rules:ESH_AL_ESH_PostRunToPrepCheck;
ESH_AL_PostRunToRun
{
ESH_Action_ComMAllow_CN_XXXXX
ESH_Action_SelfRunRequestTimer_Start
ESH_Action_OnEnterRun
ESH_Action_SwitchRun
}
Code:
1.允许Com通信;
2.更新BswM状态转换计时器;
3.请求转换到RUN ;
ComM_CommunicationAllowed(ComMConf_ComMChannel_CN_xxx, TRUE);BswM_UpdateTimer(partitionIdx, BSWM_TMR_ESH_SelfRunRequestTimer, 10u);BswM_ESH_OnEnterRun();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_RUN;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_RUN);
3.7 PostRun -> PreShutdown(third step)
rules:ESH_PostRunToPrepNested
Expression:ESH_LE_Dem_PostRunRequested
Code:1.判定当前是否有SWC模式请求;
/* Evaluate logical expression ESH_LE_Dem_PostRunRequested. */if((Request_ESH_PostRunRequest_0_requestedMode == RELEASED) && (Request_ESH_PostRunRequest_1_requestedMode == RELEASED)){/* Return conditional action list BswM_ActionList_ESH_AL_PostRunToPrepShutdown. */retVal = BSWM_ID_AL_ESH_AL_PostRunToPrepShutdown;}
Action list:
ESH_AL_PostRunToPrepShutdown
{
ESH_Action_OnEnterPrepShutdown
ESH_Action_SwitchShutdown
ESH_Action_ESH_PrepShutdown
}
Code:
1.请求进入preShutDown
BswM_ESH_OnEnterPrepShutdown();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_SHUTDOWN;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_PREP_SHUTDOWN);
3.8 PREP_SHUTDOWN-> WAIT_FOR_NVM
rules:ESH_PrepToWait
Expression:ESH_LE_PrepShutdownToWaitForNvM
Code:1.判定当前模式处于PRE_SHUTDOWN且上一次请求通知为SHUTDOWN;
if((BswM_GetGenericState(1, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_State_ESH_PREP_SHUTDOWN) && (BswM_Mode_Notification_ESH_ModeNotification_BswM_MDGP_ESH_Mode == RTE_MODE_ESH_Mode_SHUTDOWN)){/* Return conditional action list BswM_ActionList_ESH_AL_PrepShutdownToWaitForNvM. */retVal = BSWM_ID_AL_ESH_AL_PrepShutdownToWaitForNvM;}
Action list:
ESH_AL_PrepShutdownToWaitForNvM
{
ESH_Action_WriteAllTimer_Start
ESH_Action_NvMWriteAll
ESH_Action_ComMCheckPendingRequests
ESH_Action_OnEnterWaitForNvm
ESH_Action_ESH_WaitForNvm
}
Code:
1.设定NVM写超时计时器;
2.writeall;
3.根据ComM状态是否为COMM_NO_COM_NO_PENDING_REQUEST 设置BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_PENDING_REQUEST还是BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_NO_REQUEST;
4.NVM实现;
5.请求切换到ESH_WAIT_FOR_NVM
BswM_UpdateTimer(partitionIdx, BSWM_TMR_ESH_NvM_WriteAllTimer, 6000u);/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */NvM_WriteAll();/*lint -restore */ESH_ComM_CheckPendingRequests();BswM_ESH_OnEnterWaitForNvm();BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_WAIT_FOR_NVM);
3.9 WAIT_FOR_NVM -> SHUTDOWN
rules:ESH_WaitToShutdown
Expression:ESH_LE_WaitForNvMToShutdown
Code:1.判定当前状态是否为WAIT_FOR_NVM;
2.判定是否完成NVMwriteall;
3.判定是否有唤醒事件;
4.ComM是否有request;
/* Evaluate logical expression ESH_LE_WaitForNvMToShutdown. */ /* PRQA S 3415 1 */ /* MD_BSWM_3415 */if((BswM_GetGenericState(3, 0u) == BSWM_GENERICVALUE_ESH_State_ESH_WAIT_FOR_NVM) && ((BswM_GetNvMJobState(0, 0u) != NVM_REQ_PENDING) || (BswM_GetTimerState(1, 0u) != BSWM_TIMER_STARTED)) && ((EcuM_GetValidatedWakeupEvents() == 0u) && (BswM_GetGenericState(0, 0u) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_NO_REQUEST))){/* Return conditional action list BswM_ActionList_ESH_AL_WaitForNvMToShutdown. */retVal = BSWM_ID_AL_ESH_AL_WaitForNvMToShutdown;}
Action list:
ESH_AL_WaitForNvMToShutdown
{
ESH_Action_WriteAllTimer_Stop
ESH_Action_OnEnterShutdown
ESH_Action_EcuMGoToSelectedShutdownTarget
}
Code:
1.关闭NVM计时器;
2.请求到Shutdown状态;
3.用户自定义代码实现;
BswM_ESH_OnEnterShutdown();/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */(void)EcuM_GoToSelectedShutdownTarget();
3.10 WakeUp -> Run
rules:ESH_WaitToWakeup
Expression:ESH_LE_WaitForNvMToWakeup
Code:
1.判定当前模式是否在WAIT_FOR_NVM
2.是否有唤醒事件;
3.ComM是否为PENDING;
if((BswM_GetGenericState(1, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_State_ESH_WAIT_FOR_NVM) && ((EcuM_GetValidatedWakeupEvents() != 0u) || (BswM_GetGenericState(0, BswM_GetInternalPartitionIdx(SystemApplication_OsCore3)) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_PENDING_REQUEST))){/* Return conditional action list BswM_ActionList_ESH_AL_WaitForNvMWakeup. */retVal = BSWM_ID_AL_ESH_AL_WaitForNvMWakeup;}
Action list:
ESH_AL_WaitForNvMWakeup
{
ESH_Action_WriteAllTimer_Stop
ESH_Action_CancelWriteAllTimer_Start
ESH_Action_CancelNvMWriteAll
ESH_Action_OnEnterWakeup
ESH_Action_SwitchWakeup
ESH_Action_ESH_Wakeup.
}
Code:
1.更新NVM计时器防止超时;
2.取消writeall;
3.请求跳转到wakeup;
BswM_UpdateTimer(partitionIdx, BSWM_TMR_ESH_NvM_WriteAllTimer, 0u);BswM_UpdateTimer(partitionIdx, BSWM_TMR_ESH_NvM_CancelWriteAllTimer, 6000u);/*lint -save -e534 *//* PRQA S 3109, 3200 1 */ /* MD_MSR_14.3, MD_BSWM_3200 */NvM_CancelWriteAll();/*lint -restore */BswM_ESH_OnEnterWakeup();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_WAKEUP;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_WAKEUP);
3.11 WakeUp -> preshutdown
rules:ESH_WakeupToPrep
Expression:ESH_LE_WakeupToPrepShutdown
Code:
1.判定当前是否处于wankeup;
2.判定是否在执行writeAll;
3.判定cancel wariteAll是否超时;
4.是否有唤醒事件;
5.ComM是否为NO_REQUEST;
6.上一次模式请求为wankeup?
if((BswM_GetGenericState(3, 0u) == BSWM_GENERICVALUE_ESH_State_ESH_WAKEUP) && ((BswM_GetNvMJobState(0, 0u) != NVM_REQ_PENDING) || (BswM_GetTimerState(0, 0u) != BSWM_TIMER_STARTED)) && (EcuM_GetPendingWakeupEvents() == 0u) && ((EcuM_GetValidatedWakeupEvents() == 0u) && (BswM_GetGenericState(0, 0u) == BSWM_GENERICVALUE_ESH_ComMPendingRequests_ESH_COMM_NO_REQUEST)) && (BswM_Mode_Notification_ESH_ModeNotification_BswM_MDGP_ESH_Mode == RTE_MODE_ESH_Mode_WAKEUP)){/* Return conditional action list BswM_ActionList_ESH_AL_WakeupToPrep. */retVal = BSWM_ID_AL_ESH_AL_WakeupToPrep;}
Action list:
ESH_AL_WakeupToPrep
{
ESH_Action_OnEnterPrepShutdown
ESH_Action_SwitchShutdown
ESH_Action_ESH_PrepShutdown
}
Code:
1.切换模式到shutdown
用户代码自定义实现下电的相关操作。
BswM_ESH_OnEnterPrepShutdown();BswM_Switch_ESH_ModeSwitch_BswM_MDGP_ESH_Mode = RTE_MODE_ESH_Mode_SHUTDOWN;BswM_RequestMode(BSWM_GENERIC_ESH_State, BSWM_GENERICVALUE_ESH_State_ESH_PREP_SHUTDOWN);
这篇关于[AutoSar]状态管理(四)单核BswM(二)流程、配置、 代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!