跳到主要内容

7.5.17 MCU 看门狗

1. 简介

本用户文档旨在提供 WDG 驱动的相关信息,包括功能、配置参数、API。 文档每一处提及的 Wdgx,x 为索引,有效范围为0、1、2。

本用户文档旨在提供 WDG 驱动的相关信息,包括功能、配置参数、API。 文档每一处提及的 Wdgx,x 为索引,有效范围为0、1、2、3、4。

2. 概览

2.1 文件列表

Lowlevel 接口

这些是 Watchdog 底层驱动的实现和内部公共接口文件,一般用户不需要直接关注:

  • McalCdd\Wdg\inc\Wdg_Lld.h
  • McalCdd\Wdg\src\Wdg_Lld.c
  • McalCdd\Wdg\inc\Wdg_Prv.h
  • McalCdd\Wdg\src\Wdg_Common.c

Highlevel 接口

这些是用于用户调用的 API 实现文件,每一个 Wdg 的 instance 需要一份独立代码文件:

  • McalCdd\Wdg\src\Wdg0.c
  • McalCdd\Wdg\src\Wdg1.c
  • McalCdd\Wdg\src\Wdg2.c
  • McalCdd\Wdg\inc\Wdg0.h
  • McalCdd\Wdg\inc\Wdg1.h
  • McalCdd\Wdg\inc\Wdg2.h

这些是用于用户调用的 API 实现文件,每一个 Wdg 的 instance 需要一份独立代码文件:

  • McalCdd\Wdg\src\Wdg0.c
  • McalCdd\Wdg\src\Wdg1.c
  • McalCdd\Wdg\src\Wdg2.c
  • McalCdd\Wdg\src\Wdg3.c
  • McalCdd\Wdg\src\Wdg4.c
  • McalCdd\Wdg\inc\Wdg0.h
  • McalCdd\Wdg\inc\Wdg1.h
  • McalCdd\Wdg\inc\Wdg2.h
  • McalCdd\Wdg\inc\Wdg3.h
  • McalCdd\Wdg\inc\Wdg4.h

3. 应用程序接口

3.1 类型

3.1.1 导入类型

ModuleHeader FileImported Type
Std_TypesStd_Types.hStd_ReturnType
Std_TypesStd_Types.hStd_VersionInfoType
Rte_TypeRte_Type.hDem_EventIdType
Rte_TypeRte_Type.hDem_EventStatusType
WdgIfWdgIf_Types.hWdgIf_ModeType

3.1.2 类型定义

Wdg_ApiIdType
NameWdg_ApiIdTypeAnalysis
TypeEnumeration
Element0x00 WDG_INIT_API_IDAPI Id of Wdg_Init
0x01 WDG_SETMODE_API_IDAPI Id of Wdg_SetMode
0x02 WDG_SETTRIGGERCONDITION_API_IDAPI Id of Wdg_SetTriggerCondition
0x03 WDG_GETVERSION_API_IDAPI Id of Wdg_GetVersionInfo
DescriptionWDG ApiId Enumeration
Available viaWdg_Prv.h
Wdg_ErrIdType
NameWdg_ErrIdTypeAnalysis
TypeEnumeration
Element0x10 WDG_E_DRIVER_STATEError ID of wrong driver state
0x11 WDG_E_PARAM_MODEError ID of wrong mode
0x12 WDG_E_PARAM_CONFIGError ID of wrong config
0x13 WDG_E_PARAM_TIMEOUTError ID of wrong timeout
0x14 WDG_E_PARAM_POINTERError ID of wrong pointer
0x15 WDG_E_INIT_FAILEDError ID of init failed
DescriptionWDG ErrId Enumeration
Available viaWdg_Prv.h
Wdg_StateType
NameWdg_StateType
TypeEnumeration
Element0x01 WDG_UNINIT(The wdg’s state is uninitialized)
0x02 WDG_IDLE(The wdg’s state is idle)
0x03 WDG_BUSY(The wdg’s state is busy)
DescriptionWDG State Enumeration
Available viaWdg_Prv.h
Wdg_ModeType
NameWdg_ModeTypeAnalysis
TypeStructure
Elementuint32 Wdg_GptPeriodTimeout period of GPT used by WDG
const Wdg_Lld_ConfigType * Wdg_Lld_ConfigPtrPointer to WDG Low-Level Driver Config
DescriptionWDG Mode Structure
Available viaWdg_Prv.h
Wdg_ConfigType
NameWdg_ConfigTypeAnalysis
TypeStructure
ElementWdg_Lld_InstanceType Wdg_InstanceIdWDG’s instance id
WdgIf_ModeType Wdg_DefaultModeSettingWDG’s default mode setting
const Wdg_ModeType Wdg_ModeSettingsWDG Specific mode settings
Gpt_ChannelType Wdg_GptChannelChannel of GPT used by WDG
uint32 Wdg_GptFreqFrequency of GPT used by WDG
DescriptionWDG Configuration Structure
Available viaWdg_Prv.h

3.2 函数定义

3.2.1 Wdgx_Init

