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