#include "bsp_rtc.h" #define rtc_cb_max 32 static RTC_callback rtc_cb[rtc_cb_max] = {0}; //nRF52系列芯片内部有3个RTC,其中RTC0是给协议栈softdevice用,RTC1分配给 App timer用 const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2); /**< Declaring an instance of nrf_drv_rtc for RTC2. */ static rtc_t m_rtc; /** @brief: Function for handling the RTC0 interrupts. * Triggered on TICK and COMPARE0 match. */ static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { if (int_type == NRF_DRV_RTC_INT_COMPARE0) { for(int i=0;i 0 && ms < 0xFFFF){ m_rtc.Compare_ms = ms; return 0; } return -1; } void RTC_CompareEnable(void) { uint32_t err_code; err_code = nrf_drv_rtc_cc_set(&rtc,RTC_CHANNEL,m_rtc.Compare_ms,true); APP_ERROR_CHECK(err_code); // nrf_rtc_int_enable(rtc.p_reg, RTC_CHANNEL_MASK); m_rtc.is_CompareEnable = 1; } void RTC_CompareDisable(void) { uint32_t err_code; err_code = nrf_drv_rtc_cc_disable(&rtc,RTC_CHANNEL); APP_ERROR_CHECK(err_code); // nrf_rtc_int_disable(rtc.p_reg, RTC_CHANNEL_MASK); m_rtc.is_CompareEnable = 0; } unsigned char RTC_GetCompareEnableFlag() { return m_rtc.is_CompareEnable; } void lfclk_config(void) { ret_code_t err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); nrf_drv_clock_lfclk_request(NULL); } void RTC_Init(void) { uint32_t err_code; //Initialize RTC instance nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG; config.prescaler = RTC_PRESCALER; err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler); APP_ERROR_CHECK(err_code); // //Power on RTC instance // nrf_drv_rtc_enable(&rtc); }