iLLD_TC27xC  1.0
IfxPort.h
Go to the documentation of this file.
1 /**
2  * \file IfxPort.h
3  * \brief PORT basic functionality
4  * \ingroup IfxLld_Port
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  *
25  *
26  * \defgroup IfxLld_Port PORTS
27  * \ingroup IfxLld
28  * \defgroup IfxLld_Port_Std Standard Driver
29  * \ingroup IfxLld_Port
30  * \defgroup IfxLld_Port_Std_Enum Enumerations
31  * \ingroup IfxLld_Port_Std
32  * \defgroup IfxLld_Port_Std_DataStructures Data structures
33  * \ingroup IfxLld_Port_Std
34  * \defgroup IfxLld_Port_Std_SinglePin Single Pin Functions
35  * \ingroup IfxLld_Port_Std
36  * \defgroup IfxLld_Port_Std_PortGroup Group Access Functions
37  * \ingroup IfxLld_Port_Std
38  */
39 
40 #ifndef IFXPORT_H
41 #define IFXPORT_H 1
42 
43 /******************************************************************************/
44 /*----------------------------------Includes----------------------------------*/
45 /******************************************************************************/
46 
47 #include "_Impl/IfxPort_cfg.h"
48 
49 /******************************************************************************/
50 /*--------------------------------Enumerations--------------------------------*/
51 /******************************************************************************/
52 
53 /** \addtogroup IfxLld_Port_Std_Enum
54  * \{ */
55 /** \brief Ifx_P output modification modes definition.
56  */
57 typedef enum
58 {
62  IfxPort_InputMode_pullUp = 2U << 3 /**< \brief */
64 
65 /** \brief Ifx_P input / output mode definition.
66  *
67  * \see Ifx_P.IOCR, IfxPort_setPinMode()
68  */
69 typedef enum
70 {
71  IfxPort_Mode_inputNoPullDevice = 0, /**< \brief Input, No pull device connected. */
72  IfxPort_Mode_inputPullDown = 8U, /**< \brief Input, pull-down device connected. */
73  IfxPort_Mode_inputPullUp = 0x10U, /**< \brief Input, pull-up device connected. */
74  IfxPort_Mode_outputPushPullGeneral = 0x80U, /**< \brief Push-pull, General-purpose output */
75  IfxPort_Mode_outputPushPullAlt1 = 0x88U, /**< \brief Push-pull, Alternate output function 1. */
76  IfxPort_Mode_outputPushPullAlt2 = 0x90U, /**< \brief Push-pull, Alternate output function 2. */
77  IfxPort_Mode_outputPushPullAlt3 = 0x98U, /**< \brief Push-pull, Alternate output function 3. */
78  IfxPort_Mode_outputPushPullAlt4 = 0xA0U, /**< \brief Push-pull, Alternate output function 4. */
79  IfxPort_Mode_outputPushPullAlt5 = 0xA8U, /**< \brief Push-pull, Alternate output function 5. */
80  IfxPort_Mode_outputPushPullAlt6 = 0xB0U, /**< \brief Push-pull, Alternate output function 6. */
81  IfxPort_Mode_outputPushPullAlt7 = 0xB8U, /**< \brief Push-pull, Alternate output function 7. */
82  IfxPort_Mode_outputOpenDrainGeneral = 0xC0U, /**< \brief Open-drain, General-purpose output. */
83  IfxPort_Mode_outputOpenDrainAlt1 = 0xC8U, /**< \brief Open-drain, Alternate output function 1. */
84  IfxPort_Mode_outputOpenDrainAlt2 = 0xD0U, /**< \brief Open-drain, Alternate output function 2. */
85  IfxPort_Mode_outputOpenDrainAlt3 = 0xD8U, /**< \brief Open-drain, Alternate output function 3. */
86  IfxPort_Mode_outputOpenDrainAlt4 = 0xE0U, /**< \brief Open-drain, Alternate output function 4. */
87  IfxPort_Mode_outputOpenDrainAlt5 = 0xE8U, /**< \brief Open-drain, Alternate output function 5. */
88  IfxPort_Mode_outputOpenDrainAlt6 = 0xF0U, /**< \brief Open-drain, Alternate output function 6. */
89  IfxPort_Mode_outputOpenDrainAlt7 = 0xF8U /**< \brief Open-drain, Alternate output function 7. */
90 } IfxPort_Mode;
91 
92 /** \brief Pin output alternate index
93  */
94 typedef enum
95 {
97  IfxPort_OutputIdx_alt1 = 0x11U << 3,
98  IfxPort_OutputIdx_alt2 = 0x12U << 3,
99  IfxPort_OutputIdx_alt3 = 0x13U << 3,
105 
106 /** \brief Pin output mode definition
107  */
108 typedef enum
109 {
113 
114 /** \brief Pad driver mode definition (strength and slew rate).
115  *
116  * \see Ifx_P.PDR, IfxPort_setPinPadDriver()
117  */
118 typedef enum
119 {
120  IfxPort_PadDriver_cmosAutomotiveSpeed1 = 0, /**< \brief Speed grade 1. */
121  IfxPort_PadDriver_cmosAutomotiveSpeed2 = 1, /**< \brief Speed grade 2. */
122  IfxPort_PadDriver_cmosAutomotiveSpeed3 = 2, /**< \brief Speed grade 3. */
123  IfxPort_PadDriver_cmosAutomotiveSpeed4 = 3, /**< \brief Speed grade 4. */
124  IfxPort_PadDriver_ttlSpeed1 = 8, /**< \brief Speed grade 1. */
125  IfxPort_PadDriver_ttlSpeed2 = 9, /**< \brief Speed grade 2. */
126  IfxPort_PadDriver_ttlSpeed3 = 10, /**< \brief Speed grade 3. */
127  IfxPort_PadDriver_ttlSpeed4 = 11 /**< \brief Speed grade 4. */
129 
130 /** \brief Ifx_P output modification modes definition.
131  *
132  * \see Ifx_P.OMR, IfxPort_setPinState()
133  */
134 typedef enum
135 {
136  IfxPort_State_notChanged = (0 << 16) | (0 << 0), /**< \brief Ifx_P pin is left unchanged. */
137  IfxPort_State_high = (0 << 16) | (1U << 0), /**< \brief Ifx_P pin is set to high. */
138  IfxPort_State_low = (1U << 16) | (0 << 0), /**< \brief Ifx_P pin is set to low. */
139  IfxPort_State_toggled = (1U << 16) | (1U << 0) /**< \brief Ifx_P pin is toggled. */
140 } IfxPort_State;
141 
142 /** \} */
143 
144 /******************************************************************************/
145 /*-----------------------------Data Structures--------------------------------*/
146 /******************************************************************************/
147 
148 /** \addtogroup IfxLld_Port_Std_DataStructures
149  * \{ */
150 /** \brief Defines a pin
151  */
152 typedef struct
153 {
154  Ifx_P *port;
156 } IfxPort_Pin;
157 
158 /** \brief To configure pins
159  */
160 typedef struct
161 {
162  Ifx_P *port;
167 
168 /** \} */
169 
170 /** \addtogroup IfxLld_Port_Std_SinglePin
171  * \{ */
172 
173 /******************************************************************************/
174 /*-------------------------Inline Function Prototypes-------------------------*/
175 /******************************************************************************/
176 
177 /** \brief Return the port state.
178  * \param port Pointer to the port which should be accessed.
179  * \param pinIndex Specifies the pin for which the state should be returned.
180  * \return Returns TRUE the pin is high; FALSE the pin is low
181  *
182  * Coding example:
183  * \code
184  * if( IfxPort_getPinState(&MODULE_P33, 0) ) {
185  * // ...
186  * }
187  * \endcode
188  *
189  */
190 IFX_INLINE boolean IfxPort_getPinState(Ifx_P *port, uint8 pinIndex);
191 
192 /** \brief Set the port output.
193  * \param port Pointer to the port which should be accessed.
194  * \param pinIndex Specifies the pin to be set.
195  * \return None
196  *
197  * Coding example:
198  * \code
199  * IfxPort_setPinHigh(&MODULE_P33, 0);
200  * \endcode
201  *
202  * \see IfxPort_setPinState(), IfxPort_setPinLow(), IfxPort_togglePin()
203  *
204  */
205 IFX_INLINE void IfxPort_setPinHigh(Ifx_P *port, uint8 pinIndex);
206 
207 /** \brief Reset the port output.
208  * \param port Pointer to the port which should be accessed.
209  * \param pinIndex Specifies the pin to be reset.
210  * \return None
211  *
212  * Coding example:
213  * \code
214  * IfxPort_setPinLow(&MODULE_P33, 0);
215  * \endcode
216  *
217  * \see IfxPort_setPinState(), IfxPort_setPinHigh(), IfxPort_togglePin()
218  *
219  */
220 IFX_INLINE void IfxPort_setPinLow(Ifx_P *port, uint8 pinIndex);
221 
222 /** \brief Configure the port input / output mode.
223  * \param port Pointer to the port which should be accessed.
224  * \param pinIndex Specifies the pin to be configured.
225  * \param mode Specifies the port pin mode.
226  * \return None
227  *
228  * Coding example:
229  * \code
230  * IfxPort_setPinModeInput(&MODULE_P33, 0, IfxPort_InputMode_pullUp);
231  * \endcode
232  *
233  */
234 IFX_INLINE void IfxPort_setPinModeInput(Ifx_P *port, uint8 pinIndex, IfxPort_InputMode mode);
235 
236 /** \brief Configure the port input / output mode.
237  * \param port Pointer to the port which should be accessed.
238  * \param pinIndex Specifies the pin to be configured.
239  * \param mode Specifies the port pin mode.
240  * \param index Specifies the alternate (or general purpose) output channel.
241  * \return None
242  *
243  * Coding example:
244  * \code
245  * IfxPort_setPinModeOutput(&MODULE_P33, 0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
246  * \endcode
247  *
248  */
249 IFX_INLINE void IfxPort_setPinModeOutput(Ifx_P *port, uint8 pinIndex, IfxPort_OutputMode mode, IfxPort_OutputIdx index);
250 
251 /** \brief Set / Resets / Toggle the port output.
252  * \param port Pointer to the port which should be accessed.
253  * \param pinIndex Specifies the pin to modify.
254  * \param action Specifies the action: set, reset, toggle.
255  * \return None
256  *
257  * Coding example:
258  * \code
259  * IfxPort_setPinState(&MODULE_P33, 0, IfxPort_State_toggled);
260  * IfxPort_setPinState(&MODULE_P33, 0, IfxPort_State_toggled);
261  * IfxPort_setPinState(&MODULE_P33, 0, IfxPort_State_toggled);
262  * \endcode
263  *
264  */
265 IFX_INLINE void IfxPort_setPinState(Ifx_P *port, uint8 pinIndex, IfxPort_State action);
266 
267 /** \brief Toggle the port output.
268  * \param port Pointer to the port which should be accessed.
269  * \param pinIndex Specifies the pin to be toggled.
270  * \return None
271  *
272  * Coding example:
273  * \code
274  * IfxPort_togglePin(&MODULE_P33, 0);
275  * \endcode
276  *
277  * \see IfxPort_setPinState(), IfxPort_setPinLow(), IfxPort_setPinHigh()
278  *
279  */
280 IFX_INLINE void IfxPort_togglePin(Ifx_P *port, uint8 pinIndex);
281 
282 /******************************************************************************/
283 /*-------------------------Global Function Prototypes-------------------------*/
284 /******************************************************************************/
285 
286 /** \brief Disable the emergency stop function.
287  * This function disables the emergency stop function. A check is done on port functionality.
288  * \param port Pointer to the port which should be accessed.
289  * \param pinIndex Specifies the pin for which the emergency stop function should be disabled.
290  * \return Returns TRUE if the emergency stop function has been disabled; FALSE if the emergency stop function could not be disabled
291  *
292  * Coding example:
293  * /code
294  * if( !IfxPort_disableEmergencyStop(&MODULE_P33, 0) )
295  * {
296  * // failed to disable emergency stop for P33.0
297  * }
298  * /endcode
299  *
300  * \see IfxPort_disableEmergencyStop(), IfxPort_resetESR()
301  *
302  */
303 IFX_EXTERN boolean IfxPort_disableEmergencyStop(Ifx_P *port, uint8 pinIndex);
304 
305 /** \brief Enable the emergency stop function.
306  * This function enables the emergency stop function. A check is done on port functionality.
307  * \param port Pointer to the port which should be accessed.
308  * \param pinIndex Specifies the pin for which the emergency stop function should be enabled.
309  * \return Returns TRUE if the emergency stop function has been enabled; FALSE if the emergency stop function could not be enabled
310  *
311  * Coding example:
312  * \code
313  * if( !IfxPort_enableEmergencyStop(&MODULE_P33, 0) ) {
314  * // failed to enable emergency stop for P33.0
315  * }
316  * \endcode
317  *
318  * \see IfxPort_disableEmergencyStop(), IfxPort_setESR()
319  *
320  */
321 IFX_EXTERN boolean IfxPort_enableEmergencyStop(Ifx_P *port, uint8 pinIndex);
322 
323 /** \brief Configure the port input / output mode.
324  * \param port Pointer to the port which should be accessed.
325  * \param pinIndex Specifies the pin to be configured.
326  * \param mode Specifies the port pin mode.
327  * \return None
328  *
329  * Coding example:
330  * \code
331  * IfxPort_setPinMode(&MODULE_P33, 0, IfxPort_Mode_outputPushPullGeneral);
332  * \endcode
333  *
334  */
335 IFX_EXTERN void IfxPort_setPinMode(Ifx_P *port, uint8 pinIndex, IfxPort_Mode mode);
336 
337 /** \brief Configure the pad driver mode.
338  * \param port Pointer to the port which should be accessed.
339  * \param pinIndex Specifies the pin for which the mode will be set.
340  * \param padDriver Specifies the driver mode.
341  * \return None
342  *
343  * Coding example:
344  * \code
345  * // enable strong 3.3V driver
346  * IfxPort_setPinPadDriver(&MODULE_P33, 0, IfxPort_PadDriver_cmosAutomotiveSpeed1);
347  * \endcode
348  *
349  */
350 IFX_EXTERN void IfxPort_setPinPadDriver(Ifx_P *port, uint8 pinIndex, IfxPort_PadDriver padDriver);
351 
352 /** \} */
353 
354 /** \addtogroup IfxLld_Port_Std_PortGroup
355  * \{ */
356 
357 /******************************************************************************/
358 /*-------------------------Inline Function Prototypes-------------------------*/
359 /******************************************************************************/
360 
361 /** \brief Return the port group state
362  * \param port Pointer to the port which should be accessed.
363  * \param pinIndex start at the given pin
364  * \param mask selects the pins which should be read (starting from pinIndex)
365  * \return Returns the selected pin values
366  *
367  * Coding example:
368  * \code
369  * // read the current value of P33[7:0]
370  * uint16 value = IfxPort_getGroupState(&MODULE_P33, 0, 0xff);
371  * \endcode
372  *
373  */
374 IFX_INLINE uint32 IfxPort_getGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask);
375 
376 /** \brief Set the port group state.
377  * \param port Pointer to the port which should be accessed.
378  * \param pinIndex start at the given pin
379  * \param mask selects the pins which should be modified (starting from pinIndex)
380  * \param data specifies the value which should be set
381  * \return None
382  *
383  * Coding example:
384  * \code
385  * // configure P33.[7:0] as GPIO outputs
386  * IfxPort_setGroupModeOutput(&MODULE_P33, 0, 0xff, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
387  *
388  * // set initial value
389  * IfxPort_setGroupState(&MODULE_P33, 0, 0xff, 0x42);
390  * \endcode
391  *
392  */
393 IFX_INLINE void IfxPort_setGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask, uint16 data);
394 
395 /******************************************************************************/
396 /*-------------------------Global Function Prototypes-------------------------*/
397 /******************************************************************************/
398 
399 /** \brief Return port index within IfxModule_IndexMap (defined in IfxPort_cfg.c)
400  * \param port Pointer to the port for which the index number in IfxModule_IndexMap should be retrieved.
401  * \return port index of IfxModule_IndexMap. return -1 in case of unknown portIndex.
402  */
403 IFX_EXTERN sint32 IfxPort_getIndex(Ifx_P *port);
404 
405 /** \brief Set pin modes to input at the pin location specified by '1' by the mask
406  * \param port Pointer to the port which should be accessed.
407  * \param pinIndex start at the given pin
408  * \param mask selects the pins which should be modified (starting from pinIndex)
409  * \param mode Specifies the port pin mode.
410  * \return None
411  *
412  * Coding example:
413  * \code
414  * // configure P33.[7:0] as GPIO inputs with Pull-Down enabled
415  * IfxPort_setGroupModeInput(&MODULE_P33, 0, 0xff, IfxPort_InputMode_pullDown);
416  * \endcode
417  *
418  */
419 IFX_EXTERN void IfxPort_setGroupModeInput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_InputMode mode);
420 
421 /** \brief Set pin modes to output at the pin location specified by '1' by the mask starting at pinIndex
422  * \param port Pointer to the port which should be accessed.
423  * \param pinIndex start at the given pin
424  * \param mask selects the pins which should be modified (starting from pinIndex)
425  * \param mode Specifies the port pin mode.
426  * \param index Specifies the alternate (or general purpose) output channel.
427  * \return None
428  *
429  * Coding example:
430  * \code
431  * // configure P33.[7:0] as GPIO outputs
432  * IfxPort_setGroupModeOutput(&MODULE_P33, 0, 0xff, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
433  * \endcode
434  *
435  */
436 IFX_EXTERN void IfxPort_setGroupModeOutput(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_OutputMode mode, IfxPort_OutputIdx index);
437 
438 /** \brief Set pad driver strength at the pin location specified by '1' by the mask
439  * \param port Pointer to the port which should be accessed.
440  * \param pinIndex start at the given pin
441  * \param mask selects the pins which should be modified (starting from pinIndex)
442  * \param padDriver Specifies the pad driver strength.
443  * \return None
444  *
445  * Coding example:
446  * \code
447  * // configure P33.[7:0] to use CMOS pad driver with speed 1
448  * IfxPort_setGroupPadDriver(&MODULE_P33, 0, 0xff, IfxPort_PadDriver_cmosAutomotiveSpeed1);
449  * \endcode
450  *
451  */
452 IFX_EXTERN void IfxPort_setGroupPadDriver(Ifx_P *port, uint8 pinIndex, uint16 mask, IfxPort_PadDriver padDriver);
453 
454 /** \} */
455 
456 /******************************************************************************/
457 /*-------------------------Global Function Prototypes-------------------------*/
458 /******************************************************************************/
459 
460 /** \brief Disable the emergency stop function.
461  * This function disables the emergency stop function. No check is done on port functionality.
462  * \param port Pointer to the port which should be accessed.
463  * \param pinIndex Specifies the pin for which the emergency stop function should be disabled.
464  * \return None
465  *
466  * \see IfxPort_disableEmergencyStop(), \bitfield Ifx_P.ESR
467  *
468  */
469 IFX_EXTERN void IfxPort_resetESR(Ifx_P *port, uint8 pinIndex);
470 
471 /** \brief Enable the emergency stop function.
472  * This function enables the emergency stop function. No check is done on port functionality.
473  * \param port Pointer to the port which should be accessed.
474  * \param pinIndex Specifies the pin for which the emergency stop function should be enabled.
475  * \return None
476  *
477  * \see IfxPort_enableEmergencyStop(), \bitfield Ifx_P.ESR
478  *
479  */
480 IFX_EXTERN void IfxPort_setESR(Ifx_P *port, uint8 pinIndex);
481 
482 /******************************************************************************/
483 /*---------------------Inline Function Implementations------------------------*/
484 /******************************************************************************/
485 
486 IFX_INLINE boolean IfxPort_getPinState(Ifx_P *port, uint8 pinIndex)
487 {
488  return (__getbit(&port->IN.U, pinIndex) != 0) ? TRUE : FALSE;
489 }
490 
491 
492 IFX_INLINE void IfxPort_setPinHigh(Ifx_P *port, uint8 pinIndex)
493 {
494  IfxPort_setPinState(port, pinIndex, IfxPort_State_high);
495 }
496 
497 
498 IFX_INLINE void IfxPort_setPinLow(Ifx_P *port, uint8 pinIndex)
499 {
500  IfxPort_setPinState(port, pinIndex, IfxPort_State_low);
501 }
502 
503 
505 {
506  IfxPort_setPinMode(port, pinIndex, (IfxPort_Mode)mode);
507 }
508 
509 
511 {
512  IfxPort_setPinMode(port, pinIndex, (IfxPort_Mode)(index | mode));
513 }
514 
515 
516 IFX_INLINE void IfxPort_setPinState(Ifx_P *port, uint8 pinIndex, IfxPort_State action)
517 {
518  port->OMR.U = action << pinIndex;
519 }
520 
521 
522 IFX_INLINE void IfxPort_togglePin(Ifx_P *port, uint8 pinIndex)
523 {
525 }
526 
527 
528 IFX_INLINE uint32 IfxPort_getGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask)
529 {
530  return (uint32)((port->IN.U) >> (pinIndex)) & mask;
531 }
532 
533 
534 IFX_INLINE void IfxPort_setGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask, uint16 data)
535 {
536  port->OUT.U = (port->OUT.U & ~((uint32)(mask)) << pinIndex) | (data << pinIndex);
537 }
538 
539 
540 #endif /* IFXPORT_H */