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.
 
 
 

209 lines
7.5 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_smartcard_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 21-April-2017
  7. * @brief SMARTCARD HAL module driver.
  8. * This file provides extended firmware functions to manage the following
  9. * functionalities of the SmartCard.
  10. * + Initialization and de-initialization functions
  11. * + Peripheral Control functions
  12. *
  13. *
  14. @verbatim
  15. =============================================================================
  16. ##### SMARTCARD peripheral extended features #####
  17. =============================================================================
  18. [..]
  19. The Extended SMARTCARD HAL driver can be used as follows:
  20. (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
  21. then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
  22. auto-retry counter,...) in the hsmartcard AdvancedInit structure.
  23. @endverbatim
  24. ******************************************************************************
  25. * @attention
  26. *
  27. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  28. *
  29. * Redistribution and use in source and binary forms, with or without modification,
  30. * are permitted provided that the following conditions are met:
  31. * 1. Redistributions of source code must retain the above copyright notice,
  32. * this list of conditions and the following disclaimer.
  33. * 2. Redistributions in binary form must reproduce the above copyright notice,
  34. * this list of conditions and the following disclaimer in the documentation
  35. * and/or other materials provided with the distribution.
  36. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  37. * may be used to endorse or promote products derived from this software
  38. * without specific prior written permission.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  41. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  43. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  46. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  47. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  48. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  49. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. *
  51. ******************************************************************************
  52. */
  53. /* Includes ------------------------------------------------------------------*/
  54. #include "stm32l4xx_hal.h"
  55. /** @addtogroup STM32L4xx_HAL_Driver
  56. * @{
  57. */
  58. /** @defgroup SMARTCARDEx SMARTCARDEx
  59. * @brief SMARTCARD Extended HAL module driver
  60. * @{
  61. */
  62. #ifdef HAL_SMARTCARD_MODULE_ENABLED
  63. /* Private typedef -----------------------------------------------------------*/
  64. /* Private define ------------------------------------------------------------*/
  65. /* Private macros ------------------------------------------------------------*/
  66. /* Private variables ---------------------------------------------------------*/
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* Exported functions --------------------------------------------------------*/
  69. /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
  70. * @{
  71. */
  72. /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
  73. * @brief Extended control functions
  74. *
  75. @verbatim
  76. ===============================================================================
  77. ##### Peripheral Control functions #####
  78. ===============================================================================
  79. [..]
  80. This subsection provides a set of functions allowing to initialize the SMARTCARD.
  81. (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
  82. (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
  83. (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
  84. (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
  85. @endverbatim
  86. * @{
  87. */
  88. /**
  89. * @brief Update on the fly the SMARTCARD block length in RTOR register.
  90. * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
  91. * the configuration information for the specified SMARTCARD module.
  92. * @param BlockLength: SMARTCARD block length (8-bit long at most)
  93. * @retval None
  94. */
  95. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
  96. {
  97. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
  98. }
  99. /**
  100. * @brief Update on the fly the receiver timeout value in RTOR register.
  101. * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
  102. * the configuration information for the specified SMARTCARD module.
  103. * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
  104. * value must be less or equal to 0x0FFFFFFFF.
  105. * @retval None
  106. */
  107. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
  108. {
  109. assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
  110. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
  111. }
  112. /**
  113. * @brief Enable the SMARTCARD receiver timeout feature.
  114. * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
  115. * the configuration information for the specified SMARTCARD module.
  116. * @retval HAL status
  117. */
  118. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  119. {
  120. if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  121. {
  122. /* Process Locked */
  123. __HAL_LOCK(hsmartcard);
  124. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  125. /* Set the USART RTOEN bit */
  126. SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  127. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  128. /* Process Unlocked */
  129. __HAL_UNLOCK(hsmartcard);
  130. return HAL_OK;
  131. }
  132. else
  133. {
  134. return HAL_BUSY;
  135. }
  136. }
  137. /**
  138. * @brief Disable the SMARTCARD receiver timeout feature.
  139. * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
  140. * the configuration information for the specified SMARTCARD module.
  141. * @retval HAL status
  142. */
  143. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  144. {
  145. if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  146. {
  147. /* Process Locked */
  148. __HAL_LOCK(hsmartcard);
  149. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  150. /* Clear the USART RTOEN bit */
  151. CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  152. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  153. /* Process Unlocked */
  154. __HAL_UNLOCK(hsmartcard);
  155. return HAL_OK;
  156. }
  157. else
  158. {
  159. return HAL_BUSY;
  160. }
  161. }
  162. /**
  163. * @}
  164. */
  165. /**
  166. * @}
  167. */
  168. #endif /* HAL_SMARTCARD_MODULE_ENABLED */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */
  175. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/