mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_aes.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 106:ced8cbb51063
test with CLOCK_SETUP = 0
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 | 80:66393a7b209d | 5 | * @version V1.3.0 |
mbed_official | 80:66393a7b209d | 6 | * @date 31-January-2014 |
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 | 106:ced8cbb51063 | 55 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 56 | * |
mbed_official | 106:ced8cbb51063 | 57 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 106:ced8cbb51063 | 58 | * are permitted provided that the following conditions are met: |
mbed_official | 106:ced8cbb51063 | 59 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 60 | * this list of conditions and the following disclaimer. |
mbed_official | 106:ced8cbb51063 | 61 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 62 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 106:ced8cbb51063 | 63 | * and/or other materials provided with the distribution. |
mbed_official | 106:ced8cbb51063 | 64 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 106:ced8cbb51063 | 65 | * may be used to endorse or promote products derived from this software |
mbed_official | 106:ced8cbb51063 | 66 | * without specific prior written permission. |
mbed_official | 76:aeb1df146756 | 67 | * |
mbed_official | 106:ced8cbb51063 | 68 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 106:ced8cbb51063 | 69 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 106:ced8cbb51063 | 70 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 106:ced8cbb51063 | 71 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 106:ced8cbb51063 | 72 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 106:ced8cbb51063 | 73 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 106:ced8cbb51063 | 74 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 106:ced8cbb51063 | 75 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 106:ced8cbb51063 | 76 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 106:ced8cbb51063 | 77 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 76:aeb1df146756 | 78 | * |
mbed_official | 76:aeb1df146756 | 79 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 80 | */ |
mbed_official | 76:aeb1df146756 | 81 | |
mbed_official | 76:aeb1df146756 | 82 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 83 | #include "stm32l1xx_aes.h" |
mbed_official | 76:aeb1df146756 | 84 | #include "stm32l1xx_rcc.h" |
mbed_official | 76:aeb1df146756 | 85 | |
mbed_official | 76:aeb1df146756 | 86 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 87 | * @{ |
mbed_official | 76:aeb1df146756 | 88 | */ |
mbed_official | 76:aeb1df146756 | 89 | |
mbed_official | 76:aeb1df146756 | 90 | /** @defgroup AES |
mbed_official | 76:aeb1df146756 | 91 | * @brief AES driver modules |
mbed_official | 76:aeb1df146756 | 92 | * @{ |
mbed_official | 76:aeb1df146756 | 93 | */ |
mbed_official | 76:aeb1df146756 | 94 | |
mbed_official | 76:aeb1df146756 | 95 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 96 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 97 | #define CR_CLEAR_MASK ((uint32_t)0xFFFFFF81) |
mbed_official | 76:aeb1df146756 | 98 | |
mbed_official | 76:aeb1df146756 | 99 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 100 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 101 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 102 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 103 | |
mbed_official | 76:aeb1df146756 | 104 | /** @defgroup AES_Private_Functions |
mbed_official | 76:aeb1df146756 | 105 | * @{ |
mbed_official | 76:aeb1df146756 | 106 | */ |
mbed_official | 76:aeb1df146756 | 107 | |
mbed_official | 76:aeb1df146756 | 108 | /** @defgroup AES_Group1 Initialization and configuration |
mbed_official | 76:aeb1df146756 | 109 | * @brief Initialization and configuration. |
mbed_official | 76:aeb1df146756 | 110 | * |
mbed_official | 76:aeb1df146756 | 111 | @verbatim |
mbed_official | 76:aeb1df146756 | 112 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 113 | ##### Initialization and configuration ##### |
mbed_official | 76:aeb1df146756 | 114 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 115 | |
mbed_official | 76:aeb1df146756 | 116 | @endverbatim |
mbed_official | 76:aeb1df146756 | 117 | * @{ |
mbed_official | 76:aeb1df146756 | 118 | */ |
mbed_official | 76:aeb1df146756 | 119 | |
mbed_official | 76:aeb1df146756 | 120 | /** |
mbed_official | 76:aeb1df146756 | 121 | * @brief Deinitializes AES peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 122 | * @param None |
mbed_official | 76:aeb1df146756 | 123 | * @retval None |
mbed_official | 76:aeb1df146756 | 124 | */ |
mbed_official | 76:aeb1df146756 | 125 | void AES_DeInit(void) |
mbed_official | 76:aeb1df146756 | 126 | { |
mbed_official | 76:aeb1df146756 | 127 | /* Enable AES reset state */ |
mbed_official | 76:aeb1df146756 | 128 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_AES, ENABLE); |
mbed_official | 76:aeb1df146756 | 129 | /* Release AES from reset state */ |
mbed_official | 76:aeb1df146756 | 130 | RCC_AHBPeriphResetCmd(RCC_AHBPeriph_AES, DISABLE); |
mbed_official | 76:aeb1df146756 | 131 | } |
mbed_official | 76:aeb1df146756 | 132 | |
mbed_official | 76:aeb1df146756 | 133 | /** |
mbed_official | 76:aeb1df146756 | 134 | * @brief Initializes the AES peripheral according to the specified parameters |
mbed_official | 76:aeb1df146756 | 135 | * in the AES_InitStruct: |
mbed_official | 76:aeb1df146756 | 136 | * - AES_Operation: specifies the operation mode (encryption, decryption...). |
mbed_official | 76:aeb1df146756 | 137 | * - AES_Chaining: specifies the chaining mode (ECB, CBC or CTR). |
mbed_official | 76:aeb1df146756 | 138 | * - AES_DataType: specifies the data swapping type: 32-bit, 16-bit, 8-bit or 1-bit. |
mbed_official | 76:aeb1df146756 | 139 | * @note If AES is already enabled, use AES_Cmd(DISABLE) before setting the new |
mbed_official | 76:aeb1df146756 | 140 | * configuration (When AES is enabled, setting configuration is forbidden). |
mbed_official | 76:aeb1df146756 | 141 | * @param AES_InitStruct: pointer to an AES_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 142 | * the configuration information for AES peripheral. |
mbed_official | 76:aeb1df146756 | 143 | * @retval None |
mbed_official | 76:aeb1df146756 | 144 | */ |
mbed_official | 76:aeb1df146756 | 145 | void AES_Init(AES_InitTypeDef* AES_InitStruct) |
mbed_official | 76:aeb1df146756 | 146 | { |
mbed_official | 76:aeb1df146756 | 147 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 148 | |
mbed_official | 76:aeb1df146756 | 149 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 150 | assert_param(IS_AES_MODE(AES_InitStruct->AES_Operation)); |
mbed_official | 76:aeb1df146756 | 151 | assert_param(IS_AES_CHAINING(AES_InitStruct->AES_Chaining)); |
mbed_official | 76:aeb1df146756 | 152 | assert_param(IS_AES_DATATYPE(AES_InitStruct->AES_DataType)); |
mbed_official | 76:aeb1df146756 | 153 | |
mbed_official | 76:aeb1df146756 | 154 | /* Get AES CR register value */ |
mbed_official | 76:aeb1df146756 | 155 | tmpreg = AES->CR; |
mbed_official | 76:aeb1df146756 | 156 | |
mbed_official | 76:aeb1df146756 | 157 | /* Clear DATATYPE[1:0], MODE[1:0] and CHMOD[1:0] bits */ |
mbed_official | 76:aeb1df146756 | 158 | tmpreg &= (uint32_t)CR_CLEAR_MASK; |
mbed_official | 76:aeb1df146756 | 159 | |
mbed_official | 76:aeb1df146756 | 160 | tmpreg |= (AES_InitStruct->AES_Operation | AES_InitStruct->AES_Chaining | AES_InitStruct->AES_DataType); |
mbed_official | 76:aeb1df146756 | 161 | |
mbed_official | 76:aeb1df146756 | 162 | AES->CR = (uint32_t) tmpreg; |
mbed_official | 76:aeb1df146756 | 163 | } |
mbed_official | 76:aeb1df146756 | 164 | |
mbed_official | 76:aeb1df146756 | 165 | /** |
mbed_official | 76:aeb1df146756 | 166 | * @brief Initializes the AES Keys according to the specified parameters in the AES_KeyInitStruct. |
mbed_official | 76:aeb1df146756 | 167 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 168 | * contains the configuration information for the specified AES Keys. |
mbed_official | 76:aeb1df146756 | 169 | * @note This function must be called while the AES is disabled. |
mbed_official | 76:aeb1df146756 | 170 | * @note In encryption, key derivation and key derivation + decryption modes, |
mbed_official | 76:aeb1df146756 | 171 | * AES_KeyInitStruct must contain the encryption key. |
mbed_official | 76:aeb1df146756 | 172 | * In decryption mode, AES_KeyInitStruct must contain the decryption key. |
mbed_official | 76:aeb1df146756 | 173 | * @retval None |
mbed_official | 76:aeb1df146756 | 174 | */ |
mbed_official | 76:aeb1df146756 | 175 | void AES_KeyInit(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 176 | { |
mbed_official | 76:aeb1df146756 | 177 | AES->KEYR0 = AES_KeyInitStruct->AES_Key0; |
mbed_official | 76:aeb1df146756 | 178 | AES->KEYR1 = AES_KeyInitStruct->AES_Key1; |
mbed_official | 76:aeb1df146756 | 179 | AES->KEYR2 = AES_KeyInitStruct->AES_Key2; |
mbed_official | 76:aeb1df146756 | 180 | AES->KEYR3 = AES_KeyInitStruct->AES_Key3; |
mbed_official | 76:aeb1df146756 | 181 | } |
mbed_official | 76:aeb1df146756 | 182 | |
mbed_official | 76:aeb1df146756 | 183 | /** |
mbed_official | 76:aeb1df146756 | 184 | * @brief Initializes the AES Initialization Vector IV according to |
mbed_official | 76:aeb1df146756 | 185 | * the specified parameters in the AES_IVInitStruct. |
mbed_official | 76:aeb1df146756 | 186 | * @param AES_KeyInitStruct: pointer to an AES_IVInitTypeDef structure that |
mbed_official | 76:aeb1df146756 | 187 | * contains the configuration information for the specified AES IV. |
mbed_official | 76:aeb1df146756 | 188 | * @note When ECB chaining mode is selected, Initialization Vector IV has no |
mbed_official | 76:aeb1df146756 | 189 | * meaning. |
mbed_official | 76:aeb1df146756 | 190 | * When CTR chaining mode is selected, AES_IV0 contains the CTR value. |
mbed_official | 76:aeb1df146756 | 191 | * AES_IV1, AES_IV2 and AES_IV3 contains nonce value. |
mbed_official | 76:aeb1df146756 | 192 | * @retval None |
mbed_official | 76:aeb1df146756 | 193 | */ |
mbed_official | 76:aeb1df146756 | 194 | void AES_IVInit(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 195 | { |
mbed_official | 76:aeb1df146756 | 196 | AES->IVR0 = AES_IVInitStruct->AES_IV0; |
mbed_official | 76:aeb1df146756 | 197 | AES->IVR1 = AES_IVInitStruct->AES_IV1; |
mbed_official | 76:aeb1df146756 | 198 | AES->IVR2 = AES_IVInitStruct->AES_IV2; |
mbed_official | 76:aeb1df146756 | 199 | AES->IVR3 = AES_IVInitStruct->AES_IV3; |
mbed_official | 76:aeb1df146756 | 200 | } |
mbed_official | 76:aeb1df146756 | 201 | |
mbed_official | 76:aeb1df146756 | 202 | /** |
mbed_official | 76:aeb1df146756 | 203 | * @brief Enable or disable the AES peripheral. |
mbed_official | 76:aeb1df146756 | 204 | * @param NewState: new state of the AES peripheral. |
mbed_official | 76:aeb1df146756 | 205 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 206 | * @note The key must be written while AES is disabled. |
mbed_official | 76:aeb1df146756 | 207 | * @retval None |
mbed_official | 76:aeb1df146756 | 208 | */ |
mbed_official | 76:aeb1df146756 | 209 | void AES_Cmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 210 | { |
mbed_official | 76:aeb1df146756 | 211 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 212 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 213 | |
mbed_official | 76:aeb1df146756 | 214 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 215 | { |
mbed_official | 76:aeb1df146756 | 216 | /* Enable the AES peripheral */ |
mbed_official | 76:aeb1df146756 | 217 | AES->CR |= (uint32_t) AES_CR_EN; /**< AES Enable */ |
mbed_official | 76:aeb1df146756 | 218 | } |
mbed_official | 76:aeb1df146756 | 219 | else |
mbed_official | 76:aeb1df146756 | 220 | { |
mbed_official | 76:aeb1df146756 | 221 | /* Disable the AES peripheral */ |
mbed_official | 76:aeb1df146756 | 222 | AES->CR &= (uint32_t)(~AES_CR_EN); /**< AES Disable */ |
mbed_official | 76:aeb1df146756 | 223 | } |
mbed_official | 76:aeb1df146756 | 224 | } |
mbed_official | 76:aeb1df146756 | 225 | |
mbed_official | 76:aeb1df146756 | 226 | /** |
mbed_official | 76:aeb1df146756 | 227 | * @} |
mbed_official | 76:aeb1df146756 | 228 | */ |
mbed_official | 76:aeb1df146756 | 229 | |
mbed_official | 76:aeb1df146756 | 230 | /** @defgroup AES_Group2 Structures initialization functions |
mbed_official | 76:aeb1df146756 | 231 | * @brief Structures initialization. |
mbed_official | 76:aeb1df146756 | 232 | * |
mbed_official | 76:aeb1df146756 | 233 | @verbatim |
mbed_official | 76:aeb1df146756 | 234 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 235 | ##### Structures initialization functions ##### |
mbed_official | 76:aeb1df146756 | 236 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 237 | |
mbed_official | 76:aeb1df146756 | 238 | @endverbatim |
mbed_official | 76:aeb1df146756 | 239 | * @{ |
mbed_official | 76:aeb1df146756 | 240 | */ |
mbed_official | 76:aeb1df146756 | 241 | |
mbed_official | 76:aeb1df146756 | 242 | /** |
mbed_official | 76:aeb1df146756 | 243 | * @brief Fills each AES_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 244 | * @param AES_InitStruct: pointer to an AES_InitTypeDef structure which will |
mbed_official | 76:aeb1df146756 | 245 | * be initialized. |
mbed_official | 76:aeb1df146756 | 246 | * @retval None |
mbed_official | 76:aeb1df146756 | 247 | */ |
mbed_official | 76:aeb1df146756 | 248 | void AES_StructInit(AES_InitTypeDef* AES_InitStruct) |
mbed_official | 76:aeb1df146756 | 249 | { |
mbed_official | 76:aeb1df146756 | 250 | AES_InitStruct->AES_Operation = AES_Operation_Encryp; |
mbed_official | 76:aeb1df146756 | 251 | AES_InitStruct->AES_Chaining = AES_Chaining_ECB; |
mbed_official | 76:aeb1df146756 | 252 | AES_InitStruct->AES_DataType = AES_DataType_32b; |
mbed_official | 76:aeb1df146756 | 253 | } |
mbed_official | 76:aeb1df146756 | 254 | |
mbed_official | 76:aeb1df146756 | 255 | /** |
mbed_official | 76:aeb1df146756 | 256 | * @brief Fills each AES_KeyInitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 257 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitStruct structure which |
mbed_official | 76:aeb1df146756 | 258 | * will be initialized. |
mbed_official | 76:aeb1df146756 | 259 | * @retval None |
mbed_official | 76:aeb1df146756 | 260 | */ |
mbed_official | 76:aeb1df146756 | 261 | void AES_KeyStructInit(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 262 | { |
mbed_official | 76:aeb1df146756 | 263 | AES_KeyInitStruct->AES_Key0 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 264 | AES_KeyInitStruct->AES_Key1 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 265 | AES_KeyInitStruct->AES_Key2 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 266 | AES_KeyInitStruct->AES_Key3 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 267 | } |
mbed_official | 76:aeb1df146756 | 268 | |
mbed_official | 76:aeb1df146756 | 269 | /** |
mbed_official | 76:aeb1df146756 | 270 | * @brief Fills each AES_IVInitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 271 | * @param AES_IVInitStruct: pointer to an AES_IVInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 272 | * will be initialized. |
mbed_official | 76:aeb1df146756 | 273 | * @retval None |
mbed_official | 76:aeb1df146756 | 274 | */ |
mbed_official | 76:aeb1df146756 | 275 | void AES_IVStructInit(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 276 | { |
mbed_official | 76:aeb1df146756 | 277 | AES_IVInitStruct->AES_IV0 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 278 | AES_IVInitStruct->AES_IV1 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 279 | AES_IVInitStruct->AES_IV2 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 280 | AES_IVInitStruct->AES_IV3 = 0x00000000; |
mbed_official | 76:aeb1df146756 | 281 | } |
mbed_official | 76:aeb1df146756 | 282 | |
mbed_official | 76:aeb1df146756 | 283 | /** |
mbed_official | 76:aeb1df146756 | 284 | * @} |
mbed_official | 76:aeb1df146756 | 285 | */ |
mbed_official | 76:aeb1df146756 | 286 | |
mbed_official | 76:aeb1df146756 | 287 | /** @defgroup AES_Group3 AES Read and Write |
mbed_official | 76:aeb1df146756 | 288 | * @brief AES Read and Write. |
mbed_official | 76:aeb1df146756 | 289 | * |
mbed_official | 76:aeb1df146756 | 290 | @verbatim |
mbed_official | 76:aeb1df146756 | 291 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 292 | ##### AES Read and Write functions ##### |
mbed_official | 76:aeb1df146756 | 293 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 294 | |
mbed_official | 76:aeb1df146756 | 295 | @endverbatim |
mbed_official | 76:aeb1df146756 | 296 | * @{ |
mbed_official | 76:aeb1df146756 | 297 | */ |
mbed_official | 76:aeb1df146756 | 298 | |
mbed_official | 76:aeb1df146756 | 299 | /** |
mbed_official | 76:aeb1df146756 | 300 | * @brief Write data in DINR register to be processed by AES peripheral. |
mbed_official | 76:aeb1df146756 | 301 | * @note To process 128-bit data (4 * 32-bit), this function must be called |
mbed_official | 76:aeb1df146756 | 302 | * four times to write the 128-bit data in the 32-bit register DINR. |
mbed_official | 76:aeb1df146756 | 303 | * @note When an unexpected write to DOUTR register is detected, WRERR flag is |
mbed_official | 76:aeb1df146756 | 304 | * set. |
mbed_official | 76:aeb1df146756 | 305 | * @param Data: The data to be processed. |
mbed_official | 76:aeb1df146756 | 306 | * @retval None |
mbed_official | 76:aeb1df146756 | 307 | */ |
mbed_official | 76:aeb1df146756 | 308 | void AES_WriteSubData(uint32_t Data) |
mbed_official | 76:aeb1df146756 | 309 | { |
mbed_official | 76:aeb1df146756 | 310 | /* Write Data */ |
mbed_official | 76:aeb1df146756 | 311 | AES->DINR = Data; |
mbed_official | 76:aeb1df146756 | 312 | } |
mbed_official | 76:aeb1df146756 | 313 | |
mbed_official | 76:aeb1df146756 | 314 | /** |
mbed_official | 76:aeb1df146756 | 315 | * @brief Returns the data in DOUTR register processed by AES peripheral. |
mbed_official | 76:aeb1df146756 | 316 | * @note This function must be called four times to get the 128-bit data. |
mbed_official | 76:aeb1df146756 | 317 | * @note When an unexpected read of DINR register is detected, RDERR flag is |
mbed_official | 76:aeb1df146756 | 318 | * set. |
mbed_official | 76:aeb1df146756 | 319 | * @retval The processed data. |
mbed_official | 76:aeb1df146756 | 320 | */ |
mbed_official | 76:aeb1df146756 | 321 | uint32_t AES_ReadSubData(void) |
mbed_official | 76:aeb1df146756 | 322 | { |
mbed_official | 76:aeb1df146756 | 323 | /* Read Data */ |
mbed_official | 76:aeb1df146756 | 324 | return AES->DOUTR; |
mbed_official | 76:aeb1df146756 | 325 | } |
mbed_official | 76:aeb1df146756 | 326 | |
mbed_official | 76:aeb1df146756 | 327 | /** |
mbed_official | 76:aeb1df146756 | 328 | * @brief Read the Key value. |
mbed_official | 76:aeb1df146756 | 329 | * @param AES_KeyInitStruct: pointer to an AES_KeyInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 330 | * will contain the key. |
mbed_official | 76:aeb1df146756 | 331 | * @note When the key derivation mode is selected, AES must be disabled |
mbed_official | 76:aeb1df146756 | 332 | * (AES_Cmd(DISABLE)) before reading the decryption key. |
mbed_official | 76:aeb1df146756 | 333 | * Reading the key while the AES is enabled will return unpredictable |
mbed_official | 76:aeb1df146756 | 334 | * value. |
mbed_official | 76:aeb1df146756 | 335 | * @retval None |
mbed_official | 76:aeb1df146756 | 336 | */ |
mbed_official | 76:aeb1df146756 | 337 | void AES_ReadKey(AES_KeyInitTypeDef* AES_KeyInitStruct) |
mbed_official | 76:aeb1df146756 | 338 | { |
mbed_official | 76:aeb1df146756 | 339 | AES_KeyInitStruct->AES_Key0 = AES->KEYR0; |
mbed_official | 76:aeb1df146756 | 340 | AES_KeyInitStruct->AES_Key1 = AES->KEYR1; |
mbed_official | 76:aeb1df146756 | 341 | AES_KeyInitStruct->AES_Key2 = AES->KEYR2; |
mbed_official | 76:aeb1df146756 | 342 | AES_KeyInitStruct->AES_Key3 = AES->KEYR3; |
mbed_official | 76:aeb1df146756 | 343 | } |
mbed_official | 76:aeb1df146756 | 344 | |
mbed_official | 76:aeb1df146756 | 345 | /** |
mbed_official | 76:aeb1df146756 | 346 | * @brief Read the Initialization Vector IV value. |
mbed_official | 76:aeb1df146756 | 347 | * @param AES_IVInitStruct: pointer to an AES_IVInitTypeDef structure which |
mbed_official | 76:aeb1df146756 | 348 | * will contain the Initialization Vector IV. |
mbed_official | 76:aeb1df146756 | 349 | * @note When the AES is enabled Reading the Initialization Vector IV value |
mbed_official | 76:aeb1df146756 | 350 | * will return 0. The AES must be disabled using AES_Cmd(DISABLE) |
mbed_official | 76:aeb1df146756 | 351 | * to get the right value. |
mbed_official | 76:aeb1df146756 | 352 | * @note When ECB chaining mode is selected, Initialization Vector IV has no |
mbed_official | 76:aeb1df146756 | 353 | * meaning. |
mbed_official | 76:aeb1df146756 | 354 | * When CTR chaining mode is selected, AES_IV0 contains 32-bit Counter value. |
mbed_official | 76:aeb1df146756 | 355 | * AES_IV1, AES_IV2 and AES_IV3 contains nonce value. |
mbed_official | 76:aeb1df146756 | 356 | * @retval None |
mbed_official | 76:aeb1df146756 | 357 | */ |
mbed_official | 76:aeb1df146756 | 358 | void AES_ReadIV(AES_IVInitTypeDef* AES_IVInitStruct) |
mbed_official | 76:aeb1df146756 | 359 | { |
mbed_official | 76:aeb1df146756 | 360 | AES_IVInitStruct->AES_IV0 = AES->IVR0; |
mbed_official | 76:aeb1df146756 | 361 | AES_IVInitStruct->AES_IV1 = AES->IVR1; |
mbed_official | 76:aeb1df146756 | 362 | AES_IVInitStruct->AES_IV2 = AES->IVR2; |
mbed_official | 76:aeb1df146756 | 363 | AES_IVInitStruct->AES_IV3 = AES->IVR3; |
mbed_official | 76:aeb1df146756 | 364 | } |
mbed_official | 76:aeb1df146756 | 365 | |
mbed_official | 76:aeb1df146756 | 366 | /** |
mbed_official | 76:aeb1df146756 | 367 | * @} |
mbed_official | 76:aeb1df146756 | 368 | */ |
mbed_official | 76:aeb1df146756 | 369 | |
mbed_official | 76:aeb1df146756 | 370 | /** @defgroup AES_Group4 DMA transfers management functions |
mbed_official | 76:aeb1df146756 | 371 | * @brief DMA transfers management function. |
mbed_official | 76:aeb1df146756 | 372 | * |
mbed_official | 76:aeb1df146756 | 373 | @verbatim |
mbed_official | 76:aeb1df146756 | 374 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 375 | ##### DMA transfers management functions ##### |
mbed_official | 76:aeb1df146756 | 376 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 377 | |
mbed_official | 76:aeb1df146756 | 378 | @endverbatim |
mbed_official | 76:aeb1df146756 | 379 | * @{ |
mbed_official | 76:aeb1df146756 | 380 | */ |
mbed_official | 76:aeb1df146756 | 381 | |
mbed_official | 76:aeb1df146756 | 382 | /** |
mbed_official | 76:aeb1df146756 | 383 | * @brief Configures the AES DMA interface. |
mbed_official | 76:aeb1df146756 | 384 | * @param AES_DMATransfer: Specifies the AES DMA transfer. |
mbed_official | 76:aeb1df146756 | 385 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 386 | * @arg AES_DMATransfer_In: When selected, DMA manages the data input phase. |
mbed_official | 76:aeb1df146756 | 387 | * @arg AES_DMATransfer_Out: When selected, DMA manages the data output phase. |
mbed_official | 76:aeb1df146756 | 388 | * @arg AES_DMATransfer_InOut: When selected, DMA manages both the data input/output phases. |
mbed_official | 76:aeb1df146756 | 389 | * @param NewState Indicates the new state of the AES DMA interface. |
mbed_official | 76:aeb1df146756 | 390 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 391 | * @note The DMA has no action in key derivation mode. |
mbed_official | 76:aeb1df146756 | 392 | * @retval None |
mbed_official | 76:aeb1df146756 | 393 | */ |
mbed_official | 76:aeb1df146756 | 394 | void AES_DMAConfig(uint32_t AES_DMATransfer, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 395 | { |
mbed_official | 76:aeb1df146756 | 396 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 397 | assert_param(IS_AES_DMA_TRANSFER(AES_DMATransfer)); |
mbed_official | 76:aeb1df146756 | 398 | |
mbed_official | 76:aeb1df146756 | 399 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 400 | { |
mbed_official | 76:aeb1df146756 | 401 | /* Enable the DMA transfer */ |
mbed_official | 76:aeb1df146756 | 402 | AES->CR |= (uint32_t) AES_DMATransfer; |
mbed_official | 76:aeb1df146756 | 403 | } |
mbed_official | 76:aeb1df146756 | 404 | else |
mbed_official | 76:aeb1df146756 | 405 | { |
mbed_official | 76:aeb1df146756 | 406 | /* Disable the DMA transfer */ |
mbed_official | 76:aeb1df146756 | 407 | AES->CR &= (uint32_t)(~AES_DMATransfer); |
mbed_official | 76:aeb1df146756 | 408 | } |
mbed_official | 76:aeb1df146756 | 409 | } |
mbed_official | 76:aeb1df146756 | 410 | |
mbed_official | 76:aeb1df146756 | 411 | /** |
mbed_official | 76:aeb1df146756 | 412 | * @} |
mbed_official | 76:aeb1df146756 | 413 | */ |
mbed_official | 76:aeb1df146756 | 414 | |
mbed_official | 76:aeb1df146756 | 415 | /** @defgroup AES_Group5 Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 416 | * @brief Interrupts and flags management functions. |
mbed_official | 76:aeb1df146756 | 417 | * |
mbed_official | 76:aeb1df146756 | 418 | @verbatim |
mbed_official | 76:aeb1df146756 | 419 | |
mbed_official | 76:aeb1df146756 | 420 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 421 | ##### Interrupts and flags management functions ##### |
mbed_official | 76:aeb1df146756 | 422 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 423 | @endverbatim |
mbed_official | 76:aeb1df146756 | 424 | * @{ |
mbed_official | 76:aeb1df146756 | 425 | */ |
mbed_official | 76:aeb1df146756 | 426 | |
mbed_official | 76:aeb1df146756 | 427 | /** |
mbed_official | 76:aeb1df146756 | 428 | * @brief Enables or disables the specified AES interrupt. |
mbed_official | 76:aeb1df146756 | 429 | * @param AES_IT: Specifies the AES interrupt source to enable/disable. |
mbed_official | 76:aeb1df146756 | 430 | * This parameter can be any combinations of the following values: |
mbed_official | 76:aeb1df146756 | 431 | * @arg AES_IT_CC: Computation Complete Interrupt. If enabled, once CCF |
mbed_official | 76:aeb1df146756 | 432 | * flag is set an interrupt is generated. |
mbed_official | 76:aeb1df146756 | 433 | * @arg AES_IT_ERR: Error Interrupt. If enabled, once a read error |
mbed_official | 76:aeb1df146756 | 434 | * flags (RDERR) or write error flag (WRERR) is set, |
mbed_official | 76:aeb1df146756 | 435 | * an interrupt is generated. |
mbed_official | 76:aeb1df146756 | 436 | * @param NewState: The new state of the AES interrupt source. |
mbed_official | 76:aeb1df146756 | 437 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 438 | * @retval None |
mbed_official | 76:aeb1df146756 | 439 | */ |
mbed_official | 76:aeb1df146756 | 440 | void AES_ITConfig(uint32_t AES_IT, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 441 | { |
mbed_official | 76:aeb1df146756 | 442 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 443 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 444 | assert_param(IS_AES_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 445 | |
mbed_official | 76:aeb1df146756 | 446 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 447 | { |
mbed_official | 76:aeb1df146756 | 448 | AES->CR |= (uint32_t) AES_IT; /**< AES_IT Enable */ |
mbed_official | 76:aeb1df146756 | 449 | } |
mbed_official | 76:aeb1df146756 | 450 | else |
mbed_official | 76:aeb1df146756 | 451 | { |
mbed_official | 76:aeb1df146756 | 452 | AES->CR &= (uint32_t)(~AES_IT); /**< AES_IT Disable */ |
mbed_official | 76:aeb1df146756 | 453 | } |
mbed_official | 76:aeb1df146756 | 454 | } |
mbed_official | 76:aeb1df146756 | 455 | |
mbed_official | 76:aeb1df146756 | 456 | /** |
mbed_official | 76:aeb1df146756 | 457 | * @brief Checks whether the specified AES flag is set or not. |
mbed_official | 76:aeb1df146756 | 458 | * @param AES_FLAG specifies the flag to check. |
mbed_official | 76:aeb1df146756 | 459 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 460 | * @arg AES_FLAG_CCF: Computation Complete Flag is set by hardware when |
mbed_official | 76:aeb1df146756 | 461 | * he computation phase is completed. |
mbed_official | 76:aeb1df146756 | 462 | * @arg AES_FLAG_RDERR: Read Error Flag is set when an unexpected read |
mbed_official | 76:aeb1df146756 | 463 | * operation of DOUTR register is detected. |
mbed_official | 76:aeb1df146756 | 464 | * @arg AES_FLAG_WRERR: Write Error Flag is set when an unexpected write |
mbed_official | 76:aeb1df146756 | 465 | * operation in DINR is detected. |
mbed_official | 76:aeb1df146756 | 466 | * @retval FlagStatus (SET or RESET) |
mbed_official | 76:aeb1df146756 | 467 | */ |
mbed_official | 76:aeb1df146756 | 468 | FlagStatus AES_GetFlagStatus(uint32_t AES_FLAG) |
mbed_official | 76:aeb1df146756 | 469 | { |
mbed_official | 76:aeb1df146756 | 470 | FlagStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 471 | |
mbed_official | 76:aeb1df146756 | 472 | /* Check parameters */ |
mbed_official | 76:aeb1df146756 | 473 | assert_param(IS_AES_FLAG(AES_FLAG)); |
mbed_official | 76:aeb1df146756 | 474 | |
mbed_official | 76:aeb1df146756 | 475 | if ((AES->SR & AES_FLAG) != (uint32_t)RESET) |
mbed_official | 76:aeb1df146756 | 476 | { |
mbed_official | 76:aeb1df146756 | 477 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 478 | } |
mbed_official | 76:aeb1df146756 | 479 | else |
mbed_official | 76:aeb1df146756 | 480 | { |
mbed_official | 76:aeb1df146756 | 481 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 482 | } |
mbed_official | 76:aeb1df146756 | 483 | |
mbed_official | 76:aeb1df146756 | 484 | /* Return the AES_FLAG status */ |
mbed_official | 76:aeb1df146756 | 485 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 486 | } |
mbed_official | 76:aeb1df146756 | 487 | |
mbed_official | 76:aeb1df146756 | 488 | /** |
mbed_official | 76:aeb1df146756 | 489 | * @brief Clears the AES flags. |
mbed_official | 76:aeb1df146756 | 490 | * @param AES_FLAG: specifies the flag to clear. |
mbed_official | 76:aeb1df146756 | 491 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 492 | * @arg AES_FLAG_CCF: Computation Complete Flag is cleared by setting CCFC |
mbed_official | 76:aeb1df146756 | 493 | * bit in CR register. |
mbed_official | 76:aeb1df146756 | 494 | * @arg AES_FLAG_RDERR: Read Error is cleared by setting ERRC bit in |
mbed_official | 76:aeb1df146756 | 495 | * CR register. |
mbed_official | 76:aeb1df146756 | 496 | * @arg AES_FLAG_WRERR: Write Error is cleared by setting ERRC bit in |
mbed_official | 76:aeb1df146756 | 497 | * CR register. |
mbed_official | 76:aeb1df146756 | 498 | * @retval None |
mbed_official | 76:aeb1df146756 | 499 | */ |
mbed_official | 76:aeb1df146756 | 500 | void AES_ClearFlag(uint32_t AES_FLAG) |
mbed_official | 76:aeb1df146756 | 501 | { |
mbed_official | 76:aeb1df146756 | 502 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 503 | assert_param(IS_AES_FLAG(AES_FLAG)); |
mbed_official | 76:aeb1df146756 | 504 | |
mbed_official | 76:aeb1df146756 | 505 | /* Check if AES_FLAG is AES_FLAG_CCF */ |
mbed_official | 76:aeb1df146756 | 506 | if (AES_FLAG == AES_FLAG_CCF) |
mbed_official | 76:aeb1df146756 | 507 | { |
mbed_official | 76:aeb1df146756 | 508 | /* Clear CCF flag by setting CCFC bit */ |
mbed_official | 76:aeb1df146756 | 509 | AES->CR |= (uint32_t) AES_CR_CCFC; |
mbed_official | 76:aeb1df146756 | 510 | } |
mbed_official | 76:aeb1df146756 | 511 | else /* AES_FLAG is AES_FLAG_RDERR or AES_FLAG_WRERR */ |
mbed_official | 76:aeb1df146756 | 512 | { |
mbed_official | 76:aeb1df146756 | 513 | /* Clear RDERR and WRERR flags by setting ERRC bit */ |
mbed_official | 76:aeb1df146756 | 514 | AES->CR |= (uint32_t) AES_CR_ERRC; |
mbed_official | 76:aeb1df146756 | 515 | } |
mbed_official | 76:aeb1df146756 | 516 | } |
mbed_official | 76:aeb1df146756 | 517 | |
mbed_official | 76:aeb1df146756 | 518 | /** |
mbed_official | 76:aeb1df146756 | 519 | * @brief Checks whether the specified AES interrupt has occurred or not. |
mbed_official | 76:aeb1df146756 | 520 | * @param AES_IT: Specifies the AES interrupt pending bit to check. |
mbed_official | 76:aeb1df146756 | 521 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 522 | * @arg AES_IT_CC: Computation Complete Interrupt. |
mbed_official | 76:aeb1df146756 | 523 | * @arg AES_IT_ERR: Error Interrupt. |
mbed_official | 76:aeb1df146756 | 524 | * @retval ITStatus The new state of AES_IT (SET or RESET). |
mbed_official | 76:aeb1df146756 | 525 | */ |
mbed_official | 76:aeb1df146756 | 526 | ITStatus AES_GetITStatus(uint32_t AES_IT) |
mbed_official | 76:aeb1df146756 | 527 | { |
mbed_official | 76:aeb1df146756 | 528 | ITStatus itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 529 | uint32_t cciebitstatus = RESET, ccfbitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 530 | |
mbed_official | 76:aeb1df146756 | 531 | /* Check parameters */ |
mbed_official | 76:aeb1df146756 | 532 | assert_param(IS_AES_GET_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 533 | |
mbed_official | 76:aeb1df146756 | 534 | cciebitstatus = AES->CR & AES_CR_CCIE; |
mbed_official | 76:aeb1df146756 | 535 | ccfbitstatus = AES->SR & AES_SR_CCF; |
mbed_official | 76:aeb1df146756 | 536 | |
mbed_official | 76:aeb1df146756 | 537 | /* Check if AES_IT is AES_IT_CC */ |
mbed_official | 76:aeb1df146756 | 538 | if (AES_IT == AES_IT_CC) |
mbed_official | 76:aeb1df146756 | 539 | { |
mbed_official | 76:aeb1df146756 | 540 | /* Check the status of the specified AES interrupt */ |
mbed_official | 76:aeb1df146756 | 541 | if (((cciebitstatus) != (uint32_t)RESET) && ((ccfbitstatus) != (uint32_t)RESET)) |
mbed_official | 76:aeb1df146756 | 542 | { |
mbed_official | 76:aeb1df146756 | 543 | /* Interrupt occurred */ |
mbed_official | 76:aeb1df146756 | 544 | itstatus = SET; |
mbed_official | 76:aeb1df146756 | 545 | } |
mbed_official | 76:aeb1df146756 | 546 | else |
mbed_official | 76:aeb1df146756 | 547 | { |
mbed_official | 76:aeb1df146756 | 548 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 549 | itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 550 | } |
mbed_official | 76:aeb1df146756 | 551 | } |
mbed_official | 76:aeb1df146756 | 552 | else /* AES_IT is AES_IT_ERR */ |
mbed_official | 76:aeb1df146756 | 553 | { |
mbed_official | 76:aeb1df146756 | 554 | /* Check the status of the specified AES interrupt */ |
mbed_official | 76:aeb1df146756 | 555 | if ((AES->CR & AES_CR_ERRIE) != RESET) |
mbed_official | 76:aeb1df146756 | 556 | { |
mbed_official | 76:aeb1df146756 | 557 | /* Check if WRERR or RDERR flags are set */ |
mbed_official | 76:aeb1df146756 | 558 | if ((AES->SR & (uint32_t)(AES_SR_WRERR | AES_SR_RDERR)) != (uint16_t)RESET) |
mbed_official | 76:aeb1df146756 | 559 | { |
mbed_official | 76:aeb1df146756 | 560 | /* Interrupt occurred */ |
mbed_official | 76:aeb1df146756 | 561 | itstatus = SET; |
mbed_official | 76:aeb1df146756 | 562 | } |
mbed_official | 76:aeb1df146756 | 563 | else |
mbed_official | 76:aeb1df146756 | 564 | { |
mbed_official | 76:aeb1df146756 | 565 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 566 | itstatus = RESET; |
mbed_official | 76:aeb1df146756 | 567 | } |
mbed_official | 76:aeb1df146756 | 568 | } |
mbed_official | 76:aeb1df146756 | 569 | else |
mbed_official | 76:aeb1df146756 | 570 | { |
mbed_official | 76:aeb1df146756 | 571 | /* Interrupt didn't occur */ |
mbed_official | 76:aeb1df146756 | 572 | itstatus = (ITStatus) RESET; |
mbed_official | 76:aeb1df146756 | 573 | } |
mbed_official | 76:aeb1df146756 | 574 | } |
mbed_official | 76:aeb1df146756 | 575 | |
mbed_official | 76:aeb1df146756 | 576 | /* Return the AES_IT status */ |
mbed_official | 76:aeb1df146756 | 577 | return itstatus; |
mbed_official | 76:aeb1df146756 | 578 | } |
mbed_official | 76:aeb1df146756 | 579 | |
mbed_official | 76:aeb1df146756 | 580 | /** |
mbed_official | 76:aeb1df146756 | 581 | * @brief Clears the AES's interrupt pending bits. |
mbed_official | 76:aeb1df146756 | 582 | * @param AES_IT: specifies the interrupt pending bit to clear. |
mbed_official | 76:aeb1df146756 | 583 | * This parameter can be any combinations of the following values: |
mbed_official | 76:aeb1df146756 | 584 | * @arg AES_IT_CC: Computation Complete Interrupt. |
mbed_official | 76:aeb1df146756 | 585 | * @arg AES_IT_ERR: Error Interrupt. |
mbed_official | 76:aeb1df146756 | 586 | * @retval None |
mbed_official | 76:aeb1df146756 | 587 | */ |
mbed_official | 76:aeb1df146756 | 588 | void AES_ClearITPendingBit(uint32_t AES_IT) |
mbed_official | 76:aeb1df146756 | 589 | { |
mbed_official | 76:aeb1df146756 | 590 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 591 | assert_param(IS_AES_IT(AES_IT)); |
mbed_official | 76:aeb1df146756 | 592 | |
mbed_official | 76:aeb1df146756 | 593 | /* Clear the interrupt pending bit */ |
mbed_official | 76:aeb1df146756 | 594 | AES->CR |= (uint32_t) (AES_IT >> (uint32_t) 0x00000002); |
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 | */ |
mbed_official | 76:aeb1df146756 | 600 | |
mbed_official | 76:aeb1df146756 | 601 | /** |
mbed_official | 76:aeb1df146756 | 602 | * @} |
mbed_official | 76:aeb1df146756 | 603 | */ |
mbed_official | 76:aeb1df146756 | 604 | |
mbed_official | 76:aeb1df146756 | 605 | /** |
mbed_official | 76:aeb1df146756 | 606 | * @} |
mbed_official | 76:aeb1df146756 | 607 | */ |
mbed_official | 76:aeb1df146756 | 608 | |
mbed_official | 76:aeb1df146756 | 609 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |