ChibiOS 21.11.4
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 */
63typedef 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 */
71typedef uint32_t icufreq_t;
72
73/**
74 * @brief ICU counter type.
75 */
76typedef uint32_t icucnt_t;
77
78/**
79 * @brief Driver configuration structure.
80 * @note It could be empty on some architectures.
81 */
82typedef 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 */
111struct 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__)
171extern ICUDriver ICUD1;
172#endif
173
174#ifdef __cplusplus
175extern "C" {
176#endif
177 void icu_lld_init(void);
178 void icu_lld_start(ICUDriver *icup);
179 void icu_lld_stop(ICUDriver *icup);
185#ifdef __cplusplus
186}
187#endif
188
189#endif /* HAL_USE_ICU == TRUE */
190
191#endif /* HAL_ICU_LLD_H */
192
193/** @} */
bool icu_lld_wait_capture(ICUDriver *icup)
Waits for a completed capture.
ICUDriver ICUD1
ICUD1 driver identifier.
Definition hal_icu_lld.c:42
void icu_lld_start_capture(ICUDriver *icup)
Starts the input capture.
icumode_t
ICU driver mode.
Definition hal_icu_lld.h:63
icustate_t
Driver state machine possible states.
Definition hal_icu.h:53
uint32_t icufreq_t
ICU frequency type.
Definition hal_icu_lld.h:71
void(* icucallback_t)(ICUDriver *icup)
ICU notification callback type.
Definition hal_icu.h:71
void icu_lld_stop(ICUDriver *icup)
Deactivates the ICU peripheral.
void icu_lld_start(ICUDriver *icup)
Configures and activates the ICU peripheral.
Definition hal_icu_lld.c:81
void icu_lld_init(void)
Low level ICU driver initialization.
Definition hal_icu_lld.c:66
void icu_lld_disable_notifications(ICUDriver *icup)
Disables notifications.
void icu_lld_stop_capture(ICUDriver *icup)
Stops the input capture.
uint32_t icucnt_t
ICU counter type.
Definition hal_icu_lld.h:76
void icu_lld_enable_notifications(ICUDriver *icup)
Enables notifications.
@ ICU_INPUT_ACTIVE_LOW
Definition hal_icu_lld.h:65
@ ICU_INPUT_ACTIVE_HIGH
Definition hal_icu_lld.h:64
Driver configuration structure.
Definition hal_icu_lld.h:82
icucallback_t period_cb
Callback for cycle period measurement.
icufreq_t frequency
Timer clock in Hz.
Definition hal_icu_lld.h:92
icucallback_t overflow_cb
Callback for timer overflow.
icumode_t mode
Driver mode.
Definition hal_icu_lld.h:86
icucallback_t width_cb
Callback for pulse width measurement.
Definition hal_icu_lld.h:96
Structure representing an ICU driver.
const ICUConfig * config
Current configuration data.
icustate_t state
Driver state.