ChibiOS/HAL 9.0.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 */
49typedef 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. */
56
57/**
58 * @brief Type of a structure representing a GPT driver.
59 */
60typedef struct GPTDriver GPTDriver;
61
62/**
63 * @brief GPT notification callback type.
64 *
65 * @param[in] gptp pointer to a @p GPTDriver object
66 */
67typedef 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
136extern "C" {
137#endif
138 void gptInit(void);
139 void gptObjectInit(GPTDriver *gptp);
140 msg_t 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 gptPolledDelay(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode and waits for completion.
Definition hal_gpt.c:273
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 gptInit(void)
GPT Driver initialization.
Definition hal_gpt.c:56
void gptStop(GPTDriver *gptp)
Deactivates the GPT peripheral.
Definition hal_gpt.c:121
void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode.
Definition hal_gpt.c:201
void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode.
Definition hal_gpt.c:216
uint16_t gptcnt_t
GPT counter type.
Definition hal_gpt_lld.h:68
gptstate_t
Driver state machine possible states.
Definition hal_gpt.h:49
void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval)
Changes the interval of GPT peripheral.
Definition hal_gpt.c:148
void gptStopTimer(GPTDriver *gptp)
Stops the timer.
Definition hal_gpt.c:235
void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
Definition hal_gpt.c:167
void gptStopTimerI(GPTDriver *gptp)
Stops the timer.
Definition hal_gpt.c:249
void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
Definition hal_gpt.c:182
msg_t gptStart(GPTDriver *gptp, const GPTConfig *config)
Configures and activates the GPT peripheral.
Definition hal_gpt.c:83
@ GPT_READY
Definition hal_gpt.h:52
@ GPT_ONESHOT
Definition hal_gpt.h:54
@ GPT_UNINIT
Definition hal_gpt.h:50
@ GPT_STOP
Definition hal_gpt.h:51
@ GPT_CONTINUOUS
Definition hal_gpt.h:53
int32_t msg_t
Type of a message.
Definition osal.h:159
PLATFORM GPT subsystem low level driver header.
Driver configuration structure.
Definition hal_gpt_lld.h:74
Structure representing a GPT driver.
Definition hal_gpt_lld.h:92
const GPTConfig * config
Current configuration data.