ChibiOS/HAL  6.1.0
hal_icu_lld.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_icu_lld.h
19  * @brief PLATFORM ICU subsystem low level driver header.
20  *
21  * @addtogroup ICU
22  * @{
23  */
24 
25 #ifndef HAL_ICU_LLD_H
26 #define HAL_ICU_LLD_H
27 
28 #if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /*===========================================================================*/
35 /* Driver pre-compile time settings. */
36 /*===========================================================================*/
37 
38 /**
39  * @name PLATFORM configuration options
40  * @{
41  */
42 /**
43  * @brief ICUD1 driver enable switch.
44  * @details If set to @p TRUE the support for ICUD1 is included.
45  * @note The default is @p FALSE.
46  */
47 #if !defined(PLATFORM_ICU_USE_ICU1) || defined(__DOXYGEN__)
48 #define PLATFORM_ICU_USE_ICU1 FALSE
49 #endif
50 /** @} */
51 
52 /*===========================================================================*/
53 /* Derived constants and error checks. */
54 /*===========================================================================*/
55 
56 /*===========================================================================*/
57 /* Driver data structures and types. */
58 /*===========================================================================*/
59 
60 /**
61  * @brief ICU driver mode.
62  */
63 typedef enum {
64  ICU_INPUT_ACTIVE_HIGH = 0, /**< Trigger on rising edge. */
65  ICU_INPUT_ACTIVE_LOW = 1 /**< Trigger on falling edge. */
66 } icumode_t;
67 
68 /**
69  * @brief ICU frequency type.
70  */
71 typedef uint32_t icufreq_t;
72 
73 /**
74  * @brief ICU counter type.
75  */
76 typedef uint32_t icucnt_t;
77 
78 /**
79  * @brief Driver configuration structure.
80  * @note It could be empty on some architectures.
81  */
82 typedef struct {
83  /**
84  * @brief Driver mode.
85  */
87  /**
88  * @brief Timer clock in Hz.
89  * @note The low level can use assertions in order to catch invalid
90  * frequency specifications.
91  */
93  /**
94  * @brief Callback for pulse width measurement.
95  */
97  /**
98  * @brief Callback for cycle period measurement.
99  */
101  /**
102  * @brief Callback for timer overflow.
103  */
105  /* End of the mandatory fields.*/
106 } ICUConfig;
107 
108 /**
109  * @brief Structure representing an ICU driver.
110  */
111 struct ICUDriver {
112  /**
113  * @brief Driver state.
114  */
116  /**
117  * @brief Current configuration data.
118  */
120 #if defined(ICU_DRIVER_EXT_FIELDS)
121  ICU_DRIVER_EXT_FIELDS
122 #endif
123  /* End of the mandatory fields.*/
124 };
125 
126 /*===========================================================================*/
127 /* Driver macros. */
128 /*===========================================================================*/
129 
130 /**
131  * @brief Returns the width of the latest pulse.
132  * @details The pulse width is defined as number of ticks between the start
133  * edge and the stop edge.
134  *
135  * @param[in] icup pointer to the @p ICUDriver object
136  * @return The number of ticks.
137  *
138  * @notapi
139  */
140 #define icu_lld_get_width(icup) 0
141 
142 /**
143  * @brief Returns the width of the latest cycle.
144  * @details The cycle width is defined as number of ticks between a start
145  * edge and the next start edge.
146  *
147  * @param[in] icup pointer to the @p ICUDriver object
148  * @return The number of ticks.
149  *
150  * @notapi
151  */
152 #define icu_lld_get_period(icup) 0
153 
154 /**
155  * @brief Check on notifications status.
156  *
157  * @param[in] icup pointer to the @p ICUDriver object
158  * @return The notifications status.
159  * @retval false if notifications are not enabled.
160  * @retval true if notifications are enabled.
161  *
162  * @notapi
163  */
164 #define icu_lld_are_notifications_enabled(icup) false
165 
166 /*===========================================================================*/
167 /* External declarations. */
168 /*===========================================================================*/
169 
170 #if (PLATFORM_ICU_USE_ICU1 == TRUE) && !defined(__DOXYGEN__)
171 extern ICUDriver ICUD1;
172 #endif
173 
174 #ifdef __cplusplus
175 extern "C" {
176 #endif
177  void icu_lld_init(void);
178  void icu_lld_start(ICUDriver *icup);
179  void icu_lld_stop(ICUDriver *icup);
180  void icu_lld_start_capture(ICUDriver *icup);
181  bool icu_lld_wait_capture(ICUDriver *icup);
182  void icu_lld_stop_capture(ICUDriver *icup);
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* HAL_USE_ICU == TRUE */
190 
191 #endif /* HAL_ICU_LLD_H */
192 
193 /** @} */
icumode_t
ICU driver mode.
Definition: hal_icu_lld.h:63
void icu_lld_start(ICUDriver *icup)
Configures and activates the ICU peripheral.
Definition: hal_icu_lld.c:81
bool icu_lld_wait_capture(ICUDriver *icup)
Waits for a completed capture.
Definition: hal_icu_lld.c:136
void icu_lld_stop_capture(ICUDriver *icup)
Stops the input capture.
Definition: hal_icu_lld.c:150
ICUDriver ICUD1
ICUD1 driver identifier.
Definition: hal_icu_lld.c:42
Driver configuration structure.
Definition: hal_icu_lld.h:82
void icu_lld_enable_notifications(ICUDriver *icup)
Enables notifications.
Definition: hal_icu_lld.c:165
Structure representing an ICU driver.
Definition: hal_icu_lld.h:111
icustate_t
Driver state machine possible states.
Definition: hal_icu.h:49
icucallback_t width_cb
Callback for pulse width measurement.
Definition: hal_icu_lld.h:96
void icu_lld_stop(ICUDriver *icup)
Deactivates the ICU peripheral.
Definition: hal_icu_lld.c:100
icufreq_t frequency
Timer clock in Hz.
Definition: hal_icu_lld.h:92
uint32_t icufreq_t
ICU frequency type.
Definition: hal_icu_lld.h:71
const ICUConfig * config
Current configuration data.
Definition: hal_icu_lld.h:119
icumode_t mode
Driver mode.
Definition: hal_icu_lld.h:86
void(* icucallback_t)(ICUDriver *icup)
ICU notification callback type.
Definition: hal_icu.h:67
uint32_t icucnt_t
ICU counter type.
Definition: hal_icu_lld.h:76
icustate_t state
Driver state.
Definition: hal_icu_lld.h:115
void icu_lld_start_capture(ICUDriver *icup)
Starts the input capture.
Definition: hal_icu_lld.c:119
void icu_lld_init(void)
Low level ICU driver initialization.
Definition: hal_icu_lld.c:66
icucallback_t overflow_cb
Callback for timer overflow.
Definition: hal_icu_lld.h:104
void icu_lld_disable_notifications(ICUDriver *icup)
Disables notifications.
Definition: hal_icu_lld.c:180
icucallback_t period_cb
Callback for cycle period measurement.
Definition: hal_icu_lld.h:100