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