ChibiOS/HAL  6.1.0
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 /* External declarations. */
116 /*===========================================================================*/
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121  void gptInit(void);
122  void gptObjectInit(GPTDriver *gptp);
123  void gptStart(GPTDriver *gptp, const GPTConfig *config);
124  void gptStop(GPTDriver *gptp);
125  void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval);
126  void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval);
127  void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval);
128  void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval);
129  void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval);
130  void gptStopTimer(GPTDriver *gptp);
131  void gptStopTimerI(GPTDriver *gptp);
132  void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval);
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* HAL_USE_GPT == TRUE */
138 
139 #endif /* HAL_GPT_H */
140 
141 /** @} */
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