Hardware Abstraction Layer for FreeRTOS
timer_prv.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef TIMER_PRV_
7 #define TIMER_PRV_
8 #ifndef TIMER_PRV
9 # error "Never include this file out of a Timer driver"
10 #endif
11 #include <FreeRTOS.h>
12 #include <semphr.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <hal.h>
16 #define TIMER_ALREDY_INITED 1
17 int32_t timer_generic_init(struct timer *timer);
18 #define TIMER_ADDDEV(ns, p) HAL_ADDDEV(timer, ns, p)
20 #define TIMER_GET_DEV(index) HAL_GET_DEV(timer, index)
21 #ifndef CONFIG_TIMER_MULTI
22 #define TIMER_OPS(ns)
23 # define TIMER_INIT_DEV(ns)
24 #define TIMER_INIT(ns, index, prescaler, basetime, adjust) struct timer *timer_init(uint32_t index, uint32_t prescaler, uint64_t basetime, int64_t adjust)
25 #define TIMER_DEINIT(ns, t) int32_t timer_deinit(struct timer *t)
26 
27 #define TIMER_SET_OVERFLOW_CALLBACK(ns, t, callback, data) int32_t timer_setOverflowCallback(struct timer *t, bool (*callback)(struct timer *timer, void *d), void * data)
28 #define TIMER_START(ns, t) int32_t timer_start(struct timer *t)
29 #define TIMER_STOP(ns, t) int32_t timer_stop(struct timer *t)
30 #define TIMER_ONESHOT(ns, t, us) int32_t timer_oneshot(struct timer *t, uint64_t us)
31 #define TIMER_PERIODIC(ns, t, us) int32_t timer_periodic(struct timer *t, uint64_t us)
32 #define TIMER_GET_TIME(ns, t) uint64_t timer_getTime(struct timer *t)
33 #else
34 #define TIMER_OPS(ns) const struct timer_ops ns##_timer_ops = { \
35  .timer_init = &ns##_timer_init, \
36  .timer_deinit = &ns##_timer_deinit, \
37  .timer_setOverflowCallback = &ns##_timer_setOverflowCallback, \
38  .timer_start = &ns##_timer_start, \
39  .timer_stop = &ns##_timer_stop, \
40  .timer_oneshot = &ns##_timer_oneshot, \
41  .timer_periodic = &ns##_timer_periodic, \
42  .timer_getTime = &ns##_timer_getTime, \
43 }
44 # define TIMER_INIT_DEV(ns) .gen.ops = &ns##_timer_ops,
45 #define TIMER_INIT(ns, index, prescaler, basetime, adjust) static struct timer *ns##_timer_init(uint32_t index, uint32_t prescaler, uint64_t basetime, int64_t adjust)
46 #define TIMER_DEINIT(ns, t) static int32_t ns##_timer_deinit(struct timer *t)
47 
48 #define TIMER_SET_OVERFLOW_CALLBACK(ns, t, callback, data) static int32_t ns##_timer_setOverflowCallback(struct timer *t, bool (*callback)(struct timer *timer, void *d), void * data)
49 #define TIMER_START(ns, t) static int32_t ns##_timer_start(struct timer *t)
50 #define TIMER_STOP(ns, t) static int32_t ns##_timer_stop(struct timer *t)
51 #define TIMER_ONESHOT(ns, t, us) static int32_t ns##_timer_oneshot(struct timer *t, uint64_t us)
52 #define TIMER_PERIODIC(ns, t, us) static int32_t ns##_timer_periodic(struct timer *t, uint64_t us)
53 #define TIMER_GET_TIME(ns, t) static uint64_t ns##_timer_getTime(struct timer *t)
54 #endif
55 #endif
hal.h
HAL_DEFINE_GLOBAL_ARRAY
HAL_DEFINE_GLOBAL_ARRAY(timer)
timer_generic_init
int32_t timer_generic_init(struct timer *timer)