23.1 片上看门狗规格23.1.1 看门狗时钟看门狗模块有以下几个可选的时钟源 •内部低功耗振荡器(LPO_CLK) •内部低速IRC时钟(SIRC) •系统振荡器时钟(SOSC) •总线时钟 注意:对于安全应用,WDOG应该在不同于CMU的时钟上运行。WDOG_CNT重置读取值可以根据时间戳而变化,因为它是一个默认运行计数器。23.1.2看门狗低功耗模式此表显示wdog低功耗模式和相应的芯片低功耗模式。此设备不支持等待模式。有关可用电源模式的详细信息,请参阅可用低功耗模式中的模块操作。23.1.3默认的看门狗超时超时取决于看门狗时钟源计数器。在该看门狗上的初始电源被lpo128k_CLK时钟锁定后,将在1024个周期后发出超时。这将导致在大约8 ms之后生成看门狗超时,这将迫使MCU重新安装。为了避免这种情况,请确保在1024周期过去之前配置或刷新该看门狗。 23.2 介绍 看门狗定时器模块是一个可供系统使用独立的定时器。它提供了一个安全特性,以确保软件按计划执行,并且CPU不会卡在无限循环中或执行意外的代码。如果在一定时间内没有执行(刷新)wdog模块,它会复位MCU。23.2.1 特征WDOG模块的功能包括:•独立于总线时钟的可配置时钟源输入 •总线时钟 •LPO时钟 •INTCLK(内部时钟) •ERCLK(外部参考时钟)•可编程超时时间 •可编程16位超时值 •当需要更长的超时周期时,可选固定256时钟预分频器•用于计数器刷新写入序列 •刷新写入0xA602然后写入0xB480的顺序•可选窗口模式选项 •可编程16位窗口值总线•提供可靠的检查,确保程序流程快于预期 •提前刷新尝试会触发复位。•可选的超时中断,允许进行后处理诊断•具有中断向量的CPU对中断服务程序(ISR)的中断请求 •中断向量提取后,强制复位发生128个总线时钟。•配置位在复位后进行一次写入,以确保不会错误地更改看门狗配置。•强大的写序列,用于解锁一次写入配置位 •解锁写入0xC520和0xD928的序列,以允许更新一次写入配置位•软件必须在解锁后和WDOG关闭解锁窗口之前的128个总线时钟内进行更新。 23.2.2 方框图下图显示了WDOG模块的框图。23.5应用23.5.1 禁用看门狗要看门狗,首先执行解锁序列,然后取消wdogcs[en]位。下面的代码片段显示了32位写入的示例。DisableInterrupts; // disable global interrupt
WDOG_CNT = 0xD928C520; //unlockwatchdog
WDOG_CS &= ~WDOG_CS_EN_MASK; //disable watchdog
EnableInterrupts; //enable globalinterrupt
23.5.2 复位后禁用看门狗所有的看门狗寄存器都通过复位解除锁定。因此,解锁序列是不必要的,但它需要写所有的看门狗寄存器,使新的配置生效。下面的代码片段显示了复位后禁用看门狗的示例。
DisableInterrupts; //disable global interrupt
WDOG_CS &= ~WDOG_CS_EN_MASK; // disable watchdog
WDOG_TOVAL= 0xFFFF;
while(WDOG_CS[ULK]); // waitingfor lock
while(~WDOG_CS[RCS]); // waiting fornew configuration to take effect
EnableInterrupts; // enable globalinterrupt
23.5.3 配置看门狗通过设置wdogcs[UPDATE]=0可以对看门狗进行一次配置。在此之后,该看门狗在重新配置之前无法重新配置。如果在配置该看门狗时设置了wdogcs[update]=1,则可以在不强制重新配置的情况下重新配置该看门狗。下面的示例代码演示了如何在没有窗口模式的情况下配置该看门狗,时钟源为lpo、启用中断和超时值为256 clock。下面的代码段显示了32位写入的示例。
Configure onceDisableInterrupts; // disable global interrupt
WDOG_CNT = 0xD928C520; //unlock watchdog
while(WDOG_CS[ULK]==0); //wait untilregisters are unlocked
WDOG_TOVAL = 256; //set timeout value
WDOG_CS = WDOG_CS_EN(1) | WDOG_CS_CLK(1)| WDOG_CS_INT(1) |
WDOG_CS_WIN(0) | WDOG_CS_UPDATE(0);
while(WDOG_CS[RCS]==0); //wait until new configuration takes effect
EnableInterrupts; //enable global interrupt
Configure forreconfigurableDisableInterrupts; //disable global interrupt
WDOG_CNT = 0xD928C520; //unlock watchdog
while(WDOG_CS[ULK]==0); //wait until registers are unlocked
WDOG_TOVAL = 256; //set timeout value
WDOG_CS = WDOG_CS_EN(1) | WDOG_CS_CLK(1)| WDOG_CS_INT(1) |
WDOG_CS_WIN(0) | WDOG_CS_UPDATE(1);
while(WDOG_CS[RCS]==0); //wait until new configuration takeseffect
EnableInterrupts; //enable global interrupt
23.5.4 刷新看门狗若要刷新看门狗并将看门狗计数器重置为零,则需要刷新序列。下面的代码片段显示了32位写入的示例。
DisableInterrupts; // disable globalinterrupt
WDOG_CNT = 0xB480A602; // refresh watchdog
EnableInterrupts; // enable global interrupt
/*** @file Wdg_PBCfg.c
* @version 1.0.0
* @brief AUTOSAR Wdg - contains the data exported by the watchodg module
* @details Contains the information that will be exported by the module, as requested by Autosar.
*
* @addtogroup Wdg
* @{
*/
/*==================================================================================================
* Project : AUTOSAR 4.2 MCAL
* Platform : ARM
* Peripheral : Wdog
* Dependencies : none
*
* Autosar Version : 4.2.2
* Autosar Revision : ASR_REL_4_2_REV_0002
* Autosar Conf.Variant :
* SW Version : 1.0.0
* Build Version : S32K14x_MCAL_1_0_0_RTM_ASR_REL_4_2_REV_0002_20170824
*
* (c) Copyright 2006-2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
* All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/
#ifdef __cplusplus
extern "C"{
#endif
/**
* @page misra_violations MISRA-C:2004 violations
*
* @section Wdg_PBcfg_c_REF_1
* Violates MISRA 2004 Required Rule 19.15, Precautions shall be taken in order to
* prevent the contents of a header file being included twice. All header files are
* protected against multiple inclusions.
*
* @section Wdg_PBcfg_c_REF_2
* Violates MISRA 2004 Required Rule 1.4, The compiler/linker shall be checked to ensure
* that 31 character significance and case sensitivity are supported for external identifiers.
* The defines are validated.
*
* @section Wdg_PBcfg_c_REF_3
* Violates MISRA 2004 Required Rule 8.10, All declarations and definitions of objects or
* functions at file scope shall have internal linkage unless external linkage is required.
* The functions/variables are part of external configuration
*
* @section Wdg_PBcfg_c_REF_4
* Violates MISRA 2004 Advisory Rule 19.1, only preprocessor statements
* and comments before '#include'. This is an Autosar requirement about
* the memory management (Autosar requirement MEMMAP003).
* @section [global]
* Violates MISRA 2004 Required Rule 5.1, Identifiers (internal and external) shall not rely
* on the significance of more than 31 characters. The used compilers use more than 31 chars
* for identifiers.
*/
/*==================================================================================================
* INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
/**
* @file Wdg_PBCfg.c
*/
#include "Wdg_Channel.h"
#if (WDG_TYPE == WDG_INTERNAL_MODULE)
#include "Reg_eSys_Wdog_defines.h"
#endif
#if (WDG_INSTANCE0 == STD_ON)
/*==================================================================================================
* SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @file Wdg_PBCfg.c
*/
#define WDG_VENDOR_ID_PBCFG_C 43
#define WDG_AR_RELEASE_MAJOR_VERSION_PBCFG_C 4
#define WDG_AR_RELEASE_MINOR_VERSION_PBCFG_C 2
/** @violates @ref Wdg_PBcfg_c_REF_2 MISRA 2004 Rule 1.4, The compiler/linker shall be checked to ensure
* that 31 character significance and case sensitivity are supported for external identifiers. */
#define WDG_AR_RELEASE_REVISION_VERSION_PBCFG_C 2
#define WDG_SW_MAJOR_VERSION_PBCFG_C 1
#define WDG_SW_MINOR_VERSION_PBCFG_C 0
#define WDG_SW_PATCH_VERSION_PBCFG_C 0
/*==================================================================================================
* FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Wdg header file are of the same vendor */
#if (WDG_VENDOR_ID_PBCFG_C != WDG_CHANNEL_VENDOR_ID)
#error "Wdg_PBCfg.c and Wdg_Channel.h have different vendor ids"
#endif
/* Check if source file and Wdg header file are of the same Autosar version */
#if ((WDG_AR_RELEASE_MAJOR_VERSION_PBCFG_C != WDG_CHANNEL_AR_RELEASE_MAJOR_VERSION) ||
(WDG_AR_RELEASE_MINOR_VERSION_PBCFG_C != WDG_CHANNEL_AR_RELEASE_MINOR_VERSION) ||
(WDG_AR_RELEASE_REVISION_VERSION_PBCFG_C != WDG_CHANNEL_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Wdg_PBCfg.c and Wdg_Channel.h are different"
#endif
/* Check if source file and Wdg header file are of the same Software version */
#if ((WDG_SW_MAJOR_VERSION_PBCFG_C != WDG_CHANNEL_SW_MAJOR_VERSION) ||
(WDG_SW_MINOR_VERSION_PBCFG_C != WDG_CHANNEL_SW_MINOR_VERSION) ||
(WDG_SW_PATCH_VERSION_PBCFG_C != WDG_CHANNEL_SW_PATCH_VERSION))
#error "Software Version Numbers of Wdg_PBCfg.c and Wdg_Channel.h are different"
#endif
#if (WDG_TYPE == WDG_INTERNAL_MODULE)
/* Check if source file and Reg_eSys_Wdog_defines header file are of the same vendor */
#if (WDG_VENDOR_ID_PBCFG_C != REG_ESYS_WDOG_DEFINES_VENDOR_ID)
#error "Wdg_PBCfg.c and Reg_eSys_Wdog_defines.h have different vendor ids"
#endif
/* Check if source file and Reg_eSys_Wdog_defines header file are of the same Autosar version */
#if ((WDG_AR_RELEASE_MAJOR_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_AR_RELEASE_MAJOR_VERSION) ||
(WDG_AR_RELEASE_MINOR_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_AR_RELEASE_MINOR_VERSION) ||
(WDG_AR_RELEASE_REVISION_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Wdg_PBCfg.c and Reg_eSys_Wdog_defines.h are different"
#endif
/* Check if source file and Reg_eSys_Wdog_defines header file are of the same Software version */
#if ((WDG_SW_MAJOR_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_SW_MAJOR_VERSION) ||
(WDG_SW_MINOR_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_SW_MINOR_VERSION) ||
(WDG_SW_PATCH_VERSION_PBCFG_C != REG_ESYS_WDOG_DEFINES_SW_PATCH_VERSION))
#error "Software Version Numbers of Wdg_PBCfg.c and Reg_eSys_Wdog_defines.h are different"
#endif
#endif
/*==================================================================================================
* LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/
/*==================================================================================================
* LOCAL MACROS
==================================================================================================*/
/*==================================================================================================
* LOCAL CONSTANTS
==================================================================================================*/
/*==================================================================================================
* LOCAL VARIABLES
==================================================================================================*/
/*==================================================================================================
* GLOBAL FUNCTIONS
==================================================================================================*/
#define WDG_START_SEC_CODE
/**
* @brief Include Memory mapping specification
* @violates @ref Wdg_PBcfg_c_REF_1 MISRA 2004 Required Rule 19.15, precautions to prevent the contents
* of a header file being included twice
* @violates @ref Wdg_PBcfg_c_REF_4 MISRA 2004 Required Rule 19.1, only preprocessor statements
* and comments before '#include'
*/
#include "Wdg_MemMap.h"
/**
* @brief External Notifications for Wdg Interrupt
*/
extern FUNC (void, WDG_CODE) WdgExpire_Callback(void);
#define WDG_STOP_SEC_CODE
/**
* @brief Include Memory mapping specification
* @violates @ref Wdg_PBcfg_c_REF_1 MISRA 2004 Required Rule 19.15, precautions to prevent the contents
* of a header file being included twice
* @violates @ref Wdg_PBcfg_c_REF_4 MISRA 2004 Required Rule 19.1, only preprocessor statements
* and comments before '#include'
*/
#include "Wdg_MemMap.h"
/*==================================================================================================
* GLOBAL CONSTANTS
==================================================================================================*/
#define WDG_START_SEC_CONFIG_DATA_UNSPECIFIED
/**
* @brief Include Memory mapping specification
* @violates @ref Wdg_PBcfg_c_REF_1 MISRA 2004 Required Rule 19.15, precautions to prevent the contents
* of a header file being included twice
* @violates @ref Wdg_PBcfg_c_REF_4 MISRA 2004 Required Rule 19.1, only preprocessor statements
* and comments before '#include'
*/
#include "Wdg_MemMap.h"
/** @violates @ref Wdg_PBcfg_c_REF_3 MISRA 2004 Required Rule 8.10, All declarations and definitions of objects or
* functions at file scope shall have internal linkage unless external linkage is required.
*/
/** @violates @ref Wdg_PBcfg_c_REF_2 MISRA 2004 Rule 1.4, The compiler/linker shall be checked to ensure
* that 31 character significance and case sensitivity are supported for external identifiers. */
CONST(Wdg_Wdog_ConfigType, WDG_CONST) Wdg_Wdog_OffModeSettings_Instance0=
{
(uint32)( WDOG_DISABLED_U32 | WDOG_RESERVED_BIT13_U32 |WDOG_UPDATE_ENABLED_U32), /* WDG Control and configuration */
(uint32)0x00000100, /* Timeout config */
(uint32)0x00000000, /* Window config */
(boolean)FALSE,
(uint32) 0x00000001 /* Internalwdgclocksource */
};
/** @violates @ref Wdg_PBcfg_c_REF_3 MISRA 2004 Required Rule 8.10, All declarations and definitions of objects or
* functions at file scope shall have internal linkage unless external linkage is required.
*/
/** @violates @ref Wdg_PBcfg_c_REF_2 MISRA 2004 Rule 1.4, The compiler/linker shall be checked to ensure
* that 31 character significance and case sensitivity are supported for external identifiers. */
CONST(Wdg_Wdog_ConfigType, WDG_CONST) Wdg_Wdog_SlowModeSettings_0=
{
(uint32)( WDOG_ENABLED_U32 | WDOG_RESERVED_BIT13_U32 | WDOG_TRIGGER_MODE_REGULAR_U32 | WDOG_RUN_IN_HALT_U32 | WDOG_RUN_IN_DEBUG_U32 | WDOG_RUN_IN_WAIT_U32 | WDOG_INTERRUPT_ENABLED_U32 | WDOG_LPO_CLK_U32 | WDOG_USER_MODE_ENABLED_U32 | WDOG_PRES_ENABLED_U32 | WDOG_UPDATE_ENABLED_U32
), /* WDG Control and configuration */
(uint32)0x0007d000, /* Time-out config */
(uint32)0x00032000, /* Window config */
(boolean)TRUE,
(uint32)128 /* Internalwdgclocksource */
};
/** @violates @ref Wdg_PBcfg_c_REF_3 MISRA 2004 Required Rule 8.10, All declarations and definitions of objects or
* functions at file scope shall have internal linkage unless external linkage is required.
*/
/** @violates @ref Wdg_PBcfg_c_REF_2 MISRA 2004 Rule 1.4, The compiler/linker shall be checked to ensure
* that 31 character significance and case sensitivity are supported for external identifiers. */
CONST(Wdg_Wdog_ConfigType, WDG_CONST) Wdg_Wdog_FastModeSettings_0=
{
(uint32)( WDOG_ENABLED_U32 | WDOG_RESERVED_BIT13_U32 | WDOG_TRIGGER_MODE_REGULAR_U32 | WDOG_RUN_IN_HALT_U32 | WDOG_RUN_IN_DEBUG_U32 | WDOG_RUN_IN_WAIT_U32 | WDOG_INTERRUPT_ENABLED_U32 | WDOG_SIRC_CLK_U32 | WDOG_TEST_MODE_DISABLED_U32 | WDOG_PRES_ENABLED_U32 | WDOG_UPDATE_ENABLED_U32
), /* WDG Control and configuration */
(uint32)0x000c3500, /* Time-out config */
(uint32)0x0004e200, /* Window config */
(boolean)TRUE,
(uint32)8000 /* Internalwdgclocksource */
};
/**
* @brief This constant contains the configuration set for the postbuild time
*/
/** @violates @ref Wdg_PBcfg_c_REF_3 MISRA 2004 Required Rule 8.10, All declarations and definitions of objects or
* functions at file scope shall have internal linkage unless external linkage is required. */
CONST(Wdg_ConfigType, WDG_CONST)WdgSettingsConfig =
{
WDGIF_OFF_MODE,
WDG_IPW_INSTANCE0,
(Gpt_ChannelType)GptConf_GptChannelConfiguration_GptChannelConfiguration_WdgTrig,
(uint32)4000,
{ &Wdg_Wdog_OffModeSettings_Instance0, &Wdg_Wdog_SlowModeSettings_0, &Wdg_Wdog_FastModeSettings_0},
&WdgExpire_Callback /* WdgCallbackNotification */
};
#define WDG_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/**
* @brief Include Memory mapping specification
* @violates @ref Wdg_PBcfg_c_REF_1 MISRA 2004 Required Rule 19.15, precautions to prevent the contents
* of a header file being included twice
* @violates @ref Wdg_PBcfg_c_REF_4 MISRA 2004 Required Rule 19.1, only preprocessor statements
* and comments before '#include'
*/
#include "Wdg_MemMap.h"
/*==================================================================================================
* GLOBAL VARIABLES
==================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTIONS
==================================================================================================*/
#endif /* #if WDG_INSTANCE0 == STD_ON*/
#ifdef __cplusplus
}
#endif
/** @} */