跳转至

AUTOSAR ECU 电源状态管理:启动、下电、唤醒与复位流程

1. 简介和功能概述

本文档整理AUTOSAR Classic Platform标准中ECU电源状态管理的核心流程,包括STARTUP(启动)、SHUTDOWN(下电)、SLEEP/WAKEUP(睡眠与唤醒)以及RESET(复位)的标准处理流程,并收集规范中的时序图(Sequence Diagram)作为设计参考。

ECU管理器模块(ECU Manager,EcuM)是管理ECU状态的基础软件模块,负责:

  • 初始化和去初始化OS、SchM和BswM以及一些基础软件驱动模块。
  • 将ECU配置为SLEEP和SHUTDOWN状态。
  • 管理ECU上的所有唤醒事件(wakeup events),并提供唤醒验证协议(Wakeup validation protocol)以区分真实(real)和不稳定(erratic)的唤醒事件。
  • 提供部分或快速启动(Partial or fast startup)与交错启动(Interleaved startup)机制。
  • 支持多核ECU:启动、关机、睡眠和唤醒能在ECU的所有内核上进行协调。

在灵活的ECU管理(Flexible ECU Management)架构下,大多数ECU状态由BSW模式管理器(BswM)通过可配置的规则(rules)和动作列表(action lists)实现,EcuM仅在以下场景接管控制:

  • 早期启动阶段(Early STARTUP phases)。
  • 后期关闭阶段(Late SHUTDOWN phases)。
  • 调度程序锁定睡眠阶段(SLEEP phases locked out by the scheduler)。

2. 定义和缩写

Callout

Callout是指系统设计人员使用代码替换的一种Stub函数,通常在配置时为ECU管理器模块提供附件功能,分为强制性和可选性两类。

Phase(阶段)

和ECU管理器的动作及事件相关的逻辑或时间组合,例如:STARTUP、UP、SHUTDOWN、SLEEP、OFF。阶段可以由通常称为序列(Sequence)的子阶段组成。

Shutdown Target(下电目标)

ECU在进入睡眠、关闭电源或复位之前必须被关闭。SLEEP、OFF和RESET是有效的下电目标。应用程序通过选择下电目标,将其对ECU下次关闭后行为的期望传达给ECU管理器模块。

Wakeup Event / Wakeup Source / Wakeup Reason

Wakeup Event(唤醒事件)是导致唤醒的物理事件(如CAN消息或IO跳变);Wakeup Source(唤醒源)是处理唤醒事件的外围设备或ECU组件;Wakeup Reason(唤醒原因)是上次唤醒的实际原因。

Passive Wakeup(被动唤醒)

由连接的总线(Attached bus)引起的唤醒,区别于定时器或传感器活动等内部事件引起的唤醒。

BswM

基础软件模式管理器(Basic Software Mode Manager)

SchM

基础软件调度器(BSW Scheduler)

RTE

运行时环境(Runtime Environment)

WdgM

看门狗管理器(Watchdog Manager)

Mcu

微控制器单元(Microcontroller Unit)

ComM

通信管理器(Communication Manager)

3. 相关文档

[1] Specification of ECU State Manager

AUTOSAR_SWS_ECUStateManager(Document ID 78, AUTOSAR CP R22-11)

[2] Guide to Mode Management

AUTOSAR_EXP_ModeManagementGuide(Document ID 440, AUTOSAR CP Release 4.4.0)

[3] Specification of Basic Software Mode Manager

AUTOSAR_SWS_BSWModeManager

[4] Specification of Operating System

AUTOSAR_SWS_OS

4. ECU 阶段总览

EcuM将ECU生命周期划分为五个阶段(Phase):STARTUP、UP、SHUTDOWN、SLEEP和OFF。图 4.1 显示了灵活的ECU管理器模块各阶段的概览及其转换关系。

Figure7-1.png

stateDiagram-v2
    direction TB
    [*] --> STARTUP
    state STARTUP {
        [*] --> StartPreOs
        StartPreOs --> StartPostOs : OS started
        StartPostOs --> [*]
    }
    STARTUP --> UP : BswM, Os and SchM initialized
    UP --> SLEEP
    SLEEP --> UP
    UP --> SHUTDOWN
    SHUTDOWN --> STARTUP : Reset if Shutdown Target is RESET
    state SHUTDOWN {
        [*] --> OffPreOs
        OffPreOs --> OffPostOs : SchM and BswM de-initialized; OS will be shutdown
        OffPostOs --> [*]
    }
    SHUTDOWN --> [*] : OFF
    state SLEEP {
        [*] --> GoSleep
        GoSleep --> Poll
        GoSleep --> Halt
        Poll --> WakeUpRestart
        Halt --> WakeUpRestart
        WakeUpRestart --> [*]
    }
    note right of UP : After Sleep the WakeupValidation is started if needed
    note right of GoSleep : WakeUpSources will be enabled
    note right of WakeUpRestart : WakeUpSources will be disabled

(转录自规范 Figure 7.1: Phases of the ECU Manager)

阅读说明:本文所有流程插图均保留规范原图,并在原图下方附上 Mermaid 矢量版本——两者内容一致。Mermaid 图为浏览器端渲染的矢量图,放大不失真;其源码随页面一同发布,可在浏览器中通过「查看网页源代码」检索与复制。

各阶段的职责如下:

阶段 职责描述
STARTUP 初始化基础软件模块到通用模式管理设施(Generic Mode Management facilities)可运行的程度:初始化低级驱动程序、启动操作系统、初始化BSW调度程序和BswM
UP BSW调度器已启动且BswM_Init已被调用。BswM负责模式仲裁及后续BSW初始化、启动RTE(隐式启动SW-C);EcuM对来自SW-C的RUN和POST_RUN请求进行仲裁
SHUTDOWN 受控关闭基础软件模块,最终到达选定的下电目标OFF或RESET
SLEEP ECU节省能量。通常不执行代码但仍有供电,可配置为可唤醒;提供可配置的硬件睡眠模式集合(功耗与重启时间的权衡)
OFF ECU下电。仅具有集成电源控制(integrated power control)的唤醒源可在此状态唤醒;任何情况下ECU必须可启动(如通过复位事件)

图 4.2 显示了ECU管理器模块与OS、BswM、RTE、驱动等周边模块的关系。该图为模块接口关系图,包含约 40 个接口的拓扑连接,结构复杂且以布局为主,不适合用时序图或状态图表达,故保留规范原图。

Figure7-2.png

5. Startup(启动)流程

