From d512b49a6a744c00aa8db816ef0e46de5ddec514 Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Mon, 11 Aug 2025 18:02:00 +0800 Subject: [PATCH] Add watchdog --- .../board/ch569w/third_party_driver/Kconfig | 4 ++ .../board/ch569w/third_party_driver/Makefile | 4 ++ .../spi/connect_spi_flash.c | 2 +- .../ch569w/third_party_driver/wdt/Makefile | 3 + .../third_party_driver/wdt/connect_wdt.c | 71 +++++++++++++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/Makefile create mode 100644 Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/connect_wdt.c diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig index 927598866..ccc8dac9c 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Kconfig @@ -12,3 +12,7 @@ menuconfig BSP_USING_SPI if BSP_USING_SPI source "$BSP_DIR/third_party_driver/spi/Kconfig" endif + +menuconfig BSP_USING_WDT + bool "Using watchdog timer device" + default y diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile index 035498017..b4644627d 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/Makefile @@ -10,4 +10,8 @@ ifeq ($(CONFIG_BSP_USING_SPI),y) SRC_DIR += spi endif +ifeq ($(CONFIG_BSP_USING_WDT),y) + SRC_DIR += wdt +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/spi/connect_spi_flash.c b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/spi/connect_spi_flash.c index 7378911a2..e2babe5e1 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/spi/connect_spi_flash.c +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/spi/connect_spi_flash.c @@ -461,4 +461,4 @@ int SpiFlashTest(int argc, char *argv[]) } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), - test_spi, SpiFlashTest, test spi); + SpiFlashTest, SpiFlashTest, test spi); diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/Makefile b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/Makefile new file mode 100644 index 000000000..9be59f003 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := connect_wdt.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/connect_wdt.c b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/connect_wdt.c new file mode 100644 index 000000000..29d1056c5 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/wdt/connect_wdt.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan + * PSL v2. You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY + * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the + * Mulan PSL v2 for more details. + */ + +/** + * @file connect_usart.c + * @brief support ch569 uart function and register to bus framework + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2025-04-07 + */ + +#include "CH56x_common.h" +#include "xizi.h" +#include "board.h" +#include "shell.h" + +#define WDOG_MSECOND_MAX ( (0xff << 19) / (FREQ_SYS / 1000) ) // watchdog timer is clocked at Fsys/524288, arround 3~228Hz +int g_feed_wdt_stop = 0; + +int InitHwWdt(void) +{ + KPrintf("InitHwWdt WDOG_MSECOND_MAX is %d ms\n", WDOG_MSECOND_MAX); + + WWDG_SetCounter(0); + WWDG_ClearFlag(); + WWDG_ResetCfg(ENABLE); + while(1) { + WWDG_SetCounter(0); + //mDelaymS(100); + if (g_feed_wdt_stop == 1) { + KPrintf("%s watchdog feed stop!\n", __func__); + break; + } + } + + return 0; +} + +/** + * @description: Watchdog function + * @return success: EOK, failure: other + */ +int StartWatchdog(void) +{ + int ret = EOK; + + int32 WdtTask = KTaskCreate("WdtTask", (void *)InitHwWdt, NONE, 1024, 19); + StartupKTask(WdtTask); + + return EOK; +} + +int WdtTest(int argc, char *argv[]) +{ + KPrintf("WdtTest Start\n"); + g_feed_wdt_stop = 1; + + return 0; +} + +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + WdtTest, WdtTest, test wdt);