2 changed files with 51 additions and 28 deletions
-
10include/sys.h
-
53src/sys.c
@ -1,38 +1,51 @@ |
|||||
#include "sys.h" |
#include "sys.h" |
||||
static void timers_init(void) { |
|
||||
ret_code_t err_code = app_timer_init(); |
|
||||
APP_ERROR_CHECK(err_code); |
|
||||
} |
|
||||
|
|
||||
static void log_init(void) { |
|
||||
|
void zsys_init() { |
||||
|
{ |
||||
|
/******************************************************************************* |
||||
|
* 日志系统初始化 * |
||||
|
*******************************************************************************/ |
||||
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); |
||||
|
|
||||
NRF_LOG_DEFAULT_BACKENDS_INIT(); |
NRF_LOG_DEFAULT_BACKENDS_INIT(); |
||||
} |
} |
||||
|
|
||||
/**@brief Function for initializing power management. |
|
||||
*/ |
|
||||
static void power_management_init(void) { |
|
||||
ret_code_t err_code; |
|
||||
err_code = nrf_pwr_mgmt_init(); |
|
||||
|
{ |
||||
|
/******************************************************************************* |
||||
|
* 定时器初始化 * |
||||
|
*******************************************************************************/ |
||||
|
ret_code_t err_code = app_timer_init(); |
||||
APP_ERROR_CHECK(err_code); |
APP_ERROR_CHECK(err_code); |
||||
} |
} |
||||
|
|
||||
static void idle_state_handle(void) { |
|
||||
if (NRF_LOG_PROCESS() == false) { |
|
||||
nrf_pwr_mgmt_run(); |
|
||||
|
{ |
||||
|
/******************************************************************************* |
||||
|
* 电源管理初始化 * |
||||
|
*******************************************************************************/ |
||||
|
ret_code_t err_code; |
||||
|
err_code = nrf_pwr_mgmt_init(); |
||||
|
APP_ERROR_CHECK(err_code); |
||||
} |
} |
||||
|
{ |
||||
|
/******************************************************************************* |
||||
|
* 蓝牙协议栈使能 * |
||||
|
*******************************************************************************/ |
||||
|
ret_code_t err_code; |
||||
|
err_code = nrf_sdh_enable_request(); |
||||
|
APP_ERROR_CHECK(err_code); |
||||
|
uint32_t ram_start = 0; |
||||
|
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start); |
||||
|
APP_ERROR_CHECK(err_code); |
||||
|
// Enable BLE stack. |
||||
|
err_code = nrf_sdh_ble_enable(&ram_start); |
||||
|
APP_ERROR_CHECK(err_code); |
||||
} |
} |
||||
|
|
||||
void zsys_init() { |
|
||||
log_init(); |
|
||||
timers_init(); |
|
||||
power_management_init(); |
|
||||
} |
} |
||||
|
|
||||
void zsys_loop() { |
void zsys_loop() { |
||||
while (true) { |
while (true) { |
||||
idle_state_handle(); |
|
||||
|
if (NRF_LOG_PROCESS() == false) { |
||||
|
nrf_pwr_mgmt_run(); |
||||
|
} |
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue