EVE 1.0
app_timer.c
1 #include <lib/env.h>
2 #include <lib/assert.h>
3 #include <app_timer.h>
4 
5 // TODO: stub
6 
7 static app_timer_evt_schedule_func_t m_evt_schedule_func;
8 
9 void app_timer_work_cb(struct mwork_t *work)
10 {
11  app_timer_t *w = container_of(work, app_timer_t, work);
12 
13  if (w->mode != APP_TIMER_MODE_SINGLE_SHOT) {
14  w->work.at += w->interval;
15  mwork_schedule(&w->work);
16  }
17 
18  if (m_evt_schedule_func)
19  m_evt_schedule_func(w->p_timeout_handler, w->p_context);
20  else
21  w->p_timeout_handler(w->p_context);
22 }
23 
24 uint32_t app_timer_init(app_timer_evt_schedule_func_t evt_schedule_func)
25 {
26  m_evt_schedule_func = evt_schedule_func;
27  return NRF_SUCCESS;
28 }
29 
30 uint32_t app_timer_create(app_timer_id_t const * p_timer_id,
31  app_timer_mode_t mode,
32  app_timer_timeout_handler_t timeout_handler)
33 {
34  assert(timeout_handler);
35  assert(p_timer_id);
36 
37  struct app_timer_t *timer = *p_timer_id;
38  timer->mode = mode;
39  timer->p_timeout_handler = timeout_handler;
40  return NRF_SUCCESS;
41 }
42 
43 uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void *p_context)
44 {
45  assert(timer_id);
46 
47  swint_state_t swint = swint_disable();
48  timer_id->interval = timeout_ticks;
49  timer_id->work.at = mwork_now() + timeout_ticks;
50  timer_id->p_context = p_context;
51  mwork_schedule(&timer_id->work);
52  swint_enable(swint);
53  return NRF_SUCCESS;
54 }
55 
56 uint32_t app_timer_stop(app_timer_id_t timer_id)
57 {
58  assert(timer_id);
59 
60  mwork_cancel(&timer_id->work);
61  return NRF_SUCCESS;
62 }
63 
uint32_t app_timer_stop(app_timer_id_t timer_id)
Function for stopping the specified timer.
Definition: app_timer.c:56
uint32_t app_timer_init(app_timer_evt_schedule_func_t evt_schedule_func)
Function for initializing the timer module.
Definition: app_timer.c:24
uint32_t app_timer_create(app_timer_id_t const *p_timer_id, app_timer_mode_t mode, app_timer_timeout_handler_t timeout_handler)
Function for creating a timer instance.
Definition: app_timer.c:30
app_timer_mode_t
Timer modes.
Definition: app_timer.h:103
Definition: mwork.h:182
#define container_of(ptr, type, mem)
Definition: env.h:114
struct app_timer_t * app_timer_id_t
Timer ID type. Never declare a variable of this type, but use the macro APP_TIMER_DEF instead...
Definition: app_timer.h:78
static mwork_time_t mwork_now()
Definition: mwork.h:200
EVE build environment.
Definition: timer.h:86
void(* app_timer_timeout_handler_t)(void *p_context)
Application time-out handler type.
Definition: app_timer.h:96
uint32_t(* app_timer_evt_schedule_func_t)(app_timer_timeout_handler_t timeout_handler, void *p_context)
Type of function for passing events from the timer module to the scheduler.
Definition: app_timer.h:99
uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void *p_context)
Function for starting a timer.
Definition: app_timer.c:43
void mwork_schedule(struct mwork_t *work)
void swint_enable(swint_state_t state)
swint_state_t swint_disable(void)
void mwork_cancel(struct mwork_t *work)