Hardware Abstraction Layer for FreeRTOS
counter.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 COUNTER_H_
7 #define COUNTER_H_
8 #include <FreeRTOS.h>
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <system.h>
12 #include <hal.h>
25 };
31 struct counter;
32 #ifdef CONFIG_COUNTER_MULTI
33 
36 struct counter_ops {
37  struct counter *(*counter_init)(uint32_t index, enum counter_mode mode);
38  int32_t (*counter_deinit)(struct counter *counter);
39  int64_t (*counter_getValue)(struct counter *counter);
40  int32_t (*counter_reset)(struct counter *counter);
41 };
42 #endif
43 
51  bool init;
52 #ifdef CONFIG_INSTANCE_NAME
53 
56  const char *name;
57 #endif
58 #ifdef CONFIG_COUNTER_MULTI
59 
62  const struct counter_ops *ops;
63 #endif
64 };
65 #ifndef CONFIG_COUNTER_MULTI
66 
72 struct counter *counter_init(uint32_t index, enum counter_mode mode);
78 int32_t counter_deinit(struct counter *counter);
84 int64_t counter_getValue(struct counter *counter);
89 int32_t counter_reset(struct counter *counter);
90 #else
91 inline struct counter *counter_init(uint32_t index, enum counter_mode mode) {
92  HAL_DEFINE_GLOBAL_ARRAY(counter);
93  struct counter_generic *p = (struct counter_generic *) HAL_GET_DEV(counter, index);
94  if (p == NULL) {
95  return NULL;
96  }
97  return p->ops->counter_init(index, mode);
98 }
99 inline int32_t counter_deinit(struct counter *counter) {
100  struct counter_generic *p = (struct counter_generic *) counter;
101  return p->ops->counter_deinit(counter);
102 }
103 inline int64_t counter_getValue(struct counter *counter) {
104  struct counter_generic *p = (struct counter_generic *) counter;
105  return p->ops->counter_getValue(counter);
106 }
107 inline int32_t counter_reset(struct counter *counter) {
108  struct counter_generic *p = (struct counter_generic *) counter;
109  return p->ops->counter_reset(counter);
110 }
111 #endif
112 
113 #endif
114 
hal.h
counter_reset
int32_t counter_reset(struct counter *counter)
COUNTER_EITHER
@ COUNTER_EITHER
Definition: counter.h:24
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition: hal.h:149
counter_deinit
int32_t counter_deinit(struct counter *counter)
counter_init
struct counter * counter_init(uint32_t index, enum counter_mode mode)
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition: hal.h:182
counter_generic
Definition: counter.h:46
counter_getValue
int64_t counter_getValue(struct counter *counter)
COUNTER_RISING
@ COUNTER_RISING
Definition: counter.h:23
system.h
counter_generic::init
bool init
Definition: counter.h:51
COUNTER_FALLING
@ COUNTER_FALLING
Definition: counter.h:22
counter_mode
counter_mode
Definition: counter.h:21