1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_iso7816.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of ISO7816 LL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup LL_DRIVER LL Driver
43 * @{
44 */
45
46 /** @defgroup LL_ISO7816 ISO7816
47 * @brief ISO7816 LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_LL_ISO7816_H__
53 #define __GR55xx_LL_ISO7816_H__
54
55 /* Includes ------------------------------------------------------------------*/
56 #include "gr55xx.h"
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 #if defined (ISO7816)
63 /** @defgroup ISO7816_LL_STRUCTURES Structures
64 * @{
65 */
66 /* Exported types ------------------------------------------------------------*/
67 /** @defgroup ISO7816_LL_ES_INIT ISO7816 Exported init structure
68 * @{
69 */
70 /**
71 * @brief ISO7816_LL_init_structure LL ISO7816 init Structure definition
72 */
73 typedef struct _ll_iso7816_init {
74 uint32_t clk_div; /*!< clk_div is used for dividing the system clock,
75 and ISO7816 output clock is equal to (system clock)/(clk_div+1). */
76 uint32_t wait_time; /*!< Specifies the guard time value in terms of number of baud clocks */
77 uint16_t guard_time; /*!< Specifies the maximum card response time (leading edge to leading edge) */
78 uint8_t detect_coding; /*!< Specifies whether automatically detect coding convention during ATR
79 receiption. */
80 } ll_iso7816_init_t;
81 /** @} */
82 /** @} */
83
84 /**
85 * @defgroup ISO7816_LL_MACRO Defines
86 * @{
87 */
88
89 /* Exported constants --------------------------------------------------------*/
90 /** @defgroup ISO7816_LL_Exported_Constants ISO7816 Exported Constants
91 * @{
92 */
93
94 /** @defgroup ISO7816_LL_EC_ACTION Action state.
95 * @{
96 */
97 #define LL_ISO7816_ACTION_NONE 0x00000000U /**< Do Nothing. */
98 #define LL_ISO7816_ACTION_OFF 0x00000001U /**< Switch Off. */
99 #define LL_ISO7816_ACTION_STOPCLK 0x00000002U /**< Stop the clock. */
100 #define LL_ISO7816_ACTION_ON 0x00000003U /**< Switch on and receive ATR. */
101 #define LL_ISO7816_ACTION_WARMRST 0x00000004U /**< Trigger warm reset and receive ATR. */
102 #define LL_ISO7816_ACTION_RX 0x00000005U /**< Receive. */
103 #define LL_ISO7816_ACTION_TX 0x00000006U /**< Transmit. */
104 #define LL_ISO7816_ACTION_TXRX 0x00000007U /**< Transmit, followed by RX. */
105 /** @} */
106
107 /** @defgroup ISO7816_LL_EC_IT IT Defines
108 * @brief Interrupt definitions which can be used with LL_ISO7816_ReadReg and LL_ISO7816_WriteReg functions
109 * @{
110 */
111 #define LL_ISO7816_INTR_TEST ISO7816_STAT_IRQ_TEST /**< Test interrupt */
112 #define LL_ISO7816_INTR_PRESENCE ISO7816_STAT_IRQ_PRESENCE /**< Source presence interrupt */
113 #define LL_ISO7816_INTR_STATE_ERR ISO7816_STAT_IRQ_STAT_ERR /**< Source state error interrupt */
114 #define LL_ISO7816_INTR_DMA_ERR ISO7816_STAT_IRQ_DMA_ERR /**< Source dma error interrupt */
115 #define LL_ISO7816_INTR_RETRY_ERR ISO7816_STAT_IRQ_RETRY_ERR /**< Source retry error interrupt */
116 #define LL_ISO7816_INTR_RX_ERR ISO7816_STAT_IRQ_RX_ERR /**< Source rx error interrupt */
117 #define LL_ISO7816_INTR_DONE ISO7816_STAT_IRQ_DONE /**< Source done error interrupt */
118
119 #define LL_ISO7816_INTR_MASK_ALL ISO7816_INTR_ALL /**< All interrupt */
120 /** @} */
121
122 /** @defgroup ISO7816_LL_EC_PRESENCE Card Presence Defines
123 * @{
124 */
125 #define LL_ISO7816_CARD_ABSENT 0x00000000U /**< SIM Card is absent. */
126 #define LL_ISO7816_CARD_PRESENT 0x00000001U /**< SIM Card is present. */
127 /** @} */
128
129 /** @defgroup ISO7816_LL_EC_IO_STATES IO States Defines
130 * @{
131 */
132 #define LL_ISO7816_IO_STATE_OFF (0x0UL << ISO7816_STAT_IO_STAT_POS) /**< Off */
133 #define LL_ISO7816_IO_STATE_IDLE (0x1UL << ISO7816_STAT_IO_STAT_POS) /**< Idle */
134 #define LL_ISO7816_IO_STATE_RX_WAIT (0x4UL << ISO7816_STAT_IO_STAT_POS) /**< Receive Wait */
135 #define LL_ISO7816_IO_STATE_RX (0x5UL << ISO7816_STAT_IO_STAT_POS) /**< Receive */
136 #define LL_ISO7816_IO_STATE_TX (0x6UL << ISO7816_STAT_IO_STAT_POS) /**< Transmit */
137 #define LL_ISO7816_IO_STATE_TX_GUARD (0x7UL << ISO7816_STAT_IO_STAT_POS) /**< Transmit Guard */
138 /** @} */
139
140 /** @defgroup ISO7816_LL_EC_PWR_STATES Power States Defines
141 * @{
142 */
143 #define LL_ISO7816_PWR_STATE_OFF (0x0UL << ISO7816_STAT_PWR_STAT_POS) /**< Off */
144 #define LL_ISO7816_PWR_STATE_PWRUP_VCC (0x1UL << ISO7816_STAT_PWR_STAT_POS) /**< Power up VCC */
145 #define LL_ISO7816_PWR_STATE_PWRUP_RST (0x2UL << ISO7816_STAT_PWR_STAT_POS) /**< Power up reset */
146 #define LL_ISO7816_PWR_STATE_PWRDN_RST (0x3UL << ISO7816_STAT_PWR_STAT_POS) /**< Power Down reset */
147 #define LL_ISO7816_PWR_STATE_PWRDN_VCC (0x4UL << ISO7816_STAT_PWR_STAT_POS) /**< Power Down VCC */
148 #define LL_ISO7816_PWR_STATE_STOP_PRE (0x5UL << ISO7816_STAT_PWR_STAT_POS) /**< Preparing Clock Stop */
149 #define LL_ISO7816_PWR_STATE_STOP (0x6UL << ISO7816_STAT_PWR_STAT_POS) /**< Clock Stopped */
150 #define LL_ISO7816_PWR_STATE_STOP_POST (0x7UL << ISO7816_STAT_PWR_STAT_POS) /**< Exiting Clock Stop */
151 #define LL_ISO7816_PWR_STATE_IDLE (0x8UL << ISO7816_STAT_PWR_STAT_POS) /**< Idle */
152 #define LL_ISO7816_PWR_STATE_RX_TS0 (0x9UL << ISO7816_STAT_PWR_STAT_POS) /**< RX TS Character */
153 #define LL_ISO7816_PWR_STATE_RX_TS1 (0xAUL << ISO7816_STAT_PWR_STAT_POS) /**< RX TS Character */
154 #define LL_ISO7816_PWR_STATE_RX (0xBUL << ISO7816_STAT_PWR_STAT_POS) /**< Receive */
155 #define LL_ISO7816_PWR_STATE_TX (0xCUL << ISO7816_STAT_PWR_STAT_POS) /**< Transmit */
156 #define LL_ISO7816_PWR_STATE_TX_RX (0xDUL << ISO7816_STAT_PWR_STAT_POS) /**< Transmit and Receive */
157 /** @} */
158
159 /** @defgroup ISO7816_LL_EC_CLKSTOP Clock Stop Select Defines
160 * @{
161 */
162 #define LL_ISO7816_CLKSTOP_LOW (0x00000000UL) /**< Stop the clock at low level. */
163 #define LL_ISO7816_CLKSTOP_HIGH (0x80000000UL) /**< Stop the clock at high level. */
164 /** @} */
165
166 /** @defgroup ISO7816_LL_EC_CODING Coding Convention Defines
167 * @{
168 */
169 #define LL_ISO7816_CODING_DEFAULT (0x00000000UL) /**< High=1, LSB first. */
170 #define LL_ISO7816_CODING_INVERSE (0x00000001UL) /**< High=0, MSB first. */
171 /** @} */
172
173 /** @} */
174
175 /* Exported macro ------------------------------------------------------------*/
176 /** @defgroup ISO7816_LL_Exported_Macros ISO7816 Exported Macros
177 * @{
178 */
179
180 /** @defgroup ISO7816_LL_EM_WRITE_READ Common Write and read registers Macros
181 * @{
182 */
183
184 /**
185 * @brief Write a value in ISO7816 register
186 * @param __instance__ ISO7816 instance
187 * @param __REG__ Register to be written
188 * @param __VALUE__ Value to be written in the register
189 * @retval None.
190 */
191 #define LL_ISO7816_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
192
193 /**
194 * @brief Read a value in ISO7816 register
195 * @param __instance__ ISO7816 instance
196 * @param __REG__ Register to be read
197 * @retval Register value
198 */
199 #define LL_ISO7816_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
200
201 /** @} */
202
203 /** @} */
204
205 /** @} */
206
207 /* Private types -------------------------------------------------------------*/
208 /* Private variables ---------------------------------------------------------*/
209 /* Private constants ---------------------------------------------------------*/
210 /* Private macros ------------------------------------------------------------*/
211 /* Exported functions --------------------------------------------------------*/
212 /** @defgroup ISO7816_LL_DRIVER_FUNCTIONS Functions
213 * @{
214 */
215
216 /** @defgroup ISO7816_LL_EF_Configuration Configuration
217 * @{
218 */
219 /**
220 * @brief Request ISO7816 to go to the next action.
221 *
222 * Register|BitsName
223 * --------|--------
224 * CTRL | ACTION
225 *
226 * @param ISO7816x ISO7816 instance.
227 * @param action This parameter can be one of the following values:
228 * @arg @ref LL_ISO7816_ACTION_NONE
229 * @arg @ref LL_ISO7816_ACTION_OFF
230 * @arg @ref LL_ISO7816_ACTION_STOPCLK
231 * @arg @ref LL_ISO7816_ACTION_ON
232 * @arg @ref LL_ISO7816_ACTION_WARMRST
233 * @arg @ref LL_ISO7816_ACTION_RX
234 * @arg @ref LL_ISO7816_ACTION_TX
235 * @arg @ref LL_ISO7816_ACTION_TXRX
236 * @retval None.
237 */
ll_iso7816_set_action(iso7816_regs_t * ISO7816x,uint32_t action)238 __STATIC_INLINE void ll_iso7816_set_action(iso7816_regs_t *ISO7816x, uint32_t action)
239 {
240 WRITE_REG(ISO7816x->CTRL, action);
241 }
242
243 /**
244 * @brief Get ISO7816 states.
245 *
246 * Register|BitsName
247 * --------|--------
248 * CTRL | ACTION
249 *
250 * @param ISO7816x ISO7816 instance.
251 * @retval ISO7816 states
252 */
ll_iso7816_is_busy(iso7816_regs_t * ISO7816x)253 __STATIC_INLINE uint32_t ll_iso7816_is_busy(iso7816_regs_t *ISO7816x)
254 {
255 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_BUSY) == (ISO7816_STAT_BUSY));
256 }
257
258 /**
259 * @brief Clear Transmit Retries Maximum.
260 *
261 * Register|BitsName
262 * --------|--------
263 * CTRL | TX_RETRY_MAX_CLR
264 *
265 * @param ISO7816x ISO7816 instance.
266 * @retval None.
267 */
ll_iso7816_clear_tx_retry_max(iso7816_regs_t * ISO7816x)268 __STATIC_INLINE void ll_iso7816_clear_tx_retry_max(iso7816_regs_t *ISO7816x)
269 {
270 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_TX_RETYR_MC);
271 }
272
273 /**
274 * @brief Clear Receive Retries Maximum.
275 *
276 * Register|BitsName
277 * --------|--------
278 * CTRL | RX_RETRY_MAX_CLR
279 *
280 * @param ISO7816x ISO7816 instance.
281 * @retval None.
282 */
ll_iso7816_clear_rx_retry_max(iso7816_regs_t * ISO7816x)283 __STATIC_INLINE void ll_iso7816_clear_rx_retry_max(iso7816_regs_t *ISO7816x)
284 {
285 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_RX_RETYR_MC);
286 }
287
288 /**
289 * @brief Check Card presence.
290 *
291 * Register|BitsName
292 * --------|--------
293 * STAT | PRESENCE
294 *
295 * @param ISO7816x ISO7816 instance.
296 * @retval Returned value can be one of the following values:
297 * @arg @ref LL_ISO7816_CARD_ABSENT
298 * @arg @ref LL_ISO7816_CARD_PRESENT
299 */
ll_iso7816_check_card_presence(iso7816_regs_t * ISO7816x)300 __STATIC_INLINE uint32_t ll_iso7816_check_card_presence(iso7816_regs_t *ISO7816x)
301 {
302 return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_PRESENCE_STAT) >> ISO7816_STAT_PRESENCE_STAT_POS);
303 }
304
305 /**
306 * @brief Get Maximum number of seen transmit retries after error signaling by ISO7816.
307 *
308 * Register|BitsName
309 * --------|--------
310 * STAT | TX_RETRY_MAX
311 *
312 * @param ISO7816x ISO7816 instance.
313 * @retval Value range between 0x1 and 0x7.
314 */
ll_iso7816_get_tx_retry_max(iso7816_regs_t * ISO7816x)315 __STATIC_INLINE uint32_t ll_iso7816_get_tx_retry_max(iso7816_regs_t *ISO7816x)
316 {
317 return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_TX_RETRY_MAX) >> ISO7816_STAT_RX_RETRY_MAX_POS);
318 }
319
320 /**
321 * @brief Get Maximum number of seen receive retries after error signaling by ISO7816.
322 *
323 * Register|BitsName
324 * --------|--------
325 * STAT | RX_RETRY_MAX
326 *
327 * @param ISO7816x ISO7816 instance.
328 * @retval Value range between 0x1 and 0x7.
329 */
ll_iso7816_get_rx_retry_max(iso7816_regs_t * ISO7816x)330 __STATIC_INLINE uint32_t ll_iso7816_get_rx_retry_max(iso7816_regs_t *ISO7816x)
331 {
332 return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_RX_RETRY_MAX) >> ISO7816_STAT_RX_RETRY_MAX_POS);
333 }
334
335 /**
336 * @brief Get ISO7816 IO States.
337 *
338 * Register|BitsName
339 * --------|--------
340 * STAT | IO_STATE
341 *
342 * @param ISO7816x ISO7816 instance.
343 * @retval Returned value can be one or combination of the following values:
344 * @arg @ref LL_ISO7816_IO_STATE_OFF
345 * @arg @ref LL_ISO7816_IO_STATE_IDLE
346 * @arg @ref LL_ISO7816_IO_STATE_RX_WAIT
347 * @arg @ref LL_ISO7816_IO_STATE_RX
348 * @arg @ref LL_ISO7816_IO_STATE_TX
349 * @arg @ref LL_ISO7816_IO_STATE_TX_GUARD
350 */
ll_iso7816_get_io_states(iso7816_regs_t * ISO7816x)351 __STATIC_INLINE uint32_t ll_iso7816_get_io_states(iso7816_regs_t *ISO7816x)
352 {
353 return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_IO_STAT) >> ISO7816_STAT_IO_STAT_POS);
354 }
355
356 /**
357 * @brief Get ISO7816 Power States.
358 *
359 * Register|BitsName
360 * --------|--------
361 * STAT | PWR_STATE
362 *
363 * @param ISO7816x ISO7816 instance.
364 * @retval Returned value can be one of the following values:
365 * @arg @ref LL_ISO7816_PWR_STATE_OFF
366 * @arg @ref LL_ISO7816_PWR_STATE_PWRUP_VCC
367 * @arg @ref LL_ISO7816_PWR_STATE_PWRUP_RST
368 * @arg @ref LL_ISO7816_PWR_STATE_PWRDN_RST
369 * @arg @ref LL_ISO7816_PWR_STATE_PWRDN_VCC
370 * @arg @ref LL_ISO7816_PWR_STATE_STOP_PRE
371 * @arg @ref LL_ISO7816_PWR_STATE_STOP
372 * @arg @ref LL_ISO7816_PWR_STATE_STOP_POST
373 * @arg @ref LL_ISO7816_PWR_STATE_IDLE
374 * @arg @ref LL_ISO7816_PWR_STATE_RX_TS0
375 * @arg @ref LL_ISO7816_PWR_STATE_RX_TS1
376 * @arg @ref LL_ISO7816_PWR_STATE_RX
377 * @arg @ref LL_ISO7816_PWR_STATE_TX
378 * @arg @ref LL_ISO7816_PWR_STATE_TX_RX
379 */
ll_iso7816_get_power_states(iso7816_regs_t * ISO7816x)380 __STATIC_INLINE uint32_t ll_iso7816_get_power_states(iso7816_regs_t *ISO7816x)
381 {
382 return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_PWR_STAT));
383 }
384
385 /**
386 * @brief Set value of the clock output during stopped Clock.
387 *
388 * Register|BitsName
389 * --------|--------
390 * CLK_CFG | CLK_STOP_SEL
391 *
392 * @param ISO7816x ISO7816 instance.
393 * @param level This parameter can be one of the following values:
394 * @arg @ref LL_ISO7816_CLKSTOP_LOW
395 * @arg @ref LL_ISO7816_CLKSTOP_HIGH
396 * @retval None.
397 */
ll_iso7816_set_clkstop_level(iso7816_regs_t * ISO7816x,uint32_t level)398 __STATIC_INLINE void ll_iso7816_set_clkstop_level(iso7816_regs_t *ISO7816x, uint32_t level)
399 {
400 MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_STOP_SEL, level);
401 }
402
403 /**
404 * @brief Get value of the clock output during stopped Clock.
405 *
406 * Register|BitsName
407 * --------|--------
408 * CLK_CFG | CLK_STOP_SEL
409 *
410 * @param ISO7816x ISO7816 instance.
411 * @retval Returned value can be one of the following values:
412 * @arg @ref LL_ISO7816_CLKSTOP_LOW
413 * @arg @ref LL_ISO7816_CLKSTOP_HIGH
414 */
ll_iso7816_get_clkstop_level(iso7816_regs_t * ISO7816x)415 __STATIC_INLINE uint32_t ll_iso7816_get_clkstop_level(iso7816_regs_t *ISO7816x)
416 {
417 return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_STOP_SEL));
418 }
419
420 /**
421 * @brief Set clock division.
422 * @note Divide system clock by this value+1.
423 *
424 * Register|BitsName
425 * --------|--------
426 * CLK_CFG | CLK_DIV
427 *
428 * @param ISO7816x ISO7816 instance
429 * @param value This parameter should range between 0x0 and 0xFF.
430 * @retval None.
431 */
ll_iso7816_set_clkdiv(iso7816_regs_t * ISO7816x,uint32_t value)432 __STATIC_INLINE void ll_iso7816_set_clkdiv(iso7816_regs_t *ISO7816x, uint32_t value)
433 {
434 MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_DIV, value << ISO7816_CLK_CFG_CLK_DIV_POS);
435 }
436
437 /**
438 * @brief Get clock division.
439 *
440 * Register|BitsName
441 * --------|--------
442 * CLK_CFG | CLK_DIV
443 *
444 * @param ISO7816x ISO7816 instance
445 * @retval Returned value should range between 0x0 and 0xFF.
446 */
ll_iso7816_get_clkdiv(iso7816_regs_t * ISO7816x)447 __STATIC_INLINE uint32_t ll_iso7816_get_clkdiv(iso7816_regs_t *ISO7816x)
448 {
449 return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_DIV) >> ISO7816_CLK_CFG_CLK_DIV_POS);
450 }
451
452 /**
453 * @brief Set divide ISO7816 clock.
454 * @note Divide SIM clock by this value+1 to define ETU length. The reset value
455 * is the one, needed for theATR.
456 *
457 * Register|BitsName
458 * --------|--------
459 * CLK_CFG | ETU_DIV
460 *
461 * @param ISO7816x ISO7816 instance
462 * @param divide This parameter should range between 0x0 and 0x3FF.
463 * @retval None.
464 */
ll_iso7816_set_etudiv(iso7816_regs_t * ISO7816x,uint32_t divide)465 __STATIC_INLINE void ll_iso7816_set_etudiv(iso7816_regs_t *ISO7816x, uint32_t divide)
466 {
467 MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_ETU_DIV, divide);
468 }
469
470 /**
471 * @brief Get divide ISO7816 clock.
472 *
473 * Register|BitsName
474 * --------|--------
475 * CLK_CFG | ETU_DIV
476 *
477 * @param ISO7816x ISO7816 instance
478 * @retval Returned value should range between 0x0 and 0x3FF.
479 */
ll_iso7816_get_etudiv(iso7816_regs_t * ISO7816x)480 __STATIC_INLINE uint32_t ll_iso7816_get_etudiv(iso7816_regs_t *ISO7816x)
481 {
482 return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_ETU_DIV));
483 }
484
485 /**
486 * @brief Set ISO7816 wait_time in ETU.
487
488 * @note Time between the leading edges of two consecutive characters
489 *
490 * Register|BitsName
491 * --------|--------
492 * TIMES | WAIT_TIME
493 *
494 * @param ISO7816x ISO7816 instance
495 * @param wait_time This parameter should range between 0x0 and 0x3FFF.
496 * @retval None.
497 */
ll_iso7816_set_waittime(iso7816_regs_t * ISO7816x,uint32_t wait_time)498 __STATIC_INLINE void ll_iso7816_set_waittime(iso7816_regs_t *ISO7816x, uint32_t wait_time)
499 {
500 MODIFY_REG(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_WAIT_TIME, wait_time << ISO7816_TIMES_CFG_WAIT_TIME_POS);
501 }
502
503 /**
504 * @brief Get maximum card response time(leading edge to leading edge)
505 *
506 * Register|BitsName
507 * --------|--------
508 * TIMES | WAIT_TIME
509 *
510 * @param ISO7816x ISO7816 instance
511 * @retval Returned value should range between 0x0 and 0x3FFFF.
512 */
ll_iso7816_get_waittime(iso7816_regs_t * ISO7816x)513 __STATIC_INLINE uint32_t ll_iso7816_get_waittime(iso7816_regs_t *ISO7816x)
514 {
515 return (uint32_t)(READ_BITS(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_WAIT_TIME) >> ISO7816_TIMES_CFG_WAIT_TIME_POS);
516 }
517
518 /**
519 * @brief Set ISO7816 guard_time in ETU.
520
521 * @note Set time between the leading edges of two consecutive characters
522 *
523 * Register|BitsName
524 * --------|--------
525 * TIMES | GUARD_TIME
526 *
527 * @param ISO7816x ISO7816 instance
528 * @param guardtime Time between the leading edges of two consecutive characters
529 * @retval None.
530 */
ll_iso7816_set_guardtime(iso7816_regs_t * ISO7816x,uint32_t guardtime)531 __STATIC_INLINE void ll_iso7816_set_guardtime(iso7816_regs_t *ISO7816x, uint32_t guardtime)
532 {
533 MODIFY_REG(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_GUARD_TIME, guardtime);
534 }
535 /**
536 * @brief Get time between the leading edges of two consecutive characters.
537 *
538 * Register|BitsName
539 * --------|--------
540 * TIMES | GUARDTIME
541 *
542 * @param ISO7816x ISO7816 instance
543 * @retval Returned value should range between 0x0 and 0x3FF.
544 */
ll_iso7816_get_guardtime(iso7816_regs_t * ISO7816x)545 __STATIC_INLINE uint32_t ll_iso7816_get_guardtime(iso7816_regs_t *ISO7816x)
546 {
547 return (uint32_t)(READ_BITS(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_GUARD_TIME));
548 }
549
550 /**
551 * @brief Set maximum number of issued retries before giving up.
552 *
553 * Register|BitsName
554 * --------|--------
555 * DATA_CFG| RETRY_LIMIT
556 *
557 * @param ISO7816x ISO7816 instance
558 * @param number This parameter should range between 0x0 and 0x7.
559 * @retval None.
560 */
ll_iso7816_set_retry_limit(iso7816_regs_t * ISO7816x,uint32_t number)561 __STATIC_INLINE void ll_iso7816_set_retry_limit(iso7816_regs_t *ISO7816x, uint32_t number)
562 {
563 MODIFY_REG(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_RETRY_LIMIT, number << ISO7816_DATA_CFG_RETRY_LIMIT_POS);
564 }
565
566 /**
567 * @brief Get maximum number of issued retries before giving up.
568 *
569 * Register|BitsName
570 * --------|--------
571 * DATA_CFG| RETRY_LIMIT
572 *
573 * @param ISO7816x ISO7816 instance
574 * @retval Returned value should range between 0x0 and 0x7.
575 */
ll_iso7816_get_retry_limit(iso7816_regs_t * ISO7816x)576 __STATIC_INLINE uint32_t ll_iso7816_get_retry_limit(iso7816_regs_t *ISO7816x)
577 {
578 return (uint32_t)(READ_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_RETRY_LIMIT) >> ISO7816_DATA_CFG_RETRY_LIMIT_POS);
579 }
580
581 /**
582 * @brief Enable coding detection.
583 *
584 * Register|BitsName
585 * --------|--------
586 * DATA_CFG| DETECT_CODING
587 *
588 * @param ISO7816x ISO7816 instance.
589 * @retval None.
590 */
ll_iso7816_enable_coding_detection(iso7816_regs_t * ISO7816x)591 __STATIC_INLINE void ll_iso7816_enable_coding_detection(iso7816_regs_t *ISO7816x)
592 {
593 SET_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_DETECT_CODING);
594 }
595
596 /**
597 * @brief Disable coding detection.
598 *
599 * Register|BitsName
600 * --------|--------
601 * DATA_CFG| DETECT_CODING
602 *
603 * @param ISO7816x ISO7816 instance.
604 * @retval None.
605 */
ll_iso7816_disable_coding_detection(iso7816_regs_t * ISO7816x)606 __STATIC_INLINE void ll_iso7816_disable_coding_detection(iso7816_regs_t *ISO7816x)
607 {
608 CLEAR_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_DETECT_CODING);
609 }
610
611 /**
612 * @brief Set coding convention.
613 *
614 * Register|BitsName
615 * --------|--------
616 * DATA_CFG| CODING
617 *
618 * @param ISO7816x ISO7816 instance.
619 * @param convention This parameter can be one of the following values:
620 * @arg @ref LL_ISO7816_CODING_DEFAULT
621 * @arg @ref LL_ISO7816_CODING_INVERSE
622 * @retval None.
623 */
ll_iso7816_set_coding_convention(iso7816_regs_t * ISO7816x,uint32_t convention)624 __STATIC_INLINE void ll_iso7816_set_coding_convention(iso7816_regs_t *ISO7816x, uint32_t convention)
625 {
626 MODIFY_REG(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_CODING, convention);
627 }
628
629 /**
630 * @brief Get coding convention.
631 *
632 * Register|BitsName
633 * --------|--------
634 * DATA_CFG| CODING
635 *
636 * @param ISO7816x ISO7816 instance
637 * @retval Returned value can be one of the following values:
638 * @arg @ref LL_ISO7816_CODING_DEFAULT
639 * @arg @ref LL_ISO7816_CODING_INVERSE
640 */
ll_iso7816_get_coding_convention(iso7816_regs_t * ISO7816x)641 __STATIC_INLINE uint32_t ll_iso7816_get_coding_convention(iso7816_regs_t *ISO7816x)
642 {
643 return (uint32_t)(READ_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_CODING));
644 }
645
646 /**
647 * @brief Get current address relative to base_addr.
648 *
649 * Register|BitsName
650 * --------|--------
651 * ADDR | ADDR
652 *
653 * @param ISO7816x ISO7816 instance
654 * @retval Value between 0x0 and 0x3FFFF.
655 */
ll_iso7816_get_current_addr(iso7816_regs_t * ISO7816x)656 __STATIC_INLINE uint32_t ll_iso7816_get_current_addr(iso7816_regs_t *ISO7816x)
657 {
658 return (uint32_t)(READ_BITS(ISO7816x->ADDR, ISO7816_ADDR_ADDR) >> ISO7816_ADDR_ADDR_POS);
659 }
660
661 /**
662 * @brief Get address fraction.
663 *
664 * Register|BitsName
665 * --------|--------
666 * ADDR | ADDR_FRAC
667 *
668 * @param ISO7816x ISO7816 instance
669 * @retval Value between 0x0 and 0x3.
670 */
ll_iso7816_get_current_addr_frac(iso7816_regs_t * ISO7816x)671 __STATIC_INLINE uint32_t ll_iso7816_get_current_addr_frac(iso7816_regs_t *ISO7816x)
672 {
673 return (uint32_t)(READ_BITS(ISO7816x->ADDR, ISO7816_ADDR_ADDR_FRAC));
674 }
675
676 /**
677 * @brief Set start address for RX and TX buffer.
678 *
679 * Register |BitsName
680 * ---------|--------
681 * STRT_ADDR| BASE_ADDR+START_ADDR
682 *
683 * @param ISO7816x ISO7816 instance
684 * @param addr This parameter should range between 0x0 and 0xFFFFFFFF.
685 * @retval None.
686 */
ll_iso7816_set_buffer_addr(iso7816_regs_t * ISO7816x,uint32_t addr)687 __STATIC_INLINE void ll_iso7816_set_buffer_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
688 {
689 WRITE_REG(ISO7816x->START_ADDR, addr);
690 }
691
692 /**
693 * @brief Get start address for RX and TX buffer.
694 *
695 * Register |BitsName
696 * ---------|--------
697 * STRT_ADDR| BASE_ADDR+START_ADDR
698 *
699 * @param ISO7816x ISO7816 instance
700 */
ll_iso7816_get_buffer_addr(iso7816_regs_t * ISO7816x)701 __STATIC_INLINE uint32_t ll_iso7816_get_buffer_addr(iso7816_regs_t *ISO7816x)
702 {
703 return (uint32_t)(READ_REG(ISO7816x->START_ADDR));
704 }
705
706 /**
707 * @brief Set base address for RX and TX buffer.
708 *
709 * Register |BitsName
710 * ---------|--------
711 * STRT_ADDR| BASE_ADDR
712 *
713 * @param ISO7816x ISO7816 instance
714 * @param addr This parameter should range between 0x0 and 0xFFF.
715 * @retval None.
716 */
ll_iso7816_set_base_addr(iso7816_regs_t * ISO7816x,uint32_t addr)717 __STATIC_INLINE void ll_iso7816_set_base_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
718 {
719 MODIFY_REG(ISO7816x->START_ADDR, ISO7816_START_ADDR_BASE_ADDR, addr << ISO7816_START_ADDR_BASE_ADDR_POS);
720 }
721
722 /**
723 * @brief Get base address for RX and TX buffer.
724 *
725 * Register |BitsName
726 * ---------|--------
727 * STRT_ADDR| BASE_ADDR
728 *
729 * @param ISO7816x ISO7816 instance
730 * @retval Value between 0x0 and 0xFFF.
731 */
ll_iso7816_get_base_addr(iso7816_regs_t * ISO7816x)732 __STATIC_INLINE uint32_t ll_iso7816_get_base_addr(iso7816_regs_t *ISO7816x)
733 {
734 return (uint32_t)(READ_BITS(ISO7816x->START_ADDR, ISO7816_START_ADDR_BASE_ADDR) >> \
735 ISO7816_START_ADDR_BASE_ADDR_POS);
736 }
737
738 /**
739 * @brief Set start address for RX and TX buffer, relative to base_addr.
740 *
741 * Register |BitsName
742 * ---------|--------
743 * STRT_ADDR| STRT_ADDR
744 *
745 * @param ISO7816x ISO7816 instance
746 * @param addr This parameter should range between 0x0 and 0x3FFFF.
747 * @retval None.
748 */
ll_iso7816_set_start_addr(iso7816_regs_t * ISO7816x,uint32_t addr)749 __STATIC_INLINE void ll_iso7816_set_start_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
750 {
751 MODIFY_REG(ISO7816x->START_ADDR, ISO7816_START_ADDR_START_ADDR, addr << ISO7816_START_ADDR_START_ADDR_POS);
752 }
753
754 /**
755 * @brief Get start address for RX and TX buffer, relative to base_addr.
756 *
757 * Register |BitsName
758 * ---------|--------
759 * STRT_ADDR| STRT_ADDR
760 *
761 * @param ISO7816x ISO7816 instance
762 * @retval Value between 0x0 and 0x3FFFF.
763 */
ll_iso7816_get_start_addr(iso7816_regs_t * ISO7816x)764 __STATIC_INLINE uint32_t ll_iso7816_get_start_addr(iso7816_regs_t *ISO7816x)
765 {
766 return (uint32_t)(READ_BITS(ISO7816x->START_ADDR, ISO7816_START_ADDR_START_ADDR) >> \
767 ISO7816_START_ADDR_START_ADDR_POS);
768 }
769
770 /**
771 * @brief Set end address of receive buffer, relative to base_addr.
772 *
773 * Register | BitsName
774 * -----------|--------
775 * RX_END_ADDR| RX_END_ADDR+
776 *
777 * @param ISO7816x ISO7816 instance
778 * @param addr This parameter should range between 0x0 and 0x3FFFF.
779 * @retval None.
780 */
ll_iso7816_set_rx_end_addr(iso7816_regs_t * ISO7816x,uint32_t addr)781 __STATIC_INLINE void ll_iso7816_set_rx_end_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
782 {
783 MODIFY_REG(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_ADDR, addr << ISO7816_RX_END_ADDR_RX_END_ADDR_POS);
784 }
785
786 /**
787 * @brief Set RX endbyte address of receive buffer, relative to base_addr.
788 *
789 * Register | BitsName
790 * -----------|--------
791 * RX_END_ADDR| RX_END_ADDR+RX_END_AF
792 *
793 * @param ISO7816x ISO7816 instance
794 * @param addr This parameter should range between 0x0 and 0x3FFFF.
795 * @retval None.
796 */
ll_iso7816_set_rx_endbyte_addr(iso7816_regs_t * ISO7816x,uint32_t addr)797 __STATIC_INLINE void ll_iso7816_set_rx_endbyte_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
798 {
799 WRITE_REG(ISO7816x->RX_END_ADDR, addr);
800 }
801
802 /**
803 * @brief Get RX end address of receive buffer, relative to base_addr.
804 *
805 * Register | BitsName
806 * -----------|--------
807 * RX_END_ADDR| RX_END_ADDR
808 *
809 * @param ISO7816x ISO7816 instance
810 * @retval Value between 0x0 and 0x3FFFF.
811 */
ll_iso7816_get_rx_end_addr(iso7816_regs_t * ISO7816x)812 __STATIC_INLINE uint32_t ll_iso7816_get_rx_end_addr(iso7816_regs_t *ISO7816x)
813 {
814 return (uint32_t)(READ_BITS(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_ADDR) >> \
815 ISO7816_RX_END_ADDR_RX_END_ADDR_POS);
816 }
817
818 /**
819 * @brief Set RX end address fraction.
820 *
821 * Register | BitsName
822 * -----------|--------
823 * RX_END_ADDR| RX_END_AF
824 *
825 * @param ISO7816x ISO7816 instance
826 * @param frac This parameter should range between 0x0 and 0x3.
827 * @retval None.
828 */
ll_iso7816_set_rx_end_addr_frac(iso7816_regs_t * ISO7816x,uint32_t frac)829 __STATIC_INLINE void ll_iso7816_set_rx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
830 {
831 MODIFY_REG(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_AF, frac);
832 }
833
834 /**
835 * @brief Set TX endbyte address of buffer, relative to base_addr.
836 *
837 * Register | BitsName
838 * -----------|--------
839 * TX_END_ADDR| TX_END_ADDR+TX_END_AF
840 *
841 * @param ISO7816x ISO7816 instance
842 * @param addr This parameter should range between 0x0 and 0x3FFFF.
843 * @retval None.
844 */
ll_iso7816_set_tx_endbyte_addr(iso7816_regs_t * ISO7816x,uint32_t addr)845 __STATIC_INLINE void ll_iso7816_set_tx_endbyte_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
846 {
847 WRITE_REG(ISO7816x->TX_END_ADDR, addr);
848 }
849
850 /**
851 * @brief Get TX endbyte address of buffer, relative to base_addr.
852 *
853 * Register | BitsName
854 * -----------|--------
855 * TX_END_ADDR| TX_END_ADDR+TX_END_AF
856 *
857 * @param ISO7816x ISO7816 instance
858 * @retval TX endbyte address.
859 */
ll_iso7816_get_tx_endbyte_addr(iso7816_regs_t * ISO7816x)860 __STATIC_INLINE uint32_t ll_iso7816_get_tx_endbyte_addr(iso7816_regs_t *ISO7816x)
861 {
862 return READ_REG(ISO7816x->TX_END_ADDR);
863 }
864
865 /**
866 * @brief Get RX endbyte address of buffer, relative to base_addr.
867 *
868 * Register | BitsName
869 * -----------|--------
870 * TX_END_ADDR| TX_END_ADDR+TX_END_AF
871 *
872 * @param ISO7816x ISO7816 instance
873 * @retval RX endbyte address.
874 */
ll_iso7816_get_rx_endbyte_addr(iso7816_regs_t * ISO7816x)875 __STATIC_INLINE uint32_t ll_iso7816_get_rx_endbyte_addr(iso7816_regs_t *ISO7816x)
876 {
877 return READ_REG(ISO7816x->RX_END_ADDR);
878 }
879
880 /**
881 * @brief Get RX end address fraction.
882 *
883 * Register | BitsName
884 * -----------|--------
885 * RX_END_ADDR| RX_END_AF
886 *
887 * @param ISO7816x ISO7816 instance
888 * @retval Value between 0x0 and 0x3.
889 */
ll_iso7816_get_rx_end_addr_frac(iso7816_regs_t * ISO7816x)890 __STATIC_INLINE uint32_t ll_iso7816_get_rx_end_addr_frac(iso7816_regs_t *ISO7816x)
891 {
892 return (uint32_t)(READ_BITS(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_AF));
893 }
894
895 /**
896 * @brief Set end address of transmit buffer, relative to base_addr.
897 *
898 * Register | BitsName
899 * -----------|--------
900 * TX_END_ADDR| TX_END_ADDR
901 *
902 * @param ISO7816x ISO7816 instance
903 * @param addr This parameter should range between 0x0 and 0x3FFFF.
904 * @retval None.
905 */
ll_iso7816_set_tx_end_addr(iso7816_regs_t * ISO7816x,uint32_t addr)906 __STATIC_INLINE void ll_iso7816_set_tx_end_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
907 {
908 MODIFY_REG(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_ADDR, addr << ISO7816_TX_END_ADDR_TX_END_ADDR_POS);
909 }
910
911 /**
912 * @brief Get end address of transmit buffer, relative to base_addr.
913 *
914 * Register | BitsName
915 * -----------|--------
916 * TX_END_ADDR| TX_END_ADDR
917 *
918 * @param ISO7816x ISO7816 instance
919 * @retval Value between 0x0 and 0x3FFFF.
920 */
ll_iso7816_get_tx_end_addr(iso7816_regs_t * ISO7816x)921 __STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr(iso7816_regs_t *ISO7816x)
922 {
923 return (uint32_t)(READ_BITS(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_ADDR) >> \
924 ISO7816_TX_END_ADDR_TX_END_ADDR_POS);
925 }
926
927 /**
928 * @brief Set TX end address fraction.
929 *
930 * Register | BitsName
931 * -----------|--------
932 * TX_END_ADDR| TX_END_AF
933 *
934 * @param ISO7816x ISO7816 instance
935 * @param frac This parameter should range between 0x0 and 0x3.
936 * @retval None.
937 */
ll_iso7816_set_tx_end_addr_frac(iso7816_regs_t * ISO7816x,uint32_t frac)938 __STATIC_INLINE void ll_iso7816_set_tx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
939 {
940 MODIFY_REG(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_AF, frac);
941 }
942
943 /**
944 * @brief Get TX end address fraction.
945 *
946 * Register | BitsName
947 * -----------|--------
948 * TX_END_ADDR| TX_END_AF
949 *
950 * @param ISO7816x ISO7816 instance
951 * @retval Value between 0x0 and 0x3.
952 */
ll_iso7816_get_tx_end_addr_frac(iso7816_regs_t * ISO7816x)953 __STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr_frac(iso7816_regs_t *ISO7816x)
954 {
955 return (uint32_t)(READ_BITS(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_AF));
956 }
957
958 /** @} */
959
960 /** @defgroup ISO7816_LL_EF_IT_Management IT_Management
961 * @{
962 */
963
964 /**
965 * @brief Get ISO7816 interrupt flags
966 *
967 * Register|BitsName
968 * --------|--------
969 * STAT | STAT_TEST
970 * STAT | STAT_PRESENCE
971 * STAT | STAT_STATE_ERR
972 * STAT | STAT_DMA_ERR
973 * STAT | STAT_RETRY_ERR
974 * STAT | STAT_RX_ERR
975 * STAT | STAT_DONE
976 *
977 * @param ISO7816x ISO7816 instance.
978 * @retval Returned value can be one or combination of the following values:
979 * @arg @ref LL_ISO7816_INTR_TEST
980 * @arg @ref LL_ISO7816_INTR_PRESENCE
981 * @arg @ref LL_ISO7816_INTR_STATE_ERR
982 * @arg @ref LL_ISO7816_INTR_DMA_ERR
983 * @arg @ref LL_ISO7816_INTR_RETRY_ERR
984 * @arg @ref LL_ISO7816_INTR_RX_ERR
985 * @arg @ref LL_ISO7816_INTR_DONE
986 */
ll_iso7816_get_it_flag(iso7816_regs_t * ISO7816x)987 __STATIC_INLINE uint32_t ll_iso7816_get_it_flag(iso7816_regs_t *ISO7816x)
988 {
989 return (uint32_t)(READ_REG(ISO7816x->STAT) & ISO7816_INTR_ALL);
990 }
991
992 /**
993 * @brief Indicate the status of STAT_TEST flag.
994 *
995 * Register|BitsName
996 * --------|--------
997 * STAT | STAT_TEST
998 *
999 * @param ISO7816x ISO7816 instance.
1000 * @retval State of bit (1 or 0).
1001 */
ll_iso7816_is_active_flag_test(iso7816_regs_t * ISO7816x)1002 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_test(iso7816_regs_t *ISO7816x)
1003 {
1004 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_TEST) == (ISO7816_STAT_IRQ_TEST));
1005 }
1006
1007 /**
1008 * @brief Indicate the status of STAT_PRESENCE flag.
1009 *
1010 * Register|BitsName
1011 * --------|--------
1012 * STAT | STAT_PRESENCE
1013 *
1014 * @param ISO7816x ISO7816 instance.
1015 * @retval State of bit (1 or 0).
1016 */
ll_iso7816_is_active_flag_presence(iso7816_regs_t * ISO7816x)1017 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_presence(iso7816_regs_t *ISO7816x)
1018 {
1019 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_PRESENCE) == (ISO7816_STAT_IRQ_PRESENCE));
1020 }
1021
1022 /**
1023 * @brief Indicate the status of STAT_STATE_ERR flag.
1024 *
1025 * Register|BitsName
1026 * --------|--------
1027 * STAT | STAT_STATE_ERR
1028 *
1029 * @param ISO7816x ISO7816 instance.
1030 * @retval State of bit (1 or 0).
1031 */
ll_iso7816_is_active_flag_state_err(iso7816_regs_t * ISO7816x)1032 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_state_err(iso7816_regs_t *ISO7816x)
1033 {
1034 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_STAT_ERR) == (ISO7816_STAT_IRQ_STAT_ERR));
1035 }
1036
1037 /**
1038 * @brief Indicate the status of STAT_DMA_ERR flag.
1039 *
1040 * Register|BitsName
1041 * --------|--------
1042 * STAT | STAT_DMA_ERR
1043 *
1044 * @param ISO7816x ISO7816 instance.
1045 * @retval State of bit (1 or 0).
1046 */
ll_iso7816_is_active_flag_dma_err(iso7816_regs_t * ISO7816x)1047 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_dma_err(iso7816_regs_t *ISO7816x)
1048 {
1049 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_DMA_ERR) == (ISO7816_STAT_IRQ_DMA_ERR));
1050 }
1051
1052 /**
1053 * @brief Indicate the status of STAT_RETRY_ERR flag.
1054 *
1055 * Register|BitsName
1056 * --------|--------
1057 * STAT | STAT_RETRY_ERR
1058 *
1059 * @param ISO7816x ISO7816 instance.
1060 * @retval State of bit (1 or 0).
1061 */
ll_iso7816_is_active_flag_retry_err(iso7816_regs_t * ISO7816x)1062 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_retry_err(iso7816_regs_t *ISO7816x)
1063 {
1064 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_RETRY_ERR) == (ISO7816_STAT_IRQ_RETRY_ERR));
1065 }
1066
1067 /**
1068 * @brief Indicate the status of STAT_RX_ERR flag.
1069 *
1070 * Register|BitsName
1071 * --------|--------
1072 * STAT | STAT_RX_ERR
1073 *
1074 * @param ISO7816x ISO7816 instance.
1075 * @retval State of bit (1 or 0).
1076 */
ll_iso7816_is_active_flag_rx_err(iso7816_regs_t * ISO7816x)1077 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_rx_err(iso7816_regs_t *ISO7816x)
1078 {
1079 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_RX_ERR) == (ISO7816_STAT_IRQ_RX_ERR));
1080 }
1081
1082 /**
1083 * @brief Indicate the status of STAT_DONE flag.
1084 *
1085 * Register|BitsName
1086 * --------|--------
1087 * STAT | STAT_DONE
1088 *
1089 * @param ISO7816x ISO7816 instance.
1090 * @retval State of bit (1 or 0).
1091 */
ll_iso7816_is_active_flag_done(iso7816_regs_t * ISO7816x)1092 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_done(iso7816_regs_t *ISO7816x)
1093 {
1094 return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_DONE) == (ISO7816_STAT_IRQ_DONE));
1095 }
1096
1097 /**
1098 * @brief Clear the combined interrupt, all individual interrupts, and the STAT register
1099 *
1100 * Register|BitsName
1101 * --------|--------
1102 * STAT | STAT_TEST
1103 * STAT | STAT_PRESENCE
1104 * STAT | STAT_STATE_ERR
1105 * STAT | STAT_DMA_ERR
1106 * STAT | STAT_RETRY_ERR
1107 * STAT | STAT_RX_ERR
1108 * STAT | STAT_DONE
1109 *
1110 * @param ISO7816x ISO7816 instance.
1111 * @retval None.
1112 */
ll_iso7816_clear_flag_all_intr(iso7816_regs_t * ISO7816x)1113 __STATIC_INLINE void ll_iso7816_clear_flag_all_intr(iso7816_regs_t *ISO7816x)
1114 {
1115 WRITE_REG(ISO7816x->CTRL, ISO7816_INTR_ALL);
1116 }
1117
1118 /**
1119 * @brief Clear test flag.
1120 *
1121 * Register|BitsName
1122 * --------|--------
1123 * CTRL | CTRL_TEST
1124 *
1125 * @param ISO7816x ISO7816 instance.
1126 * @retval None.
1127 */
ll_iso7816_clear_flag_test(iso7816_regs_t * ISO7816x)1128 __STATIC_INLINE void ll_iso7816_clear_flag_test(iso7816_regs_t *ISO7816x)
1129 {
1130 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_TEST_CLR);
1131 }
1132
1133 /**
1134 * @brief Clear presence flag.
1135 *
1136 * Register|BitsName
1137 * --------|--------
1138 * CTRL | CTRL_PRESENCE
1139 *
1140 * @param ISO7816x ISO7816 instance.
1141 * @retval None.
1142 */
ll_iso7816_clear_flag_presence(iso7816_regs_t * ISO7816x)1143 __STATIC_INLINE void ll_iso7816_clear_flag_presence(iso7816_regs_t *ISO7816x)
1144 {
1145 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_PRESENCE_CLR);
1146 }
1147
1148 /**
1149 * @brief Clear state error flag.
1150 *
1151 * Register|BitsName
1152 * --------|--------
1153 * CTRL | CTRL_STATE_ERR
1154 *
1155 * @param ISO7816x ISO7816 instance.
1156 * @retval None.
1157 */
ll_iso7816_clear_flag_state_err(iso7816_regs_t * ISO7816x)1158 __STATIC_INLINE void ll_iso7816_clear_flag_state_err(iso7816_regs_t *ISO7816x)
1159 {
1160 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_STAT_EC);
1161 }
1162
1163 /**
1164 * @brief Clear dma error flag.
1165 *
1166 * Register|BitsName
1167 * --------|--------
1168 * CTRL | CTRL_DMA_ERR
1169 *
1170 * @param ISO7816x ISO7816 instance.
1171 * @retval None.
1172 */
ll_iso7816_clear_flag_dma_err(iso7816_regs_t * ISO7816x)1173 __STATIC_INLINE void ll_iso7816_clear_flag_dma_err(iso7816_regs_t *ISO7816x)
1174 {
1175 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_DMA_EC);
1176 }
1177
1178 /**
1179 * @brief Clear retry error flag.
1180 *
1181 * Register|BitsName
1182 * --------|--------
1183 * CTRL | CTRL_RETRY_ERR
1184 *
1185 * @param ISO7816x ISO7816 instance.
1186 * @retval None.
1187 */
ll_iso7816_clear_flag_retry_err(iso7816_regs_t * ISO7816x)1188 __STATIC_INLINE void ll_iso7816_clear_flag_retry_err(iso7816_regs_t *ISO7816x)
1189 {
1190 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_RETYR_EC);
1191 }
1192
1193 /**
1194 * @brief Clear RX error flag.
1195 *
1196 * Register|BitsName
1197 * --------|--------
1198 * CTRL | CTRL_RX_ERR
1199 *
1200 * @param ISO7816x ISO7816 instance.
1201 * @retval None.
1202 */
ll_iso7816_clear_flag_rx_err(iso7816_regs_t * ISO7816x)1203 __STATIC_INLINE void ll_iso7816_clear_flag_rx_err(iso7816_regs_t *ISO7816x)
1204 {
1205 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_RX_EC);
1206 }
1207
1208 /**
1209 * @brief Clear done flag.
1210 *
1211 * Register|BitsName
1212 * --------|--------
1213 * CTRL | CTRL_DONE
1214 *
1215 * @param ISO7816x ISO7816 instance.
1216 * @retval None.
1217 */
ll_iso7816_clear_flag_done(iso7816_regs_t * ISO7816x)1218 __STATIC_INLINE void ll_iso7816_clear_flag_done(iso7816_regs_t *ISO7816x)
1219 {
1220 WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_DONE_CLR);
1221 }
1222
1223 /** @} */
1224
1225 /** @defgroup ISO7816_LL_Init ISO7816 Initialization and de-initialization functions
1226 * @{
1227 */
1228
1229 /**
1230 * @brief Initialize the ISO7816 registers according to the specified parameters in p_iso7816_init.
1231 * @param ISO7816x ISO7816 instance.
1232 * @param p_iso7816_init pointer to a @ref ll_iso7816_init_t structure.
1233 * @retval An ErrorStatus enumeration value:
1234 * - SUCCESS: ISO7816 registers are initialized
1235 * - ERROR: Not applicable
1236 */
1237 error_status_t ll_iso7816_init(iso7816_regs_t *ISO7816x, ll_iso7816_init_t *p_iso7816_init);
1238
1239 /**
1240 * @brief De-initialize the ISO7816 registers to their default reset values.
1241 * @param ISO7816x ISO7816 instance.
1242 * @retval An ErrorStatus enumeration value:
1243 * - SUCCESS: ISO7816 registers are de-initialized
1244 * - ERROR: ISO7816 registers are not de-initialized
1245 */
1246 error_status_t ll_iso7816_deinit(iso7816_regs_t *ISO7816x);
1247
1248 /** @} */
1249 /** @} */
1250
1251 #endif /* ISO7816 */
1252
1253 #ifdef __cplusplus
1254 }
1255 #endif
1256
1257 #endif /* __GR55xx_LL_ISO7816_H__ */
1258
1259 /** @} */
1260
1261 /** @} */
1262
1263 /** @} */
1264
1265