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