|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_smartcard_ex.c 00004 * @author MCD Application Team 00005 * @brief SMARTCARD HAL模块驱动程序。 00006 * 本文件提供扩展固件功能,用于管理智能卡的以下功能: 00007 * + 初始化和去初始化函数 00008 * + 外设控制函数 00009 * 00010 ****************************************************************************** 00011 * @attention 00012 * 00013 * Copyright (c) 2019 STMicroelectronics. 00014 * All rights reserved. 00015 * 00016 * This software is licensed under terms that can be found in the LICENSE file 00017 * in the root directory of this software component. 00018 * If no LICENSE file comes with this software, it is provided AS-IS. 00019 * 00020 ****************************************************************************** 00021 @verbatim 00022 ============================================================================= 00023 ##### SMARTCARD外设扩展功能 ##### 00024 ============================================================================= 00025 [..] 00026 扩展SMARTCARD HAL驱动程序的使用方法如下: 00027 00028 (#) 使用HAL_SMARTCARD_Init()配置SMARTCARD基本功能后, 00029 可在hsmartcard AdvancedInit结构中编程SMARTCARD高级功能(TX/RX引脚交换、超时、 00030 自动重试计数器等)。 00031 00032 (#) FIFO模式使能/禁用以及RX/TX FIFO阈值编程。 00033 00034 -@- 当SMARTCARD在FIFO模式下工作时,必须在开始RX/TX传输之前使能FIFO模式。 00035 同时必须在开始RX/TX传输之前配置RX/TX FIFO阈值。 00036 00037 @endverbatim 00038 ****************************************************************************** 00039 */ 00040 ****************************************************************************** 00041 */ 00042 00043 /* Includes ------------------------------------------------------------------*/ 00044 #include "stm32g4xx_hal.h" 00045 00046 /** @addtogroup STM32G4xx_HAL_Driver 00047 * @{ 00048 */ 00049 00050 /** @defgroup SMARTCARDEx SMARTCARDEx 00051 * @brief SMARTCARD扩展HAL模块驱动程序 00052 * @{ 00053 */ 00054 #ifdef HAL_SMARTCARD_MODULE_ENABLED 00055 00056 /* Private typedef -----------------------------------------------------------*/ 00057 /* Private define ------------------------------------------------------------*/ 00058 /** @defgroup SMARTCARDEx_Private_Constants SMARTCARD Extended Private Constants 00059 * @{ 00060 */ 00061 /* UART RX FIFO depth */ 00062 #define RX_FIFO_DEPTH 8U 00063 00064 /* UART TX FIFO depth */ 00065 #define TX_FIFO_DEPTH 8U 00066 /** 00067 * @} 00068 */ 00069 00070 /* Private macros ------------------------------------------------------------*/ 00071 /* Private variables ---------------------------------------------------------*/ 00072 /* Private function prototypes -----------------------------------------------*/ 00073 static void SMARTCARDEx_SetNbDataToProcess(SMARTCARD_HandleTypeDef *hsmartcard); 00074 00075 /* Exported functions --------------------------------------------------------*/ 00076 /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions 00077 * @{ 00078 */ 00079 00080 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions 00081 * @brief 扩展控制函数 00082 * 00083 @verbatim 00084 =============================================================================== 00085 ##### 外设控制函数 ##### 00086 =============================================================================== 00087 [..] 00088 本节提供一组用于初始化SMARTCARD的函数。 00089 (+) HAL_SMARTCARDEx_BlockLength_Config() API允许动态配置块长度 00090 (+) HAL_SMARTCARDEx_TimeOut_Config() API允许动态配置接收器超时值 00091 (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API使能接收器超时功能 00092 (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API禁用接收器超时功能 00093 00094 @endverbatim 00095 * @{ 00096 */ 00097 00098 /** @brief 动态更新RTOR寄存器中的SMARTCARD块长度。 00099 * @param hsmartcard 指向SMARTCARD_HandleTypeDef结构的指针,包含 00100 * 指定SMARTCARD模块的配置信息。 00101 * @param BlockLength SMARTCARD块长度(最多8位) 00102 * @retval None 00103 */ 00104 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength) 00105 { 00106 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos)); 00107 } 00108 00109 /** @brief 动态更新RTOR寄存器中的接收器超时值。 00110 * @param hsmartcard 指向SMARTCARD_HandleTypeDef结构的指针,包含 00111 * 指定SMARTCARD模块的配置信息。 00112 * @param TimeOutValue 接收器超时值,以波特块数为单位。超时 00113 * 值必须小于或等于0x0FFFFFFFF。 00114 * @retval None 00115 */ 00116 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue) 00117 { 00118 assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue)); 00119 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue); 00120 } 00121 00122 /** @brief 使能SMARTCARD接收器超时功能。 00123 * @param hsmartcard 指向SMARTCARD_HandleTypeDef结构的指针,包含 00124 * 指定SMARTCARD模块的配置信息。 00125 * @retval HAL状态 00126 */ 00127 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard) 00128 { 00129 if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) 00130 { 00131 /* Process Locked */ 00132 __HAL_LOCK(hsmartcard); 00133 00134 hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY; 00135 00136 /* Set the USART RTOEN bit */ 00137 SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN); 00138 00139 hsmartcard->gState = HAL_SMARTCARD_STATE_READY; 00140 00141 /* Process Unlocked */ 00142 __HAL_UNLOCK(hsmartcard); 00143 00144 return HAL_OK; 00145 } 00146 else 00147 { 00148 return HAL_BUSY; 00149 } 00150 } 00151 00152 /** @brief 禁用SMARTCARD接收器超时功能。 00153 * @param hsmartcard 指向SMARTCARD_HandleTypeDef结构的指针,包含 00154 * 指定SMARTCARD模块的配置信息。 00155 * @retval HAL状态 00156 */ 00157 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard) 00158 { 00159 if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) 00160 { 00161 /* Process Locked */ 00162 __HAL_LOCK(hsmartcard); 00163 00164 hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY; 00165 00166 /* Clear the USART RTOEN bit */ 00167 CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN); 00168 00169 hsmartcard->gState = HAL_SMARTCARD_STATE_READY; 00170 00171 /* Process Unlocked */ 00172 __HAL_UNLOCK(hsmartcard); 00173 00174 return HAL_OK; 00175 } 00176 else 00177 { 00178 return HAL_BUSY; 00179 } 00180 } 00181 00182 /** 00183 * @} 00184 */ 00185 00186 /** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions 00187 * @brief SMARTCARD传输和接收函数 00188 * 00189 @verbatim 00190 =============================================================================== 00191 ##### IO操作函数 ##### 00192 =============================================================================== 00193 [..] 00194 本节提供一组与FIFO模式相关的回调函数。 00195 00196 (#) TX/RX FIFO回调: 00197 (++) HAL_SMARTCARDEx_RxFifoFullCallback() 00198 (++) HAL_SMARTCARDEx_TxFifoEmptyCallback() 00199 00200 @endverbatim 00201 * @{ 00202 */ 00203 00204 /** 00205 * @brief SMARTCARD RX FIFO满回调。 00206 * @param hsmartcard 指向SMARTCARD_HandleTypeDef结构的指针,包含 00207 * 指定SMARTCARD模块的配置信息。 00208 * @retval None 00209 */