S32DS的SDK中提供了Wdg,是属于MCAL层的,配置有点复杂,还需要以来Gpt、Mcu和Platform框架里的东西,配置到已经开发好的工程中还容易出现配置问题。本文主要讲解Software Watchdog Timer (SWT)的软件看门狗配置和使用示例,这个看门狗属于Drivers层的,配置和使用很简单,也无需额外以来其他组件。
示例Demo工程,极限喂狗时间设置为2秒,操作模式设置为喂狗超时就重启。另一种操作模式是中断通知,需要依赖中断组件,不是本次描述重点。
Software Watchdog Timer (SWT)组件添加如下图所示:
为了方便查看,在代码中引入RTT日志打印的代码。
?
测试代码如下:
?
/*==================================================================================================
* Project : RTD AUTOSAR 4.4
* Platform : CORTEXM
* Peripheral : S32K3XX
* Dependencies : none
*
* Autosar Version : 4.4.0
* Autosar Revision : ASR_REL_4_4_REV_0000
* Autosar Conf.Variant :
* SW Version : 2.0.1
* Build Version : S32K3_RTD_2_0_1_D2207_ASR_REL_4_4_REV_0000_20220707
*
* (c) Copyright 2020 - 2021 NXP Semiconductors
* All Rights Reserved.
*
* NXP Confidential. This software is owned or controlled by NXP and may only be
* used strictly in accordance with the applicable license terms. By expressly
* accepting such terms or by downloading, installing, activating and/or otherwise
* using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms. If you do not agree to be
* bound by the applicable license terms, then you may not retain, install,
* activate or otherwise use the software.
==================================================================================================*/
/**
* @file main.c
*
* @addtogroup main_module main module documentation
* @{
*/
/* Including necessary configuration files. */
#include "Clock_Ip.h"
#include "Swt_Ip_BOARD_InitPeripherals_PBcfg.h"
#include "Swt_Ip.h"
volatile int exit_code = 0;
/* User includes */
#include "SEGGER_RTT_Conf.h"
#include "SEGGER_RTT.h"
#define SWT_INST 0U
void delay(uint32 timeout)
{
volatile uint32 i = timeout;
while(i--);
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your code here */
SEGGER_RTT_printf(0,"Clock_Ip_InitClock ... \n");
Clock_Ip_InitClock(&Clock_Ip_aClockConfig[0]);
/*Initialize SWT */
SEGGER_RTT_printf(0,"Swt_Ip_Init ... \n");
Swt_Ip_Init(SWT_INST, &Swt_Ip_Cfg0);
for(;;)
{
SEGGER_RTT_printf(0,"Swt_Ip_Service ... \n");
Swt_Ip_Service(SWT_INST);
delay(1*16000000U);
}
for(;;)
{
if(exit_code != 0)
{
break;
}
}
return exit_code;
}
/** @} */
?极限喂狗时间设置为2秒,我们一秒左右喂狗一次的效果如图
我们3秒左右喂狗一次的效果如下:
因为3秒喂狗,已经超过了极限喂狗时间,所以程序反复重启。
综上所述,已经到了我们使用和验证软件看门狗的目的了。