ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_nrf5_sdk15_scheduler.c
Go to the documentation of this file.
3#if RUUVI_NRF5_SDK15_SCHEDULER_ENABLED
4
7
8#include "sdk_errors.h"
9#include "app_scheduler.h"
10
11static bool m_is_init = false;
12
14{
15 rd_status_t err_code = RD_SUCCESS;
16
17 if (m_is_init)
18 {
19 err_code |= RD_ERROR_INVALID_STATE;
20 }
21 else
22 {
23 m_is_init = true;
24 APP_SCHED_INIT (RI_SCHEDULER_SIZE, RI_SCHEDULER_LENGTH);
25 }
26
27 return err_code;
28}
29
31{
32 rd_status_t err_code = RD_SUCCESS;
33
34 if (m_is_init)
35 {
36 app_sched_execute();
37 }
38 else
39 {
40 err_code |= RD_ERROR_INVALID_STATE;
41 }
42
43 return err_code;
44}
45
46rd_status_t ri_scheduler_event_put (void const * p_event_data,
47 uint16_t event_size, ruuvi_scheduler_event_handler_t handler)
48{
49 ret_code_t err_code = NRF_SUCCESS;
50
51 if (NULL == handler)
52 {
53 err_code |= NRF_ERROR_NULL;
54 }
55 else if (m_is_init)
56 {
57 err_code = app_sched_event_put (p_event_data, event_size,
58 (app_sched_event_handler_t) handler);
59 }
60 else
61 {
62 err_code |= NRF_ERROR_INVALID_STATE;
63 }
64
65 return ruuvi_nrf5_sdk15_to_ruuvi_error (err_code);
66}
67
68// No implementation needed.
70{
71 m_is_init = false;
72 return RD_SUCCESS;
73}
74
75bool ri_scheduler_is_init (void)
76{
77 return m_is_init;
78}
79#endif
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_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
rd_status_t ri_scheduler_event_put(const void *const p_event_data, const uint16_t event_size, const ruuvi_scheduler_event_handler_t handler)
Schedule given task to be executed on next call to ri_scheduler_execute.
void(* ruuvi_scheduler_event_handler_t)(void *p_event_data, uint16_t event_size)
Type definition for scheduler event handler.
rd_status_t ri_scheduler_execute(void)
Executes all scheduled tasks.
bool ri_scheduler_is_init(void)
Check if scheduler is initialized.
rd_status_t ri_scheduler_init(void)
Enable implementation selected by application.
rd_status_t ri_scheduler_uninit(void)
Uninitialize scheduler.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Interface functions to scheduler.