1 /*********************************************************************************************************//**
2  * @file    ht32f5xxxx_sci.h
3  * @version $Rev:: 6386         $
4  * @date    $Date:: 2022-10-27 #$
5  * @brief   The header file of the SCI library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32F5XXXX_SCI_H
30 #define __HT32F5XXXX_SCI_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
40   * @{
41   */
42 
43 /** @addtogroup SCI
44   * @{
45   */
46 
47 
48 /* Exported types ------------------------------------------------------------------------------------------*/
49 /** @defgroup SCI_Exported_Types SCI exported types
50   * @{
51   */
52 typedef struct
53 {
54   u32 SCI_Mode;
55   u32 SCI_Retry;
56   u32 SCI_Convention;
57   u32 SCI_CardPolarity;
58   u32 SCI_ClockPrescale;
59 } SCI_InitTypeDef;
60 /**
61   * @}
62   */
63 
64 /* Exported constants --------------------------------------------------------------------------------------*/
65 /** @defgroup SCI_Exported_Constants SCI exported constants
66   * @{
67   */
68 #define SCI_MODE_MANUAL                             ((u32)0x00000000)
69 #define SCI_MODE_SCI                                ((u32)0x00000008)
70 
71 #define IS_SCI_MODE(MODE)                           ((MODE == SCI_MODE_MANUAL) || \
72                                                      (MODE == SCI_MODE_SCI))
73 
74 
75 #define SCI_RETRY_NO                                ((u32)0x00000000)
76 #define SCI_RETRY_4                                 ((u32)0x00000012)
77 #define SCI_RETRY_5                                 ((u32)0x00000002)
78 
79 #define IS_SCI_RETRY(RETRY)                         ((RETRY == SCI_RETRY_NO) || \
80                                                      (RETRY == SCI_RETRY_4) || \
81                                                      (RETRY == SCI_RETRY_5))
82 
83 
84 #define SCI_CONVENTION_DIRECT                       ((u32)0x00000000)
85 #define SCI_CONVENTION_INVERSE                      ((u32)0x00000001)
86 
87 #define IS_SCI_CONVENTION(CONVENTION)               ((CONVENTION == SCI_CONVENTION_DIRECT) || \
88                                                      (CONVENTION == SCI_CONVENTION_INVERSE))
89 
90 
91 #define SCI_CARDPOLARITY_LOW                        ((u32)0x00000000)
92 #define SCI_CARDPOLARITY_HIGH                       ((u32)0x00000040)
93 
94 #define IS_SCI_CARD_POLARITY(POLARITY)              ((POLARITY == SCI_CARDPOLARITY_LOW) || \
95                                                      (POLARITY == SCI_CARDPOLARITY_HIGH))
96 
97 
98 #define SCI_CLKPRESCALER_1                          ((u32)0x00000000)
99 #define SCI_CLKPRESCALER_2                          ((u32)0x00000001)
100 #define SCI_CLKPRESCALER_4                          ((u32)0x00000002)
101 #define SCI_CLKPRESCALER_6                          ((u32)0x00000003)
102 #define SCI_CLKPRESCALER_8                          ((u32)0x00000004)
103 #define SCI_CLKPRESCALER_10                         ((u32)0x00000005)
104 #define SCI_CLKPRESCALER_12                         ((u32)0x00000006)
105 #define SCI_CLKPRESCALER_14                         ((u32)0x00000007)
106 #define SCI_CLKPRESCALER_16                         ((u32)0x00000008)
107 #define SCI_CLKPRESCALER_18                         ((u32)0x00000009)
108 #define SCI_CLKPRESCALER_20                         ((u32)0x0000000A)
109 #define SCI_CLKPRESCALER_22                         ((u32)0x0000000B)
110 #define SCI_CLKPRESCALER_24                         ((u32)0x0000000C)
111 #define SCI_CLKPRESCALER_26                         ((u32)0x0000000D)
112 #define SCI_CLKPRESCALER_28                         ((u32)0x0000000E)
113 #define SCI_CLKPRESCALER_30                         ((u32)0x0000000F)
114 #define SCI_CLKPRESCALER_32                         ((u32)0x00000010)
115 #define SCI_CLKPRESCALER_34                         ((u32)0x00000011)
116 #define SCI_CLKPRESCALER_36                         ((u32)0x00000012)
117 #define SCI_CLKPRESCALER_38                         ((u32)0x00000013)
118 #define SCI_CLKPRESCALER_40                         ((u32)0x00000014)
119 #define SCI_CLKPRESCALER_42                         ((u32)0x00000015)
120 #define SCI_CLKPRESCALER_44                         ((u32)0x00000016)
121 #define SCI_CLKPRESCALER_46                         ((u32)0x00000017)
122 #define SCI_CLKPRESCALER_48                         ((u32)0x00000018)
123 #define SCI_CLKPRESCALER_50                         ((u32)0x00000019)
124 #define SCI_CLKPRESCALER_52                         ((u32)0x0000001A)
125 #define SCI_CLKPRESCALER_54                         ((u32)0x0000001B)
126 #define SCI_CLKPRESCALER_56                         ((u32)0x0000001C)
127 #define SCI_CLKPRESCALER_58                         ((u32)0x0000001D)
128 #define SCI_CLKPRESCALER_60                         ((u32)0x0000001E)
129 #define SCI_CLKPRESCALER_62                         ((u32)0x0000001F)
130 #define SCI_CLKPRESCALER_64                         ((u32)0x00000020)
131 #define SCI_CLKPRESCALER_66                         ((u32)0x00000021)
132 #define SCI_CLKPRESCALER_68                         ((u32)0x00000022)
133 #define SCI_CLKPRESCALER_70                         ((u32)0x00000023)
134 #define SCI_CLKPRESCALER_72                         ((u32)0x00000024)
135 #define SCI_CLKPRESCALER_74                         ((u32)0x00000025)
136 #define SCI_CLKPRESCALER_76                         ((u32)0x00000026)
137 #define SCI_CLKPRESCALER_78                         ((u32)0x00000027)
138 #define SCI_CLKPRESCALER_80                         ((u32)0x00000028)
139 #define SCI_CLKPRESCALER_82                         ((u32)0x00000029)
140 #define SCI_CLKPRESCALER_84                         ((u32)0x0000002A)
141 #define SCI_CLKPRESCALER_86                         ((u32)0x0000002B)
142 #define SCI_CLKPRESCALER_88                         ((u32)0x0000002C)
143 #define SCI_CLKPRESCALER_90                         ((u32)0x0000002D)
144 #define SCI_CLKPRESCALER_92                         ((u32)0x0000002E)
145 #define SCI_CLKPRESCALER_94                         ((u32)0x0000002F)
146 #define SCI_CLKPRESCALER_96                         ((u32)0x00000030)
147 #define SCI_CLKPRESCALER_98                         ((u32)0x00000031)
148 #define SCI_CLKPRESCALER_100                        ((u32)0x00000032)
149 #define SCI_CLKPRESCALER_102                        ((u32)0x00000033)
150 #define SCI_CLKPRESCALER_104                        ((u32)0x00000034)
151 #define SCI_CLKPRESCALER_106                        ((u32)0x00000035)
152 #define SCI_CLKPRESCALER_108                        ((u32)0x00000036)
153 #define SCI_CLKPRESCALER_110                        ((u32)0x00000037)
154 #define SCI_CLKPRESCALER_112                        ((u32)0x00000038)
155 #define SCI_CLKPRESCALER_114                        ((u32)0x00000039)
156 #define SCI_CLKPRESCALER_116                        ((u32)0x0000003A)
157 #define SCI_CLKPRESCALER_118                        ((u32)0x0000003B)
158 #define SCI_CLKPRESCALER_120                        ((u32)0x0000003C)
159 #define SCI_CLKPRESCALER_122                        ((u32)0x0000003D)
160 #define SCI_CLKPRESCALER_124                        ((u32)0x0000003E)
161 #define SCI_CLKPRESCALER_126                        ((u32)0x0000003F)
162 
163 #define IS_SCI_CLOCK_PRESCALER(PRESCALER)           (PRESCALER <= 0x3F)
164 
165 
166 #define SCI_COMPENSATION_ENABLE                     ((u32)0x00008000)
167 #define SCI_COMPENSATION_DISABLE                    ((u32)0x00000000)
168 
169 #define IS_SCI_ETU_COMPENSATION(COMPENSATION)       ((COMPENSATION == SCI_COMPENSATION_ENABLE) || \
170                                                      (COMPENSATION == SCI_COMPENSATION_DISABLE))
171 
172 
173 #define SCI_CLK_HARDWARE                            ((u32)0x00000080)
174 #define SCI_CLK_SOFTWARE                            ((u32)0xFFFFFF7F)
175 
176 #define IS_SCI_CLK_MODE(MODE)                       ((MODE == SCI_CLK_HARDWARE) || \
177                                                      (MODE == SCI_CLK_SOFTWARE))
178 
179 
180 #define SCI_CLK_HIGH                                ((u32)0x00000004)
181 #define SCI_CLK_LOW                                 ((u32)0xFFFFFFFB)
182 
183 #define IS_SCI_CLK(CLK)                             ((CLK == SCI_CLK_HIGH) || \
184                                                      (CLK == SCI_CLK_LOW))
185 
186 
187 #define SCI_DIO_HIGH                                ((u32)0x00000008)
188 #define SCI_DIO_LOW                                 ((u32)0xFFFFFFF7)
189 
190 #define IS_SCI_DIO(DIO)                             ((DIO == SCI_DIO_HIGH) || \
191                                                      (DIO == SCI_DIO_LOW))
192 
193 
194 #define SCI_INT_PAR                                ((u32)0x00000001)
195 #define SCI_INT_RXC                                ((u32)0x00000002)
196 #define SCI_INT_TXC                                ((u32)0x00000004)
197 #define SCI_INT_WT                                 ((u32)0x00000008)
198 #define SCI_INT_CARD                               ((u32)0x00000040)
199 #define SCI_INT_TXBE                               ((u32)0x00000080)
200 #define SCI_INT_ALL                                ((u32)0x000000CF)
201 
202 #define IS_SCI_INT(INT)                            (((INT & 0xFFFFFF30) == 0x0) && (INT != 0))
203 
204 
205 
206 #define SCI_FLAG_PAR                                ((u32)0x00000001)
207 #define SCI_FLAG_RXC                                ((u32)0x00000002)
208 #define SCI_FLAG_TXC                                ((u32)0x00000004)
209 #define SCI_FLAG_WT                                 ((u32)0x00000008)
210 #define SCI_FLAG_CARD                               ((u32)0x00000040)
211 #define SCI_FLAG_TXBE                               ((u32)0x00000080)
212 
213 #define IS_SCI_FLAG(FLAG)                           ((FLAG == SCI_FLAG_PAR) || \
214                                                      (FLAG == SCI_FLAG_RXC) || \
215                                                      (FLAG == SCI_FLAG_TXC) || \
216                                                      (FLAG == SCI_FLAG_WT) || \
217                                                      (FLAG == SCI_FLAG_CARD) || \
218                                                      (FLAG == SCI_FLAG_TXBE))
219 
220 #define IS_SCI_CLEAR_FLAG(FLAG)                     ((FLAG == SCI_FLAG_PAR) || \
221                                                      (FLAG == SCI_FLAG_TXC) || \
222                                                      (FLAG == SCI_FLAG_WT))
223 
224 
225 #define SCI_PDMAREQ_TX                              ((u32)0x00000100)
226 #define SCI_PDMAREQ_RX                              ((u32)0x00000200)
227 
228 #define IS_SCI_PDMA_REQ(REQ)                        (((REQ & 0xFFFFFCFF) == 0x0) && (REQ != 0))
229 
230 
231 #define IS_SCI_ETU(ETU)                             ((ETU >= 12) & (ETU <= 2047))
232 
233 #define IS_SCI_GUARDTIME(GUARDTIME)                 ((GUARDTIME >= 11) & (GUARDTIME <= 511))
234 
235 #define IS_SCI_WAITING_TIME(TIME)                   ((TIME >= 372) & (TIME <= 16777215))
236 /**
237   * @}
238   */
239 
240 /* Exported functions --------------------------------------------------------------------------------------*/
241 /** @defgroup SCI_Exported_Functions SCI exported functions
242   * @{
243   */
244 void SCI_DeInit(HT_SCI_TypeDef* SCIx);
245 void SCI_Init(HT_SCI_TypeDef* SCIx, SCI_InitTypeDef* SCI_InitStruct);
246 void SCI_StructInit(SCI_InitTypeDef* SCI_InitStruct);
247 void SCI_Cmd(HT_SCI_TypeDef* SCIx, ControlStatus NewState);
248 void SCI_ETUConfig(HT_SCI_TypeDef* SCIx, u32 SCI_ETU, u32 SCI_Compensation);
249 void SCI_SetGuardTimeValue(HT_SCI_TypeDef* SCIx, u16 SCI_GuardTime);
250 void SCI_SetWaitingTimeValue(HT_SCI_TypeDef* SCIx, u32 SCI_WaitingTime);
251 void SCI_WaitingTimeCounterCmd(HT_SCI_TypeDef* SCIx, ControlStatus NewState);
252 void SCI_SendData(HT_SCI_TypeDef* SCIx, u8 SCI_Data);
253 u8 SCI_ReceiveData(HT_SCI_TypeDef* SCIx);
254 void SCI_ClockModeConfig(HT_SCI_TypeDef* SCIx, u32 SCI_CLKMode);
255 void SCI_SoftwareClockCmd(HT_SCI_TypeDef* SCIx, u32 SCI_CLK);
256 void SCI_OutputDIO(HT_SCI_TypeDef* SCIx, u32 SCI_DIO);
257 void SCI_IntConfig(HT_SCI_TypeDef* SCIx, u32 SCI_Int, ControlStatus NewState);
258 FlagStatus SCI_GetFlagStatus(HT_SCI_TypeDef* SCIx, u32 SCI_Flag);
259 void SCI_ClearFlag(HT_SCI_TypeDef* SCIx, u32 SCI_Flag);
260 #if (LIBCFG_PDMA)
261 void SCI_PDMACmd(HT_SCI_TypeDef* SCIx, u32 SCI_PDMAREQ, ControlStatus NewState);
262 #endif
263 /**
264   * @}
265   */
266 
267 
268 /**
269   * @}
270   */
271 
272 /**
273   * @}
274   */
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif
281