lib_iso7816.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. ******************************************************************************
  3. * @file lib_iso7816.h
  4. * @author Application Team
  5. * @version V4.4.0
  6. * @date 2018-09-27
  7. * @brief ISO7816 library.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. ******************************************************************************
  12. */
  13. #ifndef __LIB_ISO7816_H
  14. #define __LIB_ISO7816_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "target.h"
  19. typedef struct
  20. {
  21. uint32_t FirstBit;
  22. uint32_t ACKLen;
  23. uint32_t Parity;
  24. uint32_t Baudrate;
  25. } ISO7816_InitType;
  26. //FirstBit
  27. #define ISO7816_FIRSTBIT_LSB ISO7816_INFO_LSB
  28. #define ISO7816_FIRSTBIT_MSB 0
  29. #define IS_ISO7816_FIRSTBIT(__FIRSTBIT__) (((__FIRSTBIT__) == ISO7816_FIRSTBIT_LSB) ||\
  30. ((__FIRSTBIT__) == ISO7816_FIRSTBIT_MSB))
  31. //ACKLen
  32. #define ISO7816_ACKLEN_1 0
  33. #define ISO7816_ACKLEN_2 ISO7816_CFG_ACKLEN
  34. #define IS_ISO7816_ACKLEN(__ACKLEN__) (((__ACKLEN__) == ISO7816_ACKLEN_1) ||\
  35. ((__ACKLEN__) == ISO7816_ACKLEN_2))
  36. //Parity
  37. #define ISO7816_PARITY_EVEN 0
  38. #define ISO7816_PARITY_ODD ISO7816_CFG_CHKP
  39. #define IS_ISO7816_PARITY(__PARITY__) (((__PARITY__) == ISO7816_PARITY_EVEN) || ((__PARITY__) == ISO7816_PARITY_ODD))
  40. #define IS_ISO7816_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) > 299UL)
  41. #define IS_ISO7816_PRESCALER(__PRESCALER__) (((__PRESCALER__) <= 0x80) && ((__PRESCALER__) > 0U))
  42. //interrupt
  43. #define ISO7816_INT_RXOV ISO7816_CFG_OVIE
  44. #define ISO7816_INT_TX ISO7816_CFG_SDIE
  45. #define ISO7816_INT_RX ISO7816_CFG_RCIE
  46. #define ISO7816_INT_Msk (ISO7816_INT_RXOV \
  47. |ISO7816_INT_TX \
  48. |ISO7816_INT_RX)
  49. #define IS_ISO7816_INT(__INT__) ((((__INT__) & ISO7816_INT_Msk) != 0U) &&\
  50. (((__INT__) & ~ISO7816_INT_Msk) == 0U))
  51. //INTStatus
  52. #define ISO7816_INTSTS_RXOV ISO7816_INFO_OVIF
  53. #define ISO7816_INTSTS_TX ISO7816_INFO_SDIF
  54. #define ISO7816_INTSTS_RX ISO7816_INFO_RCIF
  55. #define ISO7816_INTSTS_Msk (ISO7816_INTSTS_RXOV \
  56. |ISO7816_INTSTS_TX \
  57. |ISO7816_INTSTS_RX)
  58. #define IS_ISO7816_INTFLAGR(__INTFLAG__) (((__INTFLAG__) == ISO7816_INTSTS_RXOV) ||\
  59. ((__INTFLAG__) == ISO7816_INTSTS_TX) ||\
  60. ((__INTFLAG__) == ISO7816_INTSTS_RX))
  61. #define IS_ISO7816_INTFLAGC(__INTFLAG__) ((((__INTFLAG__)&ISO7816_INTSTS_Msk) != 0U) &&\
  62. (((__INTFLAG__)&(~ISO7816_INTSTS_Msk)) == 0U))
  63. //status
  64. #define ISO7816_FLAG_SDERR ISO7816_INFO_SDERR
  65. #define ISO7816_FLAG_RCERR ISO7816_INFO_RCERR
  66. #define ISO7816_FLAG_Msk (ISO7816_FLAG_SDERR|ISO7816_FLAG_RCERR)
  67. #define IS_ISO7816_FLAGR(__FLAG__) (((__FLAG__) == ISO7816_FLAG_SDERR) || ((__FLAG__) == ISO7816_FLAG_RCERR))
  68. #define IS_ISO7816_FLAGC(__FLAG__) ((((__FLAG__) & ISO7816_FLAG_Msk) != 0U) &&\
  69. (((__FLAG__) & (~ISO7816_FLAG_Msk)) == 0U))
  70. /* Exported Functions ------------------------------------------------------- */
  71. void ISO7816_DeInit(ISO7816_TypeDef *ISO7816x);
  72. void ISO7816_StructInit(ISO7816_InitType *InitStruct);
  73. void ISO7816_Init(ISO7816_TypeDef *ISO7816x, ISO7816_InitType *Init_Struct);
  74. void ISO7816_Cmd(ISO7816_TypeDef *ISO7816x, uint32_t NewState);
  75. void ISO7816_BaudrateConfig(ISO7816_TypeDef *ISO7816x, uint32_t BaudRate);
  76. void ISO7816_CLKDIVConfig(ISO7816_TypeDef *ISO7816x, uint32_t Prescaler);
  77. void ISO7816_CLKOutputCmd(ISO7816_TypeDef *ISO7816x, uint32_t NewState);
  78. void ISO7816_SendData(ISO7816_TypeDef *ISO7816x, uint8_t ch);
  79. uint8_t ISO7816_ReceiveData(ISO7816_TypeDef *ISO7816x);
  80. void ISO7816_INTConfig(ISO7816_TypeDef *ISO7816x, uint32_t INTMask, uint8_t NewState);
  81. uint8_t ISO7816_GetINTStatus(ISO7816_TypeDef *ISO7816x, uint32_t INTMask);
  82. void ISO7816_ClearINTStatus(ISO7816_TypeDef *ISO7816x, uint32_t INTMask);
  83. uint8_t ISO7816_GetFlag(ISO7816_TypeDef *ISO7816x, uint32_t FlagMask);
  84. void ISO7816_ClearFlag(ISO7816_TypeDef *ISO7816x, uint32_t FlagMask);
  85. uint8_t ISO7816_GetLastTransmitACK(ISO7816_TypeDef *ISO7816x);
  86. uint8_t ISO7816_GetLastReceiveCHKSUM(ISO7816_TypeDef *ISO7816x);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* __LIB_ISO7816_H */
  91. /*********************************** END OF FILE ******************************/