Browse Source

[add] 添加 RTC、WDT 驱动

Sherman 3 years ago
parent
commit
6432cf4af9

+ 8 - 2
bsp/ra6m4-cpk/.config

@@ -144,10 +144,12 @@ CONFIG_RT_USING_PIN=y
 # CONFIG_RT_USING_MTD_NOR is not set
 # CONFIG_RT_USING_MTD_NOR is not set
 # CONFIG_RT_USING_MTD_NAND is not set
 # CONFIG_RT_USING_MTD_NAND is not set
 # CONFIG_RT_USING_PM is not set
 # CONFIG_RT_USING_PM is not set
-# CONFIG_RT_USING_RTC is not set
+CONFIG_RT_USING_RTC=y
+CONFIG_RT_USING_ALARM=y
+# CONFIG_RT_USING_SOFT_RTC is not set
 # CONFIG_RT_USING_SDIO is not set
 # CONFIG_RT_USING_SDIO is not set
 # CONFIG_RT_USING_SPI 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_AUDIO is not set
 # CONFIG_RT_USING_SENSOR is not set
 # CONFIG_RT_USING_SENSOR is not set
 # CONFIG_RT_USING_TOUCH is not set
 # CONFIG_RT_USING_TOUCH is not set
@@ -587,6 +589,10 @@ CONFIG_BSP_USING_I2C=y
 CONFIG_BSP_USING_I2C1=y
 CONFIG_BSP_USING_I2C1=y
 CONFIG_BSP_I2C1_SCL_PIN=0x0512
 CONFIG_BSP_I2C1_SCL_PIN=0x0512
 CONFIG_BSP_I2C1_SDA_PIN=0x0511
 CONFIG_BSP_I2C1_SDA_PIN=0x0511
+CONFIG_BSP_USING_WDT=y
+CONFIG_BSP_USING_ONCHIP_RTC=y
+CONFIG_BSP_RTC_USING_LSE=y
+# CONFIG_BSP_RTC_USING_LSI is not set
 
 
 #
 #
 # Board extended module Drivers
 # Board extended module Drivers

+ 6 - 2
bsp/ra6m4-cpk/.settings/standalone.prefs

@@ -1,4 +1,4 @@
-#Mon Oct 18 14:30:28 CST 2021
+#Mon Oct 18 18:20:25 CST 2021
 com.renesas.cdt.ddsc.content/com.renesas.cdt.ddsc.content.defaultlinkerscript=script/fsp.scat
 com.renesas.cdt.ddsc.content/com.renesas.cdt.ddsc.content.defaultlinkerscript=script/fsp.scat
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_ioport\#\#\#\#3.1.0/all=1957950123,ra/fsp/inc/api/r_ioport_api.h|1390983687,ra/fsp/inc/instances/r_ioport.h|3204787724,ra/fsp/src/r_ioport/r_ioport.c
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_ioport\#\#\#\#3.1.0/all=1957950123,ra/fsp/inc/api/r_ioport_api.h|1390983687,ra/fsp/inc/instances/r_ioport.h|3204787724,ra/fsp/src/r_ioport/r_ioport.c
@@ -7,12 +7,16 @@ com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#Board\#\#ra6m4_cpk\#
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#\#\#3.1.0/all=2308894280,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#\#\#3.1.0/all=2308894280,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#Common\#\#all\#\#fsp_common\#\#\#\#3.1.0/all=3581546608,ra/fsp/inc/fsp_common_api.h|2247478812,ra/fsp/src/bsp/mcu/all/bsp_module_stop.h|3983299396,ra/fsp/src/bsp/mcu/all/bsp_delay.h|2308894280,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h|1222394411,ra/fsp/src/bsp/mcu/all/bsp_io.c|731782070,ra/fsp/src/bsp/mcu/all/bsp_irq.h|568600546,ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c|1390983687,ra/fsp/inc/instances/r_ioport.h|496115995,ra/fsp/src/bsp/mcu/all/bsp_register_protection.c|1552630912,ra/fsp/src/bsp/mcu/all/bsp_guard.h|3590501432,ra/fsp/src/bsp/mcu/all/bsp_io.h|521902797,ra/fsp/src/bsp/mcu/all/bsp_security.h|1630997354,ra/fsp/src/bsp/mcu/all/bsp_irq.c|2920829723,ra/fsp/src/bsp/mcu/all/bsp_guard.c|400573940,ra/fsp/src/bsp/mcu/all/bsp_register_protection.h|905231975,ra/fsp/src/bsp/mcu/all/bsp_clocks.c|1992062042,ra/fsp/src/bsp/mcu/all/bsp_compiler_support.h|1868795951,ra/fsp/inc/fsp_features.h|3984836408,ra/fsp/src/bsp/mcu/all/bsp_group_irq.h|2966752275,ra/fsp/src/bsp/mcu/all/bsp_delay.c|3098075304,ra/fsp/src/bsp/mcu/all/bsp_clocks.h|2556589544,ra/fsp/src/bsp/mcu/all/bsp_group_irq.c|2812024316,ra/fsp/src/bsp/mcu/all/bsp_common.h|1957950123,ra/fsp/inc/api/r_ioport_api.h|2906400,ra/fsp/src/bsp/mcu/all/bsp_common.c|3520119047,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/base_addresses.h|2977689308,ra/fsp/src/bsp/mcu/all/bsp_mcu_api.h|2006974055,ra/fsp/inc/api/bsp_api.h|3819230577,ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/system.c|3131094294,ra/fsp/src/bsp/mcu/all/bsp_rom_registers.c|1982083345,ra/fsp/src/bsp/mcu/all/bsp_security.c|1615019982,ra/fsp/src/bsp/mcu/all/bsp_sbrk.c|3366593968,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h|4191472725,ra/fsp/inc/fsp_version.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#Common\#\#all\#\#fsp_common\#\#\#\#3.1.0/all=3581546608,ra/fsp/inc/fsp_common_api.h|2247478812,ra/fsp/src/bsp/mcu/all/bsp_module_stop.h|3983299396,ra/fsp/src/bsp/mcu/all/bsp_delay.h|2308894280,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h|1222394411,ra/fsp/src/bsp/mcu/all/bsp_io.c|731782070,ra/fsp/src/bsp/mcu/all/bsp_irq.h|568600546,ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c|1390983687,ra/fsp/inc/instances/r_ioport.h|496115995,ra/fsp/src/bsp/mcu/all/bsp_register_protection.c|1552630912,ra/fsp/src/bsp/mcu/all/bsp_guard.h|3590501432,ra/fsp/src/bsp/mcu/all/bsp_io.h|521902797,ra/fsp/src/bsp/mcu/all/bsp_security.h|1630997354,ra/fsp/src/bsp/mcu/all/bsp_irq.c|2920829723,ra/fsp/src/bsp/mcu/all/bsp_guard.c|400573940,ra/fsp/src/bsp/mcu/all/bsp_register_protection.h|905231975,ra/fsp/src/bsp/mcu/all/bsp_clocks.c|1992062042,ra/fsp/src/bsp/mcu/all/bsp_compiler_support.h|1868795951,ra/fsp/inc/fsp_features.h|3984836408,ra/fsp/src/bsp/mcu/all/bsp_group_irq.h|2966752275,ra/fsp/src/bsp/mcu/all/bsp_delay.c|3098075304,ra/fsp/src/bsp/mcu/all/bsp_clocks.h|2556589544,ra/fsp/src/bsp/mcu/all/bsp_group_irq.c|2812024316,ra/fsp/src/bsp/mcu/all/bsp_common.h|1957950123,ra/fsp/inc/api/r_ioport_api.h|2906400,ra/fsp/src/bsp/mcu/all/bsp_common.c|3520119047,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/base_addresses.h|2977689308,ra/fsp/src/bsp/mcu/all/bsp_mcu_api.h|2006974055,ra/fsp/inc/api/bsp_api.h|3819230577,ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/system.c|3131094294,ra/fsp/src/bsp/mcu/all/bsp_rom_registers.c|1982083345,ra/fsp/src/bsp/mcu/all/bsp_security.c|1615019982,ra/fsp/src/bsp/mcu/all/bsp_sbrk.c|3366593968,ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h|4191472725,ra/fsp/inc/fsp_version.h
 com.renesas.cdt.ddsc.packs.componentfiles/Arm\#\#CMSIS\#\#CMSIS5\#\#CoreM\#\#\#\#5.7.0+fsp.3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Arm\#\#CMSIS\#\#CMSIS5\#\#CoreM\#\#\#\#5.7.0+fsp.3.1.0/libraries=
