AUTOSAR_SWS_MCUDriver 中文翻译

文档编号:020 | 状态:Final(正式发布) | 发布于:AUTOSAR CP Release 4.4.0(2018-10-31)
所属标准:AUTOSAR Classic Platform 标准 | 文档责任方:AUTOSAR | 保密等级:AUTOSAR CONFIDENTIAL

本翻译覆盖原文档 1-49 页正文,约 1.14 MB / 49 页。
原文为软件规范(SWS, Software Specification),定义微控制器单元(MCU)驱动模块的 API 与配置——含 11 个 API 函数 + 7 个开发错误 + 1 个生产错误 + 多个 SWS_Mcu_NNNNN 规范项。
本翻译为"忠实精翻+结构化索引"型——保留全部章节、API 函数、错误分类、配置参数。


1 引言与功能概述(Introduction and functional overview)

本规约规约 AUTOSAR 基础软件模块 MCU 驱动(Microcontroller Unit Driver, MCU)的功能、API 与配置。MCU 驱动位于微控制器抽象层(MCAL),提供微控制器初始化、下电功能、复位与微控制器特定功能服务(其他 MCAL 软件模块所需)。

MCU 驱动直接访问微控制器硬件。其特性:

2 缩略语与缩写(Acronyms and abbreviations)

缩略语描述
MCUMicrocontroller Unit(微控制器单元)
MCALMicrocontroller Abstraction Layer(微控制器抽象层)
PLLPhase Locked Loop(锁相环)
RAMRandom Access Memory(随机访问存储器)
DEMDiagnostic Event Manager(诊断事件管理器)
DETDefault Error Tracer(默认错误追踪器)
EcuMECU State Manager(ECU 状态管理器)
SFRSpecial Function Register(特殊功能寄存器)
OSOperating System(操作系统)
Power On Reset上电复位
Watchdog Timer Reset看门狗定时器复位

3 相关文档(Related documentation)

4 约束与假设(Constraints and assumptions)

MCU 驱动实现可能仅在 power-up/start-up 阶段执行,或仅测试运行时未共享的资源。多微控制器系统不在 MCU 驱动范围内。

5 与其他模块的依赖(Dependencies to other modules)

5.1 文件结构(File structure)

5.1.1 代码文件结构(Code File Structure)

Mcu.c                    # 主源文件
Mcu_Lcfg.c               # Link-time 配置
Mcu_PBcfg.c              # PostBuild 配置

MCU 驱动依赖 EcuM(资源管理)、DEM(错误报告)、DET(开发错误追踪)、OS(中断管理)。

6 需求可追溯性(Requirements traceability)

MCU 驱动满足 SRS_Mcu_NNNNN 中的 13 条需求(参见 SRS 翻译)以及 RS_BRF_NNNNN 顶层需求。MCU 自身的 SWS_Mcu_NNNNN 规范项 ID 约 200+ 条(详细列表见原文第 6/7/8/10 章;编号范围 00005-00258)。

7 功能规范(Functional specification)

7.1 预配置(Pre-Configuration)

MCU 驱动允许以下预配置:

7.2 通用行为(General Behavior)

MCU 驱动初始化序列:

  1. 调用 Mcu_Init() 初始化 MCU 模块(设置 SFR 寄存器);
  2. 调用 Mcu_InitRamSection() 初始化 RAM 段(可选);
  3. 调用 Mcu_InitClock() 初始化时钟系统(PLL 因子、PLL 锁定等);
  4. 调用 Mcu_DistributePllClock() 激活 PLL 时钟分布;
  5. 使用 Mcu_GetPllStatus() 检查 PLL 状态;
  6. 调用 Mcu_GetResetReason() 获取复位原因;
  7. 调用 Mcu_SetMode() 切换到节能模式(如需)。

7.3 错误分类(Error classification)

7.3.1 开发错误(Development Errors)

错误码含义
MCU_E_PARAM_CONFIG无效的配置指针
MCU_E_PARAM_CLOCK无效的时钟引用
MCU_E_PARAM_MODE无效的模式引用
MCU_E_PARAM_RAMSECTION无效的 RAM 段引用
MCU_E_PLL_NOT_LOCKEDPLL 未锁定
MCU_E_UNINITMCU 未初始化
MCU_E_PARAM_POINTER无效的指针
MCU_E_INIT_FAILED初始化失败

7.3.2 运行时错误(Runtime Errors)

无。

7.3.3 瞬态故障(Transient Faults)

无。

7.3.4 生产错误(Production Errors)

错误码含义
MCU_E_CLOCK_FAILURE时钟源失败

7.3.5 扩展生产错误(Extended Production Errors)

无。

8 API 规范(API specification)

8.1 导入类型(Imported types)

8.2 类型定义(Type Definitions)

类型描述
Mcu_ConfigTypeMCU 抽象配置类型(外部数据结构)
Mcu_PllStatusTypePLL 状态枚举(MCU_PLL_LOCKED / MCU_PLL_UNLOCKED / MCU_PLL_STATUS_UNDEFINED)
Mcu_ClockType时钟设置 ID(uint8/16/32)
Mcu_ResetType标准化复位原因枚举(MCU_POWER_ON_RESET / MCU_WATCHDOG_RESET / MCU_SOFT_RESET / MCU_HW_RESET / MCU_UNDEFINED_RESET)
Mcu_RawResetType原始复位值(µC 特定,uint8/16/32)
Mcu_ModeTypeMCU 节能模式 ID(uint8/16/32)
Mcu_RamSectionTypeRAM 段 ID(uint8/16/32)
Mcu_RamStateTypeRAM 状态枚举(MCU_RAMSTATE_INVALID / MCU_RAMSTATE_VALID)

