diff --git a/include/sys.h b/include/sys.h new file mode 100644 index 0000000..c2d9507 --- /dev/null +++ b/include/sys.h @@ -0,0 +1,34 @@ +#pragma once +#include +#include + +#include "app_timer.h" +#include "app_uart.h" +#include "app_util_platform.h" +#include "ble_advdata.h" +#include "ble_advertising.h" +#include "ble_conn_params.h" +#include "ble_hci.h" +#include "ble_nus.h" +#include "bsp_btn_ble.h" +#include "nordic_common.h" +#include "nrf.h" +#include "nrf_ble_gatt.h" +#include "nrf_ble_qwr.h" +#include "nrf_log.h" +#include "nrf_log_ctrl.h" +#include "nrf_log_default_backends.h" +#include "nrf_pwr_mgmt.h" +#include "nrf_sdh.h" +#include "nrf_sdh_ble.h" +#include "nrf_sdh_soc.h" +// +#include "version.h" + +void zsys_init(); +void zsys_loop(); + +#define ZLOGI(...) NRF_LOG_INFO(__VA_ARGS__) +#define ZLOGE(...) NRF_LOG_ERROR(__VA_ARGS__) +#define ZLOGW(...) NRF_LOG_WARNING(__VA_ARGS__) +#define ZLOGD(...) NRF_LOG_DEBUG(__VA_ARGS__) \ No newline at end of file diff --git a/src/sys.c b/src/sys.c new file mode 100644 index 0000000..545646e --- /dev/null +++ b/src/sys.c @@ -0,0 +1,39 @@ +#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) { + ret_code_t err_code = NRF_LOG_INIT(NULL); + APP_ERROR_CHECK(err_code); + + 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(); + APP_ERROR_CHECK(err_code); +} + +static void idle_state_handle(void) { + if (NRF_LOG_PROCESS() == false) { + nrf_pwr_mgmt_run(); + } +} + +void zsys_init() { + log_init(); + timers_init(); + power_management_init(); + +} + +void zsys_loop() { + while (true) { + idle_state_handle(); + } +}