-com.renesas.cdt.ddsc.settingseditor/com.renesas.cdt.ddsc.settingseditor.active_page=PinConfiguration
+com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_wdt\#\#\#\#3.1.0/all=1585385371,ra/fsp/inc/instances/r_wdt.h|3589877379,ra/fsp/inc/api/r_wdt_api.h|1520208614,ra/fsp/src/r_wdt/r_wdt.c
+com.renesas.cdt.ddsc.settingseditor/com.renesas.cdt.ddsc.settingseditor.active_page=SWPConfigurator
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_ioport\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_ioport\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#R7FA6M4AF3CFB\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#device\#\#R7FA6M4AF3CFB\#\#3.1.0/libraries=
+com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_wdt\#\#\#\#3.1.0/libraries=
+com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_rtc\#\#\#\#3.1.0/all=348129344,ra/fsp/inc/api/r_cgc_api.h|3267174292,ra/fsp/src/r_rtc/r_rtc.c|1942362170,ra/fsp/inc/api/r_rtc_api.h|2525454394,ra/fsp/inc/instances/r_rtc.h
 com.renesas.cdt.ddsc.packs.componentfiles/Arm\#\#CMSIS\#\#CMSIS5\#\#CoreM\#\#\#\#5.7.0+fsp.3.1.0/all=546157604,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv8mml.h|1372010515,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm23.h|1078551279,ra/arm/CMSIS_5/CMSIS/Core/Include/core_sc300.h|2333906976,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_version.h|1536854638,ra/arm/CMSIS_5/CMSIS/Core/Include/mpu_armv8.h|206980015,ra/arm/CMSIS_5/CMSIS/Core/Include/mpu_armv7.h|3007265674,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv8mbl.h|2024281644,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armclang_ltm.h|1017116116,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_compiler.h|4231934849,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_iccarm.h|2748964184,ra/arm/CMSIS_5/CMSIS/Core/Include/cachel1_armv7.h|377628369,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm55.h|637879414,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm33.h|4005730526,ra/arm/CMSIS_5/CMSIS/Core/Include/pmu_armv8.h|2327633156,ra/arm/CMSIS_5/CMSIS/Core/Include/core_sc000.h|2635219934,ra/arm/CMSIS_5/CMSIS/Core/Include/tz_context.h|3589068132,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armcc.h|2851112248,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm1.h|3021372151,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_gcc.h|1562896660,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm35p.h|1745843273,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm0.h|2491522803,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armclang.h|1441545198,ra/arm/CMSIS_5/LICENSE.txt|3602366610,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm3.h|3779323067,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm4.h|3442821435,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm7.h|4290386133,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm0plus.h|2686445441,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv81mml.h
 com.renesas.cdt.ddsc.packs.componentfiles/Arm\#\#CMSIS\#\#CMSIS5\#\#CoreM\#\#\#\#5.7.0+fsp.3.1.0/all=546157604,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv8mml.h|1372010515,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm23.h|1078551279,ra/arm/CMSIS_5/CMSIS/Core/Include/core_sc300.h|2333906976,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_version.h|1536854638,ra/arm/CMSIS_5/CMSIS/Core/Include/mpu_armv8.h|206980015,ra/arm/CMSIS_5/CMSIS/Core/Include/mpu_armv7.h|3007265674,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv8mbl.h|2024281644,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armclang_ltm.h|1017116116,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_compiler.h|4231934849,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_iccarm.h|2748964184,ra/arm/CMSIS_5/CMSIS/Core/Include/cachel1_armv7.h|377628369,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm55.h|637879414,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm33.h|4005730526,ra/arm/CMSIS_5/CMSIS/Core/Include/pmu_armv8.h|2327633156,ra/arm/CMSIS_5/CMSIS/Core/Include/core_sc000.h|2635219934,ra/arm/CMSIS_5/CMSIS/Core/Include/tz_context.h|3589068132,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armcc.h|2851112248,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm1.h|3021372151,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_gcc.h|1562896660,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm35p.h|1745843273,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm0.h|2491522803,ra/arm/CMSIS_5/CMSIS/Core/Include/cmsis_armclang.h|1441545198,ra/arm/CMSIS_5/LICENSE.txt|3602366610,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm3.h|3779323067,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm4.h|3442821435,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm7.h|4290386133,ra/arm/CMSIS_5/CMSIS/Core/Include/core_cm0plus.h|2686445441,ra/arm/CMSIS_5/CMSIS/Core/Include/core_armv81mml.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_sci_uart\#\#\#\#3.1.0/all=2349328507,ra/fsp/src/r_sci_uart/r_sci_uart.c|853178775,ra/fsp/inc/api/r_uart_api.h|1610456547,ra/fsp/inc/api/r_transfer_api.h|1672784957,ra/fsp/inc/instances/r_sci_uart.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_sci_uart\#\#\#\#3.1.0/all=2349328507,ra/fsp/src/r_sci_uart/r_sci_uart.c|853178775,ra/fsp/inc/api/r_uart_api.h|1610456547,ra/fsp/inc/api/r_transfer_api.h|1672784957,ra/fsp/inc/instances/r_sci_uart.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#fsp\#\#\#\#3.1.0/all=3571093944,ra/fsp/src/bsp/mcu/ra6m4/bsp_elc.h|2347061782,ra/fsp/src/bsp/mcu/ra6m4/bsp_mcu_info.h|3852442662,ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#ra6m4\#\#fsp\#\#\#\#3.1.0/all=3571093944,ra/fsp/src/bsp/mcu/ra6m4/bsp_elc.h|2347061782,ra/fsp/src/bsp/mcu/ra6m4/bsp_mcu_info.h|3852442662,ra/fsp/src/bsp/mcu/ra6m4/bsp_feature.h
+com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#HAL\ Drivers\#\#all\#\#r_rtc\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#Common\#\#all\#\#fsp_common\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#Common\#\#all\#\#fsp_common\#\#\#\#3.1.0/libraries=
 com.renesas.cdt.ddsc.threads.configurator/collapse/module.driver.uart_on_sci_uart.813326093=false
 com.renesas.cdt.ddsc.threads.configurator/collapse/module.driver.uart_on_sci_uart.813326093=false
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#Board\#\#ra6m4_cpk\#\#\#\#3.1.0/all=3938710240,ra/board/ra6m4_cpk/board_leds.c|3343992478,ra/board/ra6m4_cpk/board.h|2525887392,ra/board/ra6m4_cpk/board_ethernet_phy.h|3559227370,ra/board/ra6m4_cpk/board_init.c|3843040667,ra/board/ra6m4_cpk/board_leds.h|2967196421,ra/board/ra6m4_cpk/board_init.h
 com.renesas.cdt.ddsc.packs.componentfiles/Renesas\#\#BSP\#\#Board\#\#ra6m4_cpk\#\#\#\#3.1.0/all=3938710240,ra/board/ra6m4_cpk/board_leds.c|3343992478,ra/board/ra6m4_cpk/board.h|2525887392,ra/board/ra6m4_cpk/board_ethernet_phy.h|3559227370,ra/board/ra6m4_cpk/board_init.c|3843040667,ra/board/ra6m4_cpk/board_leds.h|2967196421,ra/board/ra6m4_cpk/board_init.h

+ 10 - 3
bsp/ra6m4-cpk/README.md

@@ -33,7 +33,11 @@
 | **片上外设** | **支持情况** | **备注**                  |
 | **片上外设** | **支持情况** | **备注**                  |
 | :----------- | :---------- | :------------------------ |
 | :----------- | :---------- | :------------------------ |
 | UART         |     支持     | UART7               |
 | UART         |     支持     | UART7               |
-| 持续更新中... |  |          |
+| GPIO | 支持 |          |
+| IIC | 支持 | 软件 |
+| WDT | 支持 | |
+| RTC | 支持 | |
+| 持续更新中... | | |
 
 
 
 
 ## 使用说明
 ## 使用说明
@@ -111,7 +115,7 @@ msh >
 
 
 **应用入口函数**
 **应用入口函数**
 
 
-应用层的入口函数在 **bsp\ra6m4-cpk\src\hal_emtry.c** 中 的 `void hal_entry(void)` 。用户编写的 .c 文件和直接放在 src 目录下
+应用层的入口函数在 **bsp\ra6m4-cpk\src\hal_emtry.c** 中 的 `void hal_entry(void)` 。用户编写的源文件可直接放在 src 目录下。
 
 
 ```c
 ```c
 void hal_entry(void)
 void hal_entry(void)