8.3 函数定义(Function definitions)

API签名功能
Mcu_Initvoid Mcu_Init(const Mcu_ConfigType* ConfigPtr)初始化 MCU 模块(设置 SFR)
Mcu_InitRamSectionStd_ReturnType Mcu_InitRamSection(Mcu_RamSectionType RamSection)初始化已配置 RAM 段
Mcu_InitClockStd_ReturnType Mcu_InitClock(Mcu_ClockType ClockSetting)初始化时钟系统(PLL 因子、PLL 锁定)
Mcu_DistributePllClockStd_ReturnType Mcu_DistributePllClock(void)激活 PLL 时钟分布到整个 MCU
Mcu_GetPllStatusMcu_PllStatusType Mcu_GetPllStatus(void)获取 PLL 锁定状态
Mcu_GetResetReasonMcu_ResetType Mcu_GetResetReason(void)获取标准化复位原因
Mcu_GetResetRawValueMcu_RawResetType Mcu_GetResetRawValue(void)获取原始复位值(µC 特定)
Mcu_PerformResetvoid Mcu_PerformReset(void)执行 MCU 复位
Mcu_SetModevoid Mcu_SetMode(Mcu_ModeType McuMode)设置 MCU 节能模式
Mcu_GetVersionInfovoid Mcu_GetVersionInfo(Std_VersionInfoType* VersionInfoPtr)获取版本信息
Mcu_GetRamStateMcu_RamStateType Mcu_GetRamState(void)获取 RAM 状态

共 11 个 API 函数。

8.4 调度函数(Scheduled functions)

MCU 驱动通常不定义调度函数(除 EcuM 状态管理所需外)。

8.5 预期接口(Expected Interfaces)

8.5.1 强制接口(Mandatory Interfaces)

8.5.2 可选接口(Optional Interfaces)

8.5.3 可配置接口(Configurable interfaces)

9 序列图(Sequence diagrams)

  1. 启动序列:应用 → Mcu_Init()Mcu_InitRamSection()Mcu_InitClock()Mcu_DistributePllClock() → 启动完成;
  2. 节能模式:应用 → Mcu_SetMode(MCU_MODE_LOW_POWER) → MCU 进入低功耗;
  3. 复位:检测到致命错误 → Mcu_PerformReset() → MCU 复位;
  4. 查询复位原因:应用 → Mcu_GetResetReason() → 返回标准化原因;
  5. 时钟失败通知:硬件时钟失败 → MCU ISR → Dem_SetEventStatus(MCU_E_CLOCK_FAILURE)

10 配置规范(Configuration specification)

10.1 容器与配置参数(Containers and configuration parameters)

10.1.1 Mcu(根容器)

参数描述
McuDevErrorDetect开发错误检测开关
McuVersionInfoApiMcu_GetVersionInfo() API 开关
McuInitClockApiMcu_InitClock() API 开关
McuDistributePllClockApiMcu_DistributePllClock() API 开关
McuGetPllStatusApiMcu_GetPllStatus() API 开关
McuPerformResetApiMcu_PerformReset() API 开关
McuGetResetReasonApiMcu_GetResetReason() API 开关
McuGetResetRawValueApiMcu_GetResetRawValue() API 开关
McuRamInitApiMcu_InitRamSection() API 开关

10.1.2 McuGeneral(通用配置)

参数描述
McuNumberOfMcuModesMCU 模式数量
McuNumberOfRamSectionsRAM 段数量
McuClockSrcFailureNotification时钟失败通知开关

10.1.3 McuClockSettingConfig(时钟设置)

参数描述
McuClockSettingId时钟设置 ID
McuClockSettingPllPLL 设置引用

10.1.4 McuPllConfig(PLL 设置)

参数描述
McuPllIdPLL ID
McuPllInputClockRefPLL 输入时钟引用
McuPllOutputClockPLL 输出时钟频率
McuPllDividerPLL 分频器
McuPllMultiplerPLL 倍频器

10.1.5 McuRamSectionConfig(RAM 段)

参数描述
McuRamSectionIdRAM 段 ID
McuRamSectionBaseAddressRAM 段基址
McuRamSectionSizeRAM 段大小
McuRamSectionInitValueRAM 段初始化值

10.1.6 McuModeConfig(MCU 模式)

参数描述
McuModeId模式 ID
McuModePowerMode电源模式(Normal/Sleep/Stop)

10.1.7 McuResetConfig(复位原因)

参数描述
McuResetId复位 ID
McuResetRawValue复位原始值(µC 特定)
McuResetReason标准化复位原因

10.2 发布信息(Published Information)

发布信息包括 MCU 模块版本、配置变体、RAM 段数量、PLL 数量、模式数量等。


📋 校对记录

校对轮次:L1 自动校对(2026-06-13)