TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_smartcard_ex.c Source File

stm32l4xx_hal_smartcard_ex.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_smartcard_ex.c
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   SMARTCARD HAL module driver.
00008   *          This file provides extended firmware functions to manage the following
00009   *          functionalities of the SmartCard.
00010   *           + Initialization and de-initialization functions
00011   *           + Peripheral Control functions
00012   *
00013   *
00014   @verbatim
00015   =============================================================================
00016                ##### SMARTCARD peripheral extended features  #####
00017   =============================================================================
00018   [..]
00019   The Extended SMARTCARD HAL driver can be used as follows:
00020 
00021     (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
00022         then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
00023         auto-retry counter,...) in the hsmartcard AdvancedInit structure.
00024 
00025 
00026 
00027   @endverbatim
00028   ******************************************************************************
00029   * @attention
00030   *
00031   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00032   *
00033   * Redistribution and use in source and binary forms, with or without modification,
00034   * are permitted provided that the following conditions are met:
00035   *   1. Redistributions of source code must retain the above copyright notice,
00036   *      this list of conditions and the following disclaimer.
00037   *   2. Redistributions in binary form must reproduce the above copyright notice,
00038   *      this list of conditions and the following disclaimer in the documentation
00039   *      and/or other materials provided with the distribution.
00040   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00041   *      may be used to endorse or promote products derived from this software
00042   *      without specific prior written permission.
00043   *
00044   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00045   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00046   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00047   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00048   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00049   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00050   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00051   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00052   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00053   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00054   *
00055   ******************************************************************************
00056   */
00057 
00058 /* Includes ------------------------------------------------------------------*/
00059 #include "stm32l4xx_hal.h"
00060 
00061 /** @addtogroup STM32L4xx_HAL_Driver
00062   * @{
00063   */
00064 
00065 /** @defgroup SMARTCARDEx SMARTCARDEx
00066   * @brief SMARTCARD Extended HAL module driver
00067   * @{
00068   */
00069 #ifdef HAL_SMARTCARD_MODULE_ENABLED
00070 
00071 /* Private typedef -----------------------------------------------------------*/
00072 /* Private define ------------------------------------------------------------*/
00073 /* Private macros ------------------------------------------------------------*/
00074 /* Private variables ---------------------------------------------------------*/
00075 /* Private function prototypes -----------------------------------------------*/
00076 
00077 /* Exported functions --------------------------------------------------------*/
00078 /** @defgroup SMARTCARDEx_Exported_Functions  SMARTCARD Extended Exported Functions
00079   * @{
00080   */
00081 
00082 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
00083   * @brief    Extended control functions
00084   *
00085 @verbatim
00086   ===============================================================================
00087                       ##### Peripheral Control functions #####
00088   ===============================================================================
00089   [..]
00090   This subsection provides a set of functions allowing to initialize the SMARTCARD.
00091      (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
00092      (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
00093      (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
00094      (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
00095 
00096 @endverbatim
00097   * @{
00098   */
00099 
00100 /**
00101   * @brief Update on the fly the SMARTCARD block length in RTOR register.
00102   * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
00103   *                    the configuration information for the specified SMARTCARD module.
00104   * @param BlockLength: SMARTCARD block length (8-bit long at most)
00105   * @retval None
00106   */
00107 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
00108 {
00109   MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
00110 }
00111 
00112 /**
00113   * @brief Update on the fly the receiver timeout value in RTOR register.
00114   * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
00115   *                    the configuration information for the specified SMARTCARD module.
00116   * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
00117   *                     value must be less or equal to 0x0FFFFFFFF.
00118   * @retval None
00119   */
00120 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
00121 {
00122   assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
00123   MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
00124 }
00125 
00126 /**
00127   * @brief Enable the SMARTCARD receiver timeout feature.
00128   * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
00129   *                    the configuration information for the specified SMARTCARD module.
00130   * @retval HAL status
00131   */
00132 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
00133 {
00134 
00135   if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
00136   {
00137     /* Process Locked */
00138     __HAL_LOCK(hsmartcard);
00139 
00140     hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
00141 
00142     /* Set the USART RTOEN bit */
00143     SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
00144 
00145     hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
00146 
00147     /* Process Unlocked */
00148     __HAL_UNLOCK(hsmartcard);
00149     
00150     return HAL_OK;
00151   }
00152   else
00153   {
00154     return HAL_BUSY;
00155   }
00156 }
00157 
00158 /**
00159   * @brief Disable the SMARTCARD receiver timeout feature.
00160   * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains
00161   *                    the configuration information for the specified SMARTCARD module.
00162   * @retval HAL status
00163   */
00164 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
00165 {
00166 
00167   if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
00168   {
00169     /* Process Locked */
00170     __HAL_LOCK(hsmartcard);
00171 
00172     hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
00173 
00174     /* Clear the USART RTOEN bit */
00175     CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
00176 
00177     hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
00178 
00179     /* Process Unlocked */
00180     __HAL_UNLOCK(hsmartcard);
00181     
00182     return HAL_OK;
00183   }
00184   else
00185   {
00186     return HAL_BUSY;
00187   }
00188 }
00189 
00190 /**
00191   * @}
00192   */
00193 
00194 /**
00195   * @}
00196   */
00197 
00198 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
00199 
00200 /**
00201   * @}
00202   */
00203 
00204 /**
00205   * @}
00206   */
00207 
00208 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/