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.
 
 
 

211 lines
7.7 KiB

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