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.
 
 
 

223 lines
7.2 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_smartcard_ex.c
  4. * @author MCD Application Team
  5. * @brief SMARTCARD HAL module driver.
  6. * This file provides extended firmware functions to manage the following
  7. * functionalities of the SmartCard.
  8. * + Initialization and de-initialization functions
  9. * + Peripheral Control functions
  10. *
  11. @verbatim
  12. =============================================================================
  13. ##### SMARTCARD peripheral extended features #####
  14. =============================================================================
  15. [..]
  16. The Extended SMARTCARD HAL driver can be used as follows:
  17. (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
  18. then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
  19. auto-retry counter,...) in the hsmartcard AdvancedInit structure.
  20. @endverbatim
  21. ******************************************************************************
  22. * @attention
  23. *
  24. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  25. * All rights reserved.</center></h2>
  26. *
  27. * This software component is licensed by ST under BSD 3-Clause license,
  28. * the "License"; You may not use this file except in compliance with the
  29. * License. You may obtain a copy of the License at:
  30. * opensource.org/licenses/BSD-3-Clause
  31. *
  32. ******************************************************************************
  33. */
  34. #if !defined (STM32L010x4) && !defined (STM32L010x6)
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "stm32l0xx_hal.h"
  37. /** @addtogroup STM32L0xx_HAL_Driver
  38. * @{
  39. */
  40. /** @defgroup SMARTCARDEx SMARTCARDEx
  41. * @brief SMARTCARD Extended HAL module driver
  42. * @{
  43. */
  44. #ifdef HAL_SMARTCARD_MODULE_ENABLED
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* Private define ------------------------------------------------------------*/
  47. /* Private macros ------------------------------------------------------------*/
  48. /* Private variables ---------------------------------------------------------*/
  49. /* Private function prototypes -----------------------------------------------*/
  50. /* Exported functions --------------------------------------------------------*/
  51. /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
  52. * @{
  53. */
  54. /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
  55. * @brief Extended control functions
  56. *
  57. @verbatim
  58. ===============================================================================
  59. ##### Peripheral Control functions #####
  60. ===============================================================================
  61. [..]
  62. This subsection provides a set of functions allowing to initialize the SMARTCARD.
  63. (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
  64. (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
  65. (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
  66. (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
  67. @endverbatim
  68. * @{
  69. */
  70. /** @brief Update on the fly the SMARTCARD block length in RTOR register.
  71. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  72. * the configuration information for the specified SMARTCARD module.
  73. * @param BlockLength SMARTCARD block length (8-bit long at most)
  74. * @retval None
  75. */
  76. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
  77. {
  78. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos));
  79. }
  80. /** @brief Update on the fly the receiver timeout value in RTOR register.
  81. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  82. * the configuration information for the specified SMARTCARD module.
  83. * @param TimeOutValue receiver timeout value in number of baud blocks. The timeout
  84. * value must be less or equal to 0x0FFFFFFFF.
  85. * @retval None
  86. */
  87. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
  88. {
  89. assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
  90. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
  91. }
  92. /** @brief Enable the SMARTCARD receiver timeout feature.
  93. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  94. * the configuration information for the specified SMARTCARD module.
  95. * @retval HAL status
  96. */
  97. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  98. {
  99. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  100. {
  101. /* Process Locked */
  102. __HAL_LOCK(hsmartcard);
  103. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  104. /* Set the USART RTOEN bit */
  105. SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  106. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  107. /* Process Unlocked */
  108. __HAL_UNLOCK(hsmartcard);
  109. return HAL_OK;
  110. }
  111. else
  112. {
  113. return HAL_BUSY;
  114. }
  115. }
  116. /** @brief Disable the SMARTCARD receiver timeout feature.
  117. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  118. * the configuration information for the specified SMARTCARD module.
  119. * @retval HAL status
  120. */
  121. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  122. {
  123. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  124. {
  125. /* Process Locked */
  126. __HAL_LOCK(hsmartcard);
  127. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  128. /* Clear the USART RTOEN bit */
  129. CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  130. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  131. /* Process Unlocked */
  132. __HAL_UNLOCK(hsmartcard);
  133. return HAL_OK;
  134. }
  135. else
  136. {
  137. return HAL_BUSY;
  138. }
  139. }
  140. /**
  141. * @}
  142. */
  143. /** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions
  144. * @brief SMARTCARD Transmit and Receive functions
  145. *
  146. @verbatim
  147. ===============================================================================
  148. ##### IO operation functions #####
  149. ===============================================================================
  150. [..]
  151. @endverbatim
  152. * @{
  153. */
  154. /**
  155. * @}
  156. */
  157. /** @defgroup SMARTCARD_Exported_Functions_Group3 Extended Peripheral Peripheral Control functions
  158. * @brief SMARTCARD control functions
  159. *
  160. @verbatim
  161. ===============================================================================
  162. ##### Peripheral Control functions #####
  163. ===============================================================================
  164. [..]
  165. @endverbatim
  166. * @{
  167. */
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. /** @defgroup SMARTCARDEx_Private_Functions SMARTCARD Extended private Functions
  175. * @{
  176. */
  177. /**
  178. * @}
  179. */
  180. #endif /* HAL_SMARTCARD_MODULE_ENABLED */
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. #endif /* !defined (STM32L010x4) && !defined (STM32L010x6) */
  188. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/