mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_aes.c@76:aeb1df146756, 2014-01-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jan 27 14:30:07 2014 +0000
- Revision:
- 76:aeb1df146756
- Child:
- 80:66393a7b209d
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd
Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/
Add NUCLEO_L152RE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file stm32l1xx_aes.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 76:aeb1df146756 | 5 | * @version V1.2.0 |
mbed_official | 76:aeb1df146756 | 6 | * @date 22-February-2013 |
mbed_official | 76:aeb1df146756 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 76:aeb1df146756 | 8 | * functionalities of the AES peripheral: |
mbed_official | 76:aeb1df146756 | 9 | * + Configuration |
mbed_official | 76:aeb1df146756 | 10 | * + Read/Write operations |
mbed_official | 76:aeb1df146756 | 11 | * + DMA transfers management |
mbed_official | 76:aeb1df146756 | 12 | * + Interrupts and flags management |
mbed_official | 76:aeb1df146756 | 13 | * |
mbed_official | 76:aeb1df146756 | 14 | * @verbatim |
mbed_official | 76:aeb1df146756 | 15 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 16 | ##### AES Peripheral features ##### |
mbed_official | 76:aeb1df146756 | 17 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 18 | ....[..] |
mbed_official | 76:aeb1df146756 | 19 | (#) The Advanced Encryption Standard hardware accelerator (AES) can be used |
mbed_official | 76:aeb1df146756 | 20 | to both encipher and decipher data using AES algorithm. |
mbed_official | 76:aeb1df146756 | 21 | (#) The AES supports 4 operation modes: |
mbed_official | 76:aeb1df146756 | 22 | (++) Encryption: It consumes 214 clock cycle when processing one 128-bit block |
mbed_official | 76:aeb1df146756 | 23 | (++) Decryption: It consumes 214 clock cycle when processing one 128-bit block |
mbed_official | 76:aeb1df146756 | 24 | (++) Key derivation for decryption: It consumes 80 clock cycle when processing one 128-bit block |
mbed_official | 76:aeb1df146756 | 25 | (++) Key Derivation and decryption: It consumes 288 clock cycle when processing one 128-bit blobk |
mbed_official | 76:aeb1df146756 | 26 | (#) Moreover 3 chaining modes are supported: |
mbed_official | 76:aeb1df146756 | 27 | (++) Electronic codebook (ECB): Each plain text is encrypted/decrypted separately |
mbed_official | 76:aeb1df146756 | 28 | (++) Cipher block chaining (CBC): Each block is XORed with the previous block |
mbed_official | 76:aeb1df146756 | 29 | (++) Counter mode (CTR): A 128-bit counter is encrypted and then XORed with the |
mbed_official | 76:aeb1df146756 | 30 | plain text to give the cipher text |
mbed_official | 76:aeb1df146756 | 31 | (#) The AES peripheral supports data swapping: 1-bit, 8-bit, 16-bit and 32-bit. |
mbed_official | 76:aeb1df146756 | 32 | (#) The AES peripheral supports write/read error handling with interrupt capability. |
mbed_official | 76:aeb1df146756 | 33 | (#) Automatic data flow control with support of direct memory access (DMA) using |
mbed_official | 76:aeb1df146756 | 34 | 2 channels, one for incoming data (DMA2 Channel5), and one for outcoming data |
mbed_official | 76:aeb1df146756 | 35 | (DMA2 Channel3). |
mbed_official | 76:aeb1df146756 | 36 | |
mbed_official | 76:aeb1df146756 | 37 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 38 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 39 | [..] |
mbed_official | 76:aeb1df146756 | 40 | (#) AES AHB clock must be enabled to get write access to AES registers |
mbed_official | 76:aeb1df146756 | 41 | using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_AES, ENABLE). |
mbed_official | 76:aeb1df146756 | 42 | (#) Initialize the key using AES_KeyInit(). |
mbed_official | 76:aeb1df146756 | 43 | (#) Configure the AES operation mode using AES_Init(). |
mbed_official | 76:aeb1df146756 | 44 | (#) If required, enable interrupt source using AES_ITConfig() and |
mbed_official | 76:aeb1df146756 | 45 | enable the AES interrupt vector using NVIC_Init(). |
mbed_official | 76:aeb1df146756 | 46 | (#) If required, when using the DMA mode. |
mbed_official | 76:aeb1df146756 | 47 | (##) Configure the DMA using DMA_Init(). |
mbed_official | 76:aeb1df146756 | 48 | (##) Enable DMA requests using AES_DMAConfig(). |
mbed_official | 76:aeb1df146756 | 49 | (#) Enable the AES peripheral using AES_Cmd(). |
mbed_official | 76:aeb1df146756 | 50 | @endverbatim |
mbed_official | 76:aeb1df146756 | 51 | |
mbed_official | 76:aeb1df146756 | 52 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 53 | * @attention |
mbed_official | 76:aeb1df146756 | 54 | * |
mbed_official | 76:aeb1df146756 | 55 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 56 | * |
mbed_official | 76:aeb1df146756 | 57 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
mbed_official | 76:aeb1df146756 | 58 | * You may not use this file except in compliance with the License. |
mbed_official | 76:aeb1df146756 | 59 | * You may obtain a copy of the License at: |
mbed_official | 76:aeb1df146756 | 60 | * |
mbed_official | 76:aeb1df146756 | 61 | * http://www.st.com/software_license_agreement_liberty_v2 |
mbed_official | 76:aeb1df146756 | 62 | * |
mbed_official | 76:aeb1df146756 | 63 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 76:aeb1df146756 | 64 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 76:aeb1df146756 | 65 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 76:aeb1df146756 | 66 | * See the License for the specific language governing permissions and |
mbed_official | 76:aeb1df146756 | 67 | * limitations under the License. |
mbed_official | 76:aeb1df146756 | 68 | * |
mbed_official | 76:aeb1df146756 | 69 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 70 | */ |
mbed_official | 76:aeb1df146756 | 71 | |
mbed_official | 76:aeb1df146756 | 72 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 73 | #include "stm32l1xx_aes.h" |
mbed_official | 76:aeb1df146756 | 74 | #include "stm32l1xx_rcc.h" |
mbed_official | 76:aeb1df146756 | 75 | |
mbed_official | 76:aeb1df146756 | 76 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 77 | * @{ |
mbed_official | 76:aeb1df146756 | 78 | */ |
mbed_official | 76:aeb1df146756 | 79 | |
mbed_official | 76:aeb1df146756 | 80 | /** @defgroup AES |
mbed_official | 76:aeb1df146756 | 81 | * @brief AES driver modules |
mbed_official | 76:aeb1df146756 | 82 | * @{ |
mbed_official | 76:aeb1df146756 | 83 | */ |
mbed_official | 76:aeb1df146756 | 84 | |
mbed_official | 76:aeb1df146756 | 85 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 86 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 87 | #define CR_CLEAR_MASK ((uint32_t)0xFFFFFF81) |
mbed_official | 76:aeb1df146756 | 88 | |
mbed_official | 76:aeb1df146756 | 89 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 90 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 91 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 92 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 93 | |
mbed_official | 76:aeb1df146756 | 94 | /** @defgroup AES_Private_Functions |
mbed_official | 76:aeb1df146756 | 95 | * @{ |
mbed_official | 76:aeb1df146756 | 96 | */ |
mbed_official | 76:aeb1df146756 | 97 | |
mbed_official | 76:aeb1df146756 | 98 | /** @defgroup AES_Group1 Initialization and configuration |
mbed_official | 76:aeb1df146756 | 99 | * @brief Initialization and configuration. |
mbed_official | 76:aeb1df146756 | 100 | * |
mbed_official | 76:aeb1df146756 | 101 | @verbatim |
mbed_official | 76:aeb1df146756 | 102 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 103 | ##### Initialization and configuration ##### |
mbed_official | 76:aeb1df146756 | 104 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 105 | |
mbed_official | 76:aeb1df146756 | 106 | @endverbatim |
mbed_official | 76:aeb1df146756 | 107 | * @{ |
mbed_official | 76:aeb1df146756 | 108 | */ |
mbed_official | 76:aeb1df146756 | 109 | |
mbed_official | 76:aeb1df146756 | 110 | /** |
mbed_official | 76:aeb1df146756 | 111 | * @brief Deinitializes AES peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 112 | * @param None |
mbed_official | 76:aeb1df146756 | 113 | * @retval None |
mbed_official | 76:aeb1df146756 | 114 | */ |
mbed_official | 76:aeb1df146756 | 115 | void AES_DeInit(void) |
mbed_official | 76:aeb1df146756 | 116 | { |
mbed_official | 76:aeb1df146756 | 117 | /* Enable AES reset state */ |
mbed_official | 76:aeb1df146756 | 118 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_AES, ENABLE); |
mbed_official | 76:aeb1df146756 | 119 | /* Release AES from reset state */ |
mbed_official | 76:aeb1df146756 | 120 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_AES, DISABLE); |
mbed_official | 76:aeb1df146756 | 121 | } |
mbed_official | 76:aeb1df146756 | 122 | |
mbed_official | 76:aeb1df146756 | 123 | /** |
mbed_official | 76:aeb1df146756 | 124 | * @brief Initializes the AES peripheral according to the specified parameters |
mbed_official | 76:aeb1df146756 | 125 | * in the AES_InitStruct: |
mbed_official | 76:aeb1df146756 | 126 | * - AES_Operation: specifies the operation mode (encryption, decryption...). |
mbed_official | 76:aeb1df146756 | 127 | * - AES_Chaining: specifies the chaining mode (ECB, CBC or CTR). |
mbed_official | 76:aeb1df146756 | 128 | * - AES_DataType: specifies the data swapping type: 32-bit, 16-bit, 8-bit or 1-bit. |
mbed_official | 76:aeb1df146756 | 129 | * @note If AES is already enabled, use AES_Cmd(DISABLE) before setting the new |
mbed_official | 76:aeb1df146756 | 130 | * configuration (When AES is enabled, setting configuration is forbidden). |
mbed_official | 76:aeb1df146756 | 131 | * @param AES_InitStruct: pointer to an AES_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 132 | * the configuration information for AES peripheral. |
mbed_official | 76:aeb1df146756 | 133 | * @retval None |
mbed_official | 76:aeb1df146756 | 134 | */ |
mbed_official | 76:aeb1df146756 | 135 | void AES_Init(AES_InitTypeDef* AES_InitStruct) |
mbed_official | 76:aeb1df146756 | 136 | { |
mbed_official | 76:aeb1df146756 | 137 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 138 | |
mbed_official | 76:aeb1df146756 | 139 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 140 | assert_param(IS_AES_MODE(AES_InitStruct->AES_Operation)); |
mbed_official | 76:aeb1df146756 | 141 | assert_param(IS_AES_CHAINING(AES_InitStruct->AES_Chaining)); |
mbed_official | 76:aeb1df146756 | 142 | assert_param(IS_AES_DATATYPE(AES_InitStruct->AES_DataType)); |
mbed_official | 76:aeb1df146756 | 143 | |
mbed_official | 76:aeb1df146756 | 144 | /* Get AES CR register value */ |
mbed_official | 76:aeb1df146756 | 145 | tmpreg = AES->CR; |
mbed_official | 76:aeb1df146756 | 146 | |
mbed_official | 76:aeb1df146756 | 147 | /* Clear DATATYPE[1:0], MODE[1:0] and CHMOD[1:0] bits */ |
mbed_official | 76:aeb1df146756 | 148 | tmpreg &= (uint32_t)CR_CLEAR_MASK; |
mbed_official | 76:aeb1df146756 | 149 | |
mbed_official | 76:aeb1df146756 | 150 | tmpreg |= (AES_InitStruct->AES_Operation | AES_InitStruct->AES_Chaining | AES_InitStruct->AES_DataType); |
mbed_official | 76:aeb1df146756 | 151 | |
mbed_official | 76:aeb1df146756 | 152 | AES->CR = (uint32_t) tmpreg; |
mbed_official | 76:aeb1df146756 | 153 | } |
mbed_official | 76:aeb1df146756 | 154 | |
mbed_official | 76:aeb1df146756 | 155 | /** |
mbed_official | 76:aeb1df146756 | 156 | * @brief Initializes the AES Keys according to the specified parameters in the AES_KeyInitStruct. |
mbed_official | 76:aeb1df146756 | 157 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 158 | * contains the configuration information for the specified AES Keys. |
mbed_official | 76:aeb1df146756 | 159 | * @note This function must be called while the AES is disabled. |
mbed_official | 76:aeb1df146756 | 160 | * @note In encryption, key derivation and key derivation + decryption modes, |
mbed_official | 76:aeb1df146756 | 161 | * AES_KeyInitStruct must contain the encryption key. |
mbed_official | 76:aeb1df146756 | 162 | * In decryption mode, AES_KeyInitStruct must contain the decryption key. |
mbed_official | 76:aeb1df146756 | 163 | * @retval None |
mbed_official | 76:aeb1df146756 | 164 | */ |
mbed_official | 76:aeb1df146756 | 165 | void AES_KeyInit(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 166 | { |
mbed_official | 76:aeb1df146756 | 167 | AES->KEYR0 = AES_KeyInitStruct->AES_Key0; |
mbed_official | 76:aeb1df146756 | 168 | AES->KEYR1 = AES_KeyInitStruct->AES_Key1; |
mbed_official | 76:aeb1df146756 | 169 | AES->KEYR2 = AES_KeyInitStruct->AES_Key2; |
mbed_official | 76:aeb1df146756 | 170 | AES->KEYR3 = AES_KeyInitStruct->AES_Key3; |
mbed_official | 76:aeb1df146756 | 171 | } |
mbed_official | 76:aeb1df146756 | 172 | |
mbed_official | 76:aeb1df146756 | 173 | /** |
mbed_official | 76:aeb1df146756 | 174 | * @brief Initializes the AES Initialization Vector IV according to |
mbed_official | 76:aeb1df146756 | 175 | * the specified parameters in the AES_IVInitStruct. |
mbed_official | 76:aeb1df146756 | 176 | * @param AES_KeyInitStruct: pointer to an AES_IVInitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 177 | * contains the configuration information for the specified AES IV. |
mbed_official | 76:aeb1df146756 | 178 | * @note When ECB chaining mode is selected, Initialization Vector IV has no |
mbed_official | 76:aeb1df146756 | 179 | * meaning. |
mbed_official | 76:aeb1df146756 | 180 | * When CTR chaining mode is selected, AES_IV0 contains the CTR value. |
mbed_official | 76:aeb1df146756 | 181 | * AES_IV1, AES_IV2 and AES_IV3 contains nonce value. |
mbed_official | 76:aeb1df146756 | 182 | * @retval None |
mbed_official | 76:aeb1df146756 | 183 | */ |
mbed_official | 76:aeb1df146756 | 184 | void AES_IVInit(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 185 | { |
mbed_official | 76:aeb1df146756 | 186 | AES->IVR0 = AES_IVInitStruct->AES_IV0; |
mbed_official | 76:aeb1df146756 | 187 | AES->IVR1 = AES_IVInitStruct->AES_IV1; |
mbed_official | 76:aeb1df146756 | 188 | AES->IVR2 = AES_IVInitStruct->AES_IV2; |
mbed_official | 76:aeb1df146756 | 189 | AES->IVR3 = AES_IVInitStruct->AES_IV3; |
mbed_official | 76:aeb1df146756 | 190 | } |
mbed_official | 76:aeb1df146756 | 191 | |
mbed_official | 76:aeb1df146756 | 192 | /** |
mbed_official | 76:aeb1df146756 | 193 | * @brief Enable or disable the AES peripheral. |
mbed_official | 76:aeb1df146756 | 194 | * @param NewState: new state of the AES peripheral. |
mbed_official | 76:aeb1df146756 | 195 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 196 | * @note The key must be written while AES is disabled. |
mbed_official | 76:aeb1df146756 | 197 | * @retval None |
mbed_official | 76:aeb1df146756 | 198 | */ |
mbed_official | 76:aeb1df146756 | 199 | void AES_Cmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 200 | { |
mbed_official | 76:aeb1df146756 | 201 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 202 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 203 | |
mbed_official | 76:aeb1df146756 | 204 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 205 | { |
mbed_official | 76:aeb1df146756 | 206 | /* Enable the AES peripheral */ |
mbed_official | 76:aeb1df146756 | 207 | AES->CR |= (uint32_t) AES_CR_EN; /**< AES Enable */ |
mbed_official | 76:aeb1df146756 | 208 | } |
mbed_official | 76:aeb1df146756 | 209 | else |
mbed_official | 76:aeb1df146756 | 210 | { |
mbed_official | 76:aeb1df146756 | 211 | /* Disable the AES peripheral */ |
mbed_official | 76:aeb1df146756 | 212 | AES->CR &= (uint32_t)(~AES_CR_EN); /**< AES Disable */ |
mbed_official | 76:aeb1df146756 | 213 | } |
mbed_official | 76:aeb1df146756 | 214 | } |
mbed_official | 76:aeb1df146756 | 215 | |
mbed_official | 76:aeb1df146756 | 216 | /** |
mbed_official | 76:aeb1df146756 | 217 | * @} |
mbed_official | 76:aeb1df146756 | 218 | */ |
mbed_official | 76:aeb1df146756 | 219 | |
mbed_official | 76:aeb1df146756 | 220 | /** @defgroup AES_Group2 Structures initialization functions |
mbed_official | 76:aeb1df146756 | 221 | * @brief Structures initialization. |
mbed_official | 76:aeb1df146756 | 222 | * |
mbed_official | 76:aeb1df146756 | 223 | @verbatim |
mbed_official | 76:aeb1df146756 | 224 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 225 | ##### Structures initialization functions ##### |
mbed_official | 76:aeb1df146756 | 226 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 227 | |
mbed_official | 76:aeb1df146756 | 228 | @endverbatim |
mbed_official | 76:aeb1df146756 | 229 | * @{ |
mbed_official | 76:aeb1df146756 | 230 | */ |
mbed_official | 76:aeb1df146756 | 231 | |
mbed_official | 76:aeb1df146756 | 232 | /** |
mbed_official | 76:aeb1df146756 | 233 | * @brief Fills each AES_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 234 | * @param AES_InitStruct: pointer to an AES_InitTypeDef structure which will |
mbed_official | 76:aeb1df146756 | 235 | * be initialized. |
mbed_official | 76:aeb1df146756 | 236 | * @retval None |
mbed_official | 76:aeb1df146756 | 237 | */ |
mbed_official | 76:aeb1df146756 | 238 | void AES_StructInit(AES_InitTypeDef* AES_InitStruct) |
mbed_official | 76:aeb1df146756 | 239 | { |
mbed_official | 76:aeb1df146756 | 240 | AES_InitStruct->AES_Operation = AES_Operation_Encryp; |
mbed_official | 76:aeb1df146756 | 241 | AES_InitStruct->AES_Chaining = AES_Chaining_ECB; |
mbed_official | 76:aeb1df146756 | 242 | AES_InitStruct->AES_DataType = AES_DataType_32b; |
mbed_official | 76:aeb1df146756 | 243 | } |
mbed_official | 76:aeb1df146756 | 244 | |
mbed_official | 76:aeb1df146756 | 245 | /** |
mbed_official | 76:aeb1df146756 | 246 | * @brief Fills each AES_KeyInitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 247 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitStruct structure which |
mbed_official | 76:aeb1df146756 | 248 | * will be initialized. |
mbed_official | 76:aeb1df146756 | 249 | * @retval None |
mbed_official | 76:aeb1df146756 | 250 | */ |
mbed_official | 76:aeb1df146756 | 251 | void AES_KeyStructInit(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 252 | { |
mbed_official | 76:aeb1df146756 | 253 | AES_KeyInitStruct->AES_Key0 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 254 | AES_KeyInitStruct->AES_Key1 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 255 | AES_KeyInitStruct->AES_Key2 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 256 | AES_KeyInitStruct->AES_Key3 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 257 | } |
mbed_official | 76:aeb1df146756 | 258 | |
mbed_official | 76:aeb1df146756 | 259 | /** |
mbed_official | 76:aeb1df146756 | 260 | * @brief Fills each AES_IVInitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 261 | * @param AES_IVInitStruct: pointer to an AES_IVInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 262 | * will be initialized. |
mbed_official | 76:aeb1df146756 | 263 | * @retval None |
mbed_official | 76:aeb1df146756 | 264 | */ |
mbed_official | 76:aeb1df146756 | 265 | void AES_IVStructInit(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 266 | { |
mbed_official | 76:aeb1df146756 | 267 | AES_IVInitStruct->AES_IV0 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 268 | AES_IVInitStruct->AES_IV1 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 269 | AES_IVInitStruct->AES_IV2 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 270 | AES_IVInitStruct->AES_IV3 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 271 | } |
mbed_official | 76:aeb1df146756 | 272 | |
mbed_official | 76:aeb1df146756 | 273 | /** |
mbed_official | 76:aeb1df146756 | 274 | * @} |
mbed_official | 76:aeb1df146756 | 275 | */ |
mbed_official | 76:aeb1df146756 | 276 | |
mbed_official | 76:aeb1df146756 | 277 | /** @defgroup AES_Group3 AES Read and Write |
mbed_official | 76:aeb1df146756 | 278 | * @brief AES Read and Write. |
mbed_official | 76:aeb1df146756 | 279 | * |
mbed_official | 76:aeb1df146756 | 280 | @verbatim |
mbed_official | 76:aeb1df146756 | 281 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 282 | ##### AES Read and Write functions ##### |
mbed_official | 76:aeb1df146756 | 283 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 284 | |
mbed_official | 76:aeb1df146756 | 285 | @endverbatim |
mbed_official | 76:aeb1df146756 | 286 | * @{ |
mbed_official | 76:aeb1df146756 | 287 | */ |
mbed_official | 76:aeb1df146756 | 288 | |
mbed_official | 76:aeb1df146756 | 289 | /** |
mbed_official | 76:aeb1df146756 | 290 | * @brief Write data in DINR register to be processed by AES peripheral. |
mbed_official | 76:aeb1df146756 | 291 | * @note To process 128-bit data (4 * 32-bit), this function must be called |
mbed_official | 76:aeb1df146756 | 292 | * four times to write the 128-bit data in the 32-bit register DINR. |
mbed_official | 76:aeb1df146756 | 293 | * @note When an unexpected write to DOUTR register is detected, WRERR flag is |
mbed_official | 76:aeb1df146756 | 294 | * set. |
mbed_official | 76:aeb1df146756 | 295 | * @param Data: The data to be processed. |
mbed_official | 76:aeb1df146756 | 296 | * @retval None |
mbed_official | 76:aeb1df146756 | 297 | */ |
mbed_official | 76:aeb1df146756 | 298 | void AES_WriteSubData(uint32_t Data) |
mbed_official | 76:aeb1df146756 | 299 | { |
mbed_official | 76:aeb1df146756 | 300 | /* Write Data */ |
mbed_official | 76:aeb1df146756 | 301 | AES->DINR = Data; |
mbed_official | 76:aeb1df146756 | 302 | } |
mbed_official | 76:aeb1df146756 | 303 | |
mbed_official | 76:aeb1df146756 | 304 | /** |
mbed_official | 76:aeb1df146756 | 305 | * @brief Returns the data in DOUTR register processed by AES peripheral. |
mbed_official | 76:aeb1df146756 | 306 | * @note This function must be called four times to get the 128-bit data. |
mbed_official | 76:aeb1df146756 | 307 | * @note When an unexpected read of DINR register is detected, RDERR flag is |
mbed_official | 76:aeb1df146756 | 308 | * set. |
mbed_official | 76:aeb1df146756 | 309 | * @retval The processed data. |
mbed_official | 76:aeb1df146756 | 310 | */ |
mbed_official | 76:aeb1df146756 | 311 | uint32_t AES_ReadSubData(void) |
mbed_official | 76:aeb1df146756 | 312 | { |
mbed_official | 76:aeb1df146756 | 313 | /* Read Data */ |
mbed_official | 76:aeb1df146756 | 314 | return AES->DOUTR; |
mbed_official | 76:aeb1df146756 | 315 | } |
mbed_official | 76:aeb1df146756 | 316 | |
mbed_official | 76:aeb1df146756 | 317 | /** |
mbed_official | 76:aeb1df146756 | 318 | * @brief Read the Key value. |
mbed_official | 76:aeb1df146756 | 319 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 320 | * will contain the key. |
mbed_official | 76:aeb1df146756 | 321 | * @note When the key derivation mode is selected, AES must be disabled |
mbed_official | 76:aeb1df146756 | 322 | * (AES_Cmd(DISABLE)) before reading the decryption key. |
mbed_official | 76:aeb1df146756 | 323 | * Reading the key while the AES is enabled will return unpredictable |
mbed_official | 76:aeb1df146756 | 324 | * value. |
mbed_official | 76:aeb1df146756 | 325 | * @retval None |
mbed_official | 76:aeb1df146756 | 326 | */ |
mbed_official | 76:aeb1df146756 | 327 | void AES_ReadKey(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 328 | { |
mbed_official | 76:aeb1df146756 | 329 | AES_KeyInitStruct->AES_Key0 = AES->KEYR0; |
mbed_official | 76:aeb1df146756 | 330 | AES_KeyInitStruct->AES_Key1 = AES->KEYR1; |
mbed_official | 76:aeb1df146756 | 331 | AES_KeyInitStruct->AES_Key2 = AES->KEYR2; |
mbed_official | 76:aeb1df146756 | 332 | AES_KeyInitStruct->AES_Key3 = AES->KEYR3; |
mbed_official | 76:aeb1df146756 | 333 | } |
mbed_official | 76:aeb1df146756 | 334 | |
mbed_official | 76:aeb1df146756 | 335 | /** |
mbed_official | 76:aeb1df146756 | 336 | * @brief Read the Initialization Vector IV value. |
mbed_official | 76:aeb1df146756 | 337 | * @param AES_IVInitStruct: pointer to an AES_IVInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 338 | * will contain the Initialization Vector IV. |
mbed_official | 76:aeb1df146756 | 339 | * @note When the AES is enabled Reading the Initialization Vector IV value |
mbed_official | 76:aeb1df146756 | 340 | * will return 0. The AES must be disabled using AES_Cmd(DISABLE) |
mbed_official | 76:aeb1df146756 | 341 | * to get the right value. |
mbed_official | 76:aeb1df146756 | 342 | * @note When ECB chaining mode is selected, Initialization Vector IV has no |
mbed_official | 76:aeb1df146756 | 343 | * meaning. |
mbed_official | 76:aeb1df146756 | 344 | * When CTR chaining mode is selected, AES_IV0 contains 32-bit Counter value. |
mbed_official | 76:aeb1df146756 | 345 | * AES_IV1, AES_IV2 and AES_IV3 contains nonce value. |
mbed_official | 76:aeb1df146756 | 346 | * @retval None |
mbed_official | 76:aeb1df146756 | 347 | */ |
mbed_official | 76:aeb1df146756 | 348 | void AES_ReadIV(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 349 | { |
mbed_official | 76:aeb1df146756 | 350 | AES_IVInitStruct->AES_IV0 = AES->IVR0; |
mbed_official | 76:aeb1df146756 | 351 | AES_IVInitStruct->AES_IV1 = AES->IVR1; |
mbed_official | 76:aeb1df146756 | 352 | AES_IVInitStruct->AES_IV2 = AES->IVR2; |
mbed_official | 76:aeb1df146756 | 353 | AES_IVInitStruct->AES_IV3 = AES->IVR3; |
mbed_official | 76:aeb1df146756 | 354 | } |
mbed_official | 76:aeb1df146756 | 355 | |
mbed_official | 76:aeb1df146756 | 356 | /** |
mbed_official | 76:aeb1df146756 | 357 | * @} |
mbed_official | 76:aeb1df146756 | 358 | */ |
mbed_official | 76:aeb1df146756 | 359 | |
mbed_official | 76:aeb1df146756 | 360 | /** @defgroup AES_Group4 DMA transfers management functions |
mbed_official | 76:aeb1df146756 | 361 | * @brief DMA transfers management function. |
mbed_official | 76:aeb1df146756 | 362 | * |
mbed_official | 76:aeb1df146756 | 363 | @verbatim |
mbed_official | 76:aeb1df146756 | 364 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 365 | ##### DMA transfers management functions ##### |
mbed_official | 76:aeb1df146756 | 366 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 367 | |
mbed_official | 76:aeb1df146756 | 368 | @endverbatim |
mbed_official | 76:aeb1df146756 | 369 | * @{ |
mbed_official | 76:aeb1df146756 | 370 | */ |
mbed_official | 76:aeb1df146756 | 371 | |
mbed_official | 76:aeb1df146756 | 372 | /** |
mbed_official | 76:aeb1df146756 | 373 | * @brief Configures the AES DMA interface. |
mbed_official | 76:aeb1df146756 | 374 | * @param AES_DMATransfer: Specifies the AES DMA transfer. |
mbed_official | 76:aeb1df146756 | 375 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 376 | * @arg AES_DMATransfer_In: When selected, DMA manages the data input phase. |
mbed_official | 76:aeb1df146756 | 377 | * @arg AES_DMATransfer_Out: When selected, DMA manages the data output phase. |
mbed_official | 76:aeb1df146756 | 378 | * @arg AES_DMATransfer_InOut: When selected, DMA manages both the data input/output phases. |
mbed_official | 76:aeb1df146756 | 379 | * @param NewState Indicates the new state of the AES DMA interface. |
mbed_official | 76:aeb1df146756 | 380 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 381 | * @note The DMA has no action in key derivation mode. |
mbed_official | 76:aeb1df146756 | 382 | * @retval None |
mbed_official | 76:aeb1df146756 | 383 | */ |
mbed_official | 76:aeb1df146756 | 384 | void AES_DMAConfig(uint32_t AES_DMATransfer, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 385 | { |
mbed_official | 76:aeb1df146756 | 386 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 387 | assert_param(IS_AES_DMA_TRANSFER(AES_DMATransfer)); |
mbed_official | 76:aeb1df146756 | 388 | |
mbed_official | 76:aeb1df146756 | 389 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 390 | { |
mbed_official | 76:aeb1df146756 | 391 | /* Enable the DMA transfer */ |
mbed_official | 76:aeb1df146756 | 392 | AES->CR |= (uint32_t) AES_DMATransfer; |
mbed_official | 76:aeb1df146756 | 393 | } |
mbed_official | 76:aeb1df146756 | 394 | else |
mbed_official | 76:aeb1df146756 | 395 | { |
mbed_official | 76:aeb1df146756 | 396 | /* Disable the DMA transfer */ |
mbed_official | 76:aeb1df146756 | 397 | AES->CR &= (uint32_t)(~AES_DMATransfer); |
mbed_official | 76:aeb1df146756 | 398 | } |
mbed_official | 76:aeb1df146756 | 399 | } |
mbed_official | 76:aeb1df146756 | 400 | |
mbed_official | 76:aeb1df146756 | 401 | /** |
mbed_official | 76:aeb1df146756 | 402 | * @} |
mbed_official | 76:aeb1df146756 | 403 | */ |
mbed_official | 76:aeb1df146756 | 404 | |
mbed_official | 76:aeb1df146756 | 405 | /** @defgroup AES_Group5 Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 406 | * @brief Interrupts and flags management functions. |
mbed_official | 76:aeb1df146756 | 407 | * |
mbed_official | 76:aeb1df146756 | 408 | @verbatim |
mbed_official | 76:aeb1df146756 | 409 | |
mbed_official | 76:aeb1df146756 | 410 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 411 | ##### Interrupts and flags management functions ##### |
mbed_official | 76:aeb1df146756 | 412 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 413 | @endverbatim |
mbed_official | 76:aeb1df146756 | 414 | * @{ |
mbed_official | 76:aeb1df146756 | 415 | */ |
mbed_official | 76:aeb1df146756 | 416 | |
mbed_official | 76:aeb1df146756 | 417 | /** |
mbed_official | 76:aeb1df146756 | 418 | * @brief Enables or disables the specified AES interrupt. |
mbed_official | 76:aeb1df146756 | 419 | * @param AES_IT: Specifies the AES interrupt source to enable/disable. |
mbed_official | 76:aeb1df146756 | 420 | * This parameter can be any combinations of the following values: |
mbed_official | 76:aeb1df146756 | 421 | * @arg AES_IT_CC: Computation Complete Interrupt. If enabled, once CCF |
mbed_official | 76:aeb1df146756 | 422 | * flag is set an interrupt is generated. |
mbed_official | 76:aeb1df146756 | 423 | * @arg AES_IT_ERR: Error Interrupt. If enabled, once a read error |
mbed_official | 76:aeb1df146756 | 424 | * flags (RDERR) or write error flag (WRERR) is set, |
mbed_official | 76:aeb1df146756 | 425 | * an interrupt is generated. |
mbed_official | 76:aeb1df146756 | 426 | * @param NewState: The new state of the AES interrupt source. |
mbed_official | 76:aeb1df146756 | 427 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 428 | * @retval None |
mbed_official | 76:aeb1df146756 | 429 | */ |
mbed_official | 76:aeb1df146756 | 430 | void AES_ITConfig(uint32_t AES_IT, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 431 | { |
mbed_official | 76:aeb1df146756 | 432 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 433 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 434 | assert_param(IS_AES_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 435 | |
mbed_official | 76:aeb1df146756 | 436 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 437 | { |
mbed_official | 76:aeb1df146756 | 438 | AES->CR |= (uint32_t) AES_IT; /**< AES_IT Enable */ |
mbed_official | 76:aeb1df146756 | 439 | } |
mbed_official | 76:aeb1df146756 | 440 | else |
mbed_official | 76:aeb1df146756 | 441 | { |
mbed_official | 76:aeb1df146756 | 442 | AES->CR &= (uint32_t)(~AES_IT); /**< AES_IT Disable */ |
mbed_official | 76:aeb1df146756 | 443 | } |
mbed_official | 76:aeb1df146756 | 444 | } |
mbed_official | 76:aeb1df146756 | 445 | |
mbed_official | 76:aeb1df146756 | 446 | /** |
mbed_official | 76:aeb1df146756 | 447 | * @brief Checks whether the specified AES flag is set or not. |
mbed_official | 76:aeb1df146756 | 448 | * @param AES_FLAG specifies the flag to check. |
mbed_official | 76:aeb1df146756 | 449 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 450 | * @arg AES_FLAG_CCF: Computation Complete Flag is set by hardware when |
mbed_official | 76:aeb1df146756 | 451 | * he computation phase is completed. |
mbed_official | 76:aeb1df146756 | 452 | * @arg AES_FLAG_RDERR: Read Error Flag is set when an unexpected read |
mbed_official | 76:aeb1df146756 | 453 | * operation of DOUTR register is detected. |
mbed_official | 76:aeb1df146756 | 454 | * @arg AES_FLAG_WRERR: Write Error Flag is set when an unexpected write |
mbed_official | 76:aeb1df146756 | 455 | * operation in DINR is detected. |
mbed_official | 76:aeb1df146756 | 456 | * @retval FlagStatus (SET or RESET) |
mbed_official | 76:aeb1df146756 | 457 | */ |
mbed_official | 76:aeb1df146756 | 458 | FlagStatus AES_GetFlagStatus(uint32_t AES_FLAG) |
mbed_official | 76:aeb1df146756 | 459 | { |
mbed_official | 76:aeb1df146756 | 460 | FlagStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 461 | |
mbed_official | 76:aeb1df146756 | 462 | /* Check parameters */ |
mbed_official | 76:aeb1df146756 | 463 | assert_param(IS_AES_FLAG(AES_FLAG)); |
mbed_official | 76:aeb1df146756 | 464 | |
mbed_official | 76:aeb1df146756 | 465 | if ((AES->SR & AES_FLAG) != (uint32_t)RESET) |
mbed_official | 76:aeb1df146756 | 466 | { |
mbed_official | 76:aeb1df146756 | 467 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 468 | } |
mbed_official | 76:aeb1df146756 | 469 | else |
mbed_official | 76:aeb1df146756 | 470 | { |
mbed_official | 76:aeb1df146756 | 471 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 472 | } |
mbed_official | 76:aeb1df146756 | 473 | |
mbed_official | 76:aeb1df146756 | 474 | /* Return the AES_FLAG status */ |
mbed_official | 76:aeb1df146756 | 475 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 476 | } |
mbed_official | 76:aeb1df146756 | 477 | |
mbed_official | 76:aeb1df146756 | 478 | /** |
mbed_official | 76:aeb1df146756 | 479 | * @brief Clears the AES flags. |
mbed_official | 76:aeb1df146756 | 480 | * @param AES_FLAG: specifies the flag to clear. |
mbed_official | 76:aeb1df146756 | 481 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 482 | * @arg AES_FLAG_CCF: Computation Complete Flag is cleared by setting CCFC |
mbed_official | 76:aeb1df146756 | 483 | * bit in CR register. |
mbed_official | 76:aeb1df146756 | 484 | * @arg AES_FLAG_RDERR: Read Error is cleared by setting ERRC bit in |
mbed_official | 76:aeb1df146756 | 485 | * CR register. |
mbed_official | 76:aeb1df146756 | 486 | * @arg AES_FLAG_WRERR: Write Error is cleared by setting ERRC bit in |
mbed_official | 76:aeb1df146756 | 487 | * CR register. |
mbed_official | 76:aeb1df146756 | 488 | * @retval None |
mbed_official | 76:aeb1df146756 | 489 | */ |
mbed_official | 76:aeb1df146756 | 490 | void AES_ClearFlag(uint32_t AES_FLAG) |
mbed_official | 76:aeb1df146756 | 491 | { |
mbed_official | 76:aeb1df146756 | 492 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 493 | assert_param(IS_AES_FLAG(AES_FLAG)); |
mbed_official | 76:aeb1df146756 | 494 | |
mbed_official | 76:aeb1df146756 | 495 | /* Check if AES_FLAG is AES_FLAG_CCF */ |
mbed_official | 76:aeb1df146756 | 496 | if (AES_FLAG == AES_FLAG_CCF) |
mbed_official | 76:aeb1df146756 | 497 | { |
mbed_official | 76:aeb1df146756 | 498 | /* Clear CCF flag by setting CCFC bit */ |
mbed_official | 76:aeb1df146756 | 499 | AES->CR |= (uint32_t) AES_CR_CCFC; |
mbed_official | 76:aeb1df146756 | 500 | } |
mbed_official | 76:aeb1df146756 | 501 | else /* AES_FLAG is AES_FLAG_RDERR or AES_FLAG_WRERR */ |
mbed_official | 76:aeb1df146756 | 502 | { |
mbed_official | 76:aeb1df146756 | 503 | /* Clear RDERR and WRERR flags by setting ERRC bit */ |
mbed_official | 76:aeb1df146756 | 504 | AES->CR |= (uint32_t) AES_CR_ERRC; |
mbed_official | 76:aeb1df146756 | 505 | } |
mbed_official | 76:aeb1df146756 | 506 | } |
mbed_official | 76:aeb1df146756 | 507 | |
mbed_official | 76:aeb1df146756 | 508 | /** |
mbed_official | 76:aeb1df146756 | 509 | * @brief Checks whether the specified AES interrupt has occurred or not. |
mbed_official | 76:aeb1df146756 | 510 | * @param AES_IT: Specifies the AES interrupt pending bit to check. |
mbed_official | 76:aeb1df146756 | 511 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 512 | * @arg AES_IT_CC: Computation Complete Interrupt. |
mbed_official | 76:aeb1df146756 | 513 | * @arg AES_IT_ERR: Error Interrupt. |
mbed_official | 76:aeb1df146756 | 514 | * @retval ITStatus The new state of AES_IT (SET or RESET). |
mbed_official | 76:aeb1df146756 | 515 | */ |
mbed_official | 76:aeb1df146756 | 516 | ITStatus AES_GetITStatus(uint32_t AES_IT) |
mbed_official | 76:aeb1df146756 | 517 | { |
mbed_official | 76:aeb1df146756 | 518 | ITStatus itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 519 | uint32_t cciebitstatus = RESET, ccfbitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 520 | |
mbed_official | 76:aeb1df146756 | 521 | /* Check parameters */ |
mbed_official | 76:aeb1df146756 | 522 | assert_param(IS_AES_GET_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 523 | |
mbed_official | 76:aeb1df146756 | 524 | cciebitstatus = AES->CR & AES_CR_CCIE; |
mbed_official | 76:aeb1df146756 | 525 | ccfbitstatus = AES->SR & AES_SR_CCF; |
mbed_official | 76:aeb1df146756 | 526 | |
mbed_official | 76:aeb1df146756 | 527 | /* Check if AES_IT is AES_IT_CC */ |
mbed_official | 76:aeb1df146756 | 528 | if (AES_IT == AES_IT_CC) |
mbed_official | 76:aeb1df146756 | 529 | { |
mbed_official | 76:aeb1df146756 | 530 | /* Check the status of the specified AES interrupt */ |
mbed_official | 76:aeb1df146756 | 531 | if (((cciebitstatus) != (uint32_t)RESET) && ((ccfbitstatus) != (uint32_t)RESET)) |
mbed_official | 76:aeb1df146756 | 532 | { |
mbed_official | 76:aeb1df146756 | 533 | /* Interrupt occurred */ |
mbed_official | 76:aeb1df146756 | 534 | itstatus = SET; |
mbed_official | 76:aeb1df146756 | 535 | } |
mbed_official | 76:aeb1df146756 | 536 | else |
mbed_official | 76:aeb1df146756 | 537 | { |
mbed_official | 76:aeb1df146756 | 538 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 539 | itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 540 | } |
mbed_official | 76:aeb1df146756 | 541 | } |
mbed_official | 76:aeb1df146756 | 542 | else /* AES_IT is AES_IT_ERR */ |
mbed_official | 76:aeb1df146756 | 543 | { |
mbed_official | 76:aeb1df146756 | 544 | /* Check the status of the specified AES interrupt */ |
mbed_official | 76:aeb1df146756 | 545 | if ((AES->CR & AES_CR_ERRIE) != RESET) |
mbed_official | 76:aeb1df146756 | 546 | { |
mbed_official | 76:aeb1df146756 | 547 | /* Check if WRERR or RDERR flags are set */ |
mbed_official | 76:aeb1df146756 | 548 | if ((AES->SR & (uint32_t)(AES_SR_WRERR | AES_SR_RDERR)) != (uint16_t)RESET) |
mbed_official | 76:aeb1df146756 | 549 | { |
mbed_official | 76:aeb1df146756 | 550 | /* Interrupt occurred */ |
mbed_official | 76:aeb1df146756 | 551 | itstatus = SET; |
mbed_official | 76:aeb1df146756 | 552 | } |
mbed_official | 76:aeb1df146756 | 553 | else |
mbed_official | 76:aeb1df146756 | 554 | { |
mbed_official | 76:aeb1df146756 | 555 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 556 | itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 557 | } |
mbed_official | 76:aeb1df146756 | 558 | } |
mbed_official | 76:aeb1df146756 | 559 | else |
mbed_official | 76:aeb1df146756 | 560 | { |
mbed_official | 76:aeb1df146756 | 561 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 562 | itstatus = (ITStatus) RESET; |
mbed_official | 76:aeb1df146756 | 563 | } |
mbed_official | 76:aeb1df146756 | 564 | } |
mbed_official | 76:aeb1df146756 | 565 | |
mbed_official | 76:aeb1df146756 | 566 | /* Return the AES_IT status */ |
mbed_official | 76:aeb1df146756 | 567 | return itstatus; |
mbed_official | 76:aeb1df146756 | 568 | } |
mbed_official | 76:aeb1df146756 | 569 | |
mbed_official | 76:aeb1df146756 | 570 | /** |
mbed_official | 76:aeb1df146756 | 571 | * @brief Clears the AES's interrupt pending bits. |
mbed_official | 76:aeb1df146756 | 572 | * @param AES_IT: specifies the interrupt pending bit to clear. |
mbed_official | 76:aeb1df146756 | 573 | * This parameter can be any combinations of the following values: |
mbed_official | 76:aeb1df146756 | 574 | * @arg AES_IT_CC: Computation Complete Interrupt. |
mbed_official | 76:aeb1df146756 | 575 | * @arg AES_IT_ERR: Error Interrupt. |
mbed_official | 76:aeb1df146756 | 576 | * @retval None |
mbed_official | 76:aeb1df146756 | 577 | */ |
mbed_official | 76:aeb1df146756 | 578 | void AES_ClearITPendingBit(uint32_t AES_IT) |
mbed_official | 76:aeb1df146756 | 579 | { |
mbed_official | 76:aeb1df146756 | 580 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 581 | assert_param(IS_AES_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 582 | |
mbed_official | 76:aeb1df146756 | 583 | /* Clear the interrupt pending bit */ |
mbed_official | 76:aeb1df146756 | 584 | AES->CR |= (uint32_t) (AES_IT >> (uint32_t) 0x00000002); |
mbed_official | 76:aeb1df146756 | 585 | } |
mbed_official | 76:aeb1df146756 | 586 | |
mbed_official | 76:aeb1df146756 | 587 | /** |
mbed_official | 76:aeb1df146756 | 588 | * @} |
mbed_official | 76:aeb1df146756 | 589 | */ |
mbed_official | 76:aeb1df146756 | 590 | |
mbed_official | 76:aeb1df146756 | 591 | /** |
mbed_official | 76:aeb1df146756 | 592 | * @} |
mbed_official | 76:aeb1df146756 | 593 | */ |
mbed_official | 76:aeb1df146756 | 594 | |
mbed_official | 76:aeb1df146756 | 595 | /** |
mbed_official | 76:aeb1df146756 | 596 | * @} |
mbed_official | 76:aeb1df146756 | 597 | */ |
mbed_official | 76:aeb1df146756 | 598 | |
mbed_official | 76:aeb1df146756 | 599 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |