Infineon MOTIX™ MCU TLE985x Device Family SDK
uart.h
Go to the documentation of this file.
1 /*
2  ***********************************************************************************************************************
3  *
4  * Copyright (c) 2018-2022, Infineon Technologies AG
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
8  * following conditions are met:
9  *
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11  * disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14  * following disclaimer in the documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  **********************************************************************************************************************/
39 /*******************************************************************************
40 ** Author(s) Identity **
41 ********************************************************************************
42 ** Initials Name **
43 ** ---------------------------------------------------------------------------**
44 ** TS T&S **
45 ** KC Kay Claussen **
46 ** JO Julia Ott **
47 ** BG Blandine Guillot **
48 *******************************************************************************/
49 
50 /*******************************************************************************
51 ** Revision Control History **
52 ********************************************************************************
53 ** V0.2.0: 2018-02-13, TS: Initial version of revision history **
54 ** V0.2.1: 2018-07-30, KC: Conditional compiling in UARTx_Init removed **
55 ** V0.2.2: 2019-01-28, TS: Revision history moved from uart.c to uart.h **
56 ** __STATIC_INLINE replaced by INLINE **
57 ** Doxygen update **
58 ** Ranges added for UART1_BaudRate_Set and **
59 ** UART2_BaudRate_Set **
60 ** Implementation of stdout_putchar, stdin_getchar **
61 ** adapted for UART1 and UART2 so that they follow **
62 ** the same procedure **
63 ** UART1_BaudRate_Value_Set, **
64 ** UART1_Fractional_Divider_Value_Set, **
65 ** UART2_BaudRate_Value_Set and **
66 ** UART2_Fractional_Divider_Value_Set added **
67 ** V0.2.3: 2019-06-13, JO: Corrected ranges for UART1_BaudRate_Set and **
68 ** UART2_BaudRate_Set **
69 ** V0.2.4: 2020-03-02, BG: Updated revision history format **
70 ** V0.2.5: 2020-03-02, JO: EP-435: Removed ARMCC v6 compiler warnings **
71 ** V0.2.6: 2022-01-21, JO: EP-934: Updated copyright and branding **
72 *******************************************************************************/
73 
74 #ifndef UART_H
75 #define UART_H
76 
77 /*******************************************************************************
78 ** Includes **
79 *******************************************************************************/
80 #include "tle985x.h"
81 #include "sfr_access.h"
82 #include "uart_defines.h"
83 #include "types.h"
84 
85 /*******************************************************************************
86 ** Global Type Definitions **
87 *******************************************************************************/
91 typedef struct
92 {
94 } TUart;
95 
96 /*******************************************************************************
97 ** Global Function Declarations **
98 *******************************************************************************/
103 void UART1_Init(void);
104 
109 void UART2_Init(void);
110 
125 void UART1_BaudRate_Set(uint32 baudrate);
126 
141 void UART2_BaudRate_Set(uint32 baudrate);
142 
143 #if ((UART1_STD_EN == 1u) || (UART2_STD_EN == 1u))
151 sint32 stdout_putchar(sint32 Char);
152 
159 sint32 stdin_getchar(void);
160 void ttywrch(int ch);
161 #endif /* ((UART1_STD_EN == 1) || (UART2_STD_EN == 1)) */
162 
163 /*******************************************************************************
164 ** Inline Function Declarations **
165 *******************************************************************************/
188 
208 
231 
251 
271 INLINE void UART1_Receiver_En(void);
272 
293 INLINE void UART1_Receiver_Dis(void);
294 
319 INLINE void UART1_BaudRateGen_En(void);
320 
345 INLINE void UART1_BaudRateGen_Dis(void);
346 
366 INLINE void UART2_Receiver_En(void);
367 
388 INLINE void UART2_Receiver_Dis(void);
389 
414 INLINE void UART2_BaudRateGen_En(void);
415 
440 INLINE void UART2_BaudRateGen_Dis(void);
441 
462 INLINE void UART1_RX_Int_Clr(void);
463 
481 INLINE void UART1_TX_Int_Clr(void);
482 
503 INLINE void UART2_RX_Int_Clr(void);
504 
522 INLINE void UART2_TX_Int_Clr(void);
523 
542 INLINE void UART1_RX_Int_En(void);
543 
562 INLINE void UART1_RX_Int_Dis(void);
563 
582 INLINE void UART1_TX_Int_En(void);
583 
602 INLINE void UART1_TX_Int_Dis(void);
603 
622 INLINE void UART2_RX_Int_En(void);
623 
642 INLINE void UART2_RX_Int_Dis(void);
643 
662 INLINE void UART2_TX_Int_En(void);
663 
682 INLINE void UART2_TX_Int_Dis(void);
683 
703 INLINE void UART2_EXINT2_Int_En(void);
704 
724 INLINE void UART2_EXINT2_Int_Dis(void);
725 
745 
766 
789 
813 
836 INLINE bool UART1_isByteReceived(void);
837 
858 
878 
899 
922 
946 
969 INLINE bool UART2_isByteReceived(void);
970 
991 
1017 
1042 
1068 
1093 
1094 /*******************************************************************************
1095 ** Inline Function Definitions **
1096 *******************************************************************************/
1098 {
1100 }
1101 
1103 {
1105 }
1106 
1108 {
1110 }
1111 
1113 {
1115 }
1116 
1118 {
1120 }
1121 
1123 {
1124  bool bRes = false;
1125  if (UART1_RX_Sts() == (uint8)1)
1126  {
1127  bRes = true;
1128  }
1129  return (bRes);
1130 }
1131 
1133 {
1135 }
1136 
1138 {
1139  bool bRes = false;
1140  if (UART1_TX_Sts() == (uint8)1)
1141  {
1142  bRes = true;
1143  }
1144  return (bRes);
1145 }
1146 
1148 {
1150 }
1151 
1153 {
1154  bool bRes = false;
1155  if (UART2_RX_Sts() == (uint8)1)
1156  {
1157  bRes = true;
1158  }
1159  return (bRes);
1160 }
1161 
1163 {
1165 }
1166 
1168 {
1169  bool bRes = false;
1170  if (UART2_TX_Sts() == (uint8)1)
1171  {
1172  bRes = true;
1173  }
1174  return (bRes);
1175 }
1176 
1178 {
1180 }
1181 
1183 {
1184  UART1_RX_Int_Clr();
1185  return(UART1_Buffer_Get());
1186 }
1187 
1189 {
1191 }
1192 
1194 {
1195  UART1_TX_Int_Clr();
1196  UART1_Buffer_Set(c);
1197 }
1198 
1200 {
1202 }
1203 
1205 {
1206  UART2_RX_Int_Clr();
1207  return(UART2_Buffer_Get());
1208 }
1209 
1211 {
1213 }
1214 
1216 {
1217  UART2_TX_Int_Clr();
1218  UART2_Buffer_Set(c);
1219 }
1220 
1222 {
1224 }
1225 
1227 {
1229 }
1230 
1232 {
1234 }
1235 
1237 {
1239 }
1240 
1242 {
1244 }
1245 
1247 {
1249 }
1250 
1252 {
1254 }
1255 
1257 {
1259 }
1260 
1262 {
1264 }
1265 
1267 {
1269 }
1270 
1272 {
1274 }
1275 
1277 {
1279 }
1280 
1282 {
1284 }
1285 
1287 {
1289 }
1290 
1292 {
1294 }
1295 
1297 {
1299 }
1300 
1302 {
1304 }
1305 
1307 {
1309 }
1310 
1312 {
1314 }
1315 
1317 {
1319 }
1320 
1322 {
1324 }
1325 
1327 {
1329 }
1330 #endif
#define UART2
Definition: tle985x.h:6284
#define UART1
Definition: tle985x.h:6283
#define SCU
Definition: tle985x.h:6277
#define SCU_MODIEN2_RIEN1_Msk
Definition: tle985x.h:10142
#define UART2_SCON_RI_Msk
Definition: tle985x.h:10919
#define UART1_SCON_REN_Msk
Definition: tle985x.h:10878
#define SCU_BG2_BG2_BR_VALUE_Pos
Definition: tle985x.h:9847
#define UART1_SBUF_VAL_Msk
Definition: tle985x.h:10869
#define SCU_MODIEN2_TIEN2_Pos
Definition: tle985x.h:10133
#define SCU_MODIEN2_EXINT2_EN_Pos
Definition: tle985x.h:10137
#define SCU_MODIEN2_RIEN2_Pos
Definition: tle985x.h:10135
#define UART2_SBUF_VAL_Pos
Definition: tle985x.h:10901
#define UART2_SCON_TI_Pos
Definition: tle985x.h:10916
#define SCU_BGL2_BG2_FD_SEL_Msk
Definition: tle985x.h:9854
#define UART1_SCON_REN_Pos
Definition: tle985x.h:10877
#define SCU_BG1_BG1_BR_VALUE_Msk
Definition: tle985x.h:9843
#define UART2_SCONCLR_TICLR_Msk
Definition: tle985x.h:10924
#define UART2_SBUF_VAL_Msk
Definition: tle985x.h:10902
#define UART2_SCON_REN_Pos
Definition: tle985x.h:10910
#define UART2_SCON_RI_Pos
Definition: tle985x.h:10918
#define SCU_BCON1_BR1_R_Pos
Definition: tle985x.h:9832
#define SCU_MODIEN2_TIEN2_Msk
Definition: tle985x.h:10134
#define SCU_BGL1_BG1_FD_SEL_Msk
Definition: tle985x.h:9851
#define UART2_SCONCLR_TICLR_Pos
Definition: tle985x.h:10923
#define SCU_BGL1_BG1_FD_SEL_Pos
Definition: tle985x.h:9850
#define UART1_SCON_RI_Pos
Definition: tle985x.h:10885
#define SCU_BCON2_BR2_R_Pos
Definition: tle985x.h:9837
#define SCU_MODIEN2_RIEN1_Pos
Definition: tle985x.h:10141
#define SCU_MODIEN2_RIEN2_Msk
Definition: tle985x.h:10136
#define UART2_SCONCLR_RICLR_Msk
Definition: tle985x.h:10926
#define UART1_SBUF_VAL_Pos
Definition: tle985x.h:10868
#define UART1_SCONCLR_TICLR_Pos
Definition: tle985x.h:10890
#define UART1_SCON_TI_Msk
Definition: tle985x.h:10884
#define SCU_MODIEN2_TIEN1_Pos
Definition: tle985x.h:10139
#define UART1_SCON_RI_Msk
Definition: tle985x.h:10886
#define UART1_SCONCLR_RICLR_Pos
Definition: tle985x.h:10892
#define UART1_SCONCLR_TICLR_Msk
Definition: tle985x.h:10891
#define UART1_SCON_TI_Pos
Definition: tle985x.h:10883
#define SCU_BG2_BG2_BR_VALUE_Msk
Definition: tle985x.h:9848
#define SCU_BG1_BG1_BR_VALUE_Pos
Definition: tle985x.h:9842
#define SCU_BCON1_BR1_R_Msk
Definition: tle985x.h:9833
#define UART1_SCONCLR_RICLR_Msk
Definition: tle985x.h:10893
#define UART2_SCON_REN_Msk
Definition: tle985x.h:10911
#define SCU_MODIEN2_TIEN1_Msk
Definition: tle985x.h:10140
#define UART2_SCONCLR_RICLR_Pos
Definition: tle985x.h:10925
#define SCU_BGL2_BG2_FD_SEL_Pos
Definition: tle985x.h:9853
#define SCU_MODIEN2_EXINT2_EN_Msk
Definition: tle985x.h:10138
#define UART2_SCON_TI_Msk
Definition: tle985x.h:10917
#define SCU_BCON2_BR2_R_Msk
Definition: tle985x.h:9838
SFR low level access library.
INLINE uint8 u1_Field_Rd32(const volatile uint32 *reg, uint8 pos, uint32 msk)
This function reads a 1-bit field of a 32-bit register.
Definition: sfr_access.h:423
INLINE void Field_Wrt32(volatile uint32 *reg, uint8 pos, uint32 msk, uint32 val)
This function writes a bit field in a 32-bit register.
Definition: sfr_access.h:358
INLINE uint8 u8_Field_Rd32(const volatile uint32 *reg, uint8 pos, uint32 msk)
This function reads a 8-bit field of a 32-bit register.
Definition: sfr_access.h:438
INLINE void Field_Mod32(volatile uint32 *reg, uint8 pos, uint32 msk, uint32 val)
This function writes a bit field in a 32-bit register.
Definition: sfr_access.h:378
This struct lists parameter (clock) of UART1/UART2.
Definition: uart.h:92
uint32 clock
Definition: uart.h:93
CMSIS register HeaderFile.
General type declarations.
#define INLINE
Definition: types.h:145
uint8_t uint8
8 bit unsigned value
Definition: types.h:153
int32_t sint32
32 bit signed value
Definition: types.h:160
uint16_t uint16
16 bit unsigned value
Definition: types.h:154
uint32_t uint32
32 bit unsigned value
Definition: types.h:155
INLINE uint8 UART2_TX_Sts(void)
Reads the transmit interrupt flag for UART2.
Definition: uart.h:1162
void UART2_BaudRate_Set(uint32 baudrate)
Sets the baudrate for UART2.
INLINE void UART2_EXINT2_Int_Dis(void)
Disables EXINT2 interrupt for UART2.
Definition: uart.h:1306
INLINE void UART1_Send_Byte(uint8 c)
Clears the UART1 Transmit interrupt and sends a Byte via UART1.
Definition: uart.h:1193
INLINE void UART1_Receiver_Dis(void)
Disables Receiver of Serial Port (UART1).
Definition: uart.h:1102
INLINE void UART2_Buffer_Set(uint8 c)
Sends a Byte via UART2.
Definition: uart.h:1210
INLINE void UART2_TX_Int_Dis(void)
Disables transmit interrupt for UART2.
Definition: uart.h:1296
INLINE void UART1_Receiver_En(void)
Enables Receiver of Serial Port (UART1).
Definition: uart.h:1097
INLINE void UART2_RX_Int_Clr(void)
Clears receive interrupt flag for UART2.
Definition: uart.h:1251
INLINE void UART1_TX_Int_Dis(void)
Disables transmit interrupt for UART1.
Definition: uart.h:1276
INLINE uint8 UART1_RX_Sts(void)
Reads the receive interrupt flag for UART1.
Definition: uart.h:1117
INLINE void UART2_BaudRateGen_En(void)
Enables Baud-rate generator (UART2).
Definition: uart.h:1221
INLINE void UART1_TX_Int_Clr(void)
Clears transmit interrupt flag for UART1.
Definition: uart.h:1246
INLINE void UART1_RX_Int_En(void)
Enables receive interrupt for UART1.
Definition: uart.h:1261
INLINE void UART2_EXINT2_Int_En(void)
Enables EXINT2 interrupt for UART2.
Definition: uart.h:1301
INLINE bool UART1_isByteTransmitted(void)
Checks if UART1 is transmitting Byte or not.
Definition: uart.h:1137
INLINE uint8 UART1_Get_Byte(void)
Clears the UART1 receive interrupt and returns the UART1 buffer.
Definition: uart.h:1182
INLINE void UART1_Fractional_Divider_Value_Set(uint8 FD_val)
Writes the Fractional Divider register (UART1).
Definition: uart.h:1316
void UART1_Init(void)
Initializes the UART1 module.
INLINE uint8 UART1_Buffer_Get(void)
Reads UART1 Buffer.
Definition: uart.h:1177
INLINE bool UART1_isByteReceived(void)
Checks if UART1 is receiving Byte or not.
Definition: uart.h:1122
INLINE void UART2_Receiver_Dis(void)
Disables Receiver of Serial Port (UART2).
Definition: uart.h:1112
INLINE void UART1_BaudRateGen_Dis(void)
Disables Baud-rate generator (UART1).
Definition: uart.h:1236
INLINE void UART2_TX_Int_Clr(void)
Clears transmit interrupt flag for UART2.
Definition: uart.h:1256
INLINE void UART2_RX_Int_Dis(void)
Disables receive interrupt for UART2.
Definition: uart.h:1286
INLINE void UART2_Fractional_Divider_Value_Set(uint8 FD_val)
Writes the Fractional Divider register (UART2).
Definition: uart.h:1326
void UART1_BaudRate_Set(uint32 baudrate)
Sets the baudrate for UART1.
INLINE void UART2_BaudRateGen_Dis(void)
Disables Baud-rate generator (UART2).
Definition: uart.h:1226
INLINE void UART2_Send_Byte(uint8 c)
Clears the UART2 Transmit interrupt and sends a Byte via UART2.
Definition: uart.h:1215
INLINE uint8 UART1_TX_Sts(void)
Reads the transmit interrupt flag for UART1.
Definition: uart.h:1132
INLINE void UART2_RX_Int_En(void)
Enables receive interrupt for UART2.
Definition: uart.h:1281
INLINE uint8 UART2_Get_Byte(void)
Clears the UART2 receive interrupt and returns the UART2 buffer.
Definition: uart.h:1204
INLINE void UART2_TX_Int_En(void)
Enables transmit interrupt for UART2.
Definition: uart.h:1291
INLINE void UART1_BaudRateGen_En(void)
Enables Baud-rate generator (UART1).
Definition: uart.h:1231
INLINE uint8 UART2_RX_Sts(void)
Reads the receive interrupt flag for UART2.
Definition: uart.h:1147
INLINE void UART1_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART1).
Definition: uart.h:1311
INLINE void UART1_RX_Int_Clr(void)
Clears receive interrupt flag for UART1.
Definition: uart.h:1241
INLINE void UART2_Receiver_En(void)
Enables Receiver of Serial Port (UART2).
Definition: uart.h:1107
INLINE void UART1_RX_Int_Dis(void)
Disables receive interrupt for UART1.
Definition: uart.h:1266
INLINE void UART1_Buffer_Set(uint8 c)
Sends a Byte via UART1.
Definition: uart.h:1188
void UART2_Init(void)
Initializes the UART2 module.
INLINE void UART2_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART2).
Definition: uart.h:1321
INLINE uint8 UART2_Buffer_Get(void)
Reads UART2 Buffer.
Definition: uart.h:1199
INLINE void UART1_TX_Int_En(void)
Enables transmit interrupt for UART1.
Definition: uart.h:1271
INLINE bool UART2_isByteReceived(void)
Checks if UART2 is receiving Byte or not.
Definition: uart.h:1152
INLINE bool UART2_isByteTransmitted(void)
Checks if UART2 is transmitting Byte or not.
Definition: uart.h:1167