@@ -120,7 +124,10 @@ void hal_entry(void)
 
 
     while (1)
     while (1)
     {
     {
-        rt_thread_mdelay(1000);
+        rt_pin_write(LED3_PIN, PIN_HIGH);
+        rt_thread_mdelay(500);
+        rt_pin_write(LED3_PIN, PIN_LOW);
+        rt_thread_mdelay(500);
     }
     }
 }
 }
 ```
 ```

+ 13 - 0
bsp/ra6m4-cpk/buildinfo.gpdsc

@@ -11,8 +11,12 @@
     <generator id="Renesas RA Smart Configurator">
     <generator id="Renesas RA Smart Configurator">
       <project_files>
       <project_files>
         <file category="include" name="src/"/>
         <file category="include" name="src/"/>
+        <file category="source" name="src/alarm_sample.c"/>
         <file category="source" name="src/hal_entry.c"/>
         <file category="source" name="src/hal_entry.c"/>
+        <file category="source" name="src/icu_sample.c"/>
+        <file category="source" name="src/rtc_sample.c"/>
         <file category="other" name="src/SConscript"/>
         <file category="other" name="src/SConscript"/>
+        <file category="source" name="src/wdt_sample.c"/>
       </project_files>
       </project_files>
     </generator>
     </generator>
   </generators>
   </generators>
@@ -58,14 +62,19 @@
         <file category="source" name="ra/board/ra6m4_cpk/board_leds.c"/>
         <file category="source" name="ra/board/ra6m4_cpk/board_leds.c"/>
         <file category="header" name="ra/board/ra6m4_cpk/board_leds.h" path=""/>
         <file category="header" name="ra/board/ra6m4_cpk/board_leds.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/bsp_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/bsp_api.h" path=""/>
+        <file category="header" name="ra/fsp/inc/api/r_cgc_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_ioport_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_ioport_api.h" path=""/>
+        <file category="header" name="ra/fsp/inc/api/r_rtc_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_transfer_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_transfer_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_uart_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/api/r_uart_api.h" path=""/>
+        <file category="header" name="ra/fsp/inc/api/r_wdt_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_common_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_common_api.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_features.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_features.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_version.h" path=""/>
         <file category="header" name="ra/fsp/inc/fsp_version.h" path=""/>
         <file category="header" name="ra/fsp/inc/instances/r_ioport.h" path=""/>
         <file category="header" name="ra/fsp/inc/instances/r_ioport.h" path=""/>
+        <file category="header" name="ra/fsp/inc/instances/r_rtc.h" path=""/>
         <file category="header" name="ra/fsp/inc/instances/r_sci_uart.h" path=""/>
         <file category="header" name="ra/fsp/inc/instances/r_sci_uart.h" path=""/>
+        <file category="header" name="ra/fsp/inc/instances/r_wdt.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/base_addresses.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/base_addresses.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/renesas.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/cmsis/Device/RENESAS/Include/system.h" path=""/>
@@ -112,8 +121,10 @@
         <file category="header" name="ra/fsp/src/bsp/mcu/ra6m4/bsp_mcu_info.h" path=""/>
         <file category="header" name="ra/fsp/src/bsp/mcu/ra6m4/bsp_mcu_info.h" path=""/>
         <file category="source" name="ra/fsp/src/r_ioport/r_ioport.c"/>
         <file category="source" name="ra/fsp/src/r_ioport/r_ioport.c"/>
         <file category="other" name="ra/fsp/src/r_ioport/r_ioport.o"/>
         <file category="other" name="ra/fsp/src/r_ioport/r_ioport.o"/>
+        <file category="source" name="ra/fsp/src/r_rtc/r_rtc.c"/>
         <file category="source" name="ra/fsp/src/r_sci_uart/r_sci_uart.c"/>
         <file category="source" name="ra/fsp/src/r_sci_uart/r_sci_uart.c"/>
         <file category="other" name="ra/fsp/src/r_sci_uart/r_sci_uart.o"/>
         <file category="other" name="ra/fsp/src/r_sci_uart/r_sci_uart.o"/>
+        <file category="source" name="ra/fsp/src/r_wdt/r_wdt.c"/>
         <file category="other" name="ra/SConscript"/>
         <file category="other" name="ra/SConscript"/>
       </files>
       </files>
     </component>
     </component>
@@ -128,7 +139,9 @@
         <file category="header" name="ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/bsp/bsp_mcu_family_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/bsp/bsp_pin_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/r_ioport_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/r_ioport_cfg.h" path=""/>
+        <file category="header" name="ra_cfg/fsp_cfg/r_rtc_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/r_sci_uart_cfg.h" path=""/>
         <file category="header" name="ra_cfg/fsp_cfg/r_sci_uart_cfg.h" path=""/>
+        <file category="header" name="ra_cfg/fsp_cfg/r_wdt_cfg.h" path=""/>
         <file category="other" name="ra_cfg/SConscript"/>
         <file category="other" name="ra_cfg/SConscript"/>
       </files>
       </files>
     </component>
     </component>

+ 40 - 0
bsp/ra6m4-cpk/configuration.xml

@@ -163,6 +163,14 @@
       <description>SCI UART</description>
       <description>SCI UART</description>
       <originalPack>Renesas.RA.3.1.0.pack</originalPack>
       <originalPack>Renesas.RA.3.1.0.pack</originalPack>
     </component>
     </component>
+    <component apiversion="" class="HAL Drivers" condition="" group="all" subgroup="r_rtc" variant="" vendor="Renesas" version="3.1.0">
+      <description>Real Time Clock</description>
+      <originalPack>Renesas.RA.3.1.0.pack</originalPack>
+    </component>
+    <component apiversion="" class="HAL Drivers" condition="" group="all" subgroup="r_wdt" variant="" vendor="Renesas" version="3.1.0">
+      <description>Watchdog Timer</description>
+      <originalPack>Renesas.RA.3.1.0.pack</originalPack>
+    </component>
   </raComponentSelection>
   </raComponentSelection>
   <raElcConfiguration/>
   <raElcConfiguration/>
   <raIcuConfiguration/>
   <raIcuConfiguration/>
@@ -196,10 +204,39 @@
       <property id="module.driver.uart.tei_ipl" value="board.icu.common.irq.priority12"/>
       <property id="module.driver.uart.tei_ipl" value="board.icu.common.irq.priority12"/>
       <property id="module.driver.uart.eri_ipl" value="board.icu.common.irq.priority12"/>
       <property id="module.driver.uart.eri_ipl" value="board.icu.common.irq.priority12"/>
     </module>
     </module>
+    <module id="module.driver.rtc_on_rtc.546341368">
+      <property id="module.driver.rtc.name" value="g_rtc"/>
+      <property id="module.driver.rtc.clock_source" value="module.driver.rtc.clock_source.clock_source_loco"/>
+      <property id="module.driver.rtc.freq_cmpr_value_loco" value="255"/>
+      <property id="module.driver.rtc.err_adjustment_mode" value="module.driver.rtc.err_adjustment_mode.m1"/>
+      <property id="module.driver.rtc.err_adjustment_period" value="module.driver.rtc.err_adjustment_period.p1"/>
+      <property id="module.driver.rtc.err_adjustment_type" value="module.driver.rtc.err_adjustment_type.t1"/>
+      <property id="module.driver.rtc.err_adjustment_value" value="0"/>
+      <property id="module.driver.rtc.p_callback" value="rtc_callback"/>
+      <property id="module.driver.rtc.alarm_ipl" value="board.icu.common.irq.priority2"/>
+      <property id="module.driver.rtc.periodic_ipl" value="board.icu.common.irq.priority2"/>
+      <property id="module.driver.rtc.carry_ipl" value="board.icu.common.irq.priority2"/>
+    </module>
+    <module id="module.driver.watchdog_on_wdt.423233170">
+      <property id="module.driver.watchdog.name" value="g_wdt"/>
+      <property id="module.driver.watchdog.timeout" value="module.driver.watchdog.timeout.16384"/>
+      <property id="module.driver.watchdog.clock_division" value="module.driver.watchdog.clock_division.8192"/>
+      <property id="module.driver.watchdog.window_start" value="module.driver.watchdog.window_start.100"/>
+      <property id="module.driver.watchdog.window_end" value="module.driver.watchdog.window_end.0"/>
+      <property id="module.driver.watchdog.reset_control" value="module.driver.watchdog.reset_control.reset"/>
+      <property id="module.driver.watchdog.stop_control" value="module.driver.watchdog.stop_control.disable"/>
+      <property id="module.driver.watchdog.nmi_callback" value="NULL"/>
+    </module>
     <context id="_hal.0">
     <context id="_hal.0">
       <stack module="module.driver.ioport_on_ioport.0"/>
       <stack module="module.driver.ioport_on_ioport.0"/>
       <stack module="module.driver.uart_on_sci_uart.813326093"/>
       <stack module="module.driver.uart_on_sci_uart.813326093"/>
