TLE986x Device Family SDK
uart.h
Go to the documentation of this file.
1 /*
2  ***********************************************************************************************************************
3  *
4  * Copyright (c) 2015, 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 ** JO Julia Ott **
44 ** BG Blandine Guillot **
45 *******************************************************************************/
46 
47 /*******************************************************************************
48 ** Revision Control History **
49 ********************************************************************************
50 ** V0.1.0: 2014-05-11, DM: Initial version **
51 ** V0.1.1: 2014-07-22, DM: BGL baudrate calculation fixed **
52 ** V0.1.2: 2015-02-10, DM: Individual header file added **
53 ** V0.1.3: 2015-07-15, DM: STDIN/STDOUT function added **
54 ** V0.1.4: 2017-02-15, DM: GetByte, isByteReceived and isByteTransmitted **
55 ** inline functions added **
56 ** Baudrate_Set function added **
57 ** V0.1.5: 2017-10-20, DM: MISRA 2012 compliance, the following PC-Lint **
58 ** rules are globally deactivated: **
59 ** - Info 793: ANSI/ISO limit of 6 'significant **
60 ** characters in an external identifier **
61 ** - Info 835: A zero has been given as right **
62 ** argument to operator **
63 ** - Info 845: The left argument to operator '&' **
64 ** is certain to be 0 **
65 ** V0.1.6: 2018-02-02, DM: BaudRate_Set function corrected **
66 ** V0.1.7: 2018-03-20, DM: Preprocessor checks modified to allow only one **
67 ** UART to be STDIN/STDOUT at a time **
68 ** V0.1.8: 2018-11-27, JO: Doxygen update, moved revision history from **
69 ** uart.c to uart.h **
70 ** Added ranges for UART1_BaudRate_Set and **
71 ** UART2_BaudRate_Set **
72 ** Adapted the implementation of stdout_putchar and **
73 ** stdin_getchar for UART1 and UART2 so that they **
74 ** follow the same procedure **
75 ** UART1_BaudRate_Value_Set() and **
76 ** UART2_BaudRate_Value_Set() functions added **
77 ** V0.1.9: 2019-05-28, JO: Corrected ranges for UART1_BaudRate_Set and **
78 ** UART2_BaudRate_Set **
79 ** V0.2.0: 2020-02-28, BG: Updated revision history format **
80 ** V0.2.1: 2020-10-12, JO: EP-506: remove ARMCC v6 Compiler warnings **
81 ** - added static to definition of uart1 and uart2 **
82 *******************************************************************************/
83 
84 #ifndef UART_H
85 #define UART_H
86 
87 /*******************************************************************************
88 ** Includes **
89 *******************************************************************************/
90 #include "tle986x.h"
91 #include "types.h"
92 #include "uart_defines.h"
93 #include "sfr_access.h"
94 
95 /*******************************************************************************
96 ** Global Type Definitions **
97 *******************************************************************************/
101 typedef struct
102 {
103  uint32 clock;
104 } TUart;
105 
106 /*******************************************************************************
107 ** Global Inline Function Definitions **
108 *******************************************************************************/
133 {
134  Field_Wrt8all(&SCU->BGH1.reg, (uint8)(br_val >> 8u));
135  Field_Wrt8all(&SCU->BGL1.reg, (uint8)(br_val & (uint16)0x00FF));
136 }
137 
161 INLINE void UART1_BaudRateGen_Dis(void)
162 {
164 }
165 
166 
190 INLINE void UART1_BaudRateGen_En(void)
191 {
193 }
194 
195 
220 {
221  Field_Wrt8all(&SCU->BGH2.reg, (uint8)(br_val >> 8u));
222  Field_Wrt8all(&SCU->BGL2.reg, (uint8)(br_val & (uint16)0x00FF));
223 }
224 
248 INLINE void UART2_BaudRateGen_Dis(void)
249 {
251 }
252 
276 INLINE void UART2_BaudRateGen_En(void)
277 {
279 }
280 
300 INLINE void UART1_Buffer_Set(uint8 data)
301 {
303 }
304 
324 INLINE void UART2_Buffer_Set(uint8 data)
325 {
327 }
328 
352 {
354 }
355 
379 {
381 }
382 
405 {
407 }
408 
431 {
433 }
434 
457 {
459 }
460 
480 {
482 }
483 
503 INLINE void UART1_Receiver_En(void)
504 {
506 }
507 
528 INLINE void UART1_Receiver_Dis(void)
529 {
531 }
532 
552 INLINE void UART2_Receiver_En(void)
553 {
555 }
556 
577 INLINE void UART2_Receiver_Dis(void)
578 {
580 }
581 
603 INLINE void UART1_RX_Int_Clr(void)
604 {
606 }
607 
625 INLINE void UART1_TX_Int_Clr(void)
626 {
628 }
629 
650 INLINE void UART2_RX_Int_Clr(void)
651 {
653 }
654 
672 INLINE void UART2_TX_Int_Clr(void)
673 {
675 }
676 
677 /* UART Interrupt Enable/Disable */
695 INLINE void UART1_RX_Int_En(void)
696 {
698 }
699 
718 INLINE void UART1_RX_Int_Dis(void)
719 {
721 }
722 
740 INLINE void UART1_TX_Int_En(void)
741 {
743 }
744 
763 INLINE void UART1_TX_Int_Dis(void)
764 {
766 }
767 
785 INLINE void UART2_RX_Int_En(void)
786 {
788 }
789 
808 INLINE void UART2_RX_Int_Dis(void)
809 {
811 }
812 
830 INLINE void UART2_TX_Int_En(void)
831 {
833 }
834 
853 INLINE void UART2_TX_Int_Dis(void)
854 {
856 }
857 
858 /*******************************************************************************
859 ** Global Function Declarations **
860 *******************************************************************************/
865 void UART1_Init(void);
866 
871 void UART2_Init(void);
872 
887 void UART1_BaudRate_Set(uint32 baudrate);
888 
903 void UART2_BaudRate_Set(uint32 baudrate);
904 
905 /*******************************************************************************
906 ** Global Inline Function Declarations **
907 *******************************************************************************/
908 #if ((UART1_STD_EN == 1) || (UART2_STD_EN == 1))
909 
916  sint32 stdout_putchar(sint32 Char);
917 
924  sint32 stdin_getchar(void);
925  void ttywrch(int ch);
926 #endif /* ((UART1_STD_EN == 1) || (UART2_STD_EN == 1)) */
927 
928 
929 /*******************************************************************************
930 ** Global Inline static Function Definitions **
931 *******************************************************************************/
951 {
953  UART1_Buffer_Set(c);
954 }
955 
978 {
980  return (UART1_Buffer_Get());
981 }
982 
1005 INLINE bool UART1_isByteReceived(void)
1006 {
1007  bool bRes = false;
1008 
1009  if (UART1_RX_Sts() == (uint8)1)
1010  {
1011  bRes = true;
1012  }
1013 
1014  return (bRes);
1015 }
1016 
1037 {
1038  bool bRes = false;
1039 
1040  if (UART1_TX_Sts() == (uint8)1)
1041  {
1042  bRes = true;
1043  }
1044 
1045  return (bRes);
1046 }
1047 
1067 {
1068  UART2_TX_Int_Clr();
1069  UART2_Buffer_Set(c);
1070 }
1071 
1094 {
1095  UART2_RX_Int_Clr();
1096  return (UART2_Buffer_Get());
1097 }
1098 
1121 INLINE bool UART2_isByteReceived(void)
1122 {
1123  bool bRes = false;
1124 
1125  if (UART2_RX_Sts() == (uint8)1)
1126  {
1127  bRes = true;
1128  }
1129 
1130  return (bRes);
1131 }
1132 
1153 {
1154  bool bRes = false;
1155 
1156  if (UART2_TX_Sts() == (uint8)1)
1157  {
1158  bRes = true;
1159  }
1160 
1161  return (bRes);
1162 }
1163 
1164 #endif
UART2_Init
void UART2_Init(void)
Initializes the UART2 module.
UART1_Get_Byte
INLINE uint8 UART1_Get_Byte(void)
Clears the UART1 receive interrupt and returns the UART1 buffer.
Definition: uart.h:969
SCU_MODIEN2_TIEN2_Pos
#define SCU_MODIEN2_TIEN2_Pos
Definition: tle986x.h:8989
UART2_Send_Byte
INLINE void UART2_Send_Byte(uint8 c)
clears the UART2 Transmit interrupt and sends a Byte via UART2.
Definition: uart.h:1058
UART2_RX_Int_Dis
INLINE void UART2_RX_Int_Dis(void)
disables receive interrupt of UART2.
Definition: uart.h:803
UART1_BaudRate_Value_Set
INLINE void UART1_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART1).
Definition: uart.h:127
UART2_SCON_RI_Msk
#define UART2_SCON_RI_Msk
Definition: tle986x.h:9897
UART1_RX_Sts
INLINE uint8 UART1_RX_Sts(void)
reads the receive interrupt flag of UART1.
Definition: uart.h:399
UART2_TX_Sts
INLINE uint8 UART2_TX_Sts(void)
reads the transmit interrupt flag of UART2.
Definition: uart.h:474
UART1_BaudRateGen_Dis
INLINE void UART1_BaudRateGen_Dis(void)
disables Baud-rate generator (UART1).
Definition: uart.h:156
UART1_SCON_RI_Pos
#define UART1_SCON_RI_Pos
Definition: tle986x.h:9865
types.h
General type declarations.
UART1_TX_Int_En
INLINE void UART1_TX_Int_En(void)
enables transmit interrupt of UART1.
Definition: uart.h:735
UART1_SCON_REN_Pos
#define UART1_SCON_REN_Pos
Definition: tle986x.h:9873
UART2_BaudRate_Set
void UART2_BaudRate_Set(uint32 baudrate)
Sets the baudrate of UART2.
SCU_MODIEN1_TIEN1_Pos
#define SCU_MODIEN1_TIEN1_Pos
Definition: tle986x.h:8978
SCU_MODIEN2_RIEN2_Msk
#define SCU_MODIEN2_RIEN2_Msk
Definition: tle986x.h:8992
UART2_TX_Int_En
INLINE void UART2_TX_Int_En(void)
enables transmit interrupt of UART2.
Definition: uart.h:825
UART1_SCON_RI_Msk
#define UART1_SCON_RI_Msk
Definition: tle986x.h:9866
UART2_BaudRateGen_En
INLINE void UART2_BaudRateGen_En(void)
enables Baud-rate generator (UART2).
Definition: uart.h:271
UART1_SCONCLR_RICLR_Msk
#define UART1_SCONCLR_RICLR_Msk
Definition: tle986x.h:9883
UART2_SCONCLR_RICLR_Msk
#define UART2_SCONCLR_RICLR_Msk
Definition: tle986x.h:9914
SCU_MODIEN1_RIEN1_Msk
#define SCU_MODIEN1_RIEN1_Msk
Definition: tle986x.h:8981
sfr_access.h
SFR low level access library.
UART2_TX_Int_Dis
INLINE void UART2_TX_Int_Dis(void)
disables transmit interrupt of UART2.
Definition: uart.h:848
UART1_Init
void UART1_Init(void)
Initializes the UART1 module.
Field_Wrt8all
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:326
INLINE
#define INLINE
Definition: types.h:134
Field_Mod8
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:346
UART2_SCON_RI_Pos
#define UART2_SCON_RI_Pos
Definition: tle986x.h:9896
u1_Field_Rd8
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:391
UART2_Receiver_En
INLINE void UART2_Receiver_En(void)
enables Receiver of Serial Port (UART2).
Definition: uart.h:547
TUart
This struct lists parameter (clock) of UART1/UART2.
Definition: uart.h:97
UART1_isByteReceived
INLINE bool UART1_isByteReceived(void)
checks if UART1 has received Byte or not.
Definition: uart.h:997
UART1_RX_Int_En
INLINE void UART1_RX_Int_En(void)
enables receive interrupt of UART1.
Definition: uart.h:690
UART2_isByteTransmitted
INLINE bool UART2_isByteTransmitted(void)
checks if UART2 has transmitted a Byte or not.
Definition: uart.h:1144
UART1_RX_Int_Dis
INLINE void UART1_RX_Int_Dis(void)
disables receive interrupt of UART1.
Definition: uart.h:713
uint16
unsigned short uint16
16 bit unsigned value
Definition: types.h:140
UART2_SBUF_VAL_Msk
#define UART2_SBUF_VAL_Msk
Definition: tle986x.h:9894
UART1_Buffer_Set
INLINE void UART1_Buffer_Set(uint8 data)
Sends a Byte via UART1.
Definition: uart.h:295
UART1_TX_Sts
INLINE uint8 UART1_TX_Sts(void)
reads the transmit interrupt flag of UART1.
Definition: uart.h:425
SCU_MODIEN1_TIEN1_Msk
#define SCU_MODIEN1_TIEN1_Msk
Definition: tle986x.h:8979
SCU_BCON2_R_Msk
#define SCU_BCON2_R_Msk
Definition: tle986x.h:8612
UART1_SCON_TI_Msk
#define UART1_SCON_TI_Msk
Definition: tle986x.h:9868
UART2_Buffer_Get
INLINE uint8 UART2_Buffer_Get(void)
Reads UART2 Buffer.
Definition: uart.h:373
SCU_MODIEN1_RIEN1_Pos
#define SCU_MODIEN1_RIEN1_Pos
Definition: tle986x.h:8980
uint8
unsigned char uint8
8 bit unsigned value
Definition: types.h:139
UART2_Get_Byte
INLINE uint8 UART2_Get_Byte(void)
Clears the UART2 receive interrupt and returns the UART2 buffer.
Definition: uart.h:1085
UART1_Receiver_En
INLINE void UART1_Receiver_En(void)
enables Receiver of Serial Port (UART1).
Definition: uart.h:498
UART2_SCON_TI_Msk
#define UART2_SCON_TI_Msk
Definition: tle986x.h:9899
u8_Field_Rd8
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:406
UART1_RX_Int_Clr
INLINE void UART1_RX_Int_Clr(void)
clears receive interrupt flag for UART1.
Definition: uart.h:598
UART2_RX_Sts
INLINE uint8 UART2_RX_Sts(void)
reads the receive interrupt flag of UART2.
Definition: uart.h:451
uint32
unsigned int uint32
32 bit unsigned value
Definition: types.h:141
UART1_SCON_TI_Pos
#define UART1_SCON_TI_Pos
Definition: tle986x.h:9867
UART1_isByteTransmitted
INLINE bool UART1_isByteTransmitted(void)
checks if UART1 has transmitted a Byte or not.
Definition: uart.h:1028
UART1_TX_Int_Clr
INLINE void UART1_TX_Int_Clr(void)
clears transmit interrupt flag of UART1.
Definition: uart.h:620
SCU_BCON2_R_Pos
#define SCU_BCON2_R_Pos
Definition: tle986x.h:8611
UART2_Receiver_Dis
INLINE void UART2_Receiver_Dis(void)
disables Receiver of Serial Port (UART2).
Definition: uart.h:572
SCU_BCON1_R_Pos
#define SCU_BCON1_R_Pos
Definition: tle986x.h:8606
UART1_SCON_REN_Msk
#define UART1_SCON_REN_Msk
Definition: tle986x.h:9874
UART2_SCON_REN_Msk
#define UART2_SCON_REN_Msk
Definition: tle986x.h:9905
UART2_SCONCLR_TICLR_Msk
#define UART2_SCONCLR_TICLR_Msk
Definition: tle986x.h:9916
UART2
#define UART2
Definition: tle986x.h:6012
UART1_SCONCLR_TICLR_Pos
#define UART1_SCONCLR_TICLR_Pos
Definition: tle986x.h:9884
UART1_Buffer_Get
INLINE uint8 UART1_Buffer_Get(void)
Reads UART1 Buffer.
Definition: uart.h:346
UART2_TX_Int_Clr
INLINE void UART2_TX_Int_Clr(void)
clears transmit interrupt flag of UART2.
Definition: uart.h:667
tle986x.h
CMSIS register HeaderFile.
UART1_SCONCLR_RICLR_Pos
#define UART1_SCONCLR_RICLR_Pos
Definition: tle986x.h:9882
SCU
#define SCU
Definition: tle986x.h:6004
UART1_Receiver_Dis
INLINE void UART1_Receiver_Dis(void)
disables Receiver of Serial Port (UART1).
Definition: uart.h:523
UART2_RX_Int_En
INLINE void UART2_RX_Int_En(void)
enables receive interrupt of UART2.
Definition: uart.h:780
UART2_BaudRate_Value_Set
INLINE void UART2_BaudRate_Value_Set(uint16 br_val)
Writes the baudrate timer register (UART2).
Definition: uart.h:214
UART2_SCON_TI_Pos
#define UART2_SCON_TI_Pos
Definition: tle986x.h:9898
UART2_SCONCLR_RICLR_Pos
#define UART2_SCONCLR_RICLR_Pos
Definition: tle986x.h:9913
UART1
#define UART1
Definition: tle986x.h:6011
SCU_BCON1_R_Msk
#define SCU_BCON1_R_Msk
Definition: tle986x.h:8607
UART1_TX_Int_Dis
INLINE void UART1_TX_Int_Dis(void)
disables transmit interrupt of UART1.
Definition: uart.h:758
UART2_SCONCLR_TICLR_Pos
#define UART2_SCONCLR_TICLR_Pos
Definition: tle986x.h:9915
UART1_BaudRateGen_En
INLINE void UART1_BaudRateGen_En(void)
enables Baud-rate generator (UART1).
Definition: uart.h:185
UART1_SBUF_VAL_Pos
#define UART1_SBUF_VAL_Pos
Definition: tle986x.h:9862
SCU_MODIEN2_RIEN2_Pos
#define SCU_MODIEN2_RIEN2_Pos
Definition: tle986x.h:8991
UART1_SBUF_VAL_Msk
#define UART1_SBUF_VAL_Msk
Definition: tle986x.h:9863
UART2_RX_Int_Clr
INLINE void UART2_RX_Int_Clr(void)
clears receive interrupt flag of UART2.
Definition: uart.h:645
UART2_SCON_REN_Pos
#define UART2_SCON_REN_Pos
Definition: tle986x.h:9904
sint32
signed int sint32
32 bit signed value
Definition: types.h:146
UART2_isByteReceived
INLINE bool UART2_isByteReceived(void)
checks if UART2 has received Byte or not.
Definition: uart.h:1113
UART2_BaudRateGen_Dis
INLINE void UART2_BaudRateGen_Dis(void)
disables Baud-rate generator (UART2).
Definition: uart.h:243
Field_Wrt8
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:331
SCU_MODIEN2_TIEN2_Msk
#define SCU_MODIEN2_TIEN2_Msk
Definition: tle986x.h:8990
UART2_Buffer_Set
INLINE void UART2_Buffer_Set(uint8 data)
Sends a Byte via UART2.
Definition: uart.h:319
UART2_SBUF_VAL_Pos
#define UART2_SBUF_VAL_Pos
Definition: tle986x.h:9893
UART1_BaudRate_Set
void UART1_BaudRate_Set(uint32 baudrate)
Sets the baudrate of UART1.
UART1_SCONCLR_TICLR_Msk
#define UART1_SCONCLR_TICLR_Msk
Definition: tle986x.h:9885
UART1_Send_Byte
INLINE void UART1_Send_Byte(uint8 c)
clears the UART1 Transmit interrupt and sends a Byte via UART1.
Definition: uart.h:942