5.1 启动流程总览

图 5.1 显示了ECU的启动行为。当通过EcuM_Init调用时,ECU管理器模块接管ECU启动流程;调用StartOS时ECU管理器暂时交出控制权,集成商(Integrator)必须实现一个自动启动的OS任务,其第一个动作调用EcuM_StartupTwo以重新获得控制权。

Figure7-3.png

sequenceDiagram
    participant BM as Boot Menu
    participant CIC as C Init Code
    participant OS as «module» Os
    participant TASK as BSW Task (OS task or cyclic call)
    participant ECUM as «module» EcuM
    note over BM: Reset
    BM->>BM: Reset Vector()
    activate CIC
    BM->>CIC: Jump()
    CIC->>CIC: Set up stack()
    CIC->>ECUM: EcuM_Init()
    activate ECUM
    rect rgb(245, 245, 245)
    note over ECUM: ref StartPreOS Sequence
    end
    ECUM->>OS: StartOS()
    activate OS
    OS->>OS: StartupHook()
    OS->>TASK: ActivateTask
    activate TASK
    TASK->>ECUM: EcuM_StartupTwo()
    rect rgb(245, 245, 245)
    note over ECUM: ref StartPostOS Sequence
    end
    deactivate TASK
    deactivate OS
    deactivate ECUM
    deactivate CIC

(转录自规范 Figure 7.3: STARTUP Phase)

注意:在EcuM_Init被调用之前,ECU管理器模块假定MCU已完成最小初始化(栈已建立、代码可执行、C变量初始化已完成)。

5.2 StartPreOS 序列

StartPreOS序列在EcuM_Init中执行,是操作系统启动前的初始化活动,标准顺序如下(表 5.1):

顺序 活动 说明 可选
1 Callout EcuM_AL_SetProgrammableInterrupts 在OS启动前设置可编程中断优先级 是
2 Callout EcuM_AL_DriverInitZero(Init block 0) 仅初始化不使用post-build配置参数的BSW模块,可包含任意pre-OS低级别初始化代码 是
3 Callout EcuM_DeterminePbConfiguration 返回包含EcuM及所有其他BSW模块post-build配置数据的EcuM_ConfigType结构指针 否
4 检查配置数据一致性 若检查失败调用EcuM_ErrorHook(ECUM_E_CONFIGURATION_DATA_INCONSISTENT)。EcuM在初始化第一个BSW模块前,不仅检查自身参数一致性,还检查所有post-build可配置BSW模块的一致性(通过配置工具计算的ECUM_CONFIGCONSISTENCY_HASH哈希值在运行时比对) 否
5 Callout EcuM_AL_DriverInitOne(Init block 1) 驱动初始化及任意pre-OS低级别初始化代码 是
6 获取复位原因 通过Mcu_GetResetReason获取,并经EcuMWakeupSource配置容器映射为唤醒源 否
7 选择默认下电目标 见[SWS_EcuM_02181] 否
8 Callout EcuM_LoopDetection 若启用环路检测,每次启动都会调用 是
9 启动OS(StartOS) 启动AUTOSAR OS,见[SWS_EcuM_02603] 否

图 5.2 显示了StartPreOS序列中EcuM、Mcu与集成代码的交互过程。

Figure7-4.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant MCU as «module» Mcu
    participant OS as «module» Os
    ECUM->>IC: EcuM_AL_DriverInitZero()
    note over IC: Init Block 0
    ECUM->>IC: EcuM_DeterminePbConfiguration(const EcuM_ConfigType*)
    activate ECUM
    ECUM->>ECUM: Check consistency of configuration data()
    opt Configuration data inconsistent
        ECUM->>IC: EcuM_ErrorHook(ECUM_E_CONFIGURATION_DATA_INCONSISTENT)
        note over IC: This call never returns!
    end
    deactivate ECUM
    ECUM->>IC: EcuM_AL_DriverInitOne()
    note over IC: Init Block 1
    ECUM->>MCU: Mcu_GetResetReason(Mcu_ResetType)
    ECUM->>ECUM: Map reset reason to wakeup source()
    ECUM->>ECUM: EcuM_SelectShutdownTarget(Std_ReturnType, EcuM_ShutdownTargetType, EcuM_ShutdownModeType)
    ECUM->>IC: EcuM_LoopDetection()
    ECUM->>OS: StartOS(ECUM_DEFAULT_APP_MODE)

(转录自规范 Figure 7.4: StartPreOS Sequence)

5.3 StartPostOS 序列

OS启动后,集成代码的任务调用EcuM_StartupTwo,EcuM继而执行StartPostOS序列(图 5.3):

  1. 调用SchM_Start启动BSW调度器;
  2. 调用BswM_Init初始化BSW模式管理器;
  3. 调用SchM_Init初始化BSW调度器(为BSW模块使用的临界区初始化信号量);
  4. 调用SchM_StartTiming启动SchM时序(启动BSW/SW-C的周期性事件)。

此后控制权移交BswM,ECU进入UP阶段。

Figure7-5.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant SCHM as «module» SchM
    participant BSWM as «module» BswM
    ECUM->>SCHM: SchM_Start(): Std_ReturnType
    ECUM->>BSWM: BswM_Init(const BswM_ConfigType *)
    ECUM->>SCHM: SchM_Init(const SchM_ConfigType*)
    ECUM->>SCHM: SchM_StartTiming(const SchM_ConfigType*)

(转录自规范 Figure 7.5: StartPostOS Sequence)

5.4 驱动初始化

驱动程序在初始化流程中的位置强烈依赖于其实现和目标硬件设计。驱动可被EcuM在STARTUP阶段的Init Block 0或Init Block 1中初始化,或在WakeupRestart序列的EcuM_AL_DriverRestart回调中重新初始化,也可由BswM在UP阶段初始化。

关键规则:

  • EcuM配置须指定Init block 0(EcuMDriverInitListZero)和Init block 1(EcuMDriverInitListOne)内的初始化调用顺序。
  • EcuM以从驱动EcuMModuleService配置容器派生的参数调用每个驱动的初始化函数。
  • 唤醒重启时,EcuMDriverRestartList中的驱动按Init block 0和Init block 1组合列表的相同顺序重新初始化;该列表可包含作为唤醒源的驱动,EcuM_AL_DriverRestart须重新布防(re-arm)这些驱动"wakeup detected"回调的触发机制。
  • DET的初始化有特殊要求:若至少有一个模块配置为跟踪开发错误,EcuM须在StartPreOS序列中、所有其他驱动之前初始化DET(调用Det_Init);但EcuM默认不启动DET(Det_Start的时机由系统设计者在EcuM_AL_DriverInitOne等回调中配置)。

