|
@ -1,5 +1,6 @@ |
|
|
#include "znordic.h" |
|
|
#include "znordic.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h> |
|
|
#include <stdbool.h> |
|
|
#include <stdbool.h> |
|
|
#include <stdint.h> |
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
@ -29,7 +30,7 @@ void znordic_init() { |
|
|
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); |
|
|
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); |
|
|
{ |
|
|
{ |
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* 日志系统�始化 * |
|
|
|
|
|
|
|
|
* ÈÕ־ϵͳ³õʼ?? * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
ret_code_t err_code = NRF_LOG_INIT(NULL); |
|
|
ret_code_t err_code = NRF_LOG_INIT(NULL); |
|
|
APP_ERROR_CHECK(err_code); |
|
|
APP_ERROR_CHECK(err_code); |
|
@ -39,7 +40,7 @@ void znordic_init() { |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* 定时器�始化 * |
|
|
|
|
|
|
|
|
* ¶¨Ê±Æ÷³õʼ»¯ * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
ret_code_t err_code = app_timer_init(); |
|
|
ret_code_t err_code = app_timer_init(); |
|
|
APP_ERROR_CHECK(err_code); |
|
|
APP_ERROR_CHECK(err_code); |
|
@ -47,7 +48,7 @@ void znordic_init() { |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* 电�管��始化 * |
|
|
|
|
|
|
|
|
* µçÔ´¹ÜÀí³õʼ?? * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
ret_code_t err_code; |
|
|
ret_code_t err_code; |
|
|
err_code = nrf_pwr_mgmt_init(); |
|
|
err_code = nrf_pwr_mgmt_init(); |
|
@ -55,7 +56,7 @@ void znordic_init() { |
|
|
} |
|
|
} |
|
|
{ |
|
|
{ |
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* è“�牙å��è®®æ ˆä½¿èƒ½ * |
|
|
|
|
|
|
|
|
* À¶ÑÀÐÒéջʹ?? * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
ret_code_t err_code; |
|
|
ret_code_t err_code; |
|
|
err_code = nrf_sdh_enable_request(); |
|
|
err_code = nrf_sdh_enable_request(); |
|
@ -72,7 +73,7 @@ void znordic_init() { |
|
|
ret_code_t errCode; |
|
|
ret_code_t errCode; |
|
|
|
|
|
|
|
|
nrf_drv_rtc_config_t rtcConfig = NRF_DRV_RTC_DEFAULT_CONFIG; // Initialize RTC instance |
|
|
nrf_drv_rtc_config_t rtcConfig = NRF_DRV_RTC_DEFAULT_CONFIG; // Initialize RTC instance |
|
|
rtcConfig.prescaler = 4095; // 如实现8HZ的频率,则PRESCALER寄å˜å™¨åº”该设为32768/8-1 = 4095 |
|
|
|
|
|
|
|
|
rtcConfig.prescaler = 4095; // Èçʵ??8HZµÄƵÂÊ£¬ÔòPRESCALER¼Ä´æÆ÷Ó¦¸ÃÉè??32768/8-1 = 4095 |
|
|
|
|
|
|
|
|
errCode = nrf_drv_rtc_init(&s_rtcHandle, &rtcConfig, rtcCallbackFunc); |
|
|
errCode = nrf_drv_rtc_init(&s_rtcHandle, &rtcConfig, rtcCallbackFunc); |
|
|
APP_ERROR_CHECK(errCode); |
|
|
APP_ERROR_CHECK(errCode); |
|
@ -93,6 +94,14 @@ void znordic_loop() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void znordic_force_flush_log() { |
|
|
|
|
|
// for (size_t i = 0; i < 5; i++) { |
|
|
|
|
|
// app_sched_execute(); |
|
|
|
|
|
// NRF_LOG_FLUSH(); |
|
|
|
|
|
// nrf_delay_ms(1); |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void znrf_gpio_cfg_output(uint32_t pin_number, nrf_gpio_pin_pull_t pull) { // |
|
|
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); |
|
|
nrf_gpio_cfg(pin_number, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, pull, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); |
|
|
} |
|
|
} |
|
@ -144,7 +153,7 @@ void znordic_rtc_gettime(ztm_t *now) { |
|
|
|
|
|
|
|
|
static void rtcCallbackFunc(nrf_drv_rtc_int_type_t interruptType) { |
|
|
static void rtcCallbackFunc(nrf_drv_rtc_int_type_t interruptType) { |
|
|
static uint8_t s_timeCount1second = 0; |
|
|
static uint8_t s_timeCount1second = 0; |
|
|
if (interruptType == NRF_DRV_RTC_INT_TICK) // 䏿–类型:滴ç”䏿– |
|
|
|
|
|
|
|
|
if (interruptType == NRF_DRV_RTC_INT_TICK) // ÖжÏÀàÐÍ£ºµÎ´ðÖÐ?? |
|
|
{ |
|
|
{ |
|
|
if (s_timeCount1second >= 7) // 125ms * 8 = 1s |
|
|
if (s_timeCount1second >= 7) // 125ms * 8 = 1s |
|
|
{ |
|
|
{ |
|
@ -155,3 +164,21 @@ static void rtcCallbackFunc(nrf_drv_rtc_int_type_t interruptType) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* fmt(const char* fmt, ...) { |
|
|
|
|
|
static char buf[256]; |
|
|
|
|
|
va_list args; |
|
|
|
|
|
va_start(args, fmt); |
|
|
|
|
|
vsnprintf(buf, 255, fmt, args); |
|
|
|
|
|
va_end(args); |
|
|
|
|
|
return buf; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* hex2str(const uint8_t* data, uint16_t len) { |
|
|
|
|
|
static char buf[256]; |
|
|
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
|
|
|
buf[i * 2] = (data[i] >> 4) + '0'; |
|
|
|
|
|
buf[i * 2 + 1] = (data[i] & 0x0f) + '0'; |
|
|
|
|
|
} |
|
|
|
|
|
return buf; |
|
|
|
|
|
} |