wm_7816.h 4.8 KB

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