ChibiOS/HAL  6.1.0
hal_pal_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_pal_lld.h
19  * @brief PLATFORM PAL subsystem low level driver header.
20  *
21  * @addtogroup PAL
22  * @{
23  */
24 
25 #ifndef HAL_PAL_LLD_H
26 #define HAL_PAL_LLD_H
27 
28 #if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Unsupported modes and specific modes */
32 /*===========================================================================*/
33 
34 /*===========================================================================*/
35 /* I/O Ports Types and constants. */
36 /*===========================================================================*/
37 
38 /**
39  * @name Port related definitions
40  * @{
41  */
42 /**
43  * @brief Width, in bits, of an I/O port.
44  */
45 #define PAL_IOPORTS_WIDTH 16U
46 
47 /**
48  * @brief Whole port mask.
49  * @details This macro specifies all the valid bits into a port.
50  */
51 #define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFU)
52 /** @} */
53 
54 /**
55  * @name Line handling macros
56  * @{
57  */
58 /**
59  * @brief Forms a line identifier.
60  * @details A port/pad pair are encoded into an @p ioline_t type. The encoding
61  * of this type is platform-dependent.
62  */
63 #define PAL_LINE(port, pad) \
64  ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad)))
65 
66 /**
67  * @brief Decodes a port identifier from a line identifier.
68  */
69 #define PAL_PORT(line) \
70  ((stm32_gpio_t *)(((uint32_t)(line)) & 0xFFFFFFF0U))
71 
72 /**
73  * @brief Decodes a pad identifier from a line identifier.
74  */
75 #define PAL_PAD(line) \
76  ((uint32_t)((uint32_t)(line) & 0x0000000FU))
77 
78 /**
79  * @brief Value identifying an invalid line.
80  */
81 #define PAL_NOLINE 0U
82 /** @} */
83 
84 /**
85  * @brief Generic I/O ports static initializer.
86  * @details An instance of this structure must be passed to @p palInit() at
87  * system startup time in order to initialized the digital I/O
88  * subsystem. This represents only the initial setup, specific pads
89  * or whole ports can be reprogrammed at later time.
90  * @note Implementations may extend this structure to contain more,
91  * architecture dependent, fields.
92  */
93 typedef struct {
94 
95 } PALConfig;
96 
97 /**
98  * @brief Digital I/O port sized unsigned type.
99  */
100 typedef uint32_t ioportmask_t;
101 
102 /**
103  * @brief Digital I/O modes.
104  */
105 typedef uint32_t iomode_t;
106 
107 /**
108  * @brief Type of an I/O line.
109  */
110 typedef uint32_t ioline_t;
111 
112 /**
113  * @brief Port Identifier.
114  * @details This type can be a scalar or some kind of pointer, do not make
115  * any assumption about it, use the provided macros when populating
116  * variables of this type.
117  */
118 typedef uint32_t ioportid_t;
119 
120 /**
121  * @brief Type of an pad identifier.
122  */
123 typedef uint32_t iopadid_t;
124 
125 /*===========================================================================*/
126 /* I/O Ports Identifiers. */
127 /*===========================================================================*/
128 
129 /**
130  * @brief First I/O port identifier.
131  * @details Low level drivers can define multiple ports, it is suggested to
132  * use this naming convention.
133  */
134 #define IOPORT1 0
135 
136 /*===========================================================================*/
137 /* Implementation, some of the following macros could be implemented as */
138 /* functions, if so please put them in pal_lld.c. */
139 /*===========================================================================*/
140 
141 /**
142  * @brief Low level PAL subsystem initialization.
143  *
144  * @param[in] config architecture-dependent ports configuration
145  *
146  * @notapi
147  */
148 #define pal_lld_init(config) _pal_lld_init(config)
149 
150 /**
151  * @brief Reads the physical I/O port states.
152  *
153  * @param[in] port port identifier
154  * @return The port bits.
155  *
156  * @notapi
157  */
158 #define pal_lld_readport(port) 0U
159 
160 /**
161  * @brief Reads the output latch.
162  * @details The purpose of this function is to read back the latched output
163  * value.
164  *
165  * @param[in] port port identifier
166  * @return The latched logical states.
167  *
168  * @notapi
169  */
170 #define pal_lld_readlatch(port) 0U
171 
172 /**
173  * @brief Writes a bits mask on a I/O port.
174  *
175  * @param[in] port port identifier
176  * @param[in] bits bits to be written on the specified port
177  *
178  * @notapi
179  */
180 #define pal_lld_writeport(port, bits) \
181  do { \
182  (void)port; \
183  (void)bits; \
184  } while (false)
185 
186 
187 /**
188  * @brief Sets a bits mask on a I/O port.
189  * @note The @ref PAL provides a default software implementation of this
190  * functionality, implement this function if can optimize it by using
191  * special hardware functionalities or special coding.
192  *
193  * @param[in] port port identifier
194  * @param[in] bits bits to be ORed on the specified port
195  *
196  * @notapi
197  */
198 #define pal_lld_setport(port, bits) \
199  do { \
200  (void)port; \
201  (void)bits; \
202  } while (false)
203 
204 
205 /**
206  * @brief Clears a bits mask on a I/O port.
207  * @note The @ref PAL provides a default software implementation of this
208  * functionality, implement this function if can optimize it by using
209  * special hardware functionalities or special coding.
210  *
211  * @param[in] port port identifier
212  * @param[in] bits bits to be cleared on the specified port
213  *
214  * @notapi
215  */
216 #define pal_lld_clearport(port, bits) \
217  do { \
218  (void)port; \
219  (void)bits; \
220  } while (false)
221 
222 
223 /**
224  * @brief Toggles a bits mask on a I/O port.
225  * @note The @ref PAL provides a default software implementation of this
226  * functionality, implement this function if can optimize it by using
227  * special hardware functionalities or special coding.
228  *
229  * @param[in] port port identifier
230  * @param[in] bits bits to be XORed on the specified port
231  *
232  * @notapi
233  */
234 #define pal_lld_toggleport(port, bits) \
235  do { \
236  (void)port; \
237  (void)bits; \
238  } while (false)
239 
240 
241 /**
242  * @brief Reads a group of bits.
243  * @note The @ref PAL provides a default software implementation of this
244  * functionality, implement this function if can optimize it by using
245  * special hardware functionalities or special coding.
246  *
247  * @param[in] port port identifier
248  * @param[in] mask group mask
249  * @param[in] offset group bit offset within the port
250  * @return The group logical states.
251  *
252  * @notapi
253  */
254 #define pal_lld_readgroup(port, mask, offset) 0U
255 
256 /**
257  * @brief Writes a group of bits.
258  * @note The @ref PAL provides a default software implementation of this
259  * functionality, implement this function if can optimize it by using
260  * special hardware functionalities or special coding.
261  *
262  * @param[in] port port identifier
263  * @param[in] mask group mask
264  * @param[in] offset group bit offset within the port
265  * @param[in] bits bits to be written. Values exceeding the group width
266  * are masked.
267  *
268  * @notapi
269  */
270 #define pal_lld_writegroup(port, mask, offset, bits) \
271  do { \
272  (void)port; \
273  (void)mask; \
274  (void)offset; \
275  (void)bits; \
276  } while (false)
277 
278 /**
279  * @brief Pads group mode setup.
280  * @details This function programs a pads group belonging to the same port
281  * with the specified mode.
282  * @note Programming an unknown or unsupported mode is silently ignored.
283  *
284  * @param[in] port port identifier
285  * @param[in] mask group mask
286  * @param[in] offset group bit offset within the port
287  * @param[in] mode group mode
288  *
289  * @notapi
290  */
291 #define pal_lld_setgroupmode(port, mask, offset, mode) \
292  _pal_lld_setgroupmode(port, mask << offset, mode)
293 
294 /**
295  * @brief Reads a logical state from an I/O pad.
296  * @note The @ref PAL provides a default software implementation of this
297  * functionality, implement this function if can optimize it by using
298  * special hardware functionalities or special coding.
299  *
300  * @param[in] port port identifier
301  * @param[in] pad pad number within the port
302  * @return The logical state.
303  * @retval PAL_LOW low logical state.
304  * @retval PAL_HIGH high logical state.
305  *
306  * @notapi
307  */
308 #define pal_lld_readpad(port, pad) PAL_LOW
309 
310 /**
311  * @brief Writes a logical state on an output pad.
312  * @note This function is not meant to be invoked directly by the
313  * application code.
314  * @note The @ref PAL provides a default software implementation of this
315  * functionality, implement this function if can optimize it by using
316  * special hardware functionalities or special coding.
317  *
318  * @param[in] port port identifier
319  * @param[in] pad pad number within the port
320  * @param[in] bit logical value, the value must be @p PAL_LOW or
321  * @p PAL_HIGH
322  *
323  * @notapi
324  */
325 #define pal_lld_writepad(port, pad, bit) \
326  do { \
327  (void)port; \
328  (void)pad; \
329  (void)bit; \
330  } while (false)
331 
332 /**
333  * @brief Sets a pad logical state to @p PAL_HIGH.
334  * @note The @ref PAL provides a default software implementation of this
335  * functionality, implement this function if can optimize it by using
336  * special hardware functionalities or special coding.
337  *
338  * @param[in] port port identifier
339  * @param[in] pad pad number within the port
340  *
341  * @notapi
342  */
343 #define pal_lld_setpad(port, pad) \
344  do { \
345  (void)port; \
346  (void)pad; \
347  } while (false)
348 
349 
350 /**
351  * @brief Clears a pad logical state to @p PAL_LOW.
352  * @note The @ref PAL provides a default software implementation of this
353  * functionality, implement this function if can optimize it by using
354  * special hardware functionalities or special coding.
355  *
356  * @param[in] port port identifier
357  * @param[in] pad pad number within the port
358  *
359  * @notapi
360  */
361 #define pal_lld_clearpad(port, pad) \
362  do { \
363  (void)port; \
364  (void)pad; \
365  } while (false)
366 
367 
368 /**
369  * @brief Toggles a pad logical state.
370  * @note The @ref PAL provides a default software implementation of this
371  * functionality, implement this function if can optimize it by using
372  * special hardware functionalities or special coding.
373  *
374  * @param[in] port port identifier
375  * @param[in] pad pad number within the port
376  *
377  * @notapi
378  */
379 #define pal_lld_togglepad(port, pad) \
380  do { \
381  (void)port; \
382  (void)pad; \
383  } while (false)
384 
385 
386 /**
387  * @brief Pad mode setup.
388  * @details This function programs a pad with the specified mode.
389  * @note The @ref PAL provides a default software implementation of this
390  * functionality, implement this function if can optimize it by using
391  * special hardware functionalities or special coding.
392  * @note Programming an unknown or unsupported mode is silently ignored.
393  *
394  * @param[in] port port identifier
395  * @param[in] pad pad number within the port
396  * @param[in] mode pad mode
397  *
398  * @notapi
399  */
400 #define pal_lld_setpadmode(port, pad, mode) \
401  do { \
402  (void)port; \
403  (void)pad; \
404  (void)mode; \
405  } while (false)
406 
407 /**
408  * @brief Returns a PAL event structure associated to a pad.
409  *
410  * @param[in] port port identifier
411  * @param[in] pad pad number within the port
412  *
413  * @notapi
414  */
415 #define pal_lld_get_pad_event(port, pad) \
416  &_pal_events[0]; (void)(port); (void)pad
417 
418 /**
419  * @brief Returns a PAL event structure associated to a line.
420  *
421  * @param[in] line line identifier
422  *
423  * @notapi
424  */
425 #define pal_lld_get_line_event(line) \
426  &_pal_events[0]; (void)line
427 
428 #if !defined(__DOXYGEN__)
429 extern const PALConfig pal_default_config;
430 extern palevent_t _pal_events[1];
431 #endif
432 
433 #ifdef __cplusplus
434 extern "C" {
435 #endif
436  void _pal_lld_init(const PALConfig *config);
438  ioportmask_t mask,
439  iomode_t mode);
440 #ifdef __cplusplus
441 }
442 #endif
443 
444 #endif /* HAL_USE_PAL == TRUE */
445 
446 #endif /* HAL_PAL_LLD_H */
447 
448 /** @} */
Type of a PAL event record.
Definition: hal_pal.h:154
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
Definition: hal_pal_lld.h:100
uint32_t iopadid_t
Type of an pad identifier.
Definition: hal_pal_lld.h:123
uint32_t ioline_t
Type of an I/O line.
Definition: hal_pal_lld.h:110
void _pal_lld_init(const PALConfig *config)
STM32 I/O ports configuration.
Definition: hal_pal_lld.c:61
uint32_t ioportid_t
Port Identifier.
Definition: hal_pal_lld.h:118
void _pal_lld_setgroupmode(ioportid_t port, ioportmask_t mask, iomode_t mode)
Pads mode setup.
Definition: hal_pal_lld.c:78
uint32_t iomode_t
Digital I/O modes.
Definition: hal_pal_lld.h:105
Generic I/O ports static initializer.
Definition: hal_pal_lld.h:93