ChibiOS/HAL  6.1.0
hal_gpt_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_gpt_lld.h
19  * @brief PLATFORM GPT subsystem low level driver header.
20  *
21  * @addtogroup GPT
22  * @{
23  */
24 
25 #ifndef HAL_GPT_LLD_H
26 #define HAL_GPT_LLD_H
27 
28 #if (HAL_USE_GPT == 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 GPTD1 driver enable switch.
44  * @details If set to @p TRUE the support for GPTD1 is included.
45  * @note The default is @p FALSE.
46  */
47 #if !defined(PLATFORM_GPT_USE_GPT1) || defined(__DOXYGEN__)
48 #define PLATFORM_GPT_USE_GPT1 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 GPT frequency type.
62  */
63 typedef uint32_t gptfreq_t;
64 
65 /**
66  * @brief GPT counter type.
67  */
68 typedef uint16_t gptcnt_t;
69 
70 /**
71  * @brief Driver configuration structure.
72  * @note It could be empty on some architectures.
73  */
74 typedef struct {
75  /**
76  * @brief Timer clock in Hz.
77  * @note The low level can use assertions in order to catch invalid
78  * frequency specifications.
79  */
81  /**
82  * @brief Timer callback pointer.
83  * @note This callback is invoked on GPT counter events.
84  */
86  /* End of the mandatory fields.*/
87 } GPTConfig;
88 
89 /**
90  * @brief Structure representing a GPT driver.
91  */
92 struct GPTDriver {
93  /**
94  * @brief Driver state.
95  */
97  /**
98  * @brief Current configuration data.
99  */
101 #if defined(GPT_DRIVER_EXT_FIELDS)
102  GPT_DRIVER_EXT_FIELDS
103 #endif
104  /* End of the mandatory fields.*/
105 };
106 
107 /*===========================================================================*/
108 /* Driver macros. */
109 /*===========================================================================*/
110 
111 /**
112  * @brief Changes the interval of GPT peripheral.
113  * @details This function changes the interval of a running GPT unit.
114  * @pre The GPT unit must have been activated using @p gptStart().
115  * @pre The GPT unit must have been running in continuous mode using
116  * @p gptStartContinuous().
117  * @post The GPT unit interval is changed to the new value.
118  * @note The function has effect at the next cycle start.
119  *
120  * @param[in] gptp pointer to a @p GPTDriver object
121  * @param[in] interval new cycle time in timer ticks
122  * @notapi
123  */
124 #define gpt_lld_change_interval(gptp, interval) { \
125  (void)gptp; \
126  (void)interval; \
127 }
128 
129 /*===========================================================================*/
130 /* External declarations. */
131 /*===========================================================================*/
132 
133 #if (PLATFORM_GPT_USE_GPT1 == TRUE) && !defined(__DOXYGEN__)
134 extern GPTDriver GPTD1;
135 #endif
136 
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
140  void gpt_lld_init(void);
141  void gpt_lld_start(GPTDriver *gptp);
142  void gpt_lld_stop(GPTDriver *gptp);
143  void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval);
144  void gpt_lld_stop_timer(GPTDriver *gptp);
145  void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval);
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif /* HAL_USE_GPT == TRUE */
151 
152 #endif /* HAL_GPT_LLD_H */
153 
154 /** @} */
void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode and waits for completion.
Definition: hal_gpt_lld.c:154
void gpt_lld_init(void)
Low level GPT driver initialization.
Definition: hal_gpt_lld.c:65
GPTDriver GPTD1
GPTD1 driver identifier.
Definition: hal_gpt_lld.c:41
void gpt_lld_stop(GPTDriver *gptp)
Deactivates the GPT peripheral.
Definition: hal_gpt_lld.c:101
void gpt_lld_start(GPTDriver *gptp)
Configures and activates the GPT peripheral.
Definition: hal_gpt_lld.c:80
Structure representing a GPT driver.
Definition: hal_gpt_lld.h:92
gptcallback_t callback
Timer callback pointer.
Definition: hal_gpt_lld.h:85
Driver configuration structure.
Definition: hal_gpt_lld.h:74
const GPTConfig * config
Current configuration data.
Definition: hal_gpt_lld.h:100
uint32_t gptfreq_t
GPT frequency type.
Definition: hal_gpt_lld.h:63
uint16_t gptcnt_t
GPT counter type.
Definition: hal_gpt_lld.h:68
gptstate_t state
Driver state.
Definition: hal_gpt_lld.h:96
void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
Definition: hal_gpt_lld.c:123
void(* gptcallback_t)(GPTDriver *gptp)
GPT notification callback type.
Definition: hal_gpt.h:67
gptstate_t
Driver state machine possible states.
Definition: hal_gpt.h:49
void gpt_lld_stop_timer(GPTDriver *gptp)
Stops the timer.
Definition: hal_gpt_lld.c:137
gptfreq_t frequency
Timer clock in Hz.
Definition: hal_gpt_lld.h:80