gr55xx_ll_iso7816.h
Go to the documentation of this file.
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 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
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 {
75  uint32_t clk_div; /*!< clk_div is used for dividing the system clock,
76  and ISO7816 output clock is equal to (system clock)/(clk_div+1).*/
77  uint32_t wait_time; /*!< Specifies the guard time value in terms of number of baud clocks */
78  uint16_t guard_time; /*!< Specifies the maximum card response time (leading edge to leading edge) */
79  uint8_t detect_coding; /*!< Specifies whether automatically detect coding convention during ATR receiption. */
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 
208 /* Private types -------------------------------------------------------------*/
209 /* Private variables ---------------------------------------------------------*/
210 /* Private constants ---------------------------------------------------------*/
211 /* Private macros ------------------------------------------------------------*/
212 /* Exported functions --------------------------------------------------------*/
213 /** @defgroup ISO7816_LL_DRIVER_FUNCTIONS Functions
214  * @{
215  */
216 
217 /** @defgroup ISO7816_LL_EF_Configuration Configuration
218  * @{
219  */
220 /**
221  * @brief Request ISO7816 to go to the next action.
222  *
223  * Register|BitsName
224  * --------|--------
225  * CTRL | ACTION
226  *
227  * @param ISO7816x ISO7816 instance.
228  * @param action This parameter can be one of the following values:
229  * @arg @ref LL_ISO7816_ACTION_NONE
230  * @arg @ref LL_ISO7816_ACTION_OFF
231  * @arg @ref LL_ISO7816_ACTION_STOPCLK
232  * @arg @ref LL_ISO7816_ACTION_ON
233  * @arg @ref LL_ISO7816_ACTION_WARMRST
234  * @arg @ref LL_ISO7816_ACTION_RX
235  * @arg @ref LL_ISO7816_ACTION_TX
236  * @arg @ref LL_ISO7816_ACTION_TXRX
237  * @retval None.
238  */
239 __STATIC_INLINE void ll_iso7816_set_action(iso7816_regs_t *ISO7816x, uint32_t action)
240 {
241  WRITE_REG(ISO7816x->CTRL, action);
242 }
243 
244 
245 /**
246  * @brief Get ISO7816 states.
247  *
248  * Register|BitsName
249  * --------|--------
250  * CTRL | ACTION
251  *
252  * @param ISO7816x ISO7816 instance.
253  * @retval ISO7816 states
254  */
255 __STATIC_INLINE uint32_t ll_iso7816_is_busy(iso7816_regs_t *ISO7816x)
256 {
257  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_BUSY) == (ISO7816_STAT_BUSY));
258 }
259 
260 /**
261  * @brief Clear Transmit Retries Maximum.
262  *
263  * Register|BitsName
264  * --------|--------
265  * CTRL | TX_RETRY_MAX_CLR
266  *
267  * @param ISO7816x ISO7816 instance.
268  * @retval None.
269  */
270 __STATIC_INLINE void ll_iso7816_clear_tx_retry_max(iso7816_regs_t *ISO7816x)
271 {
272  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_TX_RETYR_MC);
273 }
274 
275 /**
276  * @brief Clear Receive Retries Maximum.
277  *
278  * Register|BitsName
279  * --------|--------
280  * CTRL | RX_RETRY_MAX_CLR
281  *
282  * @param ISO7816x ISO7816 instance.
283  * @retval None.
284  */
285 __STATIC_INLINE void ll_iso7816_clear_rx_retry_max(iso7816_regs_t *ISO7816x)
286 {
287  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_RX_RETYR_MC);
288 }
289 
290 /**
291  * @brief Check Card presence.
292  *
293  * Register|BitsName
294  * --------|--------
295  * STAT | PRESENCE
296  *
297  * @param ISO7816x ISO7816 instance.
298  * @retval Returned value can be one of the following values:
299  * @arg @ref LL_ISO7816_CARD_ABSENT
300  * @arg @ref LL_ISO7816_CARD_PRESENT
301  */
302 __STATIC_INLINE uint32_t ll_iso7816_check_card_presence(iso7816_regs_t *ISO7816x)
303 {
304  return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_PRESENCE_STAT) >> ISO7816_STAT_PRESENCE_STAT_POS);
305 }
306 
307 /**
308  * @brief Get Maximum number of seen transmit retries after error signaling by ISO7816.
309  *
310  * Register|BitsName
311  * --------|--------
312  * STAT | TX_RETRY_MAX
313  *
314  * @param ISO7816x ISO7816 instance.
315  * @retval Value range between 0x1 and 0x7.
316  */
317 __STATIC_INLINE uint32_t ll_iso7816_get_tx_retry_max(iso7816_regs_t *ISO7816x)
318 {
319  return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_TX_RETRY_MAX) >> ISO7816_STAT_RX_RETRY_MAX_POS);
320 }
321 
322 /**
323  * @brief Get Maximum number of seen receive retries after error signaling by ISO7816.
324  *
325  * Register|BitsName
326  * --------|--------
327  * STAT | RX_RETRY_MAX
328  *
329  * @param ISO7816x ISO7816 instance.
330  * @retval Value range between 0x1 and 0x7.
331  */
332 __STATIC_INLINE uint32_t ll_iso7816_get_rx_retry_max(iso7816_regs_t *ISO7816x)
333 {
334  return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_RX_RETRY_MAX) >> ISO7816_STAT_RX_RETRY_MAX_POS);
335 }
336 
337 /**
338  * @brief Get ISO7816 IO States.
339  *
340  * Register|BitsName
341  * --------|--------
342  * STAT | IO_STATE
343  *
344  * @param ISO7816x ISO7816 instance.
345  * @retval Returned value can be one or combination of the following values:
346  * @arg @ref LL_ISO7816_IO_STATE_OFF
347  * @arg @ref LL_ISO7816_IO_STATE_IDLE
348  * @arg @ref LL_ISO7816_IO_STATE_RX_WAIT
349  * @arg @ref LL_ISO7816_IO_STATE_RX
350  * @arg @ref LL_ISO7816_IO_STATE_TX
351  * @arg @ref LL_ISO7816_IO_STATE_TX_GUARD
352  */
353 __STATIC_INLINE uint32_t ll_iso7816_get_io_states(iso7816_regs_t *ISO7816x)
354 {
355  return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_IO_STAT) >> ISO7816_STAT_IO_STAT_POS);
356 }
357 
358 /**
359  * @brief Get ISO7816 Power States.
360  *
361  * Register|BitsName
362  * --------|--------
363  * STAT | PWR_STATE
364  *
365  * @param ISO7816x ISO7816 instance.
366  * @retval Returned value can be one of the following values:
367  * @arg @ref LL_ISO7816_PWR_STATE_OFF
368  * @arg @ref LL_ISO7816_PWR_STATE_PWRUP_VCC
369  * @arg @ref LL_ISO7816_PWR_STATE_PWRUP_RST
370  * @arg @ref LL_ISO7816_PWR_STATE_PWRDN_RST
371  * @arg @ref LL_ISO7816_PWR_STATE_PWRDN_VCC
372  * @arg @ref LL_ISO7816_PWR_STATE_STOP_PRE
373  * @arg @ref LL_ISO7816_PWR_STATE_STOP
374  * @arg @ref LL_ISO7816_PWR_STATE_STOP_POST
375  * @arg @ref LL_ISO7816_PWR_STATE_IDLE
376  * @arg @ref LL_ISO7816_PWR_STATE_RX_TS0
377  * @arg @ref LL_ISO7816_PWR_STATE_RX_TS1
378  * @arg @ref LL_ISO7816_PWR_STATE_RX
379  * @arg @ref LL_ISO7816_PWR_STATE_TX
380  * @arg @ref LL_ISO7816_PWR_STATE_TX_RX
381  */
382 __STATIC_INLINE uint32_t ll_iso7816_get_power_states(iso7816_regs_t *ISO7816x)
383 {
384  return (uint32_t)(READ_BITS(ISO7816x->STAT, ISO7816_STAT_PWR_STAT));
385 }
386 
387 /**
388  * @brief Set value of the clock output during stopped Clock.
389  *
390  * Register|BitsName
391  * --------|--------
392  * CLK_CFG | CLK_STOP_SEL
393  *
394  * @param ISO7816x ISO7816 instance.
395  * @param level This parameter can be one of the following values:
396  * @arg @ref LL_ISO7816_CLKSTOP_LOW
397  * @arg @ref LL_ISO7816_CLKSTOP_HIGH
398  * @retval None.
399  */
400 __STATIC_INLINE void ll_iso7816_set_clkstop_level(iso7816_regs_t *ISO7816x, uint32_t level)
401 {
402  MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_STOP_SEL, level);
403 }
404 
405 /**
406  * @brief Get value of the clock output during stopped Clock.
407  *
408  * Register|BitsName
409  * --------|--------
410  * CLK_CFG | CLK_STOP_SEL
411  *
412  * @param ISO7816x ISO7816 instance.
413  * @retval Returned value can be one of the following values:
414  * @arg @ref LL_ISO7816_CLKSTOP_LOW
415  * @arg @ref LL_ISO7816_CLKSTOP_HIGH
416  */
417 __STATIC_INLINE uint32_t ll_iso7816_get_clkstop_level(iso7816_regs_t *ISO7816x)
418 {
419  return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_STOP_SEL));
420 }
421 
422 /**
423  * @brief Set clock division.
424  * @note Divide system clock by this value+1.
425  *
426  * Register|BitsName
427  * --------|--------
428  * CLK_CFG | CLK_DIV
429  *
430  * @param ISO7816x ISO7816 instance
431  * @param value This parameter should range between 0x0 and 0xFF.
432  * @retval None.
433  */
434 __STATIC_INLINE void ll_iso7816_set_clkdiv(iso7816_regs_t *ISO7816x, uint32_t value)
435 {
436  MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_DIV, value << ISO7816_CLK_CFG_CLK_DIV_POS);
437 }
438 
439 /**
440  * @brief Get clock division.
441  *
442  * Register|BitsName
443  * --------|--------
444  * CLK_CFG | CLK_DIV
445  *
446  * @param ISO7816x ISO7816 instance
447  * @retval Returned value should range between 0x0 and 0xFF.
448  */
449 __STATIC_INLINE uint32_t ll_iso7816_get_clkdiv(iso7816_regs_t *ISO7816x)
450 {
451  return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_CLK_DIV) >> ISO7816_CLK_CFG_CLK_DIV_POS);
452 }
453 
454 /**
455  * @brief Set divide ISO7816 clock.
456  * @note Divide SIM clock by this value+1 to define ETU length. The reset value
457  * is the one, needed for theATR.
458  *
459  * Register|BitsName
460  * --------|--------
461  * CLK_CFG | ETU_DIV
462  *
463  * @param ISO7816x ISO7816 instance
464  * @param divide This parameter should range between 0x0 and 0x3FF.
465  * @retval None.
466  */
467 __STATIC_INLINE void ll_iso7816_set_etudiv(iso7816_regs_t *ISO7816x, uint32_t divide)
468 {
469  MODIFY_REG(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_ETU_DIV, divide);
470 }
471 
472 /**
473  * @brief Get divide ISO7816 clock.
474  *
475  * Register|BitsName
476  * --------|--------
477  * CLK_CFG | ETU_DIV
478  *
479  * @param ISO7816x ISO7816 instance
480  * @retval Returned value should range between 0x0 and 0x3FF.
481  */
482 __STATIC_INLINE uint32_t ll_iso7816_get_etudiv(iso7816_regs_t *ISO7816x)
483 {
484  return (uint32_t)(READ_BITS(ISO7816x->CLK_CFG, ISO7816_CLK_CFG_ETU_DIV));
485 }
486 
487 /**
488  * @brief Set ISO7816 wait_time in ETU.
489 
490  * @note Time between the leading edges of two consecutive characters
491  *
492  * Register|BitsName
493  * --------|--------
494  * TIMES | WAIT_TIME
495  *
496  * @param ISO7816x ISO7816 instance
497  * @param wait_time This parameter should range between 0x0 and 0x3FFF.
498  * @retval None.
499  */
500 __STATIC_INLINE void ll_iso7816_set_waittime(iso7816_regs_t *ISO7816x, uint32_t wait_time)
501 {
502  MODIFY_REG(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_WAIT_TIME, wait_time << ISO7816_TIMES_CFG_WAIT_TIME_POS);
503 }
504 
505 /**
506  * @brief Get maximum card response time(leading edge to leading edge)
507  *
508  * Register|BitsName
509  * --------|--------
510  * TIMES | WAIT_TIME
511  *
512  * @param ISO7816x ISO7816 instance
513  * @retval Returned value should range between 0x0 and 0x3FFFF.
514  */
515 __STATIC_INLINE uint32_t ll_iso7816_get_waittime(iso7816_regs_t *ISO7816x)
516 {
517  return (uint32_t)(READ_BITS(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_WAIT_TIME) >> ISO7816_TIMES_CFG_WAIT_TIME_POS);
518 }
519 
520 /**
521  * @brief Set ISO7816 guard_time in ETU.
522 
523  * @note Set time between the leading edges of two consecutive characters
524  *
525  * Register|BitsName
526  * --------|--------
527  * TIMES | GUARD_TIME
528  *
529  * @param ISO7816x ISO7816 instance
530  * @param guardtime Time between the leading edges of two consecutive characters
531  * @retval None.
532  */
533 __STATIC_INLINE void ll_iso7816_set_guardtime(iso7816_regs_t *ISO7816x, uint32_t guardtime)
534 {
535  MODIFY_REG(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_GUARD_TIME, guardtime);
536 }
537 /**
538  * @brief Get time between the leading edges of two consecutive characters.
539  *
540  * Register|BitsName
541  * --------|--------
542  * TIMES | GUARDTIME
543  *
544  * @param ISO7816x ISO7816 instance
545  * @retval Returned value should range between 0x0 and 0x3FF.
546  */
547 __STATIC_INLINE uint32_t ll_iso7816_get_guardtime(iso7816_regs_t *ISO7816x)
548 {
549  return (uint32_t)(READ_BITS(ISO7816x->TIMES_CFG, ISO7816_TIMES_CFG_GUARD_TIME));
550 }
551 
552 /**
553  * @brief Set maximum number of issued retries before giving up.
554  *
555  * Register|BitsName
556  * --------|--------
557  * DATA_CFG| RETRY_LIMIT
558  *
559  * @param ISO7816x ISO7816 instance
560  * @param number This parameter should range between 0x0 and 0x7.
561  * @retval None.
562  */
563 __STATIC_INLINE void ll_iso7816_set_retry_limit(iso7816_regs_t *ISO7816x, uint32_t number)
564 {
565  MODIFY_REG(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_RETRY_LIMIT, number << ISO7816_DATA_CFG_RETRY_LIMIT_POS);
566 }
567 
568 /**
569  * @brief Get maximum number of issued retries before giving up.
570  *
571  * Register|BitsName
572  * --------|--------
573  * DATA_CFG| RETRY_LIMIT
574  *
575  * @param ISO7816x ISO7816 instance
576  * @retval Returned value should range between 0x0 and 0x7.
577  */
578 __STATIC_INLINE uint32_t ll_iso7816_get_retry_limit(iso7816_regs_t *ISO7816x)
579 {
580  return (uint32_t)(READ_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_RETRY_LIMIT) >> ISO7816_DATA_CFG_RETRY_LIMIT_POS);
581 }
582 
583 /**
584  * @brief Enable coding detection.
585  *
586  * Register|BitsName
587  * --------|--------
588  * DATA_CFG| DETECT_CODING
589  *
590  * @param ISO7816x ISO7816 instance.
591  * @retval None.
592  */
593 __STATIC_INLINE void ll_iso7816_enable_coding_detection(iso7816_regs_t *ISO7816x)
594 {
595  SET_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_DETECT_CODING);
596 }
597 
598 /**
599  * @brief Disable coding detection.
600  *
601  * Register|BitsName
602  * --------|--------
603  * DATA_CFG| DETECT_CODING
604  *
605  * @param ISO7816x ISO7816 instance.
606  * @retval None.
607  */
608 __STATIC_INLINE void ll_iso7816_disable_coding_detection(iso7816_regs_t *ISO7816x)
609 {
610  CLEAR_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_DETECT_CODING);
611 }
612 
613 /**
614  * @brief Set coding convention.
615  *
616  * Register|BitsName
617  * --------|--------
618  * DATA_CFG| CODING
619  *
620  * @param ISO7816x ISO7816 instance.
621  * @param convention This parameter can be one of the following values:
622  * @arg @ref LL_ISO7816_CODING_DEFAULT
623  * @arg @ref LL_ISO7816_CODING_INVERSE
624  * @retval None.
625  */
626 __STATIC_INLINE void ll_iso7816_set_coding_convention(iso7816_regs_t *ISO7816x, uint32_t convention)
627 {
628  MODIFY_REG(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_CODING, convention);
629 }
630 
631 /**
632  * @brief Get coding convention.
633  *
634  * Register|BitsName
635  * --------|--------
636  * DATA_CFG| CODING
637  *
638  * @param ISO7816x ISO7816 instance
639  * @retval Returned value can be one of the following values:
640  * @arg @ref LL_ISO7816_CODING_DEFAULT
641  * @arg @ref LL_ISO7816_CODING_INVERSE
642  */
643 __STATIC_INLINE uint32_t ll_iso7816_get_coding_convention(iso7816_regs_t *ISO7816x)
644 {
645  return (uint32_t)(READ_BITS(ISO7816x->DATA_CFG, ISO7816_DATA_CFG_CODING));
646 }
647 
648 /**
649  * @brief Get current address relative to base_addr.
650  *
651  * Register|BitsName
652  * --------|--------
653  * ADDR | ADDR
654  *
655  * @param ISO7816x ISO7816 instance
656  * @retval Value between 0x0 and 0x3FFFF.
657  */
658 __STATIC_INLINE uint32_t ll_iso7816_get_current_addr(iso7816_regs_t *ISO7816x)
659 {
660  return (uint32_t)(READ_BITS(ISO7816x->ADDR, ISO7816_ADDR_ADDR) >> ISO7816_ADDR_ADDR_POS);
661 }
662 
663 /**
664  * @brief Get address fraction.
665  *
666  * Register|BitsName
667  * --------|--------
668  * ADDR | ADDR_FRAC
669  *
670  * @param ISO7816x ISO7816 instance
671  * @retval Value between 0x0 and 0x3.
672  */
673 __STATIC_INLINE uint32_t ll_iso7816_get_current_addr_frac(iso7816_regs_t *ISO7816x)
674 {
675  return (uint32_t)(READ_BITS(ISO7816x->ADDR, ISO7816_ADDR_ADDR_FRAC));
676 }
677 
678 /**
679  * @brief Set start address for RX and TX buffer.
680  *
681  * Register |BitsName
682  * ---------|--------
683  * STRT_ADDR| BASE_ADDR+START_ADDR
684  *
685  * @param ISO7816x ISO7816 instance
686  * @param addr This parameter should range between 0x0 and 0xFFFFFFFF.
687  * @retval None.
688  */
689 __STATIC_INLINE void ll_iso7816_set_buffer_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
690 {
691  WRITE_REG(ISO7816x->START_ADDR, addr);
692 }
693 
694 /**
695  * @brief Get start address for RX and TX buffer.
696  *
697  * Register |BitsName
698  * ---------|--------
699  * STRT_ADDR| BASE_ADDR+START_ADDR
700  *
701  * @param ISO7816x ISO7816 instance
702  */
703 __STATIC_INLINE uint32_t ll_iso7816_get_buffer_addr(iso7816_regs_t *ISO7816x)
704 {
705  return (uint32_t)(READ_REG(ISO7816x->START_ADDR));
706 }
707 
708 /**
709  * @brief Set base address for RX and TX buffer.
710  *
711  * Register |BitsName
712  * ---------|--------
713  * STRT_ADDR| BASE_ADDR
714  *
715  * @param ISO7816x ISO7816 instance
716  * @param addr This parameter should range between 0x0 and 0xFFF.
717  * @retval None.
718  */
719 __STATIC_INLINE void ll_iso7816_set_base_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
720 {
721  MODIFY_REG(ISO7816x->START_ADDR, ISO7816_START_ADDR_BASE_ADDR, addr << ISO7816_START_ADDR_BASE_ADDR_POS);
722 }
723 
724 /**
725  * @brief Get base address for RX and TX buffer.
726  *
727  * Register |BitsName
728  * ---------|--------
729  * STRT_ADDR| BASE_ADDR
730  *
731  * @param ISO7816x ISO7816 instance
732  * @retval Value between 0x0 and 0xFFF.
733  */
734 __STATIC_INLINE uint32_t ll_iso7816_get_base_addr(iso7816_regs_t *ISO7816x)
735 {
736  return (uint32_t)(READ_BITS(ISO7816x->START_ADDR, ISO7816_START_ADDR_BASE_ADDR) >> ISO7816_START_ADDR_BASE_ADDR_POS);
737 }
738 
739 /**
740  * @brief Set start address for RX and TX buffer, relative to base_addr.
741  *
742  * Register |BitsName
743  * ---------|--------
744  * STRT_ADDR| STRT_ADDR
745  *
746  * @param ISO7816x ISO7816 instance
747  * @param addr This parameter should range between 0x0 and 0x3FFFF.
748  * @retval None.
749  */
750 __STATIC_INLINE void ll_iso7816_set_start_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
751 {
752  MODIFY_REG(ISO7816x->START_ADDR, ISO7816_START_ADDR_START_ADDR, addr << ISO7816_START_ADDR_START_ADDR_POS);
753 }
754 
755 /**
756  * @brief Get start address for RX and TX buffer, relative to base_addr.
757  *
758  * Register |BitsName
759  * ---------|--------
760  * STRT_ADDR| STRT_ADDR
761  *
762  * @param ISO7816x ISO7816 instance
763  * @retval Value between 0x0 and 0x3FFFF.
764  */
765 __STATIC_INLINE uint32_t ll_iso7816_get_start_addr(iso7816_regs_t *ISO7816x)
766 {
767  return (uint32_t)(READ_BITS(ISO7816x->START_ADDR, ISO7816_START_ADDR_START_ADDR) >> 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  */
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  */
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  */
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) >> ISO7816_RX_END_ADDR_RX_END_ADDR_POS);
815 }
816 
817 /**
818  * @brief Set RX end address fraction.
819  *
820  * Register | BitsName
821  * -----------|--------
822  * RX_END_ADDR| RX_END_AF
823  *
824  * @param ISO7816x ISO7816 instance
825  * @param frac This parameter should range between 0x0 and 0x3.
826  * @retval None.
827  */
828 __STATIC_INLINE void ll_iso7816_set_rx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
829 {
830  MODIFY_REG(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_AF, frac);
831 }
832 
833 /**
834  * @brief Set TX endbyte address of buffer, relative to base_addr.
835  *
836  * Register | BitsName
837  * -----------|--------
838  * TX_END_ADDR| TX_END_ADDR+TX_END_AF
839  *
840  * @param ISO7816x ISO7816 instance
841  * @param addr This parameter should range between 0x0 and 0x3FFFF.
842  * @retval None.
843  */
844 __STATIC_INLINE void ll_iso7816_set_tx_endbyte_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
845 {
846  WRITE_REG(ISO7816x->TX_END_ADDR, addr);
847 }
848 
849 /**
850  * @brief Get TX endbyte address of buffer, relative to base_addr.
851  *
852  * Register | BitsName
853  * -----------|--------
854  * TX_END_ADDR| TX_END_ADDR+TX_END_AF
855  *
856  * @param ISO7816x ISO7816 instance
857  * @retval TX endbyte address.
858  */
859 __STATIC_INLINE uint32_t ll_iso7816_get_tx_endbyte_addr(iso7816_regs_t *ISO7816x)
860 {
861  return READ_REG(ISO7816x->TX_END_ADDR);
862 }
863 
864 /**
865  * @brief Get RX endbyte address of buffer, relative to base_addr.
866  *
867  * Register | BitsName
868  * -----------|--------
869  * TX_END_ADDR| TX_END_ADDR+TX_END_AF
870  *
871  * @param ISO7816x ISO7816 instance
872  * @retval RX endbyte address.
873  */
874 __STATIC_INLINE uint32_t ll_iso7816_get_rx_endbyte_addr(iso7816_regs_t *ISO7816x)
875 {
876  return READ_REG(ISO7816x->RX_END_ADDR);
877 }
878 
879 /**
880  * @brief Get RX end address fraction.
881  *
882  * Register | BitsName
883  * -----------|--------
884  * RX_END_ADDR| RX_END_AF
885  *
886  * @param ISO7816x ISO7816 instance
887  * @retval Value between 0x0 and 0x3.
888  */
889 __STATIC_INLINE uint32_t ll_iso7816_get_rx_end_addr_frac(iso7816_regs_t *ISO7816x)
890 {
891  return (uint32_t)(READ_BITS(ISO7816x->RX_END_ADDR, ISO7816_RX_END_ADDR_RX_END_AF));
892 }
893 
894 /**
895  * @brief Set end address of transmit buffer, relative to base_addr.
896  *
897  * Register | BitsName
898  * -----------|--------
899  * TX_END_ADDR| TX_END_ADDR
900  *
901  * @param ISO7816x ISO7816 instance
902  * @param addr This parameter should range between 0x0 and 0x3FFFF.
903  * @retval None.
904  */
905 __STATIC_INLINE void ll_iso7816_set_tx_end_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
906 {
907  MODIFY_REG(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_ADDR, addr << ISO7816_TX_END_ADDR_TX_END_ADDR_POS);
908 }
909 
910 /**
911  * @brief Get end address of transmit buffer, relative to base_addr.
912  *
913  * Register | BitsName
914  * -----------|--------
915  * TX_END_ADDR| TX_END_ADDR
916  *
917  * @param ISO7816x ISO7816 instance
918  * @retval Value between 0x0 and 0x3FFFF.
919  */
920 __STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr(iso7816_regs_t *ISO7816x)
921 {
922  return (uint32_t)(READ_BITS(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_ADDR) >> ISO7816_TX_END_ADDR_TX_END_ADDR_POS);
923 }
924 
925 /**
926  * @brief Set TX end address fraction.
927  *
928  * Register | BitsName
929  * -----------|--------
930  * TX_END_ADDR| TX_END_AF
931  *
932  * @param ISO7816x ISO7816 instance
933  * @param frac This parameter should range between 0x0 and 0x3.
934  * @retval None.
935  */
936 __STATIC_INLINE void ll_iso7816_set_tx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
937 {
938  MODIFY_REG(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_AF, frac);
939 }
940 
941 /**
942  * @brief Get TX end address fraction.
943  *
944  * Register | BitsName
945  * -----------|--------
946  * TX_END_ADDR| TX_END_AF
947  *
948  * @param ISO7816x ISO7816 instance
949  * @retval Value between 0x0 and 0x3.
950  */
951 __STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr_frac(iso7816_regs_t *ISO7816x)
952 {
953  return (uint32_t)(READ_BITS(ISO7816x->TX_END_ADDR, ISO7816_TX_END_ADDR_TX_END_AF));
954 }
955 
956 /** @} */
957 
958 /** @defgroup ISO7816_LL_EF_IT_Management IT_Management
959  * @{
960  */
961 
962 /**
963  * @brief Get ISO7816 interrupt flags
964  *
965  * Register|BitsName
966  * --------|--------
967  * STAT | STAT_TEST
968  * STAT | STAT_PRESENCE
969  * STAT | STAT_STATE_ERR
970  * STAT | STAT_DMA_ERR
971  * STAT | STAT_RETRY_ERR
972  * STAT | STAT_RX_ERR
973  * STAT | STAT_DONE
974  *
975  * @param ISO7816x ISO7816 instance.
976  * @retval Returned value can be one or combination of the following values:
977  * @arg @ref LL_ISO7816_INTR_TEST
978  * @arg @ref LL_ISO7816_INTR_PRESENCE
979  * @arg @ref LL_ISO7816_INTR_STATE_ERR
980  * @arg @ref LL_ISO7816_INTR_DMA_ERR
981  * @arg @ref LL_ISO7816_INTR_RETRY_ERR
982  * @arg @ref LL_ISO7816_INTR_RX_ERR
983  * @arg @ref LL_ISO7816_INTR_DONE
984 */
985 __STATIC_INLINE uint32_t ll_iso7816_get_it_flag(iso7816_regs_t *ISO7816x)
986 {
987  return (uint32_t)(READ_REG(ISO7816x->STAT) & ISO7816_INTR_ALL);
988 }
989 
990 /**
991  * @brief Indicate the status of STAT_TEST flag.
992  *
993  * Register|BitsName
994  * --------|--------
995  * STAT | STAT_TEST
996  *
997  * @param ISO7816x ISO7816 instance.
998  * @retval State of bit (1 or 0).
999  */
1000 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_test(iso7816_regs_t *ISO7816x)
1001 {
1002  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_TEST) == (ISO7816_STAT_IRQ_TEST));
1003 }
1004 
1005 /**
1006  * @brief Indicate the status of STAT_PRESENCE flag.
1007  *
1008  * Register|BitsName
1009  * --------|--------
1010  * STAT | STAT_PRESENCE
1011  *
1012  * @param ISO7816x ISO7816 instance.
1013  * @retval State of bit (1 or 0).
1014  */
1015 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_presence(iso7816_regs_t *ISO7816x)
1016 {
1017  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_PRESENCE) == (ISO7816_STAT_IRQ_PRESENCE));
1018 }
1019 
1020 /**
1021  * @brief Indicate the status of STAT_STATE_ERR flag.
1022  *
1023  * Register|BitsName
1024  * --------|--------
1025  * STAT | STAT_STATE_ERR
1026  *
1027  * @param ISO7816x ISO7816 instance.
1028  * @retval State of bit (1 or 0).
1029  */
1030 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_state_err(iso7816_regs_t *ISO7816x)
1031 {
1032  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_STAT_ERR) == (ISO7816_STAT_IRQ_STAT_ERR));
1033 }
1034 
1035 /**
1036  * @brief Indicate the status of STAT_DMA_ERR flag.
1037  *
1038  * Register|BitsName
1039  * --------|--------
1040  * STAT | STAT_DMA_ERR
1041  *
1042  * @param ISO7816x ISO7816 instance.
1043  * @retval State of bit (1 or 0).
1044  */
1045 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_dma_err(iso7816_regs_t *ISO7816x)
1046 {
1047  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_DMA_ERR) == (ISO7816_STAT_IRQ_DMA_ERR));
1048 }
1049 
1050 /**
1051  * @brief Indicate the status of STAT_RETRY_ERR flag.
1052  *
1053  * Register|BitsName
1054  * --------|--------
1055  * STAT | STAT_RETRY_ERR
1056  *
1057  * @param ISO7816x ISO7816 instance.
1058  * @retval State of bit (1 or 0).
1059  */
1060 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_retry_err(iso7816_regs_t *ISO7816x)
1061 {
1062  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_RETRY_ERR) == (ISO7816_STAT_IRQ_RETRY_ERR));
1063 }
1064 
1065 /**
1066  * @brief Indicate the status of STAT_RX_ERR flag.
1067  *
1068  * Register|BitsName
1069  * --------|--------
1070  * STAT | STAT_RX_ERR
1071  *
1072  * @param ISO7816x ISO7816 instance.
1073  * @retval State of bit (1 or 0).
1074  */
1075 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_rx_err(iso7816_regs_t *ISO7816x)
1076 {
1077  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_RX_ERR) == (ISO7816_STAT_IRQ_RX_ERR));
1078 }
1079 
1080 /**
1081  * @brief Indicate the status of STAT_DONE flag.
1082  *
1083  * Register|BitsName
1084  * --------|--------
1085  * STAT | STAT_DONE
1086  *
1087  * @param ISO7816x ISO7816 instance.
1088  * @retval State of bit (1 or 0).
1089  */
1090 __STATIC_INLINE uint32_t ll_iso7816_is_active_flag_done(iso7816_regs_t *ISO7816x)
1091 {
1092  return (READ_BITS(ISO7816x->STAT, ISO7816_STAT_IRQ_DONE) == (ISO7816_STAT_IRQ_DONE));
1093 }
1094 
1095 /**
1096  * @brief Clear the combined interrupt, all individual interrupts, and the STAT register
1097  *
1098  * Register|BitsName
1099  * --------|--------
1100  * STAT | STAT_TEST
1101  * STAT | STAT_PRESENCE
1102  * STAT | STAT_STATE_ERR
1103  * STAT | STAT_DMA_ERR
1104  * STAT | STAT_RETRY_ERR
1105  * STAT | STAT_RX_ERR
1106  * STAT | STAT_DONE
1107  *
1108  * @param ISO7816x ISO7816 instance.
1109  * @retval None.
1110  */
1111 __STATIC_INLINE void ll_iso7816_clear_flag_all_intr(iso7816_regs_t *ISO7816x)
1112 {
1113  WRITE_REG(ISO7816x->CTRL, ISO7816_INTR_ALL);
1114 }
1115 
1116 /**
1117  * @brief Clear test flag.
1118  *
1119  * Register|BitsName
1120  * --------|--------
1121  * CTRL | CTRL_TEST
1122  *
1123  * @param ISO7816x ISO7816 instance.
1124  * @retval None.
1125  */
1126 __STATIC_INLINE void ll_iso7816_clear_flag_test(iso7816_regs_t *ISO7816x)
1127 {
1128  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_TEST_CLR);
1129 }
1130 
1131 /**
1132  * @brief Clear presence flag.
1133  *
1134  * Register|BitsName
1135  * --------|--------
1136  * CTRL | CTRL_PRESENCE
1137  *
1138  * @param ISO7816x ISO7816 instance.
1139  * @retval None.
1140  */
1141 __STATIC_INLINE void ll_iso7816_clear_flag_presence(iso7816_regs_t *ISO7816x)
1142 {
1143  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_PRESENCE_CLR);
1144 }
1145 
1146 /**
1147  * @brief Clear state error flag.
1148  *
1149  * Register|BitsName
1150  * --------|--------
1151  * CTRL | CTRL_STATE_ERR
1152  *
1153  * @param ISO7816x ISO7816 instance.
1154  * @retval None.
1155  */
1156 __STATIC_INLINE void ll_iso7816_clear_flag_state_err(iso7816_regs_t *ISO7816x)
1157 {
1158  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_STAT_EC);
1159 }
1160 
1161 /**
1162  * @brief Clear dma error flag.
1163  *
1164  * Register|BitsName
1165  * --------|--------
1166  * CTRL | CTRL_DMA_ERR
1167  *
1168  * @param ISO7816x ISO7816 instance.
1169  * @retval None.
1170  */
1171 __STATIC_INLINE void ll_iso7816_clear_flag_dma_err(iso7816_regs_t *ISO7816x)
1172 {
1173  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_DMA_EC);
1174 }
1175 
1176 /**
1177  * @brief Clear retry error flag.
1178  *
1179  * Register|BitsName
1180  * --------|--------
1181  * CTRL | CTRL_RETRY_ERR
1182  *
1183  * @param ISO7816x ISO7816 instance.
1184  * @retval None.
1185  */
1186 __STATIC_INLINE void ll_iso7816_clear_flag_retry_err(iso7816_regs_t *ISO7816x)
1187 {
1188  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_RETYR_EC);
1189 }
1190 
1191 /**
1192  * @brief Clear RX error flag.
1193  *
1194  * Register|BitsName
1195  * --------|--------
1196  * CTRL | CTRL_RX_ERR
1197  *
1198  * @param ISO7816x ISO7816 instance.
1199  * @retval None.
1200  */
1201 __STATIC_INLINE void ll_iso7816_clear_flag_rx_err(iso7816_regs_t *ISO7816x)
1202 {
1203  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_RX_EC);
1204 }
1205 
1206 /**
1207  * @brief Clear done flag.
1208  *
1209  * Register|BitsName
1210  * --------|--------
1211  * CTRL | CTRL_DONE
1212  *
1213  * @param ISO7816x ISO7816 instance.
1214  * @retval None.
1215  */
1216 __STATIC_INLINE void ll_iso7816_clear_flag_done(iso7816_regs_t *ISO7816x)
1217 {
1218  WRITE_REG(ISO7816x->CTRL, ISO7816_CTRL_IRQ_DONE_CLR);
1219 }
1220 
1221 /** @} */
1222 
1223 
1224 /** @defgroup ISO7816_LL_Init ISO7816 Initialization and de-initialization functions
1225  * @{
1226  */
1227 
1228 /**
1229  * @brief Initialize the ISO7816 registers according to the specified parameters in p_iso7816_init.
1230  * @param ISO7816x ISO7816 instance.
1231  * @param p_iso7816_init pointer to a @ref ll_iso7816_init_t structure.
1232  * @retval An ErrorStatus enumeration value:
1233  * - SUCCESS: ISO7816 registers are initialized
1234  * - ERROR: Not applicable
1235  */
1236 error_status_t ll_iso7816_init(iso7816_regs_t *ISO7816x, ll_iso7816_init_t *p_iso7816_init);
1237 
1238 /**
1239  * @brief De-initialize the ISO7816 registers to their default reset values.
1240  * @param ISO7816x ISO7816 instance.
1241  * @retval An ErrorStatus enumeration value:
1242  * - SUCCESS: ISO7816 registers are de-initialized
1243  * - ERROR: ISO7816 registers are not de-initialized
1244  */
1245 error_status_t ll_iso7816_deinit(iso7816_regs_t *ISO7816x);
1246 
1247 /** @} */
1248 /** @} */
1249 
1250 #endif /* ISO7816 */
1251 
1252 #ifdef __cplusplus
1253 }
1254 #endif
1255 
1256 #endif /* __GR55xx_LL_ISO7816_H__ */
1257 
1258 /** @} */
1259 
1260 /** @} */
1261 
1262 /** @} */
1263 
ll_iso7816_get_tx_retry_max
__STATIC_INLINE uint32_t ll_iso7816_get_tx_retry_max(iso7816_regs_t *ISO7816x)
Get Maximum number of seen transmit retries after error signaling by ISO7816.
Definition: gr55xx_ll_iso7816.h:317
ll_iso7816_get_it_flag
__STATIC_INLINE uint32_t ll_iso7816_get_it_flag(iso7816_regs_t *ISO7816x)
Get ISO7816 interrupt flags.
Definition: gr55xx_ll_iso7816.h:985
_ll_iso7816_init::detect_coding
uint8_t detect_coding
Definition: gr55xx_ll_iso7816.h:79
ll_iso7816_clear_flag_all_intr
__STATIC_INLINE void ll_iso7816_clear_flag_all_intr(iso7816_regs_t *ISO7816x)
Clear the combined interrupt, all individual interrupts, and the STAT register.
Definition: gr55xx_ll_iso7816.h:1111
ll_iso7816_get_tx_endbyte_addr
__STATIC_INLINE uint32_t ll_iso7816_get_tx_endbyte_addr(iso7816_regs_t *ISO7816x)
Get TX endbyte address of buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:859
ll_iso7816_get_current_addr_frac
__STATIC_INLINE uint32_t ll_iso7816_get_current_addr_frac(iso7816_regs_t *ISO7816x)
Get address fraction.
Definition: gr55xx_ll_iso7816.h:673
ll_iso7816_clear_flag_retry_err
__STATIC_INLINE void ll_iso7816_clear_flag_retry_err(iso7816_regs_t *ISO7816x)
Clear retry error flag.
Definition: gr55xx_ll_iso7816.h:1186
ll_iso7816_is_active_flag_retry_err
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_retry_err(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_RETRY_ERR flag.
Definition: gr55xx_ll_iso7816.h:1060
ll_iso7816_set_tx_end_addr
__STATIC_INLINE void ll_iso7816_set_tx_end_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set end address of transmit buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:905
_ll_iso7816_init
ISO7816_LL_init_structure LL ISO7816 init Structure definition.
Definition: gr55xx_ll_iso7816.h:74
ll_iso7816_is_active_flag_state_err
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_state_err(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_STATE_ERR flag.
Definition: gr55xx_ll_iso7816.h:1030
ll_iso7816_set_coding_convention
__STATIC_INLINE void ll_iso7816_set_coding_convention(iso7816_regs_t *ISO7816x, uint32_t convention)
Set coding convention.
Definition: gr55xx_ll_iso7816.h:626
ll_iso7816_get_start_addr
__STATIC_INLINE uint32_t ll_iso7816_get_start_addr(iso7816_regs_t *ISO7816x)
Get start address for RX and TX buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:765
ll_iso7816_get_buffer_addr
__STATIC_INLINE uint32_t ll_iso7816_get_buffer_addr(iso7816_regs_t *ISO7816x)
Get start address for RX and TX buffer.
Definition: gr55xx_ll_iso7816.h:703
ll_iso7816_get_coding_convention
__STATIC_INLINE uint32_t ll_iso7816_get_coding_convention(iso7816_regs_t *ISO7816x)
Get coding convention.
Definition: gr55xx_ll_iso7816.h:643
ll_iso7816_clear_flag_rx_err
__STATIC_INLINE void ll_iso7816_clear_flag_rx_err(iso7816_regs_t *ISO7816x)
Clear RX error flag.
Definition: gr55xx_ll_iso7816.h:1201
ll_iso7816_set_action
__STATIC_INLINE void ll_iso7816_set_action(iso7816_regs_t *ISO7816x, uint32_t action)
Request ISO7816 to go to the next action.
Definition: gr55xx_ll_iso7816.h:239
ll_iso7816_get_rx_end_addr_frac
__STATIC_INLINE uint32_t ll_iso7816_get_rx_end_addr_frac(iso7816_regs_t *ISO7816x)
Get RX end address fraction.
Definition: gr55xx_ll_iso7816.h:889
ll_iso7816_get_guardtime
__STATIC_INLINE uint32_t ll_iso7816_get_guardtime(iso7816_regs_t *ISO7816x)
Get time between the leading edges of two consecutive characters.
Definition: gr55xx_ll_iso7816.h:547
ll_iso7816_set_base_addr
__STATIC_INLINE void ll_iso7816_set_base_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set base address for RX and TX buffer.
Definition: gr55xx_ll_iso7816.h:719
ll_iso7816_get_waittime
__STATIC_INLINE uint32_t ll_iso7816_get_waittime(iso7816_regs_t *ISO7816x)
Get maximum card response time(leading edge to leading edge)
Definition: gr55xx_ll_iso7816.h:515
ll_iso7816_get_tx_end_addr_frac
__STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr_frac(iso7816_regs_t *ISO7816x)
Get TX end address fraction.
Definition: gr55xx_ll_iso7816.h:951
ll_iso7816_is_active_flag_presence
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_presence(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_PRESENCE flag.
Definition: gr55xx_ll_iso7816.h:1015
ll_iso7816_get_tx_end_addr
__STATIC_INLINE uint32_t ll_iso7816_get_tx_end_addr(iso7816_regs_t *ISO7816x)
Get end address of transmit buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:920
ll_iso7816_set_rx_endbyte_addr
__STATIC_INLINE void ll_iso7816_set_rx_endbyte_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set RX endbyte address of receive buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:797
_ll_iso7816_init::clk_div
uint32_t clk_div
Definition: gr55xx_ll_iso7816.h:75
ll_iso7816_clear_rx_retry_max
__STATIC_INLINE void ll_iso7816_clear_rx_retry_max(iso7816_regs_t *ISO7816x)
Clear Receive Retries Maximum.
Definition: gr55xx_ll_iso7816.h:285
ll_iso7816_is_active_flag_dma_err
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_dma_err(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_DMA_ERR flag.
Definition: gr55xx_ll_iso7816.h:1045
ll_iso7816_deinit
error_status_t ll_iso7816_deinit(iso7816_regs_t *ISO7816x)
De-initialize the ISO7816 registers to their default reset values.
ll_iso7816_get_etudiv
__STATIC_INLINE uint32_t ll_iso7816_get_etudiv(iso7816_regs_t *ISO7816x)
Get divide ISO7816 clock.
Definition: gr55xx_ll_iso7816.h:482
ll_iso7816_is_busy
__STATIC_INLINE uint32_t ll_iso7816_is_busy(iso7816_regs_t *ISO7816x)
Get ISO7816 states.
Definition: gr55xx_ll_iso7816.h:255
ll_iso7816_set_rx_end_addr_frac
__STATIC_INLINE void ll_iso7816_set_rx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
Set RX end address fraction.
Definition: gr55xx_ll_iso7816.h:828
ll_iso7816_set_rx_end_addr
__STATIC_INLINE void ll_iso7816_set_rx_end_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set end address of receive buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:781
ll_iso7816_set_tx_end_addr_frac
__STATIC_INLINE void ll_iso7816_set_tx_end_addr_frac(iso7816_regs_t *ISO7816x, uint32_t frac)
Set TX end address fraction.
Definition: gr55xx_ll_iso7816.h:936
ll_iso7816_get_base_addr
__STATIC_INLINE uint32_t ll_iso7816_get_base_addr(iso7816_regs_t *ISO7816x)
Get base address for RX and TX buffer.
Definition: gr55xx_ll_iso7816.h:734
ll_iso7816_set_waittime
__STATIC_INLINE void ll_iso7816_set_waittime(iso7816_regs_t *ISO7816x, uint32_t wait_time)
Set ISO7816 wait_time in ETU.
Definition: gr55xx_ll_iso7816.h:500
ll_iso7816_get_power_states
__STATIC_INLINE uint32_t ll_iso7816_get_power_states(iso7816_regs_t *ISO7816x)
Get ISO7816 Power States.
Definition: gr55xx_ll_iso7816.h:382
_ll_iso7816_init::guard_time
uint16_t guard_time
Definition: gr55xx_ll_iso7816.h:78
ll_iso7816_clear_flag_test
__STATIC_INLINE void ll_iso7816_clear_flag_test(iso7816_regs_t *ISO7816x)
Clear test flag.
Definition: gr55xx_ll_iso7816.h:1126
ll_iso7816_get_current_addr
__STATIC_INLINE uint32_t ll_iso7816_get_current_addr(iso7816_regs_t *ISO7816x)
Get current address relative to base_addr.
Definition: gr55xx_ll_iso7816.h:658
ll_iso7816_set_tx_endbyte_addr
__STATIC_INLINE void ll_iso7816_set_tx_endbyte_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set TX endbyte address of buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:844
ll_iso7816_set_guardtime
__STATIC_INLINE void ll_iso7816_set_guardtime(iso7816_regs_t *ISO7816x, uint32_t guardtime)
Set ISO7816 guard_time in ETU.
Definition: gr55xx_ll_iso7816.h:533
ll_iso7816_clear_flag_state_err
__STATIC_INLINE void ll_iso7816_clear_flag_state_err(iso7816_regs_t *ISO7816x)
Clear state error flag.
Definition: gr55xx_ll_iso7816.h:1156
ll_iso7816_set_retry_limit
__STATIC_INLINE void ll_iso7816_set_retry_limit(iso7816_regs_t *ISO7816x, uint32_t number)
Set maximum number of issued retries before giving up.
Definition: gr55xx_ll_iso7816.h:563
ll_iso7816_get_rx_endbyte_addr
__STATIC_INLINE uint32_t ll_iso7816_get_rx_endbyte_addr(iso7816_regs_t *ISO7816x)
Get RX endbyte address of buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:874
ll_iso7816_init
error_status_t ll_iso7816_init(iso7816_regs_t *ISO7816x, ll_iso7816_init_t *p_iso7816_init)
Initialize the ISO7816 registers according to the specified parameters in p_iso7816_init.
ll_iso7816_init_t
struct _ll_iso7816_init ll_iso7816_init_t
ISO7816_LL_init_structure LL ISO7816 init Structure definition.
ll_iso7816_clear_flag_presence
__STATIC_INLINE void ll_iso7816_clear_flag_presence(iso7816_regs_t *ISO7816x)
Clear presence flag.
Definition: gr55xx_ll_iso7816.h:1141
ll_iso7816_enable_coding_detection
__STATIC_INLINE void ll_iso7816_enable_coding_detection(iso7816_regs_t *ISO7816x)
Enable coding detection.
Definition: gr55xx_ll_iso7816.h:593
_ll_iso7816_init::wait_time
uint32_t wait_time
Definition: gr55xx_ll_iso7816.h:77
ll_iso7816_set_start_addr
__STATIC_INLINE void ll_iso7816_set_start_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set start address for RX and TX buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:750
ll_iso7816_get_io_states
__STATIC_INLINE uint32_t ll_iso7816_get_io_states(iso7816_regs_t *ISO7816x)
Get ISO7816 IO States.
Definition: gr55xx_ll_iso7816.h:353
ll_iso7816_is_active_flag_rx_err
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_rx_err(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_RX_ERR flag.
Definition: gr55xx_ll_iso7816.h:1075
ll_iso7816_get_clkdiv
__STATIC_INLINE uint32_t ll_iso7816_get_clkdiv(iso7816_regs_t *ISO7816x)
Get clock division.
Definition: gr55xx_ll_iso7816.h:449
ll_iso7816_check_card_presence
__STATIC_INLINE uint32_t ll_iso7816_check_card_presence(iso7816_regs_t *ISO7816x)
Check Card presence.
Definition: gr55xx_ll_iso7816.h:302
ll_iso7816_set_buffer_addr
__STATIC_INLINE void ll_iso7816_set_buffer_addr(iso7816_regs_t *ISO7816x, uint32_t addr)
Set start address for RX and TX buffer.
Definition: gr55xx_ll_iso7816.h:689
ll_iso7816_clear_flag_done
__STATIC_INLINE void ll_iso7816_clear_flag_done(iso7816_regs_t *ISO7816x)
Clear done flag.
Definition: gr55xx_ll_iso7816.h:1216
ll_iso7816_disable_coding_detection
__STATIC_INLINE void ll_iso7816_disable_coding_detection(iso7816_regs_t *ISO7816x)
Disable coding detection.
Definition: gr55xx_ll_iso7816.h:608
ll_iso7816_clear_flag_dma_err
__STATIC_INLINE void ll_iso7816_clear_flag_dma_err(iso7816_regs_t *ISO7816x)
Clear dma error flag.
Definition: gr55xx_ll_iso7816.h:1171
ll_iso7816_set_clkstop_level
__STATIC_INLINE void ll_iso7816_set_clkstop_level(iso7816_regs_t *ISO7816x, uint32_t level)
Set value of the clock output during stopped Clock.
Definition: gr55xx_ll_iso7816.h:400
ll_iso7816_get_rx_retry_max
__STATIC_INLINE uint32_t ll_iso7816_get_rx_retry_max(iso7816_regs_t *ISO7816x)
Get Maximum number of seen receive retries after error signaling by ISO7816.
Definition: gr55xx_ll_iso7816.h:332
ll_iso7816_is_active_flag_done
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_done(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_DONE flag.
Definition: gr55xx_ll_iso7816.h:1090
ll_iso7816_set_clkdiv
__STATIC_INLINE void ll_iso7816_set_clkdiv(iso7816_regs_t *ISO7816x, uint32_t value)
Set clock division.
Definition: gr55xx_ll_iso7816.h:434
ll_iso7816_get_retry_limit
__STATIC_INLINE uint32_t ll_iso7816_get_retry_limit(iso7816_regs_t *ISO7816x)
Get maximum number of issued retries before giving up.
Definition: gr55xx_ll_iso7816.h:578
ll_iso7816_is_active_flag_test
__STATIC_INLINE uint32_t ll_iso7816_is_active_flag_test(iso7816_regs_t *ISO7816x)
Indicate the status of STAT_TEST flag.
Definition: gr55xx_ll_iso7816.h:1000
ll_iso7816_get_clkstop_level
__STATIC_INLINE uint32_t ll_iso7816_get_clkstop_level(iso7816_regs_t *ISO7816x)
Get value of the clock output during stopped Clock.
Definition: gr55xx_ll_iso7816.h:417
ll_iso7816_clear_tx_retry_max
__STATIC_INLINE void ll_iso7816_clear_tx_retry_max(iso7816_regs_t *ISO7816x)
Clear Transmit Retries Maximum.
Definition: gr55xx_ll_iso7816.h:270
ll_iso7816_set_etudiv
__STATIC_INLINE void ll_iso7816_set_etudiv(iso7816_regs_t *ISO7816x, uint32_t divide)
Set divide ISO7816 clock.
Definition: gr55xx_ll_iso7816.h:467
ll_iso7816_get_rx_end_addr
__STATIC_INLINE uint32_t ll_iso7816_get_rx_end_addr(iso7816_regs_t *ISO7816x)
Get RX end address of receive buffer, relative to base_addr.
Definition: gr55xx_ll_iso7816.h:812