|
|
@ -107,23 +107,23 @@ int16_t znrf_adc_channel_read_val(uint16_t channel) { |
|
|
|
/******************************************************************************* |
|
|
|
* RTC * |
|
|
|
*******************************************************************************/ |
|
|
|
volatile uint32_t g_timestamp = 0; |
|
|
|
volatile uint32_t g_power_on_rtc = 0; |
|
|
|
static uint8_t s_timeCount1second = 0; |
|
|
|
volatile uint32_t g_timestamp = 0; |
|
|
|
volatile uint32_t g_power_on_rtc = 0; |
|
|
|
// static uint8_t s_timeCount1second = 0; |
|
|
|
|
|
|
|
uint32_t znordic_getpower_on_s() { |
|
|
|
|
|
|
|
uint32_t znordic_getpower_on_ms() { |
|
|
|
__disable_irq(); |
|
|
|
uint32_t reg = g_timestamp; |
|
|
|
uint32_t ret = g_timestamp * 125; |
|
|
|
__enable_irq(); |
|
|
|
return reg; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
uint32_t znordic_getpower_on_ms() { |
|
|
|
uint32_t znordic_getpower_on_s() { |
|
|
|
__disable_irq(); |
|
|
|
uint32_t ret = g_timestamp * 1000 + s_timeCount1second * 125; |
|
|
|
uint32_t reg = znordic_getpower_on_ms() / 1000; |
|
|
|
__enable_irq(); |
|
|
|
return ret; |
|
|
|
return reg; |
|
|
|
} |
|
|
|
|
|
|
|
uint32_t znordic_haspassed_ms(uint32_t last) { |
|
|
|
uint32_t now = znordic_getpower_on_ms(); |
|
|
|
if (now < last) { |
|
|
@ -134,12 +134,12 @@ uint32_t znordic_haspassed_ms(uint32_t last) { |
|
|
|
} |
|
|
|
|
|
|
|
void znordic_rtc_settime_s(uint32_t timestampNow) { |
|
|
|
if (timestampNow < g_timestamp) { |
|
|
|
if (timestampNow < znordic_getpower_on_s()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
g_power_on_rtc = timestampNow - g_timestamp; |
|
|
|
g_power_on_rtc = timestampNow - znordic_getpower_on_s(); |
|
|
|
} |
|
|
|
uint32_t znordic_rtc_gettime_s(void) { return g_timestamp + g_power_on_rtc; } |
|
|
|
uint32_t znordic_rtc_gettime_s(void) { return znordic_getpower_on_s() + g_power_on_rtc; } |
|
|
|
void znordic_rtc_settime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) { |
|
|
|
static struct tm s_tm; |
|
|
|
memset(&s_tm, 0, sizeof(s_tm)); |
|
|
@ -152,24 +152,25 @@ void znordic_rtc_settime(uint16_t year, uint8_t month, uint8_t day, uint8_t |
|
|
|
s_tm.tm_isdst = -1; |
|
|
|
|
|
|
|
uint32_t nowtimestamp = mktime(&s_tm); |
|
|
|
g_power_on_rtc = nowtimestamp - g_timestamp; |
|
|
|
g_power_on_rtc = nowtimestamp - znordic_getpower_on_s(); |
|
|
|
} |
|
|
|
|
|
|
|
void znordic_rtc_gettime(ztm_t* now) { |
|
|
|
time_t now_s = g_timestamp + g_power_on_rtc; |
|
|
|
time_t now_s = (g_timestamp * 125) / 1000 + g_power_on_rtc; |
|
|
|
*now = *localtime(&now_s); |
|
|
|
} |
|
|
|
|
|
|
|
static void rtcCallbackFunc(nrf_drv_rtc_int_type_t interruptType) { |
|
|
|
if (interruptType == NRF_DRV_RTC_INT_TICK) // ÖжÏÀàÐÍ£ºµÎ´ðÖÐ?? |
|
|
|
{ |
|
|
|
if (s_timeCount1second >= 7) // 125ms * 8 = 1s |
|
|
|
{ |
|
|
|
s_timeCount1second = 0; |
|
|
|
g_timestamp++; |
|
|
|
} else { |
|
|
|
s_timeCount1second++; |
|
|
|
} |
|
|
|
g_timestamp++; |
|
|
|
// if (s_timeCount1second >= 7) // 125ms * 8 = 1s |
|
|
|
// { |
|
|
|
// s_timeCount1second = 0; |
|
|
|
// g_timestamp++; |
|
|
|
// } else { |
|
|
|
// s_timeCount1second++; |
|
|
|
// } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|