Skip to main content

7.5.17 MCU Watchdog

1. Introduction

This user document provides information about the WDG driver, including features, configuration parameters, and APIs. Wherever Wdgx is mentioned in this document, x is an index with a valid range of 0, 1, and 2.

This user document provides information about the WDG driver, including features, configuration parameters, and APIs. Wherever Wdgx is mentioned in this document, x is an index with a valid range of 0, 1, 2, 3, and 4.

2. Overview

2.1 File List

Low-Level Interface

These are the Watchdog low-level driver implementation and internal common interface files. General users do not need to focus on them directly:

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

High-Level Interface

These are the API implementation files for user calls. Each Wdg instance requires a separate code file:

  • 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

These are the API implementation files for user calls. Each Wdg instance requires a separate code file:

  • 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. Application Programming Interface

3.1 Types

3.1.1 Imported Types

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 Type Definitions

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 Function Definitions

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 Interrupt Handling

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 Critical Sections

Use SchM_Enter_Wdg_ExclusiveZone_XX and SchM_Exit_Wdg_ExclusiveZone_XX to define operations for entering and exiting critical sections. The WDG driver requires users to handle critical sections according to their actual application deployment. These functions are already called in the driver.

Protects Wdg_LastMode:

  • SchM_Enter_Wdg_ExclusiveZone_00
  • SchM_Exit_Wdg_ExclusiveZone_00

Protects Wdg_CurrMode:

  • SchM_Enter_Wdg_ExclusiveZone_01
  • SchM_Exit_Wdg_ExclusiveZone_01

Protects Wdg_State:

  • SchM_Enter_Wdg_ExclusiveZone_02
  • SchM_Exit_Wdg_ExclusiveZone_02

Protects Wdg_GptPeriod:

  • SchM_Enter_Wdg_ExclusiveZone_03
  • SchM_Exit_Wdg_ExclusiveZone_03

Protects Wdg_Timeout:

  • SchM_Enter_Wdg_ExclusiveZone_04
  • SchM_Exit_Wdg_ExclusiveZone_04

Protects Wdg_PausePtr:

  • SchM_Enter_Wdg_ExclusiveZone_05
  • SchM_Exit_Wdg_ExclusiveZone_05

Protects Wdg_Lld_Rst:

  • SchM_Enter_Wdg_ExclusiveZone_06
  • SchM_Exit_Wdg_ExclusiveZone_06

4. A-Core Watchdog Timeout MCU Handling Flow

4.1 Reset Configuration Enable

Call Wdg_Enable_RstConfig() in Target's main.c (implementation in Wdg_Common.c, declaration in Wdg_Prv.h) to complete the low-level enablement related to the watchdog-side and MCU reset/notification link.

NameDescription
Wdg_Enable_RstConfigReset configuration

4.2 MCU-Side Handling Flow

When the A-core watchdog times out, an interrupt is sent to MCU0. MCU0 then initiates a reset after a delay so that the A-core can print stack and other information.

The flow is: interrupt sets flag → dedicated task delays → trigger long reset. The responsibility for executing the long reset lies with the OS task.

NameLocationDescription
Interrupt (entry)Target...\HorizonISR.c: ISR(Wdt_CfIntIsr)Set g_need_reset = 1 (g_need_reset is in McalCdd\Wdg\src\Wdg_Common.c), Os_Disable_Wdt_CfIntIsr(); bound to IntRouter and ConfigInterrupts.h
OS task (delay + long reset)Target...\HorizonTask.c: TASK(OsTask_SysCore_WDG_RST)When g_need_reset is true: log → vTaskDelay(MS_TO_TICK(5000)) (approx. 5s) → Rfchm_TriggerSocLongReset() executes SoC long reset