Service NameWdgx_Init
Syntaxvoid Wdgx_Init(const Wdg_ConfigType *ConfigPtr)
Sync/AsyncSynchronous
ReentrancyNon Reentrant
Parameters (in)ConfigPtr:Pointer to configuration set
Parameters (inout)None
Parameters (out)None
Return valueNone
DescriptionInitializes the module
Available viaWdgx.h

3.2.2 Wdgx_SetMode

Service NameWdgx_SetMode
SyntaxStd_ReturnType Wdgx_SetMode(WdgIf_ModeType Mode)
Sync/AsyncSynchronous
ReentrancyNon Reentrant
Parameters (in)Mode:WDGIF_OFF_MODE/WDGIF_SLOW_MODE/WDGIF_FAST_MODE
Parameters (inout)None
Parameters (out)None
Return valueStd_ReturnType
DescriptionSwitches the Watchdog into the mode Mode.
Available viaWdgx.h

3.2.3 Wdgx_SetTriggerCondition

Service NameWdgx_SetTriggerCondition
Syntaxvoid Wdgx_SetTriggerCondition(uint16 timeout)
Sync/AsyncSynchronous
ReentrancyNon Reentrant
Parameters (in)Timeout:Timeout value (milliseconds) for setting the trigger counter.
Parameters (inout)None
Parameters (out)None
Return valueNone
DescriptionSets the timeout value for the trigger counter.
Available viaWdgx.h

3.2.4 Wdgx_GetVersionInfo

Service NameWdgx_GetVersionInfo
Syntaxvoid Wdgx_GetVersionInfo(Std_VersionInfoType *VersionInfoPtr)
Sync/AsyncSynchronous
ReentrancyReentrant
Parameters (in)None
Parameters (inout)None
Parameters (out)VersionInfoPtr:Pointer to where to store the version information of this module.
Return valueNone
DescriptionReturns the version information of the module.
Available viaWdgx.h

3.3 中断处理

ISR NameHardware Interrupt Vector
Wdg_Ins0IntIsr71
Wdg_Ins0RstIsr72
Wdg_Ins1IntIsr73
Wdg_Ins1RstIsr74
Wdg_Ins2IntIsr75
Wdg_Ins2RstIsr76
ISR NameHardware Interrupt Vector
Wdg_Ins0IntIsr93
Wdg_Ins0RstIsr94
Wdg_Ins1IntIsr95
Wdg_Ins1RstIsr96
Wdg_Ins2IntIsr97
Wdg_Ins2RstIsr98
Wdg_Ins3IntIsr99
Wdg_Ins3RstIsr100
Wdg_Ins4IntIsr101
Wdg_Ins4RstIsr102

3.4 临界区

使用SchM_Enter_Wdg_ExclusiveZone_XXSchM_Exit_Wdg_ExclusiveZone_XX来定义进入和退出临界区的操作,WDG 驱动程序需要用户结合实际应用部署情况来处理临界区,其函数已在驱动中调用。

保护Wdg_LastMode:

  • SchM_Enter_Wdg_ExclusiveZone_00
  • SchM_Exit_Wdg_ExclusiveZone_00

保护Wdg_CurrMode:

  • SchM_Enter_Wdg_ExclusiveZone_01
  • SchM_Exit_Wdg_ExclusiveZone_01

保护Wdg_State:

  • SchM_Enter_Wdg_ExclusiveZone_02
  • SchM_Exit_Wdg_ExclusiveZone_02

保护Wdg_GptPeriod:

  • SchM_Enter_Wdg_ExclusiveZone_03
  • SchM_Exit_Wdg_ExclusiveZone_03

保护Wdg_Timeout:

  • SchM_Enter_Wdg_ExclusiveZone_04
  • SchM_Exit_Wdg_ExclusiveZone_04

保护Wdg_PausePtr:

  • SchM_Enter_Wdg_ExclusiveZone_05
  • SchM_Exit_Wdg_ExclusiveZone_05

保护Wdg_Lld_Rst:

  • SchM_Enter_Wdg_ExclusiveZone_06
  • SchM_Exit_Wdg_ExclusiveZone_06

4. Acore 看门狗超时 MCU 处理流程

4.1 复位配置使能

在 Target 的 main.c 调用 Wdg_Enable_RstConfig()(实现见 Wdg_Common.c,声明见 Wdg_Prv.h),完成看门狗侧与 MCU 复位/通知链路相关的底层使能。

NameDescription
Wdg_Enable_RstConfig复位配置

4.2 MCU 侧处理流程

Acore 侧看门狗超时触发中断送到 MCU0侧,由 MCU0侧在延时后发起复位,以便 Acore 打印栈等信息。

流程为 中断置标志 → 专用任务里延时 → 触发长复位,执行长复位的责任在 OS 任务。

NameLocationDescription
中断(入口)Target...\HorizonISR.c:ISR(Wdt_CfIntIsr)置 g_need_reset = 1(g_need_reset 在 McalCdd\Wdg\src\Wdg_Common.c),Os_Disable_Wdt_CfIntIsr();与 IntRouter、ConfigInterrupts.h 绑定
OS 任务(延时 + 长复位)Target...\HorizonTask.c:TASK(OsTask_SysCore_WDG_RST)g_need_reset 为真时:日志 → vTaskDelay(MS_TO_TICK(5000))(约 5s)→ Rfchm_TriggerSocLongReset() 执行 SoC 长复位