5.5 BSW 初始化与 UP 阶段

其余BSW模块由BswM初始化:BswM使用EcuM的配置函数(EcuMDriverInitCalloutName)执行由EcuMDriverInitListBswM配置的初始化函数列表,配置须指定BSW初始化内的调用顺序。

进入UP阶段时,NvM的初始化和NvM_Readall的调用也成为集成代码——集成商负责在NvM_ReadAll结束时触发Com、DEM和FIM的初始化,NvM完成NvM_ReadAll时通知BswM。RTE可在NvM和COM初始化之后启动。

6. 下电(SHUTDOWN)流程

6.1 下电目标(Shutdown Targets)

下电目标是状态机离开UP阶段时到达的目标状态,共三种:OFF、SLEEP、RESET。由于BswM控制大多数ECU资源,由BswM决定何时设置下电目标(例如在调用EcuM_GoDownHaltPoll前将默认目标改为ECUM_STATE_SLEEP)。

复位的执行有多种模态(reset modalities),由不同模块控制或触发:

  • Mcu_PerformReset
  • WdgM_PerformReset
  • 通过DIO/SPI触发I/O引脚

EcuM通过跟踪历史复位的时间和原因来管理这些复位模态,各种复位模态被当作复位模式(reset modes),使用与睡眠相同的模式设施管理。

EcuM_GoDownHaltPoll(带下电目标RESET或OFF)启动SHUTDOWN阶段;带下电目标SLEEP则启动SLEEP阶段。

6.2 SHUTDOWN 阶段总览

图 6.1 显示了SHUTDOWN阶段的总体流程:BswM(或SW-C)调用EcuM_GoDownHaltPoll后,EcuM执行OffPreOS序列,OS关闭时调用关闭钩子(ShutdownHook),最终调用EcuM_Shutdown(该函数不返回,直接关闭ECU或触发复位)。

Figure7-7.png

sequenceDiagram
    participant BSWM as «module» BswM
    participant ECUM as «module» EcuM
    participant OS as «module» Os
    participant IC as Integration Code
    BSWM->>ECUM: EcuM_SelectShutdownTarget(Std_ReturnType, EcuM_ShutdownTargetType, EcuM_ShutdownModeType)
    BSWM->>ECUM: EcuM_GoDownHaltPoll(Std_ReturnType, EcuM_UserType)
    activate ECUM
    rect rgb(245, 245, 245)
    note over ECUM: ref OffPreOS Sequence
    end
    ECUM->>OS: ShutdownOS()
    activate OS
    OS->>IC: ShutdownHook()
    activate IC
    IC->>ECUM: EcuM_Shutdown()
    rect rgb(245, 245, 245)
    note over ECUM: ref OffPostOS Sequence
    end
    deactivate IC
    deactivate OS
    deactivate ECUM

(转录自规范 Figure 7.7: SHUTDOWN Phase)

6.3 OffPreOS 序列

OffPreOS序列在OS关闭前执行,标准活动顺序如下(表 6.1):

顺序 活动 说明 可选
1 去初始化BswM(BswM_Deinit) — 否
2 去初始化BSW调度器(SchM_Deinit) — 否
3 检查唤醒事件 根据EcuMIgnoreWakeupEvValOffPreOS配置,考虑所有挂起的唤醒事件或仅关闭期间验证过的唤醒事件,目的是检测关闭过程中发生的唤醒事件 否
4 若存在挂起唤醒事件,将RESET设为下电目标 仅在检测到挂起唤醒事件时执行(使用EcuMDefaultResetModeRef的默认复位模式),以便立即启动 否
5 ShutdownOS 此OS任务中的最后一个操作 否

关于唤醒事件检查的细化规则:

  • 若EcuMIgnoreWakeupEvValOffPreOS配置为true,仅考虑不需要验证的唤醒事件,其他唤醒事件被忽略。
  • 若配置为false,不需要验证的唤醒事件和需要验证的挂起唤醒事件都会被考虑。
  • 注意:由于SchM已在OffPreOS序列中去初始化,调度函数不再执行,因此无法再进行唤醒验证。

图 6.2 显示了OffPreOS序列的详细交互。

Figure7-8.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant BSWM as «module» BswM
    participant SCHM as «module» SchM
    participant OS as «module» Os
    ECUM->>IC: EcuM_OnGoOffOne()
    ECUM->>BSWM: BswM_Deinit()
    ECUM->>SCHM: SchM_Deinit()
    alt EcuMIgnoreWakeupEvValOffPreOS is TRUE
        ECUM->>ECUM: EcuM_GetValidatedWakeupEvents(EcuM_WakeupSourceType)
    else EcuMIgnoreWakeupEvValOffPreOS is FALSE
        ECUM->>ECUM: EcuM_GetPendingWakeupEvents(EcuM_WakeupSourceType)
    end
    opt Pending wakeup events?
        ECUM->>ECUM: EcuM_SelectShutdownTarget(Std_ReturnType, EcuM_ShutdownTargetType, EcuM_ShutdownModeType)
    end
    ECUM->>OS: ShutdownOS()

(转录自规范 Figure 7.8: OffPreOS Sequence)

6.4 OffPostOS 序列

OffPostOS序列实现OS关闭后到达下电目标的最终步骤,由EcuM_Shutdown启动(图 6.3):

  • 下电目标为RESET时,EcuM调用EcuM_AL_Reset回调(复位模态由复位模式决定);
  • 下电目标为OFF时,EcuM调用EcuM_AL_SwitchOff回调;
  • 之前EcuM会先调用EcuM_OnGoOffTwo回调。

注意:OS在关闭结束时调用关闭钩子(ShutdownHook),关闭钩子必须调用EcuM_Shutdown来终止关闭流程。

Figure7-9.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    ECUM->>IC: EcuM_OnGoOffTwo()
    alt Shutdown Target
        ECUM->>IC: [Reset] EcuM_AL_Reset(EcuM_ResetType)
    else Shutdown Target
        ECUM->>IC: [Off] EcuM_AL_SwitchOff()
    end

(转录自规范 Figure 7.9: OffPostOS Sequence)

7. SLEEP 与唤醒流程

7.1 SLEEP 阶段总览

