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  * 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  **********************************************************************************************************************/
37 /*******************************************************************************
38 ** Author(s) Identity **
39 ********************************************************************************
40 ** Initials Name **
41 ** ---------------------------------------------------------------------------**
42 ** DM Daniel Mysliwitz **
43 ** BG Blandine Guillot **
44 ** JO Julia Ott **
45 ** VO Vanessa Ongaro **
46 *******************************************************************************/
47 
48 /*******************************************************************************
49 ** Revision Control History **
50 ********************************************************************************
51 ** V0.1.0: 2014-05-11, DM: Initial version **
52 ** V0.1.1: 2014-07-22, DM: BGL baudrate calculation fixed **
53 ** V0.1.2: 2015-02-10, DM: Individual header file added **
54 ** V0.1.3: 2015-07-15, DM: STDIN/STDOUT function added **
55 ** V0.1.4: 2017-02-15, DM: GetByte, isByteReceived and isByteTransmitted **
56 ** inline functions added **
57 ** Baudrate_Set function added **
58 ** V0.1.5: 2017-10-20, DM: MISRA 2012 compliance, the following PC-Lint **
59 ** rules are globally deactivated: **
60 ** - Info 793: ANSI/ISO limit of 6 'significant **
61 ** characters in an external identifier **
62 ** - Info 835: A zero has been given as right **
63 ** argument to operator **
64 ** - Info 845: The left argument to operator '&' **
65 ** is certain to be 0 **
66 ** V0.1.6: 2018-02-02, DM: BaudRate_Set function corrected **
67 ** V0.1.7: 2018-03-20, DM: Preprocessor checks modified to allow only one **
68 ** UART to be STDIN/STDOUT at a time **
69 ** V0.1.8: 2018-11-27, JO: Doxygen update **
70 ** Moved revision history from uart.c to uart.h **
71 ** Added ranges for UART1_BaudRate_Set and **
72 ** UART2_BaudRate_Set **
73 ** Adapted the implementation of stdout_putchar **
74 ** and stdin_getchar for UART1 and UART2 so that **
75 ** they follow the same procedure **
76 ** UART1_BaudRate_Value_Set(), **
77 ** UART2_BaudRate_Value_Set() functions added **
78 ** V0.1.9: 2019-09-11, JO: Corrected ranges for UART1_BaudRate_Set and **
79 ** UART2_BaudRate_Set **
80 ** V0.2.0: 2020-04-15, BG: Updated revision history format **
81 ** V0.2.1: 2020-07-13, JO: EP-431: remove ARMCC v6 Compiler warnings **
82 ** - added static to definition of uart1 and uart2 **
83 ** V0.2.2: 2020-07-21, BG: EP-439: Formatted .h/.c files **
84 ** V0.2.3: 2022-02-28, JO: EP-936: Updated copyright and branding **
85 ** V0.2.4: 2022-10-18, VO: EP-1252: Updated sruct definition **
86 *******************************************************************************/
87 
88 #ifndef UART_H
89 #define UART_H
90 
91 /*******************************************************************************
92 ** Includes **
93 *******************************************************************************/
94 #include "tle987x.h"
95 #include "types.h"
96 #include "uart_defines.h"
97 #include "sfr_access.h"
98 
99 /*******************************************************************************
100 ** Global Type Definitions **
101 *******************************************************************************/
105 typedef struct Uart
106 {
109 
110 /*******************************************************************************
111 ** Global Inline Function Definitions **
112 *******************************************************************************/
137 {
138  Field_Wrt8all(&SCU->BGH1.reg, (uint8)(br_val >> 8u));
139  Field_Wrt8all(&SCU->BGL1.reg, (uint8)(br_val & (uint16)0x00FF));
140 }
141 
166 {
168 }
169 
170 
195 {
197 }
198 
199 
224 {
225  Field_Wrt8all(&SCU->BGH2.reg, (uint8)(br_val >> 8u));
226  Field_Wrt8all(&SCU->BGL2.reg, (uint8)(br_val & (uint16)0x00FF));
227 }
228 
253 {
255 }
256 
281 {
283 }
284 
305 {
307 }
308 
329 {
331 }
332 
356 {
358 }
359 
383 {
385 }
386 
409 {
411 }
412 
435 {
437 }
438 
461 {
463 }
464 
484 {
486 }
487 
508 {
510 }
511 
533 {
535 }
536 
557 {
559 }
560 
582 {
584 }
585 
608 {
610 }
611 
630 {
632 }
633 
655 {
657 }
658 
677 {
679 }
680 
681 /* UART Interrupt Enable/Disable */
700 {
702 }
703 
723 {
725 }
726 
745 {
747 }
748 
768 {
770 }
771 
790 {
792 }
793 
813 {
815 }
816 
835 {
837 }
838 
858 {
860 }
861 
862 /*******************************************************************************
863 ** Global Function Declarations **
864 *******************************************************************************/
869 void UART1_Init(void);
870 
875 void UART2_Init(void);
876 
891 void UART1_BaudRate_Set(uint32 baudrate);
892 
907 void UART2_BaudRate_Set(uint32 baudrate);
908 
909 /*******************************************************************************
910 ** Global Inline Function Declarations **
911 *******************************************************************************/
912 #if ((UART1_STD_EN == 1) || (UART2_STD_EN == 1))
920  sint32 stdout_putchar(sint32 Char);
921 
928  sint32 stdin_getchar(void);
929  void ttywrch(int ch);
930 #endif /* ((UART1_STD_EN == 1) || (UART2_STD_EN == 1)) */
931 
932 
933 /*******************************************************************************
934 ** Global Inline Static Function Definitions **
935 *******************************************************************************/
955 {
957  UART1_Buffer_Set(c);
958 }
959 
982 {
984  return (UART1_Buffer_Get());
985 }
986 
1010 {
1011  bool bRes = false;
1012 
1013  if (UART1_RX_Sts() == (uint8)1)
1014  {
1015  bRes = true;
1016  }
1017 
1018  return (bRes);
1019 }
1020 
1041 {
1042  bool bRes = false;
1043 
1044  if (UART1_TX_Sts() == (uint8)1)
1045  {
1046  bRes = true;
1047  }
1048 
1049  return (bRes);
1050 }
1051 
1071 {
1072  UART2_TX_Int_Clr();
1073  UART2_Buffer_Set(c);
1074 }
1075 
1098 {
1099  UART2_RX_Int_Clr();
1100  return (UART2_Buffer_Get());
1101 }
1102 
1126 {
1127  bool bRes = false;
1128 
1129  if (UART2_RX_Sts() == (uint8)1)
1130  {
1131  bRes = true;
1132  }
1133 
1134  return (bRes);
1135 }
1136 
1157 {
1158  bool bRes = false;
1159 
1160  if (UART2_TX_Sts() == (uint8)1)
1161  {
1162  bRes = true;
1163  }
1164 
1165  return (bRes);
1166 }
1167 
1168 #endif
#define UART2
Definition: tle987x.h:6105
#define UART1
Definition: tle987x.h:6104
#define SCU
Definition: tle987x.h:6097
#define UART2_SCON_RI_Msk
Definition: tle987x.h:10136
#define UART1_SCON_REN_Msk
Definition: tle987x.h:10113
#define SCU_MODIEN1_TIEN1_Pos
Definition: tle987x.h:9133
#define UART1_SBUF_VAL_Msk
Definition: tle987x.h:10102
#define SCU_MODIEN2_TIEN2_Pos
Definition: tle987x.h:9144
#define SCU_MODIEN2_RIEN2_Pos
Definition: tle987x.h:9146
#define UART2_SBUF_VAL_Pos
Definition: tle987x.h:10132
#define UART2_SCON_TI_Pos
Definition: tle987x.h:10137
#define SCU_MODIEN1_TIEN1_Msk
Definition: tle987x.h:9134
#define UART1_SCON_REN_Pos
Definition: tle987x.h:10112
#define UART2_SCONCLR_TICLR_Msk
Definition: tle987x.h:10155
#define UART2_SBUF_VAL_Msk
Definition: tle987x.h:10133
#define UART2_SCON_REN_Pos
Definition: tle987x.h:10143
#define UART2_SCON_RI_Pos
Definition: tle987x.h:10135
#define SCU_MODIEN2_TIEN2_Msk
Definition: tle987x.h:9145
#define UART2_SCONCLR_TICLR_Pos
Definition: tle987x.h:10154
#define SCU_BCON2_R_Msk
Definition: tle987x.h:8767
#define UART1_SCON_RI_Pos
Definition: tle987x.h:10104
#define SCU_MODIEN2_RIEN2_Msk
Definition: tle987x.h:9147
#define SCU_BCON1_R_Msk
Definition: tle987x.h:8762
#define UART2_SCONCLR_RICLR_Msk
Definition: tle987x.h:10153
#define UART1_SBUF_VAL_Pos
Definition: tle987x.h:10101
#define SCU_MODIEN1_RIEN1_Pos
Definition: tle987x.h:9135
#define UART1_SCONCLR_TICLR_Pos
Definition: tle987x.h:10123
#define UART1_SCON_TI_Msk
Definition: tle987x.h:10107
#define UART1_SCON_RI_Msk
Definition: tle987x.h:10105
#define SCU_MODIEN1_RIEN1_Msk
Definition: tle987x.h:9136
#define UART1_SCONCLR_RICLR_Pos
Definition: tle987x.h:10121
#define UART1_SCONCLR_TICLR_Msk
Definition: tle987x.h:10124
#define UART1_SCON_TI_Pos
Definition: tle987x.h:10106
#define UART1_SCONCLR_RICLR_Msk
Definition: tle987x.h:10122
#define SCU_BCON2_R_Pos
Definition: tle987x.h:8766
#define UART2_SCON_REN_Msk
Definition: tle987x.h:10144
#define SCU_BCON1_R_Pos
Definition: tle987x.h:8761
#define UART2_SCONCLR_RICLR_Pos
Definition: tle987x.h:10152
#define UART2_SCON_TI_Msk
Definition: tle987x.h:10138
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:337
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:412
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:332
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:397
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:352
Definition: uart.h:106
uint32 clock
Definition: uart.h:107
CMSIS register HeaderFile.
General type declarations.
#define INLINE
Definition: types.h:148
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 of UART2.
Definition: uart.h:483
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:954
INLINE void UART1_Receiver_Dis(void)
disables Receiver of Serial Port (UART1).
Definition: uart.h:532
INLINE void UART2_TX_Int_Dis(void)
disables transmit interrupt of UART2.
Definition: uart.h:857
INLINE void UART1_Receiver_En(void)
enables Receiver of Serial Port (UART1).
Definition: uart.h:507
INLINE void UART2_RX_Int_Clr(void)
clears receive interrupt flag of UART2.
Definition: uart.h:654
INLINE void UART1_TX_Int_Dis(void)
disables transmit interrupt of UART1.
Definition: uart.h:767
INLINE uint8 UART1_RX_Sts(void)
reads the receive interrupt flag of UART1.
Definition: uart.h:408
INLINE void UART2_BaudRateGen_En(void)
enables Baud-rate generator (UART2).
Definition: uart.h:280
INLINE void UART1_TX_Int_Clr(void)
clears transmit interrupt flag of UART1.
Definition: uart.h:629
INLINE void UART1_RX_Int_En(void)
enables receive interrupt of UART1.
Definition: uart.h:699
struct Uart TUart
INLINE bool UART1_isByteTransmitted(void)
checks if UART1 has transmitted a Byte or not.
Definition: uart.h:1040
INLINE uint8 UART1_Get_Byte(void)
Clears the UART1 receive interrupt and returns the UART1 buffer.
Definition: uart.h:981
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:355
INLINE bool UART1_isByteReceived(void)
checks if UART1 has received Byte or not.
Definition: uart.h:1009
INLINE void UART2_Receiver_Dis(void)
disables Receiver of Serial Port (UART2).
Definition: uart.h:581
INLINE void UART1_BaudRateGen_Dis(void)
disables Baud-rate generator (UART1).
Definition: uart.h:165
INLINE void UART2_TX_Int_Clr(void)
clears transmit interrupt flag of UART2.
Definition: uart.h:676
INLINE void UART2_RX_Int_Dis(void)
disables receive interrupt of UART2.
Definition: uart.h:812
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:252
INLINE void UART1_Buffer_Set(uint8 data)
Sends a Byte via UART1.
Definition: uart.h:304
INLINE void UART2_Send_Byte(uint8 c)
clears the UART2 Transmit interrupt and sends a Byte via UART2.
Definition: uart.h:1070
INLINE uint8 UART1_TX_Sts(void)
reads the transmit interrupt flag of UART1.
Definition: uart.h:434
INLINE void UART2_RX_Int_En(void)
enables receive interrupt of UART2.
Definition: uart.h:789
INLINE uint8 UART2_Get_Byte(void)
Clears the UART2 receive interrupt and returns the UART2 buffer.
Definition: uart.h:1097
INLINE void UART2_TX_Int_En(void)
enables transmit interrupt of UART2.
Definition: uart.h:834
INLINE void UART1_BaudRateGen_En(void)
enables Baud-rate generator (UART1).
Definition: uart.h:194
INLINE uint8 UART2_RX_Sts(void)
reads the receive interrupt flag of UART2.
Definition: uart.h:460
INLINE void UART1_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART1).
Definition: uart.h:136
INLINE void UART1_RX_Int_Clr(void)
clears receive interrupt flag for UART1.
Definition: uart.h:607
INLINE void UART2_Receiver_En(void)
enables Receiver of Serial Port (UART2).
Definition: uart.h:556
INLINE void UART1_RX_Int_Dis(void)
disables receive interrupt of UART1.
Definition: uart.h:722
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:223
INLINE void UART2_Buffer_Set(uint8 data)
Sends a Byte via UART2.
Definition: uart.h:328
INLINE uint8 UART2_Buffer_Get(void)
Reads UART2 Buffer.
Definition: uart.h:382
INLINE void UART1_TX_Int_En(void)
enables transmit interrupt of UART1.
Definition: uart.h:744
INLINE bool UART2_isByteReceived(void)
checks if UART2 has received Byte or not.
Definition: uart.h:1125
INLINE bool UART2_isByteTransmitted(void)
checks if UART2 has transmitted a Byte or not.
Definition: uart.h:1156