配置操作
在一个component下面可以创建多个看门狗,一般会有个限制,就是不能创建多个
看门狗比较简单,在configurations list里面新建软件看门狗,配置里面的名字、超时时间等配置即可。
代码对应
生成的代码在watchdog1.c和 watchdog1.h里面。
watchdog1是一个components,在watchdog1.h里面定义。
/*! @brief Device instance number */
#define INST_WATCHDOG1 0U
两个看门狗watchdog1_Config0和watchdog1_Config1在watchdog1.h里面声明,watchdog1.c里面定义。
/*! watchdog1 configuration structures */
const wdog_user_config_t watchdog1_Config0 = {
.clkSource = WDOG_LPO_CLOCK, /* WDOG clock source *///时钟源
.opMode = {
false, /* Wait Mode *///等待模式
false, /* Stop Mode *///停止模式
false /* Debug Mode *///调试模式
},
.updateEnable = true, /* Enable/Disable further updates of the WDOG configuration *///更新使能
.intEnable = false, /* Timeout interrupt disabled *///中断使能
.winEnable = false, /* Enable/Disable Window mode *///窗口模式
.windowValue = 0U, /* Window value *///窗口数值
.timeoutValue = 3000U, /* Timeout value *///超时值
.prescalerEnable = true /* WDOG prescaler *///分频使能
};
const wdog_user_config_t watchdog1_Config1 = {
.clkSource = WDOG_BUS_CLOCK, /* WDOG clock source */
.opMode = {
true, /* Wait Mode */
true, /* Stop Mode */
true /* Debug Mode */
},
.updateEnable = true, /* Enable/Disable further updates of the WDOG configuration */
.intEnable = true, /* Timeout interrupt disabled */
.winEnable = true, /* Enable/Disable Window mode */
.windowValue = 0U, /* Window value */
.timeoutValue = 1000U, /* Timeout value */
.prescalerEnable = true /* WDOG prescaler */
};
/* END watchdog1. */
一般配置成watchdog1_Config0那样就行,其他的基本用不到。
接口使用
WDOG_DRV_Init
初始化函数,每次只能初始化一个看门狗。譬如初始化watchdog1_Config0就调用WDOG_DRV_Init(INST_WATCHDOG1, &watchdog1_Config0);
/*FUNCTION**********************************************************************
*
* Function Name : WDOG_DRV_Init
* Description : initialize the WDOG driver
*
* Implements : WDOG_DRV_Init_Activity
*END**************************************************************************/
status_t WDOG_DRV_Init(uint32_t instance,
const wdog_user_config_t * userConfigPtr)
{
DEV_ASSERT(instance < WDOG_INSTANCE_COUNT);
DEV_ASSERT(userConfigPtr != NULL);
WDOG_Type * base = s_wdogBase[instance];
status_t status = STATUS_SUCCESS;
status_t statusClockSource = STATUS_SUCCESS;
#ifdef DEV_ERROR_DETECT
uint32_t prevClockHz, crtClockHz;
/* Check if the previous clock source and the configuration clock source
* are enabled(if not, the counter will not be incremented) */
prevClockHz = WDOG_DRV_GetClockSourceFreq(WDOG_GetClockSource(s_wdogBase[instance]));
crtClockHz = WDOG_DRV_GetClockSourceFreq(userConfigPtr->clkSource);
if ((prevClockHz == 0U) || (crtClockHz == 0U))
{
statusClockSource = STATUS_ERROR;
}
#endif
/* If clock source disabled */
if (statusClockSource == STATUS_SUCCESS)
{
/* If window mode enabled and window value greater than or equal to the timeout value. Or timeout value is 0 */
if (((userConfigPtr->winEnable) && (userConfigPtr->windowValue >= userConfigPtr->timeoutValue)) \
|| (userConfigPtr->timeoutValue <= FEATURE_WDOG_MINIMUM_TIMEOUT_VALUE))
{
status = STATUS_ERROR;
}
else
{
/* Configure the WDOG module */
status = WDOG_Config(base, userConfigPtr);
}
if (status == STATUS_SUCCESS)
{
/* enable WDOG timeout interrupt */
INT_SYS_EnableIRQ(s_wdogIrqId[instance]);
}
}
else
{
status = STATUS_ERROR;
}
return status;
}
WDOG_DRV_Deinit
反初始化,但一反初始化就是一整个component的所有看门狗。