Browse Source

support RTC0, RTC1, RTC2 select

chenyingchun0312 4 years ago
parent
commit
c5b0a848dc

+ 6 - 2
bsp/nrf5x/libraries/drivers/drv_rtc.c

@@ -18,7 +18,7 @@
 #ifdef BSP_USING_ONCHIP_RTC
 
 #define LOG_TAG             "drv.rtc"
-#define DBG_LVL               DBG_LOG
+#define DBG_LVL              DBG_LOG
 #include <rtdbg.h>
 
 /* 2018-01-30 14:44:50 = RTC_TIME_INIT(2018, 1, 30, 14, 44, 50)  */
@@ -29,6 +29,10 @@
 #define ONCHIP_RTC_TIME_DEFAULT                    RTC_TIME_INIT(2018, 1, 1, 0, 0 ,0)
 #endif
 
+#ifndef RTC_INSTANCE_ID
+#define RTC_INSTANCE_ID (2)
+#endif
+
 #define TICK_FREQUENCE_HZ        (RT_TICK_PER_SECOND)     // RTC tick frequence, in HZ
 
 static struct rt_device rtc;
@@ -54,7 +58,7 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
     #define SYSTICK_CLOCK_HZ    (32768UL)
     #define RTC_PRESCALER       ((uint32_t) (NRFX_ROUNDED_DIV(SYSTICK_CLOCK_HZ, TICK_FREQUENCE_HZ) - 1))
 
-    const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2);
+    const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(RTC_INSTANCE_ID);
     nrf_clock_lf_src_set(NRF_CLOCK, (nrf_clock_lfclk_t)NRFX_CLOCK_CONFIG_LF_SRC);
     nrfx_clock_lfclk_start();
 

+ 17 - 5
bsp/nrf5x/nrf52832/board/Kconfig

@@ -318,21 +318,33 @@ endif
     bool "Enable RTC"
     select RT_USING_RTC
     select RT_USING_LIBC
-    select NRFX_CLOCK_ENABLED
     default n
     if BSP_USING_ONCHIP_RTC
         config NRFX_CLOCK_ENABLED
         int 
         default 1
+        config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
+        int
+        default 7
         config NRFX_RTC_ENABLED
         int 
         default 1
-        config NRFX_RTC2_ENABLED
-        int 
+        config NRFX_RTC0_ENABLED
+        int
         default 1
-        config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
+        config NRFX_RTC1_ENABLED
         int
-        default 7
+        default 1
+        config NRFX_RTC2_ENABLED
+        int
+        default 1
+        config RTC_INSTANCE_ID
+        int 
+        default 2
+        config RTC_INSTANCE_ID
+            int "select RTC instance id, must be 0, 1, 2"
+            range 0 2
+            default 2
     endif
 endmenu
 

+ 34 - 1
bsp/nrf5x/nrf52840/board/Kconfig

@@ -346,8 +346,41 @@ menu "On-chip Peripheral Drivers"
         int
         default 1
     endif
-endmenu
 
+    menuconfig BSP_USING_ONCHIP_RTC
+    bool "Enable RTC"
+    select RT_USING_RTC
+    select RT_USING_LIBC
+    default n
+    if BSP_USING_ONCHIP_RTC
+        config NRFX_CLOCK_ENABLED
+        int 
+        default 1
+        config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
+        int
+        default 7
+        config NRFX_RTC_ENABLED
+        int 
+        default 1
+        config NRFX_RTC0_ENABLED
+        int
+        default 1
+        config NRFX_RTC1_ENABLED
+        int
+        default 1
+        config NRFX_RTC2_ENABLED
+        int
+        default 1
+        config RTC_INSTANCE_ID
+        int 
+        default 2
+        config RTC_INSTANCE_ID
+            int "select RTC instance id, must be 0, 1, 2"
+            range 0 2
+            default 2
+    endif
+
+endmenu
 
 choice
 prompt "BLE STACK"