#include "sdk_common.h" #include "app_timer.h" #include "bsp_time.h" #include "nrf_drv_timer.h" #include "SEGGER_RTT.h" #include "system.h" #include "app_timer.h" #include "nrf_drv_rtc.h" #include "nrf_pwr_mgmt.h" #include "hal_imu.h" /********************** 变量区 *************************/ static const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2); static uint8_t isSleep = 0; volatile static uint32_t time_1ms = 0; volatile uint32_t time_10ms_flag = 0; #define time_cb_max 32 static TIME_callback time_cb[time_cb_max]={0}; /********************** 函数声明区 *************************/ static void rtc_tick_handler(nrf_drv_rtc_int_type_t int_type) { uint32_t err_code; if (int_type == NRF_DRV_RTC_INT_COMPARE0) { // SEGGER_RTT_printf(0,"1"); // uint32_t tem1 = NRF_RTC0->COUNTER; nrf_drv_rtc_counter_clear(&rtc); err_code = nrf_drv_rtc_cc_set(&rtc,NRF_DRV_RTC_INT_COMPARE0,330,true); APP_ERROR_CHECK(err_code); if(isSleep==0){ time_1ms+=10; time_10ms_flag =1; for(int i=0;iCOUNTER; // if(tem20) SEGGER_RTT_printf(0,"rtc_tick_handler(%d)\n",tem2-tem1); } } else if (int_type == NRF_DRV_RTC_INT_TICK) { // SEGGER_RTT_printf(0,"NRF_DRV_RTC_INT_TICK(0x%X)\n",NRF_RTC0->COUNTER); } } /********************** 外部函数声明区 *************************/ //=== 系统滴答时间 ===// uint32_t TIME_GetTicks(void) { return time_1ms; } int TIME_Regist(TIME_callback cb) { for(int i=0;iCOUNTER; // pending_number_before = CheckPending_IRQ(&result[0][0],60); // sd_evt_get(&p_evt_id_before); // ispr0_before = NVIC->ISPR[0]; // ispr1_before = NVIC->ISPR[1]; // // nrf_pwr_mgmt_run(); // // ispr0_after = NVIC->ISPR[0]; // ispr1_after = NVIC->ISPR[1]; // sd_evt_get(&p_evt_id_after); // pending_number_after = CheckPending_IRQ(&result[1][0],60); // region_end = NRF_RTC2->COUNTER; // // // CRITICAL_REGION_EXIT(); // // SEGGER_RTT_printf(0,"*******wakeup result start*******\n"); // // if (pending_number_before) // { // for(i=0;iISPR[0]:0x%X, NVIC->ISPR[1]:0x%X\n",ispr0_before,ispr1_before); // SEGGER_RTT_printf(0,"after----NVIC->ISPR[0]:0x%X, NVIC->ISPR[1]:0x%X\n",ispr0_after,ispr1_after); // // SEGGER_RTT_printf(0,"*******wakeup result end*******\n"); // // SEGGER_RTT_printf (0,"region times: %d\n",region_end-region_start); //} uint32_t rtc_sleep(void) { uint32_t tem1 = NRF_RTC0->COUNTER; uint32_t ret = 0; uint32_t err_code; isSleep = 1; if(IMU_isLoader()==0){ err_code = nrf_drv_rtc_cc_set(&rtc,0,33000,true); APP_ERROR_CHECK(err_code);} else { err_code = nrf_drv_rtc_cc_set(&rtc,0,3300,true); APP_ERROR_CHECK(err_code);} nrf_drv_rtc_counter_clear(&rtc); while(nrf_drv_rtc_counter_get(&rtc) != 0); //进入睡眠 for(int i=0;i<5;i++){ uint32_t cnt1 = NRF_RTC0->COUNTER; nrf_pwr_mgmt_run(); // idle_state_handle(); uint32_t cnt2 = NRF_RTC0->COUNTER; if(cnt232) break; } err_code = nrf_drv_rtc_cc_set(&rtc,0,330,true); APP_ERROR_CHECK(err_code); nrf_drv_rtc_counter_clear(&rtc); while(nrf_drv_rtc_counter_get(&rtc) != 0); isSleep = 0; uint32_t tem2 = NRF_RTC0->COUNTER; if(tem2