ChibiOS/HAL  6.1.0
hal_ext.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_ext.h
19  * @brief EXT Driver macros and structures.
20  *
21  * @addtogroup EXT
22  * @{
23  */
24 
25 #ifndef HAL_EXT_H
26 #define HAL_EXT_H
27 
28 #if (HAL_USE_EXT == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @name EXT channel modes
36  * @{
37  */
38 #define EXT_CH_MODE_EDGES_MASK 3U /**< @brief Mask of edges field. */
39 #define EXT_CH_MODE_DISABLED 0U /**< @brief Channel disabled. */
40 #define EXT_CH_MODE_RISING_EDGE 1U /**< @brief Rising edge callback. */
41 #define EXT_CH_MODE_FALLING_EDGE 2U /**< @brief Falling edge callback. */
42 #define EXT_CH_MODE_BOTH_EDGES 3U /**< @brief Both edges callback. */
43 #define EXT_CH_MODE_LOW_LEVEL 5U /**< @brief low level callback. */
44 
45 #define EXT_CH_MODE_AUTOSTART 4U /**< @brief Channel started
46  automatically on driver start. */
47 /** @} */
48 
49 /*===========================================================================*/
50 /* Driver pre-compile time settings. */
51 /*===========================================================================*/
52 
53 /*===========================================================================*/
54 /* Derived constants and error checks. */
55 /*===========================================================================*/
56 
57 /*===========================================================================*/
58 /* Driver data structures and types. */
59 /*===========================================================================*/
60 
61 /**
62  * @brief Driver state machine possible states.
63  */
64 typedef enum {
65  EXT_UNINIT = 0, /**< Not initialized. */
66  EXT_STOP = 1, /**< Stopped. */
67  EXT_ACTIVE = 2 /**< Active. */
69 
70 /**
71  * @brief Type of a structure representing a EXT driver.
72  */
73 typedef struct EXTDriver EXTDriver;
74 
75 #include "hal_ext_lld.h"
76 
77 /*===========================================================================*/
78 /* Driver macros. */
79 /*===========================================================================*/
80 
81 /**
82  * @name Macro Functions
83  * @{
84  */
85 /**
86  * @brief Enables an EXT channel.
87  *
88  * @param[in] extp pointer to the @p EXTDriver object
89  * @param[in] channel channel to be enabled
90  *
91  * @iclass
92  */
93 #define extChannelEnableI(extp, channel) ext_lld_channel_enable(extp, channel)
94 
95 /**
96  * @brief Disables an EXT channel.
97  *
98  * @param[in] extp pointer to the @p EXTDriver object
99  * @param[in] channel channel to be disabled
100  *
101  * @iclass
102  */
103 #define extChannelDisableI(extp, channel) ext_lld_channel_disable(extp, channel)
105 /**
106  * @brief Changes the operation mode of a channel.
107  * @note This function attempts to write over the current configuration
108  * structure that must have been not declared constant. This
109  * violates the @p const qualifier in @p extStart() but it is
110  * intentional. This function cannot be used if the configuration
111  * structure is declared @p const.
112  *
113  * @param[in] extp pointer to the @p EXTDriver object
114  * @param[in] channel channel to be changed
115  * @param[in] extcp new configuration for the channel
116  *
117  * @api
118  */
119 #define extSetChannelMode(extp, channel, extcp) { \
120  osalSysLock(); \
121  extSetChannelModeI(extp, channel, extcp); \
122  osalSysUnlock(); \
123 }
124 
125 /** @} */
126 
127 /*===========================================================================*/
128 /* External declarations. */
129 /*===========================================================================*/
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134  void extInit(void);
135  void extObjectInit(EXTDriver *extp);
136  void extStart(EXTDriver *extp, const EXTConfig *config);
137  void extStop(EXTDriver *extp);
138  void extChannelEnable(EXTDriver *extp, expchannel_t channel);
139  void extChannelDisable(EXTDriver *extp, expchannel_t channel);
140  void extSetChannelModeI(EXTDriver *extp,
141  expchannel_t channel,
142  const EXTChannelConfig *extcp);
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* HAL_USE_EXT == TRUE */
148 
149 #endif /* HAL_EXT_H */
150 
151 /** @} */
Channel configuration structure.
Definition: hal_ext_lld.h:81
uint32_t expchannel_t
EXT channel identifier.
Definition: hal_ext_lld.h:68
void extInit(void)
EXT Driver initialization.
Definition: hal_ext.c:56
void extChannelEnable(EXTDriver *extp, expchannel_t channel)
Enables an EXT channel.
Definition: hal_ext.c:129
const EXTConfig * config
Current configuration data.
Definition: hal_ext_lld.h:118
void extStart(EXTDriver *extp, const EXTConfig *config)
Configures and activates the EXT peripheral.
Definition: hal_ext.c:84
void extStop(EXTDriver *extp)
Deactivates the EXT peripheral.
Definition: hal_ext.c:104
PLATFORM EXT subsystem low level driver header.
void extChannelDisable(EXTDriver *extp, expchannel_t channel)
Disables an EXT channel.
Definition: hal_ext.c:151
extstate_t
Driver state machine possible states.
Definition: hal_ext.h:65
Driver configuration structure.
Definition: hal_ext_lld.h:99
Structure representing an EXT driver.
Definition: hal_ext_lld.h:110
void extSetChannelModeI(EXTDriver *extp, expchannel_t channel, const EXTChannelConfig *extcp)
Changes the operation mode of a channel.
Definition: hal_ext.c:181
void extObjectInit(EXTDriver *extp)
Initializes the standard part of a EXTDriver structure.
Definition: hal_ext.c:68