feat: add iwdg driver
This commit is contained in:
parent
85da2247c0
commit
d573f6f646
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-01-22 shelton first version
|
||||
* 2021-11-10 breo.com porting to n32
|
||||
*/
|
||||
|
||||
#include <board.h>
|
||||
#include <drivers/watchdog.h>
|
||||
|
||||
#ifdef RT_USING_WDT
|
||||
#ifdef BSP_USING_WDT
|
||||
|
||||
#define LSI_VALUE 40000
|
||||
|
||||
//#define DRV_DEBUG
|
||||
#define LOG_TAG "drv.wdt"
|
||||
#include <drv_log.h>
|
||||
|
||||
struct n32_wdt_obj
|
||||
{
|
||||
IWDG_Module *instance;
|
||||
rt_uint32_t Prescaler;
|
||||
rt_uint32_t Reload;
|
||||
rt_uint16_t is_start;
|
||||
};
|
||||
static struct n32_wdt_obj n32_wdt;
|
||||
static struct rt_watchdog_ops ops;
|
||||
static rt_watchdog_t watchdog;
|
||||
|
||||
static rt_err_t wdt_init(rt_watchdog_t *wdt)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
/* feed the watchdog */
|
||||
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
|
||||
IWDG_ReloadKey();
|
||||
break;
|
||||
/* set watchdog timeout */
|
||||
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
|
||||
#if defined(LSI_VALUE)
|
||||
if (LSI_VALUE)
|
||||
{
|
||||
n32_wdt.Reload = (*((rt_uint32_t *)arg)) * LSI_VALUE / 256 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Please define the value of LSI_VALUE!");
|
||||
}
|
||||
if (n32_wdt.Reload > 0xFFF)
|
||||
{
|
||||
LOG_E("wdg set timeout parameter too large, please less than %ds", 0xFFF * 256 / LSI_VALUE);
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
#else
|
||||
#error "Please define the value of LSI_VALUE!"
|
||||
#endif
|
||||
if (n32_wdt.is_start)
|
||||
{
|
||||
IWDG_WriteConfig(IWDG_WRITE_ENABLE);
|
||||
IWDG_SetPrescalerDiv(n32_wdt.Prescaler);
|
||||
IWDG_CntReload(n32_wdt.Reload);
|
||||
IWDG_WriteConfig(IWDG_WRITE_DISABLE);
|
||||
IWDG_Enable();
|
||||
}
|
||||
break;
|
||||
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
|
||||
#if defined(LSI_VALUE)
|
||||
if (LSI_VALUE)
|
||||
{
|
||||
(*((rt_uint32_t *)arg)) = n32_wdt.Reload * 256 / LSI_VALUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Please define the value of LSI_VALUE!");
|
||||
}
|
||||
#else
|
||||
#error "Please define the value of LSI_VALUE!"
|
||||
#endif
|
||||
break;
|
||||
case RT_DEVICE_CTRL_WDT_START:
|
||||
IWDG_WriteConfig(IWDG_WRITE_ENABLE);
|
||||
IWDG_SetPrescalerDiv(n32_wdt.Prescaler);
|
||||
IWDG_CntReload(n32_wdt.Reload);
|
||||
IWDG_WriteConfig(IWDG_WRITE_DISABLE);
|
||||
IWDG_Enable();
|
||||
n32_wdt.is_start = 1;
|
||||
break;
|
||||
default:
|
||||
LOG_W("This command is not supported.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
int rt_hw_wdt_init(void)
|
||||
{
|
||||
n32_wdt.instance = IWDG;
|
||||
n32_wdt.Prescaler = IWDG_PRESCALER_DIV256;
|
||||
n32_wdt.Reload = 0x00000FFF;
|
||||
n32_wdt.is_start = 0;
|
||||
|
||||
ops.init = &wdt_init;
|
||||
ops.control = &wdt_control;
|
||||
watchdog.ops = &ops;
|
||||
/* register watchdog device */
|
||||
if (rt_hw_watchdog_register(&watchdog, "wdt", RT_DEVICE_FLAG_DEACTIVATE, RT_NULL) != RT_EOK)
|
||||
{
|
||||
LOG_E("wdt device register failed.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
LOG_D("wdt device register success.");
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_wdt_init);
|
||||
|
||||
#endif /* BSP_USING_WDT */
|
||||
#endif /* RT_USING_WDT */
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
# RT-Thread Kernel
|
||||
#
|
||||
CONFIG_RT_NAME_MAX=8
|
||||
# CONFIG_RT_USING_BIG_ENDIAN is not set
|
||||
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
|
||||
# CONFIG_RT_USING_SMP is not set
|
||||
CONFIG_RT_ALIGN_SIZE=4
|
||||
|
@ -142,7 +143,7 @@ CONFIG_RT_USING_PWM=y
|
|||
# CONFIG_RT_USING_RTC is not set
|
||||
# CONFIG_RT_USING_SDIO is not set
|
||||
# CONFIG_RT_USING_SPI is not set
|
||||
# CONFIG_RT_USING_WDT is not set
|
||||
CONFIG_RT_USING_WDT=y
|
||||
# CONFIG_RT_USING_AUDIO is not set
|
||||
# CONFIG_RT_USING_SENSOR is not set
|
||||
# CONFIG_RT_USING_TOUCH is not set
|
||||
|
@ -154,6 +155,7 @@ CONFIG_RT_USING_PWM=y
|
|||
#
|
||||
# Using USB
|
||||
#
|
||||
# CONFIG_RT_USING_USB is not set
|
||||
# CONFIG_RT_USING_USB_HOST is not set
|
||||
# CONFIG_RT_USING_USB_DEVICE is not set
|
||||
|
||||
|
@ -161,10 +163,11 @@ CONFIG_RT_USING_PWM=y
|
|||
# POSIX layer and C standard library
|
||||
#
|
||||
CONFIG_RT_USING_LIBC=y
|
||||
# CONFIG_RT_USING_PTHREADS is not set
|
||||
CONFIG_RT_LIBC_USING_TIME=y
|
||||
# CONFIG_RT_LIBC_USING_FILEIO is not set
|
||||
# CONFIG_RT_USING_MODULE is not set
|
||||
CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_PTHREADS is not set
|
||||
|
||||
#
|
||||
# Network
|
||||
|
@ -201,6 +204,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
|||
# CONFIG_RT_USING_RYM is not set
|
||||
# CONFIG_RT_USING_ULOG is not set
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
|
||||
#
|
||||
|
@ -297,10 +301,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
|||
# CONFIG_PKG_USING_AGILE_FTP is not set
|
||||
# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
|
||||
# CONFIG_PKG_USING_RT_LINK_HW is not set
|
||||
# CONFIG_PKG_USING_LORA_PKT_FWD is not set
|
||||
# CONFIG_PKG_USING_LORA_GW_DRIVER_LIB is not set
|
||||
# CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set
|
||||
# CONFIG_PKG_USING_HM is not set
|
||||
|
||||
#
|
||||
# security packages
|
||||
|
@ -334,13 +334,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
|||
# CONFIG_PKG_USING_NUEMWIN is not set
|
||||
# CONFIG_PKG_USING_MP3PLAYER is not set
|
||||
# CONFIG_PKG_USING_TINYJPEG is not set
|
||||
# CONFIG_PKG_USING_UGUI is not set
|
||||
|
||||
#
|
||||
# U8G2: a monochrome graphic library
|
||||
#
|
||||
# CONFIG_PKG_USING_U8G2_OFFICIAL is not set
|
||||
# CONFIG_PKG_USING_U8G2 is not set
|
||||
|
||||
#
|
||||
# tools packages
|
||||
|
@ -449,6 +442,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
|||
# CONFIG_PKG_USING_AS7341 is not set
|
||||
# CONFIG_PKG_USING_STM32_SDIO is not set
|
||||
# CONFIG_PKG_USING_ICM20608 is not set
|
||||
# CONFIG_PKG_USING_U8G2 is not set
|
||||
# CONFIG_PKG_USING_BUTTON is not set
|
||||
# CONFIG_PKG_USING_PCF8574 is not set
|
||||
# CONFIG_PKG_USING_SX12XX is not set
|
||||
|
@ -510,8 +504,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
|||
# CONFIG_PKG_USING_MCP23008 is not set
|
||||
# CONFIG_PKG_USING_BLUETRUM_SDK is not set
|
||||
# CONFIG_PKG_USING_MISAKA_AT24CXX is not set
|
||||
# CONFIG_PKG_USING_MISAKA_RGB_BLING is not set
|
||||
# CONFIG_PKG_USING_BL_MCU_SDK is not set
|
||||
|
||||
#
|
||||
# AI packages
|
||||
|
@ -594,6 +586,7 @@ CONFIG_SOC_N32G452XX=y
|
|||
#
|
||||
CONFIG_RT_USING_GPIO=y
|
||||
# CONFIG_BSP_USING_ON_CHIP_FLASH is not set
|
||||
# CONFIG_BSP_USING_WDT is not set
|
||||
CONFIG_BSP_USING_UART=y
|
||||
CONFIG_BSP_USING_UART1=y
|
||||
# CONFIG_BSP_USING_UART2 is not set
|
||||
|
|
|
@ -26,7 +26,12 @@ menu "On-chip Peripheral Drivers"
|
|||
|
||||
config BSP_USING_ON_CHIP_FLASH
|
||||
bool "Enable on-chip FLASH"
|
||||
default n
|
||||
default n
|
||||
|
||||
config BSP_USING_WDT
|
||||
bool "Enable Watchdog Timer"
|
||||
select RT_USING_WDT
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_UART
|
||||
bool "Enable UART"
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
#define RT_SERIAL_RB_BUFSZ 64
|
||||
#define RT_USING_PIN
|
||||
#define RT_USING_PWM
|
||||
#define RT_USING_WDT
|
||||
|
||||
/* Using USB */
|
||||
|
||||
|
@ -143,9 +144,6 @@
|
|||
/* multimedia packages */
|
||||
|
||||
|
||||
/* U8G2: a monochrome graphic library */
|
||||
|
||||
|
||||
/* tools packages */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue