Browse Source

update

master
zhaohe 1 year ago
parent
commit
0252fc4554
  1. 13
      include/znordic.h
  2. 35
      src/znordic.c

13
include/znordic.h

@ -44,15 +44,17 @@
*******************************************************************************/
typedef struct tm ztm_t;
void znordic_init();
void znordic_loop();
void znordic_init();
void znordic_loop();
void znrf_gpio_cfg_output(uint32_t pin_number, nrf_gpio_pin_pull_t pull);
int16_t znrf_adc_channel_read_val(uint16_t channel);
void znordic_rtc_settime_s(uint32_t timestamp_s);
uint32_t znordic_rtc_gettime_s(void);
uint32_t znordic_getpower_on_s(void); //
uint32_t znordic_getpower_on_s(void); //
uint32_t znordic_getpower_on_ms(void); // 125ms
uint32_t znordic_haspassed_ms(uint32_t last);
void znordic_rtc_gettime(ztm_t* now);
void znordic_rtc_settime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec);
void znordic_force_flush_log();
@ -106,7 +108,6 @@ const char* hex2str(const uint8_t* data, uint16_t len);
if (!(expr)) { \
ZLOGI("%s:%d ZASSERT(%s) fail", __FILE__, __LINE__, #expr); \
NRF_LOG_PROCESS(); \
app_sched_execute(); \
app_error_handler_bare(0); \
APP_ERROR_CHECK_BOOL(false); \
} \
} while (!(expr))
} while (0)

35
src/znordic.c

@ -14,8 +14,6 @@
#include "nrf_log_default_backends.h"
#include "nrfx_rtc.h"
/*******************************************************************************
* RTC *
*******************************************************************************/
@ -89,9 +87,7 @@ void znordic_loop() {
}
}
}
void znordic_force_flush_log() {
NRF_LOG_FLUSH();
}
void znordic_force_flush_log() { NRF_LOG_FLUSH(); }
void znrf_gpio_cfg_output(uint32_t pin_number, nrf_gpio_pin_pull_t pull) { //
nrf_gpio_cfg(pin_number, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, pull, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
@ -111,9 +107,31 @@ 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;
uint32_t znordic_getpower_on_s() { return g_timestamp; }
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() {
__disable_irq();
uint32_t reg = g_timestamp;
__enable_irq();
return reg;
}
uint32_t znordic_getpower_on_ms() {
__disable_irq();
uint32_t ret = g_timestamp * 1000 + s_timeCount1second * 125;
__enable_irq();
return ret;
}
uint32_t znordic_haspassed_ms(uint32_t last) {
uint32_t now = znordic_getpower_on_ms();
if (now < last) {
return 0xFFFFFFFF - last + now;
} else {
return now - last;
}
}
void znordic_rtc_settime_s(uint32_t timestampNow) {
if (timestampNow < g_timestamp) {
@ -143,7 +161,6 @@ void znordic_rtc_gettime(ztm_t* now) {
}
static void rtcCallbackFunc(nrf_drv_rtc_int_type_t interruptType) {
static uint8_t s_timeCount1second = 0;
if (interruptType == NRF_DRV_RTC_INT_TICK) // ÖÐÏÀàÐÍ£ºµÎ´ðÖÐ??
{
if (s_timeCount1second >= 7) // 125ms * 8 = 1s

Loading…
Cancel
Save