Appiko
ms_timer.h
1 
30 #ifndef CODEBASE_MS_TIMER_H_
31 #define CODEBASE_MS_TIMER_H_
32 
33 #include <stdint.h>
34 #include <stdbool.h>
35 #include "common_util.h"
36 #include "nrf_peripherals.h"
37 #include "nrf.h"
38 #include "hal_clocks.h"
39 
40 #if SYS_CFG_PRESENT == 1
41 #include "sys_config.h"
42 #endif
43 #ifndef RTC_USED_MS_TIMER
44 #define RTC_USED_MS_TIMER 1
45 #endif
46 
48 #define MS_TIMER_RTC_USED RTC_USED_MS_TIMER
49 
51 #define MS_TIMER_CC_COUNT CONCAT_3(RTC, MS_TIMER_RTC_USED, _CC_NUM)
52 
54 #ifndef MS_TIMER_FREQ
55 #define MS_TIMER_FREQ 32768
56 #endif
57 
58 /* Check if MS_TIMER_FREQ is between 8 Hz and 32768 Hz as these are valid RTC prescalar values */
59 #if ((MS_TIMER_FREQ < 8) || (MS_TIMER_FREQ > LFCLK_FREQ))
60 #error MS_TIMER_FREQ value should be between 8 and 32768
61 #endif
62 
64 #define MS_TIMER_TICKS_MS(ms) ((uint32_t) ROUNDED_DIV( (MS_TIMER_FREQ*(uint64_t)(ms)) , 1000) )
65 
68 typedef enum {
72 #if (MS_TIMER_CC_COUNT == 4)
73  MS_TIMER3,
74 #endif
77 
81 typedef enum {
85 
93 void ms_timer_init(uint32_t irq_priority);
94 
105 void ms_timer_start(ms_timer_num id, ms_timer_mode mode, uint64_t ticks, void (*handler)(void));
106 
113 void ms_timer_stop(ms_timer_num id);
114 
121 
127 inline uint32_t ms_timer_get_current_count(void){
128  return CONCAT_2(NRF_RTC,MS_TIMER_RTC_USED)->COUNTER;
129 }
130 
131 #endif /* CODEBASE_MS_TIMER_H_ */
132 
uint32_t ms_timer_get_current_count(void)
Return the current count (24 bit) of the RTC timer used.
Definition: ms_timer.h:127
#define CONCAT_2(p1, p2)
Concatenates or joins two parameters.
Definition: common_util.h:48
Millisecond Timer 2.
Definition: ms_timer.h:71
Repeated call of the timer.
Definition: ms_timer.h:83
bool ms_timer_get_on_status(ms_timer_num id)
Definition: ms_timer.c:186
Not a timer, just used to find the number of timers.
Definition: ms_timer.h:75
void ms_timer_init(uint32_t irq_priority)
Definition: ms_timer.c:111
ms_timer_mode
Enumeration to specify the mode of operation of the timer.
Definition: ms_timer.h:81
#define MS_TIMER_RTC_USED
Definition: ms_timer.h:48
Millisecond Timer 1.
Definition: ms_timer.h:70
Millisecond Timer 0.
Definition: ms_timer.h:69
void ms_timer_start(ms_timer_num id, ms_timer_mode mode, uint64_t ticks, void(*handler)(void))
Definition: ms_timer.c:134
ms_timer_num
Enumeration used for specifying the timers that can be used with a RTC peripheral.
Definition: ms_timer.h:68
void ms_timer_stop(ms_timer_num id)
Definition: ms_timer.c:173
One shot call of the timer.
Definition: ms_timer.h:82