SLEEP阶段中ECU节省能量,通常不执行代码但仍有供电。EcuM提供可配置的硬件睡眠模式集合(EcuMSleepModeSuspend参数选择),通常是功耗与重启时间之间的权衡。

EcuM_GoDownHaltPoll(下电目标SLEEP)触发两条控制流(图 7.1):Halt(休眠,微控制器停止,EcuM不执行任何代码)和Poll(轮询),它们共享睡眠准备与恢复的序列。

Figure7-10.png

sequenceDiagram
    participant BSWM as «module» BswM
    participant ECUM as «module» EcuM
    note over BSWM, ECUM: Halt 与 Poll 在睡眠机制上结构不同,但共享睡眠准备与恢复的序列
    BSWM->>ECUM: EcuM_SelectShutdownTarget(Std_ReturnType, EcuM_ShutdownTargetType, EcuM_ShutdownModeType)
    BSWM->>ECUM: EcuM_GoDownHaltPoll(Std_ReturnType, EcuM_UserType)
    activate ECUM
    rect rgb(245, 245, 245)
    note over ECUM: ref GoSleep Sequence
    end
    alt EcuM_GoDownHaltPoll called
        rect rgb(245, 245, 245)
        note over ECUM: ref Halt Sequence
        end
    else EcuM_GoDownHaltPoll called
        rect rgb(245, 245, 245)
        note over ECUM: ref Polling Sequence
        end
    end
    rect rgb(245, 245, 245)
    note over ECUM: ref WakeupRestart Sequence
    end
    deactivate ECUM

(转录自规范 Figure 7.10: SLEEP Phase)

7.2 GoSleep 序列

在GoSleep序列中,EcuM为即将到来的睡眠阶段配置硬件,并为下一次唤醒事件设置ECU(图 7.2):

  • 对目标睡眠模式的EcuMWakeupSourceMask中配置的每个唤醒源执行EcuM_EnableWakeupSources回调;
  • 多核ECU上EcuM为每个核保留专用资源(RES_AUTOSAR_ECUM),在GoSleep期间分配。

