Infineon MOTIX™ MCU TLE987x Device Family SDK
uart.h
Go to the documentation of this file.
1 /*
2  ***********************************************************************************************************************
3  *
4  * Copyright (c) Infineon Technologies AG
5  * All rights reserved.
6  *
7  * The applicable license agreement can be found at this pack's installation directory in the file
8  * license/IFX_SW_Licence_MOTIX_LITIX.txt
9  *
10  **********************************************************************************************************************/
20 /*******************************************************************************
21 ** Author(s) Identity **
22 ********************************************************************************
23 ** Initials Name **
24 ** ---------------------------------------------------------------------------**
25 ** DM Daniel Mysliwitz **
26 ** BG Blandine Guillot **
27 ** JO Julia Ott **
28 ** VO Vanessa Ongaro **
29 *******************************************************************************/
30 
31 /*******************************************************************************
32 ** Revision Control History **
33 ********************************************************************************
34 ** V0.1.0: 2014-05-11, DM: Initial version **
35 ** V0.1.1: 2014-07-22, DM: BGL baudrate calculation fixed **
36 ** V0.1.2: 2015-02-10, DM: Individual header file added **
37 ** V0.1.3: 2015-07-15, DM: STDIN/STDOUT function added **
38 ** V0.1.4: 2017-02-15, DM: GetByte, isByteReceived and isByteTransmitted **
39 ** inline functions added **
40 ** Baudrate_Set function added **
41 ** V0.1.5: 2017-10-20, DM: MISRA 2012 compliance, the following PC-Lint **
42 ** rules are globally deactivated: **
43 ** - Info 793: ANSI/ISO limit of 6 'significant **
44 ** characters in an external identifier **
45 ** - Info 835: A zero has been given as right **
46 ** argument to operator **
47 ** - Info 845: The left argument to operator '&' **
48 ** is certain to be 0 **
49 ** V0.1.6: 2018-02-02, DM: BaudRate_Set function corrected **
50 ** V0.1.7: 2018-03-20, DM: Preprocessor checks modified to allow only one **
51 ** UART to be STDIN/STDOUT at a time **
52 ** V0.1.8: 2018-11-27, JO: Doxygen update **
53 ** Moved revision history from uart.c to uart.h **
54 ** Added ranges for UART1_BaudRate_Set and **
55 ** UART2_BaudRate_Set **
56 ** Adapted the implementation of stdout_putchar **
57 ** and stdin_getchar for UART1 and UART2 so that **
58 ** they follow the same procedure **
59 ** UART1_BaudRate_Value_Set(), **
60 ** UART2_BaudRate_Value_Set() functions added **
61 ** V0.1.9: 2019-09-11, JO: Corrected ranges for UART1_BaudRate_Set and **
62 ** UART2_BaudRate_Set **
63 ** V0.2.0: 2020-04-15, BG: Updated revision history format **
64 ** V0.2.1: 2020-07-13, JO: EP-431: remove ARMCC v6 Compiler warnings **
65 ** - added static to definition of uart1 and uart2 **
66 ** V0.2.2: 2020-07-21, BG: EP-439: Formatted .h/.c files **
67 ** V0.2.3: 2022-02-28, JO: EP-936: Updated copyright and branding **
68 ** V0.2.4: 2022-10-18, VO: EP-1252: Updated sruct definition **
69 ** V0.2.5: 2025-01-02, JO: EP-1493: Updated license **
70 *******************************************************************************/
71 
72 #ifndef UART_H
73 #define UART_H
74 
75 /*******************************************************************************
76 ** Includes **
77 *******************************************************************************/
78 #include "tle987x.h"
79 #include "types.h"
80 #include "uart_defines.h"
81 #include "sfr_access.h"
82 
83 /*******************************************************************************
84 ** Global Type Definitions **
85 *******************************************************************************/
89 typedef struct Uart
90 {
93 
94 /*******************************************************************************
95 ** Global Inline Function Definitions **
96 *******************************************************************************/
121 {
122  Field_Wrt8all(&SCU->BGH1.reg, (uint8)(br_val >> 8u));
123  Field_Wrt8all(&SCU->BGL1.reg, (uint8)(br_val & (uint16)0x00FF));
124 }
125 
150 {
152 }
153 
154 
179 {
181 }
182 
183 
208 {
209  Field_Wrt8all(&SCU->BGH2.reg, (uint8)(br_val >> 8u));
210  Field_Wrt8all(&SCU->BGL2.reg, (uint8)(br_val & (uint16)0x00FF));
211 }
212 
237 {
239 }
240 
265 {
267 }
268 
289 {
291 }
292 
313 {
315 }
316 
340 {
342 }
343 
367 {
369 }
370 
393 {
395 }
396 
419 {
421 }
422 
445 {
447 }
448 
468 {
470 }
471 
492 {
494 }
495 
517 {
519 }
520 
541 {
543 }
544 
566 {
568 }
569 
592 {
594 }
595 
614 {
616 }
617 
639 {
641 }
642 
661 {
663 }
664 
665 /* UART Interrupt Enable/Disable */
684 {
686 }
687 
707 {
709 }
710 
729 {
731 }
732 
752 {
754 }
755 
774 {
776 }
777 
797 {
799 }
800 
819 {
821 }
822 
842 {
844 }
845 
846 /*******************************************************************************
847 ** Global Function Declarations **
848 *******************************************************************************/
853 void UART1_Init(void);
854 
859 void UART2_Init(void);
860 
875 void UART1_BaudRate_Set(uint32 baudrate);
876 
891 void UART2_BaudRate_Set(uint32 baudrate);
892 
893 /*******************************************************************************
894 ** Global Inline Function Declarations **
895 *******************************************************************************/
896 #if ((UART1_STD_EN == 1) || (UART2_STD_EN == 1))
904  sint32 stdout_putchar(sint32 Char);
905 
912  sint32 stdin_getchar(void);
913  void ttywrch(int ch);
914 #endif /* ((UART1_STD_EN == 1) || (UART2_STD_EN == 1)) */
915 
916 
917 /*******************************************************************************
918 ** Global Inline Static Function Definitions **
919 *******************************************************************************/
939 {
941  UART1_Buffer_Set(c);
942 }
943 
966 {
968  return (UART1_Buffer_Get());
969 }
970 
994 {
995  bool bRes = false;
996 
997  if (UART1_RX_Sts() == (uint8)1)
998  {
999  bRes = true;
1000  }
1001 
1002  return (bRes);
1003 }
1004 
1025 {
1026  bool bRes = false;
1027 
1028  if (UART1_TX_Sts() == (uint8)1)
1029  {
1030  bRes = true;
1031  }
1032 
1033  return (bRes);
1034 }
1035 
1055 {
1056  UART2_TX_Int_Clr();
1057  UART2_Buffer_Set(c);
1058 }
1059 
1082 {
1083  UART2_RX_Int_Clr();
1084  return (UART2_Buffer_Get());
1085 }
1086 
1110 {
1111  bool bRes = false;
1112 
1113  if (UART2_RX_Sts() == (uint8)1)
1114  {
1115  bRes = true;
1116  }
1117 
1118  return (bRes);
1119 }
1120 
1141 {
1142  bool bRes = false;
1143 
1144  if (UART2_TX_Sts() == (uint8)1)
1145  {
1146  bRes = true;
1147  }
1148 
1149  return (bRes);
1150 }
1151 
1152 #endif
#define UART2
Definition: tle987x.h:6079
#define UART1
Definition: tle987x.h:6078
#define SCU
Definition: tle987x.h:6071
#define UART2_SCON_RI_Msk
Definition: tle987x.h:10110
#define UART1_SCON_REN_Msk
Definition: tle987x.h:10087
#define SCU_MODIEN1_TIEN1_Pos
Definition: tle987x.h:9107
#define UART1_SBUF_VAL_Msk
Definition: tle987x.h:10076
#define SCU_MODIEN2_TIEN2_Pos
Definition: tle987x.h:9118
#define SCU_MODIEN2_RIEN2_Pos
Definition: tle987x.h:9120
#define UART2_SBUF_VAL_Pos
Definition: tle987x.h:10106
#define UART2_SCON_TI_Pos
Definition: tle987x.h:10111
#define SCU_MODIEN1_TIEN1_Msk
Definition: tle987x.h:9108
#define UART1_SCON_REN_Pos
Definition: tle987x.h:10086
#define UART2_SCONCLR_TICLR_Msk
Definition: tle987x.h:10129
#define UART2_SBUF_VAL_Msk
Definition: tle987x.h:10107
#define UART2_SCON_REN_Pos
Definition: tle987x.h:10117
#define UART2_SCON_RI_Pos
Definition: tle987x.h:10109
#define SCU_MODIEN2_TIEN2_Msk
Definition: tle987x.h:9119
#define UART2_SCONCLR_TICLR_Pos
Definition: tle987x.h:10128
#define SCU_BCON2_R_Msk
Definition: tle987x.h:8741
#define UART1_SCON_RI_Pos
Definition: tle987x.h:10078
#define SCU_MODIEN2_RIEN2_Msk
Definition: tle987x.h:9121
#define SCU_BCON1_R_Msk
Definition: tle987x.h:8736
#define UART2_SCONCLR_RICLR_Msk
Definition: tle987x.h:10127
#define UART1_SBUF_VAL_Pos
Definition: tle987x.h:10075
#define SCU_MODIEN1_RIEN1_Pos
Definition: tle987x.h:9109
#define UART1_SCONCLR_TICLR_Pos
Definition: tle987x.h:10097
#define UART1_SCON_TI_Msk
Definition: tle987x.h:10081
#define UART1_SCON_RI_Msk
Definition: tle987x.h:10079
#define SCU_MODIEN1_RIEN1_Msk
Definition: tle987x.h:9110
#define UART1_SCONCLR_RICLR_Pos
Definition: tle987x.h:10095
#define UART1_SCONCLR_TICLR_Msk
Definition: tle987x.h:10098
#define UART1_SCON_TI_Pos
Definition: tle987x.h:10080
#define UART1_SCONCLR_RICLR_Msk
Definition: tle987x.h:10096
#define SCU_BCON2_R_Pos
Definition: tle987x.h:8740
#define UART2_SCON_REN_Msk
Definition: tle987x.h:10118
#define SCU_BCON1_R_Pos
Definition: tle987x.h:8735
#define UART2_SCONCLR_RICLR_Pos
Definition: tle987x.h:10126
#define UART2_SCON_TI_Msk
Definition: tle987x.h:10112
SFR low level access library.
INLINE void Field_Wrt8(volatile uint8 *reg, uint8 pos, uint8 msk, uint8 val)
This function writes a bit field in a 8-bit register.
Definition: sfr_access.h:322
INLINE uint8 u8_Field_Rd8(const volatile uint8 *reg, uint8 pos, uint8 msk)
This function reads a 8-bit field of a 8-bit register.
Definition: sfr_access.h:397
INLINE void Field_Wrt8all(volatile uint8 *reg, uint8 val)
This function writes an 8-bit register directly, no mask/position needed.
Definition: sfr_access.h:317
INLINE uint8 u1_Field_Rd8(const volatile uint8 *reg, uint8 pos, uint8 msk)
This function reads a 1-bit field of a 8-bit register.
Definition: sfr_access.h:382
INLINE void Field_Mod8(volatile uint8 *reg, uint8 pos, uint8 msk, uint8 val)
This function writes a bit field in a 8-bit register.
Definition: sfr_access.h:337
Definition: uart.h:90
uint32 clock
Definition: uart.h:91
CMSIS register HeaderFile.
General type declarations.
#define INLINE
Definition: types.h:132
uint8_t uint8
8 bit unsigned value
Definition: types.h:137
int32_t sint32
32 bit signed value
Definition: types.h:144
uint16_t uint16
16 bit unsigned value
Definition: types.h:138
uint32_t uint32
32 bit unsigned value
Definition: types.h:139
INLINE uint8 UART2_TX_Sts(void)
reads the transmit interrupt flag of UART2.
Definition: uart.h:467
void UART2_BaudRate_Set(uint32 baudrate)
Sets the baudrate of UART2.
INLINE void UART1_Send_Byte(uint8 c)
clears the UART1 Transmit interrupt and sends a Byte via UART1.
Definition: uart.h:938
INLINE void UART1_Receiver_Dis(void)
disables Receiver of Serial Port (UART1).
Definition: uart.h:516
INLINE void UART2_TX_Int_Dis(void)
disables transmit interrupt of UART2.
Definition: uart.h:841
INLINE void UART1_Receiver_En(void)
enables Receiver of Serial Port (UART1).
Definition: uart.h:491
INLINE void UART2_RX_Int_Clr(void)
clears receive interrupt flag of UART2.
Definition: uart.h:638
INLINE void UART1_TX_Int_Dis(void)
disables transmit interrupt of UART1.
Definition: uart.h:751
INLINE uint8 UART1_RX_Sts(void)
reads the receive interrupt flag of UART1.
Definition: uart.h:392
INLINE void UART2_BaudRateGen_En(void)
enables Baud-rate generator (UART2).
Definition: uart.h:264
INLINE void UART1_TX_Int_Clr(void)
clears transmit interrupt flag of UART1.
Definition: uart.h:613
INLINE void UART1_RX_Int_En(void)
enables receive interrupt of UART1.
Definition: uart.h:683
struct Uart TUart
INLINE bool UART1_isByteTransmitted(void)
checks if UART1 has transmitted a Byte or not.
Definition: uart.h:1024
INLINE uint8 UART1_Get_Byte(void)
Clears the UART1 receive interrupt and returns the UART1 buffer.
Definition: uart.h:965
void UART1_Init(void)
Initializes the UART1 module based on the Config Wizard for MOTIX MCU configuration.
INLINE uint8 UART1_Buffer_Get(void)
Reads UART1 Buffer.
Definition: uart.h:339
INLINE bool UART1_isByteReceived(void)
checks if UART1 has received Byte or not.
Definition: uart.h:993
INLINE void UART2_Receiver_Dis(void)
disables Receiver of Serial Port (UART2).
Definition: uart.h:565
INLINE void UART1_BaudRateGen_Dis(void)
disables Baud-rate generator (UART1).
Definition: uart.h:149
INLINE void UART2_TX_Int_Clr(void)
clears transmit interrupt flag of UART2.
Definition: uart.h:660
INLINE void UART2_RX_Int_Dis(void)
disables receive interrupt of UART2.
Definition: uart.h:796
void UART1_BaudRate_Set(uint32 baudrate)
Sets the baudrate of UART1.
INLINE void UART2_BaudRateGen_Dis(void)
disables Baud-rate generator (UART2).
Definition: uart.h:236
INLINE void UART1_Buffer_Set(uint8 data)
Sends a Byte via UART1.
Definition: uart.h:288
INLINE void UART2_Send_Byte(uint8 c)
clears the UART2 Transmit interrupt and sends a Byte via UART2.
Definition: uart.h:1054
INLINE uint8 UART1_TX_Sts(void)
reads the transmit interrupt flag of UART1.
Definition: uart.h:418
INLINE void UART2_RX_Int_En(void)
enables receive interrupt of UART2.
Definition: uart.h:773
INLINE uint8 UART2_Get_Byte(void)
Clears the UART2 receive interrupt and returns the UART2 buffer.
Definition: uart.h:1081
INLINE void UART2_TX_Int_En(void)
enables transmit interrupt of UART2.
Definition: uart.h:818
INLINE void UART1_BaudRateGen_En(void)
enables Baud-rate generator (UART1).
Definition: uart.h:178
INLINE uint8 UART2_RX_Sts(void)
reads the receive interrupt flag of UART2.
Definition: uart.h:444
INLINE void UART1_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART1).
Definition: uart.h:120
INLINE void UART1_RX_Int_Clr(void)
clears receive interrupt flag for UART1.
Definition: uart.h:591
INLINE void UART2_Receiver_En(void)
enables Receiver of Serial Port (UART2).
Definition: uart.h:540
INLINE void UART1_RX_Int_Dis(void)
disables receive interrupt of UART1.
Definition: uart.h:706
void UART2_Init(void)
Initializes the UART2 module based on the Config Wizard for MOTIX MCU configuration.
INLINE void UART2_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART2).
Definition: uart.h:207
INLINE void UART2_Buffer_Set(uint8 data)
Sends a Byte via UART2.
Definition: uart.h:312
INLINE uint8 UART2_Buffer_Get(void)
Reads UART2 Buffer.
Definition: uart.h:366
INLINE void UART1_TX_Int_En(void)
enables transmit interrupt of UART1.
Definition: uart.h:728
INLINE bool UART2_isByteReceived(void)
checks if UART2 has received Byte or not.
Definition: uart.h:1109
INLINE bool UART2_isByteTransmitted(void)
checks if UART2 has transmitted a Byte or not.
Definition: uart.h:1140