1 /*
2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /****************************************************************************
17 * @file wm_7816.h
18 * @author
19 * @version
20 * @date
21 * @brief
22 * @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
23 *****************************************************************************/
24 #ifndef WM_7816_H_
25 #define WM_7816_H_
26
27 #include <string.h>
28 #include <stdbool.h>
29 #include "wm_regs.h"
30 #include "wm_type_def.h"
31 #include "wm_io.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define WM_SC_DEFAULT_FD (372)
38
39 typedef struct sc_io_map_ {
40 enum tls_io_name clk_pin_num;
41 uint32_t clk_opt;
42 enum tls_io_name io_pin_num;
43 uint32_t io_opt;
44 uint8_t initialed;
45 } sc_io_map;
46
47 extern sc_io_map sc_io;
48
49 /**
50 * @defgroup Driver_APIs Driver APIs
51 * @brief Driver APIs
52 */
53
54 /**
55 * @addtogroup Driver_APIs
56 * @{
57 */
58
59 /**
60 * @defgroup 7816_Driver_APIs 7816 Driver APIs
61 * @brief 7816 driver APIs
62 */
63
64 /**
65 * @addtogroup 7816_Driver_APIs
66 * @{
67 */
68
69 /**
70 * @brief
71 * This function is used to config the pin in gpio or 7816 mode for the 7816 power on timing
72 *
73 * @param[in] mode : 1--gpio mode ; 0--7816 mode
74 *
75 * @retval
76 */
77 void wm_sc_io_clk_config(uint8_t mode);
78
79 /**
80 * @brief
81 * close af to use as gpio
82 * @retval
83 */
84 void wm_sc_powerInit(void);
85
86 /**
87 * @brief
88 * power on the 7816 device if power is controled by GPIO
89 * @retval
90 */
91 void wm_sc_poweron(void);
92
93 /**
94 * @brief
95 * power off the 7816 device if power is controled by GPIO
96 * @retval
97 */
98 void wm_sc_poweroff(void);
99
100 /**
101 * @brief
102 * driver the reset gpio in low level
103 * @retval
104 */
105 void wm_sc_rst_low(void);
106
107 /**
108 * @brief
109 * driver the reset gpio in high level
110 * @retval
111 */
112 void wm_sc_rst_high(void);
113
114 /**
115 * @brief
116 * hotrest the 7816 device obey the 7816-3 timing
117 * @retval
118 */
119 void wm_sc_hotreset(void);
120
121 /**
122 * @brief
123 * colreset the 7816 device obey the 7816-3 timing
124 * @retval
125 */
126 void wm_sc_colreset(void);
127
128 /**
129 * @brief
130 * deactive the 7816 device obey the 7816-3 timing
131 * @retval
132 */
133 void wm_sc_deactive(void);
134
135 /**
136 * @brief
137 * This function is used to config the block guard time param in 7816 mode
138 * @param[in] bgt : the value of blcok guard time will be set
139 * @retval
140 */
141 void wm_sc_set_bgt(uint8_t bgt);
142
143 /**
144 * @brief
145 * This function is used to config the tx retry count when detect err signal
146 * @param[in] count : the value of retry time will be set 7 for max
147 * @retval
148 */
149 void wm_sc_tx_retry_times(uint8_t count);
150
151 /**
152 * @brief
153 * This function is used to config the rx retry count when detect parity error
154 * @param[in] count : the value of retry time will be set 7 for max
155 * @retval
156 */
157 void wm_sc_rx_retry_times(uint8_t count);
158
159 /**
160 * @brief
161 * This function is used to config the etu param
162 * @param[in] etu : the value of etu will be set
163 * @retval
164 */
165 void wm_sc_set_etu(uint16_t etu);
166
167 /**
168 * @brief
169 * This function config the module clock freq
170 * @param[in] freq : the value of clock freq
171 * @retval
172 */
173 void wm_sc_set_frequency(uint32_t freq);
174
175 /**
176 * @brief
177 * config recv or not when parity error
178 * @param[in] bl : 1--- recv
179 * 0--- don't recv
180 * @retval
181 */
wm_sc_parity_recv(bool bl)182 static inline void wm_sc_parity_recv(bool bl)
183 {
184 tls_bitband_write(HR_UART2_LINE_CTRL, 9, bl);
185 }
186
187 /**
188 * @brief
189 * select the model in 7816 or uart function
190 * @param[in] bl : 1---7816 mode
191 * 0---uart mode
192 * @retval
193 */
wm_sc_7816_mode(bool bl)194 static inline void wm_sc_7816_mode(bool bl)
195 {
196 tls_bitband_write(HR_UART2_LINE_CTRL, 24, bl);
197 }
198
199 /**
200 * @brief
201 * This function is used to config the guard time param
202 * @param[in] bwt : the value of the guard time will be set
203 * @retval
204 */
wm_sc_set_guardtime(uint8_t gt)205 static inline void wm_sc_set_guardtime(uint8_t gt)
206 {
207 tls_reg_write32(HR_UART2_GUARD_TIME, gt);
208 }
209
210 /**
211 * @brief
212 * This function is used to config the CWT or BWT param
213 * @param[in] bwt : the value of CWT or BWT will be set
214 * @retval
215 */
wm_sc_set_bcwt(uint32_t bwt)216 static inline void wm_sc_set_bcwt(uint32_t bwt)
217 {
218 bwt = (bwt > 0xFFFFFF) ? 0xFFFFFF : bwt;
219 tls_reg_write32(HR_UART2_WAIT_TIME, bwt);
220 }
221
222 /**
223 * @brief
224 * module errsignal int enable or disable
225 * @param[in] bl : 1---enable
226 * 0---disable
227 * @retval
228 */
wm_sc_tx_errsignal_mask(bool bl)229 static inline void wm_sc_tx_errsignal_mask(bool bl)
230 {
231 tls_bitband_write(HR_UART2_INT_MASK, 9, bl);
232 }
233
234 /**
235 * @brief
236 * config the module protol
237 * @param[in] bl : 1--- T1 protocol
238 * 0--- T0 protocol
239 * @retval
240 */
wm_sc_set_protocol(bool bl)241 static inline void wm_sc_set_protocol(bool bl)
242 {
243 tls_bitband_write(HR_UART2_LINE_CTRL, 8, bl);
244 }
245
246 /**
247 * @brief
248 * get the module protol
249 * @retval
250 * 1--- T1 protocol
251 * 0--- T0 protocol
252 */
wm_sc_get_protocol()253 static inline uint8_t wm_sc_get_protocol()
254 {
255 return tls_bitband_read(HR_UART2_LINE_CTRL, 8);
256 }
257
258 /**
259 * @brief
260 * smart card clock output enable or disable
261 * @param[in] bl : 0---enable;
262 * 1---disable;
263 * @retval
264 */
wm_sc_clk_enable(bool bl)265 static inline void wm_sc_clk_enable(bool bl)
266 {
267 tls_bitband_write(HR_UART2_LINE_CTRL, 10, bl);
268 }
269
270 /**
271 * @}
272 */
273
274 /**
275 * @}
276 */
277
278 #ifdef __cplusplus
279 }
280 #endif
281
282 #endif
283