ChibiOS  19.1.4
hal_gpt.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.h
19  * @brief GPT Driver macros and structures.
20  *
21  * @addtogroup GPT
22  * @{
23  */
24 
25 #ifndef HAL_GPT_H
26 #define HAL_GPT_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 /* Derived constants and error checks. */
40 /*===========================================================================*/
41 
42 /*===========================================================================*/
43 /* Driver data structures and types. */
44 /*===========================================================================*/
45 
46 /**
47  * @brief Driver state machine possible states.
48  */
49 typedef enum {
50  GPT_UNINIT = 0, /**< Not initialized. */
51  GPT_STOP = 1, /**< Stopped. */
52  GPT_READY = 2, /**< Ready. */
53  GPT_CONTINUOUS = 3, /**< Active in continuous mode. */
54  GPT_ONESHOT = 4 /**< Active in one shot mode. */
55 } gptstate_t;
56 
57 /**
58  * @brief Type of a structure representing a GPT driver.
59  */
60 typedef struct GPTDriver GPTDriver;
61 
62 /**
63  * @brief GPT notification callback type.
64  *
65  * @param[in] gptp pointer to a @p GPTDriver object
66  */
67 typedef void (*gptcallback_t)(GPTDriver *gptp);
68 
69 #include "hal_gpt_lld.h"
70 
71 /*===========================================================================*/
72 /* Driver macros. */
73 /*===========================================================================*/
74 
75 /**
76  * @brief Changes the interval of GPT peripheral.
77  * @details This function changes the interval of a running GPT unit.
78  * @pre The GPT unit must be running in continuous mode.
79  * @post The GPT unit interval is changed to the new value.
80  *
81  * @param[in] gptp pointer to a @p GPTDriver object
82  * @param[in] interval new cycle time in timer ticks
83  *
84  * @iclass
85  */
86 #define gptChangeIntervalI(gptp, interval) { \
87  gpt_lld_change_interval(gptp, interval); \
88 }
89 
90 /**
91  * @brief Returns the interval of GPT peripheral.
92  * @pre The GPT unit must be running in continuous mode.
93  *
94  * @param[in] gptp pointer to a @p GPTDriver object
95  * @return The current interval.
96  *
97  * @xclass
98  */
99 #define gptGetIntervalX(gptp) gpt_lld_get_interval(gptp)
100 
101 /**
102  * @brief Returns the counter value of GPT peripheral.
103  * @pre The GPT unit must be running in continuous mode.
104  * @note The nature of the counter is not defined, it may count upward
105  * or downward, it could be continuously running or not.
106  *
107  * @param[in] gptp pointer to a @p GPTDriver object
108  * @return The current counter value.
109  *
110  * @xclass
111  */
112 #define gptGetCounterX(gptp) gpt_lld_get_counter(gptp)
113 
114 /**
115  * @brief Common ISR code, GPT period event.
116  *
117  * @param[in] gptp pointer to the @p GPTDriver object
118  *
119  * @notapi
120  */
121 #define _gpt_isr_invoke_cb(gptp) do { \
122  if ((gptp)->state == GPT_ONESHOT) { \
123  (gptp)->state = GPT_READY; \
124  gpt_lld_stop_timer(gptp); \
125  } \
126  if ((gptp)->config->callback != NULL) { \
127  (gptp)->config->callback(gptp); \
128  } \
129 } while (0)
130 
131 /*===========================================================================*/
132 /* External declarations. */
133 /*===========================================================================*/
134 
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138  void gptInit(void);
139  void gptObjectInit(GPTDriver *gptp);
140  void gptStart(GPTDriver *gptp, const GPTConfig *config);
141  void gptStop(GPTDriver *gptp);
142  void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval);
143  void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval);
144  void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval);
145  void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval);
146  void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval);
147  void gptStopTimer(GPTDriver *gptp);
148  void gptStopTimerI(GPTDriver *gptp);
149  void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval);
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* HAL_USE_GPT == TRUE */
155 
156 #endif /* HAL_GPT_H */
157 
158 /** @} */
void gptStopTimerI(GPTDriver *gptp)
Stops the timer.
Definition: hal_gpt.c:230
void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
Definition: hal_gpt.c:148
void gptStopTimer(GPTDriver *gptp)
Stops the timer.
Definition: hal_gpt.c:216
Structure representing a GPT driver.
Definition: hal_gpt_lld.h:92
void gptInit(void)
GPT Driver initialization.
Definition: hal_gpt.c:56
void gptStart(GPTDriver *gptp, const GPTConfig *config)
Configures and activates the GPT peripheral.
Definition: hal_gpt.c:82
Driver configuration structure.
Definition: hal_gpt_lld.h:74
const GPTConfig * config
Current configuration data.
Definition: hal_gpt_lld.h:100
void gptStop(GPTDriver *gptp)
Deactivates the GPT peripheral.
Definition: hal_gpt.c:102
uint16_t gptcnt_t
GPT counter type.
Definition: hal_gpt_lld.h:68
void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval)
Changes the interval of GPT peripheral.
Definition: hal_gpt.c:129
PLATFORM GPT subsystem low level driver header.
void gptObjectInit(GPTDriver *gptp)
Initializes the standard part of a GPTDriver structure.
Definition: hal_gpt.c:68
void(* gptcallback_t)(GPTDriver *gptp)
GPT notification callback type.
Definition: hal_gpt.h:67
void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode and waits for completion.
Definition: hal_gpt.c:254
void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode.
Definition: hal_gpt.c:197
gptstate_t
Driver state machine possible states.
Definition: hal_gpt.h:49
void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
Definition: hal_gpt.c:163
void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode.
Definition: hal_gpt.c:182