3 #if RUUVI_NRF5_SDK15_TIMER_ENABLED
9 #include "nrf_drv_clock.h"
10 #include "sdk_errors.h"
11 #include "app_timer.h"
15 #if RI_TIMER_MAX_INSTANCES > 10
16 #error "Allocating over 10 timers is not supported"
18 #if RI_TIMER_MAX_INSTANCES > 9
19 APP_TIMER_DEF (timer_9);
21 #if RI_TIMER_MAX_INSTANCES > 8
22 APP_TIMER_DEF (timer_8);
24 #if RI_TIMER_MAX_INSTANCES > 7
25 APP_TIMER_DEF (timer_7);
27 #if RI_TIMER_MAX_INSTANCES > 6
28 APP_TIMER_DEF (timer_6);
30 #if RI_TIMER_MAX_INSTANCES > 5
31 APP_TIMER_DEF (timer_5);
33 #if RI_TIMER_MAX_INSTANCES > 4
34 APP_TIMER_DEF (timer_4);
36 #if RI_TIMER_MAX_INSTANCES > 3
37 APP_TIMER_DEF (timer_3);
39 #if RI_TIMER_MAX_INSTANCES > 2
40 APP_TIMER_DEF (timer_2);
42 #if RI_TIMER_MAX_INSTANCES > 1
43 APP_TIMER_DEF (timer_1);
45 #if RI_TIMER_MAX_INSTANCES > 0
46 APP_TIMER_DEF (timer_0);
48 #if 0 >= RI_TIMER_MAX_INSTANCES
49 #error "No instances enabled for application timer"
52 static uint8_t timer_idx = 0;
53 static bool m_is_init =
false;
58 static app_timer_id_t get_timer_id (
void)
62 #if RI_TIMER_MAX_INSTANCES > 0
67 #if RI_TIMER_MAX_INSTANCES > 1
72 #if RI_TIMER_MAX_INSTANCES > 2
77 #if RI_TIMER_MAX_INSTANCES > 3
82 #if RI_TIMER_MAX_INSTANCES > 4
87 #if RI_TIMER_MAX_INSTANCES > 5
92 #if RI_TIMER_MAX_INSTANCES > 6
97 #if RI_TIMER_MAX_INSTANCES > 7
102 #if RI_TIMER_MAX_INSTANCES > 8
107 #if RI_TIMER_MAX_INSTANCES > 9
121 ret_code_t nrf_code = NRF_SUCCESS;
128 else if (
false == nrf_drv_clock_init_check())
130 nrf_code |= nrf_drv_clock_init();
136 nrf_drv_clock_lfclk_request (NULL);
137 nrf_code |= app_timer_init();
140 if (NRF_SUCCESS == nrf_code)
159 app_timer_mode_t nrf_mode = APP_TIMER_MODE_SINGLE_SHOT;
165 nrf_mode = APP_TIMER_MODE_REPEATED;
168 app_timer_id_t tid = get_timer_id();
172 ret_code_t nrf_code = app_timer_create (&tid,
174 (app_timer_timeout_handler_t) timeout_handler);
176 if (NRF_SUCCESS == nrf_code)
178 *p_timer_id = (
void *) tid;
197 timer_id,
const uint32_t ms,
198 void *
const context)
202 if (APP_TIMER_TICKS (ms) >= (1 << 24))
208 ret_code_t err_code = app_timer_start ( (app_timer_id_t) timer_id, APP_TIMER_TICKS (ms),
215 ret_code_t err_code = app_timer_stop ( (app_timer_id_t) timer_id);
221 app_timer_stop_all();
222 nrf_drv_clock_lfclk_release();
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
uint32_t rd_status_t
bitfield for representing errors
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_ERROR_RESOURCES
Not enough resources for operation.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
void ri_log(const ri_log_severity_t severity, const char *const message)
Queues messages into log.
bool ri_timer_is_init(void)
Check if timer is initialized.
rd_status_t ri_timer_uninit(void)
rd_status_t ri_timer_start(ri_timer_id_t timer_id, uint32_t ms, void *const context)
Start given timer at a mode defined in ri_timer_create.
rd_status_t ri_timer_create(ri_timer_id_t *p_timer_id, ri_timer_mode_t mode, ruuvi_timer_timeout_handler_t timeout_handler)
void(* ruuvi_timer_timeout_handler_t)(void *const p_context)
Function to be called when timer times out.
rd_status_t ri_timer_init(void)
ri_timer_mode_t
Enable implementation selected by application.
rd_status_t ri_timer_stop(ri_timer_id_t timer_id)
void * ri_timer_id_t
Pointer to timer data.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Interface functions to timer.