From bfe1e72378e8578d8f2475919a1ce23bb3e0cab7 Mon Sep 17 00:00:00 2001 From: wuzheng Date: Tue, 7 Feb 2023 16:48:52 +0800 Subject: [PATCH] Format rtc and watchdog driver for hc32 --- .../third_party_driver/rtc/connect_rtc.c | 4 +-- .../third_party_driver/watchdog/connect_wdt.c | 28 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/rtc/connect_rtc.c b/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/rtc/connect_rtc.c index d47668697..a5bedccfa 100644 --- a/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/rtc/connect_rtc.c +++ b/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/rtc/connect_rtc.c @@ -174,8 +174,8 @@ int HwRtcInit(void) (void)RTC_StructInit(&stcRtcInit); /* Configuration RTC structure */ - stcRtcInit.u8ClockSrc = RTC_CLK_SRC_XTAL32; - stcRtcInit.u8HourFormat = RTC_HOUR_FMT_24H; + stcRtcInit.u8ClockSrc = RTC_CLK_SRC_XTAL32; + stcRtcInit.u8HourFormat= RTC_HOUR_FMT_24H; stcRtcInit.u8IntPeriod = RTC_INT_PERIOD_PER_SEC; (void)RTC_Init(&stcRtcInit); diff --git a/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/watchdog/connect_wdt.c b/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/watchdog/connect_wdt.c index 0ce649aaf..d0271264d 100644 --- a/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/watchdog/connect_wdt.c +++ b/Ubiquitous/XiZi_IIoT/board/hc32f4a0/third_party_driver/watchdog/connect_wdt.c @@ -27,10 +27,10 @@ static uint32 WdtOpen(void *dev) NULL_PARAM_CHECK(dev); stc_wdt_init_t stcWdtInit; - stcWdtInit.u32CountPeriod = WDT_CNT_PERIOD65536; - stcWdtInit.u32ClockDiv = WDT_CLK_DIV1024; - stcWdtInit.u32RefreshRange = WDT_RANGE_0TO25PCT; - stcWdtInit.u32LPMCount = WDT_LPM_CNT_STOP; + stcWdtInit.u32CountPeriod = WDT_CNT_PERIOD65536; + stcWdtInit.u32ClockDiv = WDT_CLK_DIV1024; + stcWdtInit.u32RefreshRange = WDT_RANGE_0TO25PCT; + stcWdtInit.u32LPMCount = WDT_LPM_CNT_STOP; stcWdtInit.u32ExceptionType = WDT_EXP_TYPE_RST; (void)WDT_Init(&stcWdtInit); return EOK; @@ -42,13 +42,25 @@ static uint32 WdtConfigure(void *drv, struct BusConfigureInfo *args) NULL_PARAM_CHECK(args); stc_wdt_init_t stcWdtInit; + + int period_option = *((int*)args->private_data); + if(period_option<=256){ + period_option = WDT_CNT_PERIOD256; + }else if(period_option<=4096){ + period_option = WDT_CNT_PERIOD4096; + }else if(period_option<=16384){ + period_option = WDT_CNT_PERIOD16384; + }else{ + period_option = WDT_CNT_PERIOD65536; + } + switch (args->configure_cmd) { case OPER_WDT_SET_TIMEOUT: - stcWdtInit.u32CountPeriod = WDT_CNT_PERIOD65536; - stcWdtInit.u32ClockDiv = WDT_CLK_DIV1024; - stcWdtInit.u32RefreshRange = WDT_RANGE_0TO25PCT; - stcWdtInit.u32LPMCount = WDT_LPM_CNT_STOP; + stcWdtInit.u32CountPeriod = period_option; + stcWdtInit.u32ClockDiv = WDT_CLK_DIV1024; + stcWdtInit.u32RefreshRange = WDT_RANGE_0TO25PCT; + stcWdtInit.u32LPMCount = WDT_LPM_CNT_STOP; stcWdtInit.u32ExceptionType = WDT_EXP_TYPE_RST; if (WDT_Init(&stcWdtInit) != 0) { return ERROR;