[add] 添加 RTC、WDT 驱动

This commit is contained in:
Sherman committed 2021-10-22 15:37:05 +08:00
1 parent 1e880bc30a
commit 6432cf4af9
12 files changed
+634 -150

No files matched your search

+8 -2
View File
@@ -144,10 +144,12 @@ CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND 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_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
@@ -587,6 +589,10 @@ CONFIG_BSP_USING_I2C=y
CONFIG_BSP_USING_I2C1=y
CONFIG_BSP_I2C1_SCL_PIN=0x0512
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
+6 -2
View File
@@ -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.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
@@ -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\#\#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.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\#\#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/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\#\#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.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
+10 -3
View File
@@ -33,7 +33,11 @@
| **片上外设** | **支持情况** | **备注** |
| :----------- | :---------- | :------------------------ |
| 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
void hal_entry(void)
@@ -120,7 +124,10 @@ void hal_entry(void)
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
View File
@@ -11,8 +11,12 @@
<generator id="Renesas RA Smart Configurator">
<project_files>
<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/icu_sample.c"/>
<file category="source" name="src/rtc_sample.c"/>
<file category="other" name="src/SConscript"/>
<file category="source" name="src/wdt_sample.c"/>
</project_files>
</generator>
</generators>
@@ -58,14 +62,19 @@
<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/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_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_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_features.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_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_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/renesas.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="source" name="ra/fsp/src/r_ioport/r_ioport.c"/>
<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="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"/>
</files>
</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_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_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_wdt_cfg.h" path=""/>
<file category="other" name="ra_cfg/SConscript"/>
</files>
</component>
+40
View File
@@ -163,6 +163,14 @@
<description>SCI UART</description>
<originalPack>Renesas.RA.3.1.0.pack</originalPack>
</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>
<raElcConfiguration/>
<raIcuConfiguration/>
@@ -196,10 +204,39 @@
<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"/>
</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">
<stack module="module.driver.ioport_on_ioport.0"/>
<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>
<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">
<property id="config.driver.ioport.checking" value="config.driver.ioport.checking.system"/>
</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.flow_control" value="config.driver.sci_uart.flow_control.disabled"/>
</config>
<config id="config.driver.rtc">
<property id="config.driver.rtc.param_checking_enable" value="config.driver.rtc.param_checking_enable.bsp"/>
</config>
</raModuleConfiguration>
<raPinConfiguration>
<symbolicName propertyId="p000.symbolic_name" value="ARDUINO_AN00"/>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 47 KiB

@@ -15,8 +15,81 @@
## UART
- 添加一个 UART 端口外设配置
如何添加一个 UART 端口外设配置?
1. 选择 Stacks 配置页,点击 New Stack 找到 UART。
![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
View File
@@ -73,6 +73,28 @@ menu "Hardware Drivers Config"
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
menu "Board extended module Drivers"
+3
View File
@@ -22,6 +22,9 @@ if GetDepend(['RT_USING_PIN']):
if GetDepend(['RT_USING_WDT']):
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('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
src += ['drv_soft_i2c.c']
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+95
View File
@@ -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 */