+      <stack module="module.driver.rtc_on_rtc.546341368"/>
+      <stack module="module.driver.watchdog_on_wdt.423233170"/>
     </context>
     </context>
+    <config id="config.driver.wdt">
+      <property id="config.driver.wdt.param_checking_enable" value="config.driver.wdt.param_checking_enable.bsp"/>
+      <property id="config.driver.wdt.register_start_nmi_supported" value="config.driver.wdt.register_start_nmi_supported.disabled"/>
+    </config>
     <config id="config.driver.ioport">
     <config id="config.driver.ioport">
       <property id="config.driver.ioport.checking" value="config.driver.ioport.checking.system"/>
       <property id="config.driver.ioport.checking" value="config.driver.ioport.checking.system"/>
     </config>
     </config>
@@ -209,6 +246,9 @@
       <property id="config.driver.sci_uart.dtc_support" value="config.driver.sci_uart.dtc_support.disabled"/>
       <property id="config.driver.sci_uart.dtc_support" value="config.driver.sci_uart.dtc_support.disabled"/>
       <property id="config.driver.sci_uart.flow_control" value="config.driver.sci_uart.flow_control.disabled"/>
       <property id="config.driver.sci_uart.flow_control" value="config.driver.sci_uart.flow_control.disabled"/>
     </config>
     </config>
+    <config id="config.driver.rtc">
+      <property id="config.driver.rtc.param_checking_enable" value="config.driver.rtc.param_checking_enable.bsp"/>
+    </config>
   </raModuleConfiguration>
   </raModuleConfiguration>
   <raPinConfiguration>
   <raPinConfiguration>
     <symbolicName propertyId="p000.symbolic_name" value="ARDUINO_AN00"/>
     <symbolicName propertyId="p000.symbolic_name" value="ARDUINO_AN00"/>

BIN
bsp/ra6m4-cpk/docs/picture/rascuart.png


+ 75 - 2
bsp/ra6m4-cpk/docs/使用瑞萨FSP配置工具.md

@@ -15,8 +15,81 @@
 
 
 ## UART
 ## UART
 
 
-- 添加一个 UART 端口外设配置
+如何添加一个 UART 端口外设配置?
+
+1. 选择 Stacks 配置页,点击 New Stack 找到 UART。
 
 
 ![image.png](picture/rascuart.png)
 ![image.png](picture/rascuart.png)
 
 
-![image.png](picture/rascuart1.png)
+2. 配置 UART 参数,因为需要适配 RT-Thread 驱动中使用的命名,所以需要修改命名,设置 **name** 、**channel**  、**callback** 是一致的标号。
+![image.png](picture/rascuart1.png)
+
+
+
+## GPIO 中断
+
+如何添加一个 IO 中断?
+
+1. 选择引脚编号,进入配置,比如选择 P402 做为中断引脚。
+
+![image-20211019142514276](picture/gpio.png)
+  2. 打开 ICU 中断通道 IRQ4
+
+![image-20211019142801323](picture/gpio_irq.png)
+  3. 创建 stack 并进入配置。因为需要适配 RT-Thread 驱动中使用的命名,所以需要修改命名,设置 **name** 、**channel**  、**callback** 是一致的标号。选择你希望的触发方式。最后保存配置,生成配置代码。
+
+![image-20211019142910292](picture/icu_stack.png)
+
+![image-20211019143151891](picture/config_irq4.png)
+
+4. 测试中断是否能够成功开启
+
+   ```c
+   
+   void irq_callback_test(void *args)
+   {
+       rt_kprintf("\n Irq4 triggered \n");
+   }
+   
+   void icu_sample(void)
+   {
+       /* 初始化P*/
+       rt_uint32_t pin = rt_pin_get("P402");
+       rt_kprintf("\n pin number : 0x%04X \n", pin);
+       rt_err_t err = rt_pin_attach_irq(pin, PIN_IRQ_MODE_RISING, irq_callback_test, RT_NULL);
+       if(RT_EOK != err)
+       {
+           rt_kprintf("\n attach irq failed. \n");
+       }
+       err = rt_pin_irq_enable(pin, PIN_IRQ_ENABLE);
+       if(RT_EOK != err)
+       {
+           rt_kprintf("\n enable irq failed. \n");
+       }
+   }
+   MSH_CMD_EXPORT(icu_sample, icu sample);
+   ```
+
+## WDT
+
+1. 创建 WDT 
+
+![image-20211019152302939](picture/wdt.png)
+
+2. 配置 WDT,需要注意在 RT-Thread 中只是用了一个 WDT 设备,所以没有对其进行编号,如果是新创建的 WDT 设备需要注意 name 字段,在驱动中默认使用的是 `g_wdt` 。
+
+![image-20211019152407572](picture/wdt_config.png)
+
+3. [如何在 ENV 中打开 WDT](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/watchdog/watchdog) 
+
+## RTC
+
+1. 添加 RTC 设备
+
+![image-20211019152536749](picture/rtc.png)
+
+2. 配置 RTC,需要注意在 RT-Thread 中只是用了一个 RTC 设备,所以没有对其进行编号,如果是新创建的 RTC 设备需要注意 name 字段,在驱动中默认使用的是 `g_rtc` 。
+
+![image-20211019152627412](picture/rtc_config.png)
+
+3.  [如何在 ENV 中打开 RTC](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/rtc/rtc) 

+ 22 - 0
bsp/ra6m4-cpk/drivers/Kconfig

@@ -73,6 +73,28 @@ menu "Hardware Drivers Config"
                     endif
                     endif
             endif
             endif
 
 
+        config BSP_USING_WDT
+            bool "Enable Watchdog Timer"
+            select RT_USING_WDT
+            default n
+
+        menuconfig BSP_USING_ONCHIP_RTC
+            bool "Enable RTC"
+            select RT_USING_RTC
+            default n
+            if BSP_USING_ONCHIP_RTC
+                choice
+                    prompt "Select clock source"
+                    default BSP_RTC_USING_LSE
+
+                    config BSP_RTC_USING_LSE
+                        bool "RTC USING LSE"
+
+                    config BSP_RTC_USING_LSI
+                        bool "RTC USING LSI"
+                endchoice
+            endif
+
     endmenu
     endmenu
 
 
     menu "Board extended module Drivers"
     menu "Board extended module Drivers"

+ 3 - 0
bsp/ra6m4-cpk/drivers/SConscript

@@ -22,6 +22,9 @@ if GetDepend(['RT_USING_PIN']):
 if GetDepend(['RT_USING_WDT']):
 if GetDepend(['RT_USING_WDT']):
     src += ['drv_wdt.c']
     src += ['drv_wdt.c']
 
 
+if GetDepend(['BSP_USING_ONCHIP_RTC']):
+    src += ['drv_rtc.c']
+
 if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
 if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
     if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
     if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
         src += ['drv_soft_i2c.c']
         src += ['drv_soft_i2c.c']

+ 157 - 157
bsp/ra6m4-cpk/drivers/drv_gpio.c

@@ -14,94 +14,94 @@
 
 
 #define DBG_TAG              "drv.gpio"
 #define DBG_TAG              "drv.gpio"
 #ifdef DRV_DEBUG
 #ifdef DRV_DEBUG
-#define DBG_LVL               DBG_LOG
+    #define DBG_LVL               DBG_LOG
 #else
 #else
