You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

280 lines
13 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_smartcard_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of SMARTCARD HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32L0xx_HAL_SMARTCARD_EX_H
  21. #define STM32L0xx_HAL_SMARTCARD_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if !defined (STM32L010x4) && !defined (STM32L010x6)
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32l0xx_hal_def.h"
  28. /** @addtogroup STM32L0xx_HAL_Driver
  29. * @{
  30. */
  31. /** @addtogroup SMARTCARDEx
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /* Exported constants --------------------------------------------------------*/
  36. /** @addtogroup SMARTCARDEx_Exported_Constants SMARTCARD Extended Exported Constants
  37. * @{
  38. */
  39. /** @defgroup SMARTCARDEx_Transmission_Completion_Indication SMARTCARD Transmission Completion Indication
  40. * @{
  41. */
  42. #if defined(USART_TCBGT_SUPPORT)
  43. #define SMARTCARD_TCBGT SMARTCARD_IT_TCBGT /*!< SMARTCARD transmission complete before guard time */
  44. #endif /* USART_TCBGT_SUPPORT */
  45. #define SMARTCARD_TC SMARTCARD_IT_TC /*!< SMARTCARD transmission complete (flag raised when guard time has elapsed) */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup SMARTCARDEx_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
  50. * @{
  51. */
  52. #define SMARTCARD_ADVFEATURE_NO_INIT 0x00000000U /*!< No advanced feature initialization */
  53. #define SMARTCARD_ADVFEATURE_TXINVERT_INIT 0x00000001U /*!< TX pin active level inversion */
  54. #define SMARTCARD_ADVFEATURE_RXINVERT_INIT 0x00000002U /*!< RX pin active level inversion */
  55. #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT 0x00000004U /*!< Binary data inversion */
  56. #define SMARTCARD_ADVFEATURE_SWAP_INIT 0x00000008U /*!< TX/RX pins swap */
  57. #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT 0x00000010U /*!< RX overrun disable */
  58. #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT 0x00000020U /*!< DMA disable on Reception Error */
  59. #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT 0x00000080U /*!< Most significant bit sent/received first */
  60. #if defined(USART_TCBGT_SUPPORT)
  61. #define SMARTCARD_ADVFEATURE_TXCOMPLETION 0x00000100U /*!< TX completion indication before of after guard time */
  62. #endif /* USART_TCBGT_SUPPORT */
  63. /**
  64. * @}
  65. */
  66. /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags
  67. * Elements values convention: 0xXXXX
  68. * - 0xXXXX : Flag mask in the ISR register
  69. * @{
  70. */
  71. #if defined(USART_TCBGT_SUPPORT)
  72. #define SMARTCARD_FLAG_TCBGT USART_ISR_TCBGT /*!< SMARTCARD transmission complete before guard time completion */
  73. #endif /* USART_TCBGT_SUPPORT */
  74. #define SMARTCARD_FLAG_REACK USART_ISR_REACK /*!< SMARTCARD receive enable acknowledge flag */
  75. #define SMARTCARD_FLAG_TEACK USART_ISR_TEACK /*!< SMARTCARD transmit enable acknowledge flag */
  76. #define SMARTCARD_FLAG_BUSY USART_ISR_BUSY /*!< SMARTCARD busy flag */
  77. #define SMARTCARD_FLAG_EOBF USART_ISR_EOBF /*!< SMARTCARD end of block flag */
  78. #define SMARTCARD_FLAG_RTOF USART_ISR_RTOF /*!< SMARTCARD receiver timeout flag */
  79. #define SMARTCARD_FLAG_TXE USART_ISR_TXE /*!< SMARTCARD transmit data register empty */
  80. #define SMARTCARD_FLAG_TC USART_ISR_TC /*!< SMARTCARD transmission complete */
  81. #define SMARTCARD_FLAG_RXNE USART_ISR_RXNE /*!< SMARTCARD read data register not empty */
  82. #define SMARTCARD_FLAG_IDLE USART_ISR_IDLE /*!< SMARTCARD idle line detection */
  83. #define SMARTCARD_FLAG_ORE USART_ISR_ORE /*!< SMARTCARD overrun error */
  84. #define SMARTCARD_FLAG_NE USART_ISR_NE /*!< SMARTCARD noise error */
  85. #define SMARTCARD_FLAG_FE USART_ISR_FE /*!< SMARTCARD frame error */
  86. #define SMARTCARD_FLAG_PE USART_ISR_PE /*!< SMARTCARD parity error */
  87. /**
  88. * @}
  89. */
  90. /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition
  91. * Elements values convention: 000ZZZZZ0XXYYYYYb
  92. * - YYYYY : Interrupt source position in the XX register (5 bits)
  93. * - XX : Interrupt source register (2 bits)
  94. * - 01: CR1 register
  95. * - 10: CR2 register
  96. * - 11: CR3 register
  97. * - ZZZZZ : Flag position in the ISR register(5 bits)
  98. * @{
  99. */
  100. #define SMARTCARD_IT_PE 0x0028U /*!< SMARTCARD parity error interruption */
  101. #define SMARTCARD_IT_TXE 0x0727U /*!< SMARTCARD transmit data register empty interruption */
  102. #define SMARTCARD_IT_TC 0x0626U /*!< SMARTCARD transmission complete interruption */
  103. #define SMARTCARD_IT_RXNE 0x0525U /*!< SMARTCARD read data register not empty interruption */
  104. #define SMARTCARD_IT_IDLE 0x0424U /*!< SMARTCARD idle line detection interruption */
  105. #define SMARTCARD_IT_ERR 0x0060U /*!< SMARTCARD error interruption */
  106. #define SMARTCARD_IT_ORE 0x0300U /*!< SMARTCARD overrun error interruption */
  107. #define SMARTCARD_IT_NE 0x0200U /*!< SMARTCARD noise error interruption */
  108. #define SMARTCARD_IT_FE 0x0100U /*!< SMARTCARD frame error interruption */
  109. #define SMARTCARD_IT_EOB 0x0C3BU /*!< SMARTCARD end of block interruption */
  110. #define SMARTCARD_IT_RTO 0x0B3AU /*!< SMARTCARD receiver timeout interruption */
  111. #if defined(USART_TCBGT_SUPPORT)
  112. #define SMARTCARD_IT_TCBGT 0x1978U /*!< SMARTCARD transmission complete before guard time completion interruption */
  113. #endif /* USART_TCBGT_SUPPORT */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
  118. * @{
  119. */
  120. #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< SMARTCARD parity error clear flag */
  121. #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< SMARTCARD framing error clear flag */
  122. #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< SMARTCARD noise error detected clear flag */
  123. #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< SMARTCARD overrun error clear flag */
  124. #define SMARTCARD_CLEAR_IDLEF USART_ICR_IDLECF /*!< SMARTCARD idle line detected clear flag */
  125. #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< SMARTCARD transmission complete clear flag */
  126. #if defined(USART_TCBGT_SUPPORT)
  127. #define SMARTCARD_CLEAR_TCBGTF USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */
  128. #endif /* USART_TCBGT_SUPPORT */
  129. #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< SMARTCARD receiver time out clear flag */
  130. #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< SMARTCARD end of block clear flag */
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @}
  136. */
  137. /* Exported macros -----------------------------------------------------------*/
  138. /* Private macros ------------------------------------------------------------*/
  139. /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros
  140. * @{
  141. */
  142. /** @brief Set the Transmission Completion flag
  143. * @param __HANDLE__ specifies the SMARTCARD Handle.
  144. * @note If TCBGT (Transmission Complete Before Guard Time) flag is not available or if
  145. * AdvancedInit.TxCompletionIndication is not already filled, the latter is forced
  146. * to SMARTCARD_TC (transmission completion indication when guard time has elapsed).
  147. * @retval None
  148. */
  149. #if defined(USART_TCBGT_SUPPORT)
  150. #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \
  151. do { \
  152. if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION)) \
  153. { \
  154. (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
  155. } \
  156. else \
  157. { \
  158. assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \
  159. } \
  160. } while(0U)
  161. #else
  162. #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \
  163. do { \
  164. (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
  165. } while(0U)
  166. #endif /* USART_TCBGT_SUPPORT */
  167. /** @brief Return the transmission completion flag.
  168. * @param __HANDLE__ specifies the SMARTCARD Handle.
  169. * @note Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag.
  170. * When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is
  171. * reported.
  172. * @retval Transmission completion flag
  173. */
  174. #if defined(USART_TCBGT_SUPPORT)
  175. #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) \
  176. (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) : (SMARTCARD_FLAG_TCBGT))
  177. #else
  178. #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) (SMARTCARD_FLAG_TC)
  179. #endif /* USART_TCBGT_SUPPORT */
  180. /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid.
  181. * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag.
  182. * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid)
  183. */
  184. #if defined(USART_TCBGT_SUPPORT)
  185. #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \
  186. ((__TXCOMPLETE__) == SMARTCARD_TC))
  187. #else
  188. #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC)
  189. #endif /* USART_TCBGT_SUPPORT */
  190. /**
  191. * @}
  192. */
  193. /* Exported functions --------------------------------------------------------*/
  194. /** @addtogroup SMARTCARDEx_Exported_Functions
  195. * @{
  196. */
  197. /* Initialization and de-initialization functions ****************************/
  198. /* IO operation methods *******************************************************/
  199. /** @addtogroup SMARTCARDEx_Exported_Functions_Group1
  200. * @{
  201. */
  202. /* Peripheral Control functions ***********************************************/
  203. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength);
  204. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue);
  205. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
  206. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
  207. /**
  208. * @}
  209. */
  210. /* Exported functions --------------------------------------------------------*/
  211. /** @addtogroup SMARTCARDEx_Exported_Functions_Group2
  212. * @{
  213. */
  214. /* IO operation functions *****************************************************/
  215. /**
  216. * @}
  217. */
  218. /** @addtogroup SMARTCARDEx_Exported_Functions_Group3
  219. * @{
  220. */
  221. /* Peripheral Control functions ***********************************************/
  222. /**
  223. * @}
  224. */
  225. /**
  226. * @}
  227. */
  228. /* Private functions ---------------------------------------------------------*/
  229. /**
  230. * @}
  231. */
  232. /**
  233. * @}
  234. */
  235. #endif /* !defined (STM32L010x4) && !defined (STM32L010x6) */
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* STM32L0xx_HAL_SMARTCARD_EX_H */
  240. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/