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