-#define DBG_LVL               DBG_INFO
+    #define DBG_LVL               DBG_INFO
 #endif /* DRV_DEBUG */
 #endif /* DRV_DEBUG */
 
 
 #ifdef R_ICU_H
 #ifdef R_ICU_H
 static rt_base_t ra_pin_get_irqx(rt_uint32_t pin)
 static rt_base_t ra_pin_get_irqx(rt_uint32_t pin)
 {
 {
-    switch(pin)
+    switch (pin)
     {
     {
-        case BSP_IO_PORT_04_PIN_00:
-        case BSP_IO_PORT_02_PIN_06:
-        case BSP_IO_PORT_01_PIN_05:
-            return 0;
-
-        case BSP_IO_PORT_02_PIN_05:
-        case BSP_IO_PORT_01_PIN_01:
-        case BSP_IO_PORT_01_PIN_04:
-            return 1;
-
-        case BSP_IO_PORT_02_PIN_03:
-        case BSP_IO_PORT_01_PIN_00:
-        case BSP_IO_PORT_02_PIN_13:
-            return 2;
-
-        case BSP_IO_PORT_02_PIN_02:
-        case BSP_IO_PORT_01_PIN_10:
-        case BSP_IO_PORT_02_PIN_12:
-            return 3;
-
-        case BSP_IO_PORT_04_PIN_02:
-        case BSP_IO_PORT_01_PIN_11:
-        case BSP_IO_PORT_04_PIN_11:
-            return 4;
-
-        case BSP_IO_PORT_04_PIN_01:
-        case BSP_IO_PORT_03_PIN_02:
-        case BSP_IO_PORT_04_PIN_10:
-            return 5;
-
-        case BSP_IO_PORT_03_PIN_01:
-        case BSP_IO_PORT_00_PIN_00:
-        case BSP_IO_PORT_04_PIN_09:
-            return 6;
-
-        case BSP_IO_PORT_00_PIN_01:
-        case BSP_IO_PORT_04_PIN_08:
-            return 7;
-
-        case BSP_IO_PORT_00_PIN_02:
-        case BSP_IO_PORT_03_PIN_05:
-        case BSP_IO_PORT_04_PIN_15:
-            return 8;
-
-        case BSP_IO_PORT_00_PIN_04:
-        case BSP_IO_PORT_03_PIN_04:
-        case BSP_IO_PORT_04_PIN_14:
-            return 9;
-
-        case BSP_IO_PORT_00_PIN_05:
-        case BSP_IO_PORT_07_PIN_09:
-            return 10;
-
-        case BSP_IO_PORT_05_PIN_01:
-        case BSP_IO_PORT_00_PIN_06:
-        case BSP_IO_PORT_07_PIN_08:
-            return 11;
-
-        case BSP_IO_PORT_05_PIN_02:
-        case BSP_IO_PORT_00_PIN_08:
-            return 12;
-
-        case BSP_IO_PORT_00_PIN_15:
-        case BSP_IO_PORT_00_PIN_09:
-            return 13;
-
-        case BSP_IO_PORT_04_PIN_03:
-        case BSP_IO_PORT_05_PIN_12:
-        case BSP_IO_PORT_05_PIN_05:
-            return 14;
-
-        case BSP_IO_PORT_04_PIN_04:
-        case BSP_IO_PORT_05_PIN_11:
-        case BSP_IO_PORT_05_PIN_06:
-            return 15;
-
-        default  :
-            return -1;
+    case BSP_IO_PORT_04_PIN_00:
+    case BSP_IO_PORT_02_PIN_06:
+    case BSP_IO_PORT_01_PIN_05:
+        return 0;
+
+    case BSP_IO_PORT_02_PIN_05:
+    case BSP_IO_PORT_01_PIN_01:
+    case BSP_IO_PORT_01_PIN_04:
+        return 1;
+
+    case BSP_IO_PORT_02_PIN_03:
+    case BSP_IO_PORT_01_PIN_00:
+    case BSP_IO_PORT_02_PIN_13:
+        return 2;
+
+    case BSP_IO_PORT_02_PIN_02:
+    case BSP_IO_PORT_01_PIN_10:
+    case BSP_IO_PORT_02_PIN_12:
+        return 3;
+
+    case BSP_IO_PORT_04_PIN_02:
+    case BSP_IO_PORT_01_PIN_11:
+    case BSP_IO_PORT_04_PIN_11:
+        return 4;
+
+    case BSP_IO_PORT_04_PIN_01:
+    case BSP_IO_PORT_03_PIN_02:
+    case BSP_IO_PORT_04_PIN_10:
+        return 5;
+
+    case BSP_IO_PORT_03_PIN_01:
+    case BSP_IO_PORT_00_PIN_00:
+    case BSP_IO_PORT_04_PIN_09:
+        return 6;
+
+    case BSP_IO_PORT_00_PIN_01:
+    case BSP_IO_PORT_04_PIN_08:
+        return 7;
+
+    case BSP_IO_PORT_00_PIN_02:
+    case BSP_IO_PORT_03_PIN_05:
+    case BSP_IO_PORT_04_PIN_15:
+        return 8;
+
+    case BSP_IO_PORT_00_PIN_04:
+    case BSP_IO_PORT_03_PIN_04:
+    case BSP_IO_PORT_04_PIN_14:
+        return 9;
+
+    case BSP_IO_PORT_00_PIN_05:
+    case BSP_IO_PORT_07_PIN_09:
+        return 10;
+
+    case BSP_IO_PORT_05_PIN_01:
+    case BSP_IO_PORT_00_PIN_06:
+    case BSP_IO_PORT_07_PIN_08:
+        return 11;
+
+    case BSP_IO_PORT_05_PIN_02:
+    case BSP_IO_PORT_00_PIN_08:
+        return 12;
+
+    case BSP_IO_PORT_00_PIN_15:
+    case BSP_IO_PORT_00_PIN_09:
+        return 13;
+
+    case BSP_IO_PORT_04_PIN_03:
+    case BSP_IO_PORT_05_PIN_12:
+    case BSP_IO_PORT_05_PIN_05:
+        return 14;
+
+    case BSP_IO_PORT_04_PIN_04:
+    case BSP_IO_PORT_05_PIN_11:
+    case BSP_IO_PORT_05_PIN_06:
+        return 15;
+
+    default  :
+        return -1;
     }
     }
 }
 }
 
 
@@ -209,34 +209,34 @@ static void ra_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
         return;
         return;
     }
     }
 
 
-    switch(mode)
+    switch (mode)
     {
     {
-        case PIN_MODE_OUTPUT:
-            err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, BSP_IO_DIRECTION_OUTPUT);
-            if (err != FSP_SUCCESS)
-            {
-                LOG_E("PIN_MODE_OUTPUT configuration failed");
-                return;
-            }
-            break;
+    case PIN_MODE_OUTPUT:
+        err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, BSP_IO_DIRECTION_OUTPUT);
+        if (err != FSP_SUCCESS)
+        {
+            LOG_E("PIN_MODE_OUTPUT configuration failed");
+            return;
+        }
+        break;
 
 
-        case PIN_MODE_INPUT:
-            err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, BSP_IO_DIRECTION_INPUT);
-            if (err != FSP_SUCCESS)
-            {
-                LOG_E("PIN_MODE_INPUT configuration failed");
-                return;
-            }
-            break;
+    case PIN_MODE_INPUT:
+        err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, BSP_IO_DIRECTION_INPUT);
+        if (err != FSP_SUCCESS)
+        {
+            LOG_E("PIN_MODE_INPUT configuration failed");
+            return;
+        }
+        break;
 
 
-        case PIN_MODE_OUTPUT_OD:
-            err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, IOPORT_CFG_NMOS_ENABLE);
-            if (err != FSP_SUCCESS)
-            {
-                LOG_E("PIN_MODE_OUTPUT_OD configuration failed");
-                return;
-            }
-            break;
+    case PIN_MODE_OUTPUT_OD:
+        err = R_IOPORT_PinCfg(&g_ioport_ctrl, pin, IOPORT_CFG_NMOS_ENABLE);
+        if (err != FSP_SUCCESS)
+        {
+            LOG_E("PIN_MODE_OUTPUT_OD configuration failed");
+            return;
+        }
+        break;
     }
     }
 }
 }
 
 
@@ -269,12 +269,12 @@ static rt_err_t ra_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_ui
 #ifdef R_ICU_H
 #ifdef R_ICU_H
     rt_err_t err;
     rt_err_t err;
     rt_int32_t irqx = ra_pin_get_irqx(pin);
     rt_int32_t irqx = ra_pin_get_irqx(pin);