Figure7-11.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant BSWM as «module» :BswM
    participant OS as «module» Os
    ECUM->>BSWM: BswM_EcuM_CurrentWakeup(sources, ECUM_WKSTATUS_NONE)
    activate BSWM
    deactivate BSWM
    ECUM->>IC: EcuM_EnableWakeupSources(EcuM_WakeupSourceType)
    activate IC
    deactivate IC
    ECUM->>OS: GetResource(RES_AUTOSAR_ECUM_<core#>)

(转录自规范 Figure 7.11: GoSleep Sequence)

7.3 Halt 与 Poll 序列

Halt序列(图 7.3)在使微控制器休眠的睡眠模式中执行:

  • EcuM在休眠微控制器前调用EcuM_GenerateRamHash回调,在处理器从休眠返回后调用EcuM_CheckRamHash回调(防止长期睡眠后RAM数据损坏导致不可预见行为;多核场景下由"master"EcuM执行);
  • 若ECU处于Halt或Poll时发生不规则事件(硬件复位或电源循环),EcuM须在STARTUP阶段重启ECU;
  • 若调度器未作为资源获取,无法保证HALT指令后程序流继续(ISR Cat 2发生后会重新调度)。

Figure7-12.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant WS as «module» Wakeup Source
    participant PWS as «Peripheral» Wakeup Source
    participant BSWM as «module» :BswM
    ECUM->>OS: DisableInterruptSource(StatusType, ISRType)
    ECUM->>IC: EcuM_GenerateRamHash()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    note over ECUM: HALT(微控制器停止,EcuM 不执行任何代码)
    PWS->>WS: Interrupt()
    WS->>ECUM: EcuM_CheckWakeup(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
    IC->>IC: Activate PLL()
    IC->>ECUM: EcuM_StartCheckWakeup()
    IC->>WS: <Module>_CheckWakeup()
    opt Wakeup handling
        note over ECUM, WS: [Wakeup detected]
        WS->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
    end

(转录自规范 Figure 7.12: Halt Sequence)

Poll序列(图 7.4)适用于轮询睡眠模式:EcuM周期性地调用EcuM_CheckWakeup与EcuM_SleepActivity,通过Mcu_SetMode设置MCU模式。

Figure7-13.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant WS as «module» Wakeup Source
    participant BSWM as «module» :BswM
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    loop WHILE no pending/validated wakeup events
        note over ECUM: Additional Condition to Loop: While (AlarmClockService Present AND EcuM_AlarmClock only pending event AND Alarm not expired)
        ECUM->>IC: EcuM_SleepActivity()
        loop FOR all wakeup sources that need polling
            ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
            IC->>WS: <Module>_CheckWakeup()
            opt Wakeup handling
                note over ECUM, WS: [Wakeup detected]
                WS->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
            end
        end
        ECUM->>ECUM: EcuM_GetPendingWakeupEvents(EcuM_WakeupSourceType)
    end
    alt Validation Needed
        ECUM->>BSWM: [Yes] BswM_EcuM_CurrentWakeup(sources, ECUM_WKSTATUS_PENDING)
    else Validation Needed
        ECUM->>BSWM: [No] BswM_EcuM_CurrentWakeup(sources, ECUM_WKSTATUS_VALIDATED)
    end

(转录自规范 Figure 7.13: Poll Sequence)

7.4 WakeupRestart 序列

唤醒事件(如IO跳变)发生时,ECU从SLEEP状态唤醒,执行在MCU驱动的Mcu_SetMode服务内恢复。WakeupRestart序列自动执行(图 7.5):

  • EcuM调用EcuM_AL_DriverRestart回调,用于重新初始化驱动程序(作为唤醒源的驱动通常需要重新初始化);
  • 重新初始化期间,驱动须检查其唤醒源之一是否为上次唤醒的原因,若为真必须调用其"wakeup detected"回调,进而调用EcuM_SetWakeupEvent;驱动只应调用一次唤醒回调,之后须被显式重新布防才能再次触发;
  • 序列结束时EcuM获得待验证的唤醒事件候选列表。

Figure7-14.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    note over ECUM: [SWS_EcuM_04066]
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>ECUM: EcuM_GetPendingWakeupEvents(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_DisableWakeupSources(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_AL_DriverRestart()
    ECUM->>OS: ReleaseResource(RES_AUTOSAR_ECUM_<core#>)

(转录自规范 Figure 7.14: WakeupRestart Sequence)

7.5 WakeupValidation(唤醒验证)序列

由于唤醒事件可能无意产生(如CAN线上的EVM毛刺),ECU恢复全面运行前必须验证唤醒。验证机制对所有唤醒源相同:需要验证的唤醒事件由EcuM_MainFunction中的验证协议处理,超时时间由配置(ECUC_EcuM_00148)定义。验证可由BSW中任意一个(但仅一个)合适的模块(驱动、接口、句柄或管理器)通过调用EcuM_ValidateWakeupEvent完成。

图 7.6 显示了以CAN唤醒为例的完整验证序列:EcuM启动唤醒源与验证超时,CanIf循环检查验证结果——验证成功则调用EcuM_ValidateWakeupEvent并通知ComM/BswM;验证超时则通知BswM ECUM_WKSTATUS_EXPIRED并停止唤醒源。

Figure7-16.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant WS as «module» Wakeup Source
    participant COMM as «module» ComM
    participant BSWM as «module» BswM
    participant CANSM as «module» CanSM
    ECUM->>ECUM: EcuM_GetPendingWakeupEvents(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_StartWakeupSources(EcuM_WakeupSourceType)
    activate IC
    IC->>CANSM: CanSM_StartWakeupSource(Std_ReturnType, NetworkHandleType)
    deactivate IC
    ECUM->>ECUM: Start validation timeout()
    loop WHILE no wakeup event has been validated AND timeout not expired
        ECUM->>IC: EcuM_CheckValidation(EcuM_WakeupSourceType)
        IC->>WS: <Module>_CheckValidation()
        opt wakeup validated
            WS->>ECUM: EcuM_ValidateWakeupEvent(EcuM_WakeupSourceType)
            ECUM->>COMM: ComM_EcuM_WakeUpIndication(NetworkHandleType)
            ECUM->>COMM: ComM_EcuM_PNCWakeUpIndication(PNCHandleType)
            ECUM->>BSWM: BswM_EcuM_CurrentWakeup(Source, ECUM_WKSTATUS_VALIDATED)
        end
    end
    opt No wakeup event was validated
        ECUM->>BSWM: BswM_EcuM_CurrentWakeup(Source, ECUM_WKSTATUS_EXPIRED)
        ECUM->>IC: EcuM_StopWakeupSources(EcuM_WakeupSourceType)
        IC->>CANSM: CanSM_StopWakeupSource(Std_ReturnType, NetworkHandleType)
    end

(转录自规范 Figure 7.16: The WakeupValidation Sequence)

注意:EcuM从不对以下唤醒源执行验证:ECUM_WKSOURCE_POWER、ECUM_WKSOURCE_RESET、ECUM_WKSOURCE_INTERNAL_RESET、ECUM_WKSOURCE_INTERNAL_WDG、ECUM_WKSOURCE_EXTERNAL_WDG。

7.6 唤醒源状态机

EcuM用EcuM_WakeupSourceType位掩码管理最多32个唤醒源的状态,每个唤醒源经历NONE→PENDING→VALIDATED/EXPIRED的状态迁移(图 7.7):

  • ECUM_WKSTATUS_NONE:初始状态;
  • ECUM_WKSTATUS_PENDING:EcuM_SetWakeupEvent被调用(需验证时进入),执行唤醒验证序列;
  • ECUM_WKSTATUS_VALIDATED:EcuM_ValidateWakeupEvent验证通过;
  • ECUM_WKSTATUS_EXPIRED:验证超时。

EcuM提供EcuM_GetPendingWakeupEvents、EcuM_GetValidatedWakeupEvents、EcuM_GetExpiredWakeupEvents查询接口,以及EcuM_SetWakeupEvent、EcuM_ValidateWakeupEvent、EcuM_ClearWakeupEvent、EcuM_CheckWakeup、EcuM_EnableWakeupSources、EcuM_DisableWakeupSources、EcuM_StartWakeupSources、EcuM_StopWakeupSources等操纵接口。

Figure7-15.png

stateDiagram-v2
    [*] --> NONE : Power On / Initial
    state "ECUM_WKSTATUS_NONE<br/>entry / BswM_EcuM_CurrentWakeup(sources, NONE)" as NONE
    NONE --> PENDING : EcuM_SetWakeupEvent(sources) [With Validation]
    NONE --> VALIDATED : EcuM_SetWakeupEvent(sources) [No Validation]
    PENDING --> NONE : EcuM_ClearWakeupEvent(sources)
    state "Validation(超态)" as Validation {
        state "ECUM_WKSTATUS_PENDING<br/>entry / BswM_EcuM_CurrentWakeup(sources, PENDING)<br/>entry / EcuM_StartWakeupSources()<br/>do / exec. wakeup validation seq." as PENDING
        state "ECUM_WKSTATUS_VALIDATED<br/>entry / BswM_EcuM_CurrentWakeup(sources, VALIDATED)<br/>entry / ComM_EcuM_WakeUpIndication()" as VALIDATED
        state "ECUM_WKSTATUS_EXPIRED<br/>entry / BswM_EcuM_CurrentWakeup(sources, EXPIRED)<br/>entry / EcuM_StopWakeupSources()" as EXPIRED
        PENDING --> VALIDATED : EcuM_ValidateWakeupEvent()
        PENDING --> EXPIRED : Timer Expired
    }

(转录自规范 Figure 7.15: Wakeup Source States;规范注明 Disabled 与 Validation 两个超态仅为便于理解而绘出)

7.7 典型唤醒源时序

规范第 9 章给出了各类唤醒源的详细时序。以下收集最典型的几种:

GPT 唤醒(中断方式,图 7.8):GPT通常在ECU睡眠前启动,硬件定时器到期产生中断唤醒微控制器,GPT模块的中断处理程序通知EcuM发生了GPT唤醒;集成商可为每个GPT通道分配不同的唤醒源标识符以区分不同通道引起的唤醒。

Figure9-1.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant GPT as «module» Gpt
    participant GPTHW as «Peripheral» GPT Hardware
    rect rgb(235, 245, 255)
    note over ECUM: GOSLEEP
    ECUM->>IC: EcuM_EnableWakeupSources(EcuM_WakeupSourceType)
    IC->>GPT: Gpt_EnableWakeup(Gpt_ChannelType)
    IC->>GPT: Gpt_StartTimer(Gpt_ChannelType, Gpt_ValueType)
    IC->>GPT: Gpt_SetMode(Gpt_ModeType)
    ECUM->>OS: GetResource(RES_AUTOSAR_ECUM_<core#>)
    end
    rect rgb(235, 245, 255)
    note over ECUM: SLEEP
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    note over ECUM, MCU: 若调度器未作为资源获取,无法保证 HALT 指令后程序流继续(ISR Cat 2 发生后会重新调度)
    note over ECUM: HALT
    end
    GPTHW->>GPT: Wakeup interrupt()
    GPT->>ECUM: EcuM_CheckWakeup(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
    IC->>GPT: Gpt_CheckWakeup(EcuM_WakeupSourceType)
    GPT->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
    GPT-->>GPTHW: Return from interrupt()
    note over ECUM, MCU: Execution continues after HALT instruction.
    MCU-->>ECUM: Mcu_SetMode()
    ECUM->>OS: EnableAllInterrupts()
    rect rgb(235, 245, 255)
    note over ECUM: WAKEUP I
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>IC: EcuM_DisableWakeupSources(EcuM_WakeupSourceType)
    IC->>GPT: Gpt_DisableWakeup(Gpt_ChannelType)
    IC->>GPT: Gpt_SetMode(Gpt_ModeType)
    ECUM->>OS: ReleaseResource(RES_AUTOSAR_ECUM_<core#>)
    note over ECUM, OS: Release Scheduler resource to allow other tasks to run.
    end

(转录自规范 Figure 9.1: GPT wake up by interrupt)

GPT 唤醒(轮询方式,图 7.9):若GPT硬件能够锁存定时器溢出,也可轮询GPT获取唤醒事件。

Figure9-2.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant GPT as «module» Gpt
    rect rgb(235, 245, 255)
    note over ECUM: GOSLEEP
    ECUM->>IC: EcuM_EnableWakeupSources(EcuM_WakeupSourceType)
    IC->>GPT: Gpt_EnableWakeup(Gpt_ChannelType)
    IC->>GPT: Gpt_StartTimer(Gpt_ChannelType, Gpt_ValueType)
    IC->>GPT: Gpt_SetMode(Gpt_ModeType)
    ECUM->>OS: GetResource(RES_AUTOSAR_ECUM_<core#>)
    note over ECUM, OS: Acquire the Scheduler to prevent other tasks from running.
    end
    rect rgb(235, 245, 255)
    note over ECUM: SLEEP
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    note over ECUM, MCU: Mcu_SetMode() puts the microcontroller in some power saving mode. In this mode software execution continues, but with reduced clock speed.
    ECUM->>OS: EnableAllInterrupts()
    loop WHILE no pending/validated events
        ECUM->>IC: EcuM_SleepActivity()
        ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
        IC->>GPT: Gpt_CheckWakeup(EcuM_WakeupSourceType)
        opt Wakeup detected
            GPT->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
        end
    end
    end
    rect rgb(235, 245, 255)
    note over ECUM: WAKEUP I
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>IC: EcuM_DisableWakeupSources(EcuM_WakeupSourceType)
    IC->>GPT: Gpt_DisableWakeup(Gpt_ChannelType)
    IC->>GPT: Gpt_SetMode(Gpt_ModeType)
    ECUM->>OS: ReleaseResource(RES_AUTOSAR_ECUM_<core#>)
    note over ECUM, OS: Release Scheduler resource to allow other tasks to run.
    end

(转录自规范 Figure 9.2: GPT wake up by polling)

CAN 收发器唤醒(中断方式,图 7.10):CAN总线活动引起唤醒,中断通常由ICU驱动处理,CanTrcv/CanIf将事件上报EcuM。

Figure9-4.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant ICU as «module» Icu
    participant CANIF as «module» CanIf
    participant CAN as «module» Can
    participant CANTRCV as «module» CanTrcv
    participant CANCTRL as «Peripheral» CanController
    participant ETHHW as «Peripheral» ETH Hardware (PHY)
    rect rgb(235, 245, 255)
    note over ECUM: GOSLEEP
    ECUM->>IC: EcuM_EnableWakeupSources(EcuM_WakeupSourceType)
    IC->>CANIF: CanIf_SetTrcvWakeupMode(uint8, CanTrcv_TrcvWakeupModeType)
    CANIF->>CANTRCV: CanTrcv_SetWakeupMode(uint8, CanTrcv_TrcvWakeupModeType)
    IC->>ICU: Icu_EnableWakeup(Icu_ChannelType)
    ECUM->>OS: GetResource(uint8)
    note over ECUM, CANIF: CanSM will have called CanIf_SetControllerMode and CanIf_SetTransceiverMode when going to sleep.
    end
    rect rgb(235, 245, 255)
    note over ECUM: SLEEP
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    note over ECUM, MCU: 若调度器未作为资源获取,无法保证 HALT 指令后程序流继续(ISR Cat 2 发生后会重新调度)
    note over ECUM: HALT
    end
    ETHHW->>ICU: Wakeup interrupt()
    ICU->>ECUM: EcuM_CheckWakeup(EcuM_WakeupSourceType)
    ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
    IC->>IC: activate PLL()
    IC->>CANIF: CanIf_CheckWakeup(EcuM_WakeupSourceType): Std_ReturnType
    CANIF->>CANTRCV: CanTrcv_CheckWakeup(uint8): Std_ReturnType
    CANTRCV->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
    ICU-->>ETHHW: Return from interrupt()
    note over ECUM, MCU: Execution continues after HALT instruction.
    rect rgb(235, 245, 255)
    note over ECUM: WAKEUP I
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>IC: EcuM_DisableWakeupSources(EcuM_WakeupSourceType)
    IC->>ICU: Icu_DisableWakeup(Icu_ChannelType)
    IC->>CANIF: CanIf_SetTrcvWakeupMode(uint8, CanTrcv_TrcvWakeupModeType)
    CANIF->>CANTRCV: CanTrcv_SetWakeupMode(uint8, CanTrcv_TrcvWakeupModeType)
    ECUM->>OS: ReleaseResource(uint8)
    note over ECUM, OS: Release Scheduler resource to allow other tasks to run.
    end

(转录自规范 Figure 9.4: CAN transceiver wake up by interrupt)

CAN 控制器/收发器唤醒(轮询方式,图 7.11):EcuM周期调用EcuM_CheckWakeup,CanIf/CanTrcv检查硬件状态。

Figure9-6.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant OS as «module» Os
    participant MCU as «module» Mcu
    participant ICU as «module» Icu
    participant CANIF as «module» CanIf
    participant CAN as «module» Can
    participant CANTRCV as «module» CanTrcv
    participant CANCTRL as «Peripheral» CanController
    participant ETHHW as «Peripheral» ETH Hardware (PHY)
    rect rgb(235, 245, 255)
    note over ECUM: GOSLEEP
    ECUM->>IC: EcuM_EnableWakeupSources(EcuM_WakeupSourceType)
    ECUM->>OS: GetResource(uint8)
    note over ECUM, OS: Acquire the Scheduler to prevent other tasks from running.
    end
    rect rgb(235, 245, 255)
    note over ECUM: SLEEP
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    note over ECUM, MCU: Mcu_SetMode() puts the microcontroller in some power saving mode. In this mode software execution continues, but with reduced clock speed.
    ECUM->>OS: EnableAllInterrupts()
    loop WHILE no pending/validated events
        ECUM->>IC: EcuM_SleepActivity()
        ECUM->>IC: EcuM_CheckWakeupHook(EcuM_WakeupSourceType)
        IC->>CANIF: CanIf_CheckWakeup(EcuM_WakeupSourceType): Std_ReturnType
        alt WakeupSource parameter of CanIf_CheckWakeup()
            CANIF->>CAN: [CAN Controller] Can_CheckWakeup(Std_ReturnType, uint8)
            CAN->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
        else WakeupSource parameter of CanIf_CheckWakeup()
            CANIF->>CANTRCV: [CAN Transceiver] CanTrcv_CheckWakeup(Std_ReturnType, uint8)
            CANTRCV->>ECUM: EcuM_SetWakeupEvent(EcuM_WakeupSourceType)
        end
    end
    end
    rect rgb(235, 245, 255)
    note over ECUM: WAKEUP I
    ECUM->>OS: DisableAllInterrupts()
    ECUM->>MCU: Mcu_SetMode(Mcu_ModeType)
    ECUM->>OS: EnableAllInterrupts()
    ECUM->>IC: EcuM_DisableWakeupSources(EcuM_WakeupSourceType)
    ECUM->>OS: ReleaseResource(uint8)
    note over ECUM, OS: Release Scheduler resource to allow other tasks to run.
    end
    note over ECUM: WAKEUP VALIDATION

(转录自规范 Figure 9.6: CAN controller or transceiver wake up by polling)

CAN 唤醒验证(图 7.12):检测到唤醒事件后,CanSM启动唤醒源,EcuM启动验证超时;CanIf循环检查验证结果,CAN成功验证由正确接收的消息指示。验证成功/超时/未验证的分支处理如图所示。

Figure9-7.png

sequenceDiagram
    participant ECUM as «module» EcuM
    participant IC as Integration Code
    participant CANSM as «module» CanSM
    participant MCU as «module» Mcu
    participant ICU as «module» Icu
    participant CANIF as «module» CanIf
    rect rgb(235, 245, 255)
    note over ECUM: WAKEUP VALIDATION
    ECUM->>IC: EcuM_StartWakeupSources(EcuM_WakeupSourceType)
    IC->>CANSM: CanSM_StartWakeupSource(Std_ReturnType, NetworkHandleType)
    ECUM->>ECUM: Start validation timeout()
    loop Validate Wakeup Event
        ECUM->>IC: EcuM_CheckValidation(EcuM_WakeupSourceType)
        IC->>CANIF: CanIf_CheckValidation(EcuM_WakeupSourceType)
        alt Check Validation Result
            CANIF->>ECUM: [SUCCESSFUL VALIDATION] EcuM_ValidateWakeupEvent(EcuM_WakeupSourceType)
            ECUM->>ECUM: Stop validation timeout()
            note over ECUM, CANIF: On CAN successful validation is indicated by a correctly received message
        else Check Validation Result
            note over ECUM: [NO VALIDATION YET]
        else Check Validation Result
            note over ECUM: [VALIDATION TIMEOUT]
            ECUM->>ECUM: Detect validation timeout()
        end
    end
    ECUM->>IC: EcuM_StopWakeupSources(EcuM_WakeupSourceType)
    IC->>CANSM: CanSM_StopWakeupSource(Std_ReturnType, NetworkHandleType)
    end
    note over ECUM: GOSLEEP

(转录自规范 Figure 9.7: CAN wake up validation)

集成电源控制的唤醒源:SLEEP可由控制MCU电源供应的系统芯片实现(如带集成电源的CAN收发器,其在应用请求时切断电源、在CAN活动时打开电源)。此时对EcuM而言SLEEP就像OFF,被动CAN唤醒看起来就像上电复位,ECU将在唤醒事件后继续STARTUP序列——唤醒验证仍然必要,且系统设计者须负责检查CAN收发器的唤醒原因并通过EcuM_SetWakeupEvent/EcuM_ClearWakeupEvent将信息传递给EcuM。

8. Reset(复位)流程

8.1 复位与下电目标的关系

RESET是三种下电目标之一。当BswM(或SW-C)通过EcuM_SelectShutdownTarget选择RESET目标并调用EcuM_GoDownHaltPoll后,ECU按第 6 章的SHUTDOWN流程关闭BSW,最终在OffPostOS序列中由EcuM_AL_Reset回调执行具体复位,复位模态由EcuM_ResetType(复位模式)决定。

此外,OffPreOS序列中检测到挂起的唤醒事件时,EcuM会自动将RESET设为下电目标(使用EcuMDefaultResetModeRef的默认复位模式),以便立即启动。

若EcuM无法确定Mcu驱动返回的复位原因,则EcuM为默认唤醒源ECUM_WKSOURCE_RESET设置唤醒事件。

8.2 Boot Target(启动目标)选择

Bootloader、系统供应商Bootloader和应用是独立的程序镜像,多数情况下可以分别刷写。从一个镜像进入另一个镜像的唯一方式是通过复位。启动菜单(Boot Menu)根据所选的启动目标(Boot Target)分支进入相应的镜像(图 8.1)。

Figure7-36.png

flowchart LR
    R([Reset]) --> BM([Boot Menu])
    BM --> DT{Boot Target}
    DT --> APP([Application])
    DT --> BL([Bootloader])
    DT --> SSBL([SS Bootloader])

(转录自规范 Figure 7.36: Selection of Boot Targets)

8.3 复位相关模块交互

WdgM(看门狗管理器):WdgM_PerformReset是一种复位模态;看门狗相关唤醒源(ECUM_WKSOURCE_INTERNAL_WDG、ECUM_WKSOURCE_EXTERNAL_WDG)不需要唤醒验证。

DCM(诊断通信管理器):诊断ECU复位(ECU Reset)场景中,DCM通过BswM通知ECU:① 准备ECU执行特定复位;② 显式执行该复位。根据诊断服务的不同,DCM等待ECU就绪确认(通过EcuMode通知)或立即切换到EXECUTE模式,后者将触发BswM调用EcuM_GoDown。

Mcu(微控制器驱动):Mcu_PerformReset执行硬件复位;Mcu_GetResetReason在StartPreOS序列中提供复位原因,经EcuMWakeupSource配置映射为唤醒源,EcuM须记住该映射结果供EcuM_MainFunction验证。

9. 多核 ECU 协调

多核ECU上,STARTUP、SHUTDOWN、SLEEP和WAKEUP在所有核上协调执行。EcuM分为master和slave实例:

  • Master Core:StartPreOS/StartPostOS/OffPreOS/OffPostOS/GoSleep/Halt/Poll/WakeupRestart各序列由master EcuM主导;
  • Slave Core:slave EcuM通过核间信号(SetEvent/WaitEvent)与master同步;
  • Shutdown Synchronization:各核在调用ShutdownAllCores前通过事件掩码同步,确保所有核就绪后统一关闭。

图 9.1 显示了Master/Slave核关闭同步的示例(规范注明此为示例而非强制流程)。

Figure7-18.png

sequenceDiagram
    box Master Core
        participant BSWM as «module» :BswM
        participant MECUM as «module» Master: EcuM
        participant MCOS as «module» Master: McOs
    end
    box Slave Core n
        participant SECUM as «module» Slave n: EcuM
        participant SSCHM as «module» Slave n: SchM
        participant SCOS as «module» Slave n: :McOs
    end
    BSWM->>MECUM: EcuM_GoDownHaltPoll(Std_ReturnType, EcuM_UserType)
    activate MECUM
    note over MECUM: Set a shutdown flag which can be read by all EcuMs of all slave cores
    note over MECUM: BSW De-Initialization on Master Core
    loop until all cores done
        opt resource or spinlock already taken
            MECUM->>MCOS: GetEvent(Mask)
        end
        MECUM->>MCOS: WaitEvent(Mask)
    end
    note over MECUM: Unset the shutdown flag
    MECUM->>MCOS: ShutdownAllCores(StatusType)
    deactivate MECUM
    SECUM->>SECUM: EcuM_MainFunction()
    note over SECUM: BSW De-Initialization on Slave Core
    note over SECUM: Shutdown flag is read by the slave core
    SECUM->>SCOS: SetEvent(TaskId, Mask)

(转录自规范 Figure 7.18: Master / Slave Core Shutdown Synchronization,规范注明此为示例而非强制流程)

10. BswM 配套规则(集成指南)

根据Guide to Mode Management,BswM的规则(rules)和动作列表(action lists)配置是项目与ECU特定的,AUTOSAR 无法标准化,但规范给出了典型场景的配置指导:

启动(Startup):BswM的ECU Mode Handling规则在EcuM初始化后初始化其余BSW模块(LinSM_Init、FrIf_Init、PduR_Init、CANNM_Init、COM_Init、DCM_Init、ComM_Init、DEM_Init、FIM_Init等),启动RTE(Rte_Start→Rte_Init→Rte_StartTiming),最后通过**EcuM_SetState(ECU_RUN)**置位运行状态。NvM_ReadAll作业完成后触发剩余初始化。

运行(Run):只要至少一个应用SW-C请求RUN状态,ECU就保持运行;EcuM对SW-C的RUN/POST_RUN请求进行仲裁,通过BswM_EcuM_RequestedState通知BswM。

下电与睡眠(Shutdown & Sleep):所有ComM通道报告无挂起请求后,BswM协调POST_RUN阶段、去初始化各模块,根据下电目标调用EcuM_GoDown(下电)或EcuM_GoHalt/EcuM_GoPoll(睡眠)。进入睡眠与下电序列类似,只是调用不同的EcuM下行API。

唤醒(Wakeup):唤醒后的正确行为完全配置在BswM中——规则根据发生的EcuM_WakeupSource唤醒事件决定是否启动ECU,否则ECU将立即再次关闭。唤醒源验证有效时BswM将ECU恢复到RUN状态;所有唤醒事件回到NONE或EXPIRED后,BswM为SLEEP或OFF准备BSW并调用EcuM_GoDownHaltPoll。

诊断复位(ECU Reset):DCM作为诊断用例的总模式管理器,通过模式接口通知BswM准备并执行ECU复位。

分区重启(Reset of partitions):某分区出错需重启时,该分区的BSW模块须重新初始化;通过BswMPartitionRestarted模式请求源确定被重启的分区。

错误处理:EcuM忽略初始化期间发生的所有类型错误(如初始化函数返回值)——初始化是配置问题(EcuMDriverInitListZero、EcuMDriverInitListOne、EcuMDriverInitRestartList),无法标准化。BSW模块自行负责向DEM或DET报告初始化错误并采取特殊措施。

11. 小结

本文档基于AUTOSAR CP R22-11 ECU状态管理器规范及4.4.0模式管理指南,整理了标准ECU电源状态管理的完整流程:

  1. Startup:EcuM_Init前最小MCU初始化 → StartPreOS(中断设置、驱动Init Block 0/1、配置一致性检查、复位原因获取、默认下电目标选择、启动OS)→ StartPostOS(SchM_Start、BswM_Init、SchM_Init、SchM_StartTiming)→ BswM初始化其余BSW并启动RTE → UP阶段。
  2. 下电:BswM选择下电目标(OFF/SLEEP/RESET)并调用EcuM_GoDownHaltPoll → OffPreOS(BswM_Deinit、SchM_Deinit、唤醒事件检查、必要时改设RESET目标)→ ShutdownOS → ShutdownHook调用EcuM_Shutdown → OffPostOS(EcuM_AL_SwitchOff或EcuM_AL_Reset)。
  3. 唤醒:GoSleep(使能唤醒源)→ Halt/Poll(RAM哈希、Mcu_SetMode)→ 唤醒事件 → WakeupRestart(驱动重启、唤醒回调重新布防)→ WakeupValidation(NONE→PENDING→VALIDATED/EXPIRED状态机)。
  4. Reset:作为下电目标经OffPostOS的EcuM_AL_Reset执行;支持Mcu_PerformReset、WdgM_PerformReset、DIO/SPI触发等多种复位模态;诊断ECU复位由DCM经BswM协调;启动目标(Boot Target)选择依赖复位在Bootloader与应用镜像间分支。

微信扫一扫,获取更多及时资讯

微信扫一扫