-    if(PIN_IRQ_ENABLE == enabled)
+    if (PIN_IRQ_ENABLE == enabled)
     {
     {
-        if(0 <= irqx && irqx < sizeof(pin_irq_map) / sizeof(pin_irq_map[0]))
+        if (0 <= irqx && irqx < sizeof(pin_irq_map) / sizeof(pin_irq_map[0]))
         {
         {
-            err = R_ICU_ExternalIrqOpen((external_irq_ctrl_t * const)pin_irq_map[irqx].irq_ctrl, 
-                        (external_irq_cfg_t const * const)pin_irq_map[irqx].irq_cfg);
+            err = R_ICU_ExternalIrqOpen((external_irq_ctrl_t *const)pin_irq_map[irqx].irq_ctrl,
+                                        (external_irq_cfg_t const * const)pin_irq_map[irqx].irq_cfg);
             /* Handle error */
             /* Handle error */
             if (FSP_SUCCESS != err)
             if (FSP_SUCCESS != err)
             {
             {
@@ -282,8 +282,8 @@ static rt_err_t ra_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_ui
                 LOG_E("\r\n**R_ICU_ExternalIrqOpen API FAILED**\r\n");
                 LOG_E("\r\n**R_ICU_ExternalIrqOpen API FAILED**\r\n");
                 return -RT_ERROR;
                 return -RT_ERROR;
             }
             }
-            
-            err = R_ICU_ExternalIrqEnable((external_irq_ctrl_t * const)pin_irq_map[irqx].irq_ctrl);
+
+            err = R_ICU_ExternalIrqEnable((external_irq_ctrl_t *const)pin_irq_map[irqx].irq_ctrl);
             /* Handle error */
             /* Handle error */
             if (FSP_SUCCESS != err)
             if (FSP_SUCCESS != err)
             {
             {
@@ -293,16 +293,16 @@ static rt_err_t ra_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_ui
             }
             }
         }
         }
     }
     }
-    else if(PIN_IRQ_DISABLE == enabled)
+    else if (PIN_IRQ_DISABLE == enabled)
     {
     {
-        err = R_ICU_ExternalIrqDisable((external_irq_ctrl_t * const)pin_irq_map[irqx].irq_ctrl);
+        err = R_ICU_ExternalIrqDisable((external_irq_ctrl_t *const)pin_irq_map[irqx].irq_ctrl);
         if (FSP_SUCCESS != err)
         if (FSP_SUCCESS != err)
         {
         {
             /* ICU Disable failure message */
             /* ICU Disable failure message */
             LOG_E("\r\n**R_ICU_ExternalIrqDisable API FAILED**\r\n");
             LOG_E("\r\n**R_ICU_ExternalIrqDisable API FAILED**\r\n");
             return -RT_ERROR;
             return -RT_ERROR;
         }
         }
-        err = R_ICU_ExternalIrqClose((external_irq_ctrl_t * const)pin_irq_map[irqx].irq_ctrl);
+        err = R_ICU_ExternalIrqClose((external_irq_ctrl_t *const)pin_irq_map[irqx].irq_ctrl);
         if (FSP_SUCCESS != err)
         if (FSP_SUCCESS != err)
         {
         {
             /* ICU Close failure message */
             /* ICU Close failure message */
@@ -317,31 +317,31 @@ static rt_err_t ra_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_ui
 }
 }
 
 
 static rt_err_t ra_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
 static rt_err_t ra_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
-                                     rt_uint32_t mode, void (*hdr)(void *args), void *args)
+                                  rt_uint32_t mode, void (*hdr)(void *args), void *args)
 {
 {
 #ifdef R_ICU_H
 #ifdef R_ICU_H
     rt_int32_t irqx = ra_pin_get_irqx(pin);
     rt_int32_t irqx = ra_pin_get_irqx(pin);
-    if(0 <= irqx && irqx < (sizeof(pin_irq_map) / sizeof(pin_irq_map[0])))
-    {
-    int level = rt_hw_interrupt_disable();
-    if (pin_irq_hdr_tab[irqx].pin == irqx &&
-        pin_irq_hdr_tab[irqx].hdr == hdr &&
-        pin_irq_hdr_tab[irqx].mode == mode &&
-        pin_irq_hdr_tab[irqx].args == args)
-    {
-        rt_hw_interrupt_enable(level);
-        return RT_EOK;
-    }
-    if(pin_irq_hdr_tab[irqx].pin != -1)
+    if (0 <= irqx && irqx < (sizeof(pin_irq_map) / sizeof(pin_irq_map[0])))
     {
     {
+        int level = rt_hw_interrupt_disable();
+        if (pin_irq_hdr_tab[irqx].pin == irqx &&
+                pin_irq_hdr_tab[irqx].hdr == hdr &&
+                pin_irq_hdr_tab[irqx].mode == mode &&
+                pin_irq_hdr_tab[irqx].args == args)
+        {
+            rt_hw_interrupt_enable(level);
+            return RT_EOK;
+        }
+        if (pin_irq_hdr_tab[irqx].pin != -1)
+        {
+            rt_hw_interrupt_enable(level);
+            return RT_EBUSY;
+        }
+        pin_irq_hdr_tab[irqx].pin = irqx;
+        pin_irq_hdr_tab[irqx].hdr = hdr;
+        pin_irq_hdr_tab[irqx].mode = mode;
+        pin_irq_hdr_tab[irqx].args = args;
         rt_hw_interrupt_enable(level);
         rt_hw_interrupt_enable(level);
-        return RT_EBUSY;
-    }
-    pin_irq_hdr_tab[irqx].pin = irqx;
-    pin_irq_hdr_tab[irqx].hdr = hdr;
-    pin_irq_hdr_tab[irqx].mode = mode;
-    pin_irq_hdr_tab[irqx].args = args;
-    rt_hw_interrupt_enable(level);
     }
     }
     else return -RT_ERROR;
     else return -RT_ERROR;
     return RT_EOK;
     return RT_EOK;
@@ -354,7 +354,7 @@ static rt_err_t ra_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
 {
 {
 #ifdef R_ICU_H
 #ifdef R_ICU_H
     rt_int32_t irqx = ra_pin_get_irqx(pin);
     rt_int32_t irqx = ra_pin_get_irqx(pin);
-    if(0 <= irqx && irqx < sizeof(pin_irq_map) / sizeof(pin_irq_map[0]))
+    if (0 <= irqx && irqx < sizeof(pin_irq_map) / sizeof(pin_irq_map[0]))
     {
     {
         int level = rt_hw_interrupt_disable();
         int level = rt_hw_interrupt_disable();
         if (pin_irq_hdr_tab[irqx].pin == -1)
         if (pin_irq_hdr_tab[irqx].pin == -1)
@@ -381,16 +381,16 @@ static rt_err_t ra_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
 static rt_base_t ra_pin_get(const char *name)
 static rt_base_t ra_pin_get(const char *name)
 {
 {
     int pin_number = -1, port = -1, pin = -1;
     int pin_number = -1, port = -1, pin = -1;
-    if(rt_strlen(name) != 4)
+    if (rt_strlen(name) != 4)
         return -1;
         return -1;
-    if(name[0] == 'P')
+    if (name[0] == 'P')
     {
     {
-        if('0' <= (int)name[1] && (int)name[1] <= '9')
+        if ('0' <= (int)name[1] && (int)name[1] <= '9')
         {
         {
             port = ((int)name[1] - 48) * 16 * 16;
             port = ((int)name[1] - 48) * 16 * 16;
-            if('0' <= (int)name[2] && (int)name[2] <= '9')
+            if ('0' <= (int)name[2] && (int)name[2] <= '9')
             {
             {
-                if('0' <= (int)name[3] && (int)name[3] <= '9')
+                if ('0' <= (int)name[3] && (int)name[3] <= '9')
                 {
                 {
                     pin = ((int)name[2] - 48) * 10;
                     pin = ((int)name[2] - 48) * 10;
                     pin += (int)name[3] - 48;
                     pin += (int)name[3] - 48;
@@ -428,7 +428,7 @@ int rt_hw_pin_init(void)
 void irq0_callback(external_irq_callback_args_t *p_args)
 void irq0_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(0 == pin_irq_hdr_tab[0].pin)
+    if (0 == pin_irq_hdr_tab[0].pin)
     {
     {
         pin_irq_hdr_tab[0].hdr(pin_irq_hdr_tab[0].args);
         pin_irq_hdr_tab[0].hdr(pin_irq_hdr_tab[0].args);
     }
     }
@@ -438,7 +438,7 @@ void irq0_callback(external_irq_callback_args_t *p_args)
 void irq1_callback(external_irq_callback_args_t *p_args)
 void irq1_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(1 == pin_irq_hdr_tab[1].pin)
+    if (1 == pin_irq_hdr_tab[1].pin)
     {
     {
         pin_irq_hdr_tab[1].hdr(pin_irq_hdr_tab[1].args);
         pin_irq_hdr_tab[1].hdr(pin_irq_hdr_tab[1].args);
     }
     }
@@ -448,7 +448,7 @@ void irq1_callback(external_irq_callback_args_t *p_args)
 void irq2_callback(external_irq_callback_args_t *p_args)
 void irq2_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(2 == pin_irq_hdr_tab[2].pin)
+    if (2 == pin_irq_hdr_tab[2].pin)
     {
     {
         pin_irq_hdr_tab[2].hdr(pin_irq_hdr_tab[2].args);
         pin_irq_hdr_tab[2].hdr(pin_irq_hdr_tab[2].args);
     }
     }
@@ -458,7 +458,7 @@ void irq2_callback(external_irq_callback_args_t *p_args)
 void irq3_callback(external_irq_callback_args_t *p_args)
 void irq3_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(3 == pin_irq_hdr_tab[3].pin)
+    if (3 == pin_irq_hdr_tab[3].pin)
     {
     {
         pin_irq_hdr_tab[3].hdr(pin_irq_hdr_tab[3].args);
         pin_irq_hdr_tab[3].hdr(pin_irq_hdr_tab[3].args);
     }
     }
@@ -468,7 +468,7 @@ void irq3_callback(external_irq_callback_args_t *p_args)
 void irq4_callback(external_irq_callback_args_t *p_args)
 void irq4_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(4 == pin_irq_hdr_tab[4].pin)
+    if (4 == pin_irq_hdr_tab[4].pin)
     {
     {
         pin_irq_hdr_tab[4].hdr(pin_irq_hdr_tab[4].args);
         pin_irq_hdr_tab[4].hdr(pin_irq_hdr_tab[4].args);
     }
     }
@@ -478,7 +478,7 @@ void irq4_callback(external_irq_callback_args_t *p_args)
 void irq5_callback(external_irq_callback_args_t *p_args)
 void irq5_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(5 == pin_irq_hdr_tab[5].pin)
+    if (5 == pin_irq_hdr_tab[5].pin)
     {
     {
         pin_irq_hdr_tab[5].hdr(pin_irq_hdr_tab[5].args);
         pin_irq_hdr_tab[5].hdr(pin_irq_hdr_tab[5].args);
     }
     }
@@ -488,7 +488,7 @@ void irq5_callback(external_irq_callback_args_t *p_args)
 void irq6_callback(external_irq_callback_args_t *p_args)
 void irq6_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(6 == pin_irq_hdr_tab[6].pin)
+    if (6 == pin_irq_hdr_tab[6].pin)
     {
     {
         pin_irq_hdr_tab[6].hdr(pin_irq_hdr_tab[6].args);
         pin_irq_hdr_tab[6].hdr(pin_irq_hdr_tab[6].args);
     }
     }
@@ -498,7 +498,7 @@ void irq6_callback(external_irq_callback_args_t *p_args)
 void irq7_callback(external_irq_callback_args_t *p_args)
 void irq7_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(7 == pin_irq_hdr_tab[7].pin)
+    if (7 == pin_irq_hdr_tab[7].pin)
     {
     {
         pin_irq_hdr_tab[7].hdr(pin_irq_hdr_tab[7].args);
         pin_irq_hdr_tab[7].hdr(pin_irq_hdr_tab[7].args);
     }
     }
@@ -508,7 +508,7 @@ void irq7_callback(external_irq_callback_args_t *p_args)
 void irq8_callback(external_irq_callback_args_t *p_args)
 void irq8_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(8 == pin_irq_hdr_tab[8].pin)
+    if (8 == pin_irq_hdr_tab[8].pin)
     {
     {
         pin_irq_hdr_tab[8].hdr(pin_irq_hdr_tab[8].args);
         pin_irq_hdr_tab[8].hdr(pin_irq_hdr_tab[8].args);
     }
     }
@@ -518,7 +518,7 @@ void irq8_callback(external_irq_callback_args_t *p_args)
 void irq9_callback(external_irq_callback_args_t *p_args)
 void irq9_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(9 == pin_irq_hdr_tab[9].pin)
+    if (9 == pin_irq_hdr_tab[9].pin)
     {
     {
         pin_irq_hdr_tab[9].hdr(pin_irq_hdr_tab[9].args);
         pin_irq_hdr_tab[9].hdr(pin_irq_hdr_tab[9].args);
     }
     }
@@ -528,7 +528,7 @@ void irq9_callback(external_irq_callback_args_t *p_args)
 void irq10_callback(external_irq_callback_args_t *p_args)
 void irq10_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(10 == pin_irq_hdr_tab[10].pin)
+    if (10 == pin_irq_hdr_tab[10].pin)
     {
     {
         pin_irq_hdr_tab[10].hdr(pin_irq_hdr_tab[10].args);
         pin_irq_hdr_tab[10].hdr(pin_irq_hdr_tab[10].args);
     }
     }
@@ -538,7 +538,7 @@ void irq10_callback(external_irq_callback_args_t *p_args)
 void irq11_callback(external_irq_callback_args_t *p_args)
 void irq11_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(11 == pin_irq_hdr_tab[11].pin)
+    if (11 == pin_irq_hdr_tab[11].pin)
     {
     {
         pin_irq_hdr_tab[11].hdr(pin_irq_hdr_tab[11].args);
         pin_irq_hdr_tab[11].hdr(pin_irq_hdr_tab[11].args);
     }
     }
@@ -548,7 +548,7 @@ void irq11_callback(external_irq_callback_args_t *p_args)
 void irq12_callback(external_irq_callback_args_t *p_args)
 void irq12_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(12 == pin_irq_hdr_tab[12].pin)
+    if (12 == pin_irq_hdr_tab[12].pin)
     {
     {
         pin_irq_hdr_tab[12].hdr(pin_irq_hdr_tab[12].args);
         pin_irq_hdr_tab[12].hdr(pin_irq_hdr_tab[12].args);
     }
     }
@@ -558,7 +558,7 @@ void irq12_callback(external_irq_callback_args_t *p_args)
 void irq13_callback(external_irq_callback_args_t *p_args)
 void irq13_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(13 == pin_irq_hdr_tab[13].pin)
+    if (13 == pin_irq_hdr_tab[13].pin)
     {
     {
         pin_irq_hdr_tab[13].hdr(pin_irq_hdr_tab[13].args);
         pin_irq_hdr_tab[13].hdr(pin_irq_hdr_tab[13].args);
     }
     }
@@ -568,7 +568,7 @@ void irq13_callback(external_irq_callback_args_t *p_args)
 void irq14_callback(external_irq_callback_args_t *p_args)
 void irq14_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(14 == pin_irq_hdr_tab[14].pin)
+    if (14 == pin_irq_hdr_tab[14].pin)
     {
     {
         pin_irq_hdr_tab[14].hdr(pin_irq_hdr_tab[14].args);
         pin_irq_hdr_tab[14].hdr(pin_irq_hdr_tab[14].args);
     }
     }
@@ -578,7 +578,7 @@ void irq14_callback(external_irq_callback_args_t *p_args)
 void irq15_callback(external_irq_callback_args_t *p_args)
 void irq15_callback(external_irq_callback_args_t *p_args)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    if(15 == pin_irq_hdr_tab[15].pin)
+    if (15 == pin_irq_hdr_tab[15].pin)
     {
     {
         pin_irq_hdr_tab[15].hdr(pin_irq_hdr_tab[15].args);
         pin_irq_hdr_tab[15].hdr(pin_irq_hdr_tab[15].args);
     }
     }

+ 221 - 0
bsp/ra6m4-cpk/drivers/drv_rtc.c

@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2021-08-14     Mr.Tiger     first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+#include "board.h"
+#include <sys/time.h>
+#include "hal_data.h"
+
+#ifdef BSP_USING_ONCHIP_RTC
+
+#define DBG_TAG              "drv.rtc"
+#ifdef DRV_DEBUG
+    #define DBG_LVL               DBG_LOG
+#else
+    #define DBG_LVL               DBG_INFO
+#endif /* DRV_DEBUG */
+#include <rtdbg.h>
+
+static rt_err_t ra_rtc_init(void)
+{
+    rt_err_t result = RT_EOK;
+
+    if (R_RTC_Open(&g_rtc_ctrl, &g_rtc_cfg) != RT_EOK)
+    {
+        LOG_E("rtc init failed.");
+        result = -RT_ERROR;
+    }
+
+    return result;
+}
+
+static time_t get_rtc_timestamp(void)
+{
+    struct tm tm_new = {0};
+    rtc_time_t g_current_time = {0};
+
+    R_RTC_CalendarTimeGet(&g_rtc_ctrl, &g_current_time);
+
+    tm_new.tm_year  = g_current_time.tm_year;
+    tm_new.tm_mon   = g_current_time.tm_mon;
+    tm_new.tm_mday  = g_current_time.tm_mday;
+
+    tm_new.tm_hour  = g_current_time.tm_hour;
+    tm_new.tm_min   = g_current_time.tm_min;
+    tm_new.tm_sec   = g_current_time.tm_sec;
+
+    tm_new.tm_wday  = g_current_time.tm_wday;
+    tm_new.tm_yday  = g_current_time.tm_yday;
+    tm_new.tm_isdst = g_current_time.tm_isdst;
+
+    return timegm(&tm_new);
+}
+
+static rt_err_t ra_get_secs(void *args)
+{
+    *(rt_uint32_t *)args = get_rtc_timestamp();
+    LOG_D("RTC: get rtc_time %x\n", *(rt_uint32_t *)args);
+
+    return RT_EOK;
+}
+
+static rt_err_t set_rtc_time_stamp(time_t time_stamp)
+{
+    struct tm *p_tm;
+    rtc_time_t g_current_time = {0};
+    p_tm = gmtime(&time_stamp);
+    if (p_tm->tm_year < 100)
+    {
+        return -RT_ERROR;
+    }
+
+    g_current_time.tm_sec    = p_tm->tm_sec ;
+    g_current_time.tm_min    = p_tm->tm_min ;
+    g_current_time.tm_hour   = p_tm->tm_hour;
+
+    g_current_time.tm_mday   = p_tm->tm_mday;
+    g_current_time.tm_mon    = p_tm->tm_mon;
+    g_current_time.tm_year   = p_tm->tm_year;
+
+    g_current_time.tm_wday   = p_tm->tm_wday;
+    g_current_time.tm_yday   = p_tm->tm_yday;
+
+    if (R_RTC_CalendarTimeSet(&g_rtc_ctrl, &g_current_time) != FSP_SUCCESS)
+    {
+        LOG_E("set rtc time failed.");
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+
+static rt_err_t ra_set_secs(void *args)
+{
+
+    rt_err_t result = RT_EOK;
+
+    if (set_rtc_time_stamp(*(rt_uint32_t *)args))
+    {
+        result = -RT_ERROR;
+    }
+    LOG_D("RTC: set rtc_time %x\n", *(rt_uint32_t *)args);
+
+    return result;
+}
+
+static rt_err_t ra_get_alarm(void *arg)
+{
+    rt_err_t result = RT_EOK;
+    struct rt_rtc_wkalarm *wkalarm = (struct rt_rtc_wkalarm *)arg;
+    rtc_alarm_time_t alarm_time_get =
+    {
+        .sec_match        =  RT_FALSE,
+        .min_match        =  RT_FALSE,
+        .hour_match       =  RT_FALSE,
+        .mday_match       =  RT_FALSE,
+        .mon_match        =  RT_FALSE,
+        .year_match       =  RT_FALSE,
+        .dayofweek_match  =  RT_FALSE,
+    };
+
+    if (RT_EOK == R_RTC_CalendarAlarmGet(&g_rtc_ctrl, &alarm_time_get))
+    {
+        wkalarm->tm_hour = alarm_time_get.time.tm_hour;
+        wkalarm->tm_min  = alarm_time_get.time.tm_min;
+        wkalarm->tm_sec  = alarm_time_get.time.tm_sec;
+    }
+    else
+    {
+        LOG_E("Calendar alarm Get failed.");
+    }
+
+    return result;
+}
+
+static rt_err_t ra_set_alarm(void *arg)
+{
+    rt_err_t result = RT_EOK;
+    struct rt_rtc_wkalarm *wkalarm = (struct rt_rtc_wkalarm *)arg;
+    rtc_alarm_time_t alarm_time_set =
+    {
+        .sec_match        =  RT_TRUE,
+        .min_match        =  RT_TRUE,
+        .hour_match       =  RT_TRUE,
+        .mday_match       =  RT_FALSE,
+        .mon_match        =  RT_FALSE,
+        .year_match       =  RT_FALSE,
+        .dayofweek_match  =  RT_FALSE,
+    };
+
+    alarm_time_set.time.tm_hour = wkalarm->tm_hour;
+    alarm_time_set.time.tm_min  = wkalarm->tm_min;
+    alarm_time_set.time.tm_sec  = wkalarm->tm_sec;
+    if (1 == wkalarm->enable)
+    {
+        if (RT_EOK != R_RTC_CalendarAlarmSet(&g_rtc_ctrl, &alarm_time_set))
+        {
+            LOG_E("Calendar alarm Set failed.");
+            result = -RT_ERROR;
+        }
+    }
+    else
+    {
+        alarm_time_set.sec_match        =  RT_FALSE;
+        alarm_time_set.min_match        =  RT_FALSE;
+        alarm_time_set.hour_match       =  RT_FALSE;
+        if (RT_EOK != R_RTC_CalendarAlarmSet(&g_rtc_ctrl, &alarm_time_set))
+        {
+            LOG_E("Calendar alarm Stop failed.");
+            result = -RT_ERROR;
+        }
+    }
+    return result;
+}
+
+static rt_device_t ra_device;
+
+void rtc_callback(rtc_callback_args_t *p_args)
+{
+    if (RTC_EVENT_ALARM_IRQ == p_args->event)
+    {
+        rt_alarm_update(ra_device, 1);
+    }
+}
+
+static const struct rt_rtc_ops ra_rtc_ops =
+{
+    .init      = ra_rtc_init,
+    .get_secs  = ra_get_secs,
+    .set_secs  = ra_set_secs,
+    .set_alarm = ra_set_alarm,
+    .get_alarm = ra_get_alarm,
+};
+
+static rt_rtc_dev_t ra_rtc_dev;
+
+static int rt_hw_rtc_init(void)
+{
+    rt_err_t result;
+
+    ra_rtc_dev.ops = &ra_rtc_ops;
+
+    result = rt_hw_rtc_register(&ra_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL);
+    if (result != RT_EOK)
+    {
+        LOG_E("rtc register err code: %d", result);
+        return result;
+    }
+    LOG_D("rtc init success");
+
+    return RT_EOK;
+}
+INIT_DEVICE_EXPORT(rt_hw_rtc_init);
+#endif

+ 95 - 0
bsp/ra6m4-cpk/drivers/drv_wdt.c

@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2021-08-20     Mr.Tiger     first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <rthw.h>
+#include <drv_common.h>
+#include <drv_config.h>
+#include <hal_data.h>
+
+#ifdef RT_USING_WDT
+
+//#define DRV_DEBUG
+#define LOG_TAG             "drv.wdt"
+#include <rtdbg.h>
+
+static struct rt_watchdog_device ra_wdt_dev;
+static struct rt_watchdog_ops ops;
+
+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)
+{
+    struct st_wdt_timeout_values *wdt_value = {0};
+    switch (cmd)
+    {
+        /* feed the watchdog */
+    case RT_DEVICE_CTRL_WDT_KEEPALIVE:
+        if(R_WDT_Refresh(&g_wdt_ctrl) != FSP_SUCCESS)
+        {
+            LOG_E("watch dog keepalive fail.");
+        }
+        break;
+        /* set watchdog timeout */
+    case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
+        /**< set*/
+//        g_wdt_cfg.timeout = *(rt_uint32_t *)arg;
+        break;
+    case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
+        wdt_value = (struct st_wdt_timeout_values *)arg;
+        if(R_WDT_TimeoutGet(&g_wdt_ctrl,wdt_value) != FSP_SUCCESS)
+        {
+            LOG_E("wdt get timeout failed.");
+            return -RT_ERROR;
+        }
+        break;
+    case RT_DEVICE_CTRL_WDT_START:
+        if(R_WDT_Open(&g_wdt_ctrl, &g_wdt_cfg) == FSP_SUCCESS)
+        {
+            if(R_WDT_Refresh(&g_wdt_ctrl) != FSP_SUCCESS)
+            {
+                LOG_E("wdt start failed.");
+                return -RT_ERROR;
+            }
+        }
+        else
+        {
+            LOG_E("wdt start failed.");
+            return -RT_ERROR;
+        }
+        break;
+    default:
+        LOG_W("This command is not supported.");
+        return -RT_ERROR;
+    }
+    return RT_EOK;
+}
+
+int rt_wdt_init(void)
+{
+    ops.init = &wdt_init;
+    ops.control = &wdt_control;
+    ra_wdt_dev.ops = &ops;
+    /* register watchdog device */
+    if (rt_hw_watchdog_register(&ra_wdt_dev, "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_wdt_init);
+
+#endif /* RT_USING_WDT */