Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_bee.h@0:fbdae7e6d805, 2018-05-14 (annotated)
- Committer:
- borlanic
- Date:
- Mon May 14 11:29:06 2018 +0000
- Revision:
- 0:fbdae7e6d805
BBR
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| borlanic | 0:fbdae7e6d805 | 1 | /* |
| borlanic | 0:fbdae7e6d805 | 2 | * Copyright 2017 NXP |
| borlanic | 0:fbdae7e6d805 | 3 | * All rights reserved. |
| borlanic | 0:fbdae7e6d805 | 4 | * |
| borlanic | 0:fbdae7e6d805 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
| borlanic | 0:fbdae7e6d805 | 6 | * are permitted provided that the following conditions are met: |
| borlanic | 0:fbdae7e6d805 | 7 | * |
| borlanic | 0:fbdae7e6d805 | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
| borlanic | 0:fbdae7e6d805 | 9 | * of conditions and the following disclaimer. |
| borlanic | 0:fbdae7e6d805 | 10 | * |
| borlanic | 0:fbdae7e6d805 | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
| borlanic | 0:fbdae7e6d805 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
| borlanic | 0:fbdae7e6d805 | 13 | * other materials provided with the distribution. |
| borlanic | 0:fbdae7e6d805 | 14 | * |
| borlanic | 0:fbdae7e6d805 | 15 | * o Neither the name of the copyright holder nor the names of its |
| borlanic | 0:fbdae7e6d805 | 16 | * contributors may be used to endorse or promote products derived from this |
| borlanic | 0:fbdae7e6d805 | 17 | * software without specific prior written permission. |
| borlanic | 0:fbdae7e6d805 | 18 | * |
| borlanic | 0:fbdae7e6d805 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| borlanic | 0:fbdae7e6d805 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| borlanic | 0:fbdae7e6d805 | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| borlanic | 0:fbdae7e6d805 | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| borlanic | 0:fbdae7e6d805 | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| borlanic | 0:fbdae7e6d805 | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| borlanic | 0:fbdae7e6d805 | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| borlanic | 0:fbdae7e6d805 | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| borlanic | 0:fbdae7e6d805 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| borlanic | 0:fbdae7e6d805 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| borlanic | 0:fbdae7e6d805 | 29 | */ |
| borlanic | 0:fbdae7e6d805 | 30 | |
| borlanic | 0:fbdae7e6d805 | 31 | #ifndef _FSL_BEE_H_ |
| borlanic | 0:fbdae7e6d805 | 32 | #define _FSL_BEE_H_ |
| borlanic | 0:fbdae7e6d805 | 33 | |
| borlanic | 0:fbdae7e6d805 | 34 | #include "fsl_common.h" |
| borlanic | 0:fbdae7e6d805 | 35 | |
| borlanic | 0:fbdae7e6d805 | 36 | /******************************************************************************* |
| borlanic | 0:fbdae7e6d805 | 37 | * Definitions |
| borlanic | 0:fbdae7e6d805 | 38 | *******************************************************************************/ |
| borlanic | 0:fbdae7e6d805 | 39 | |
| borlanic | 0:fbdae7e6d805 | 40 | /*! @name Driver version */ |
| borlanic | 0:fbdae7e6d805 | 41 | /*@{*/ |
| borlanic | 0:fbdae7e6d805 | 42 | /*! @brief BEE driver version. Version 2.0.0. |
| borlanic | 0:fbdae7e6d805 | 43 | * |
| borlanic | 0:fbdae7e6d805 | 44 | * Current version: 2.0.0 |
| borlanic | 0:fbdae7e6d805 | 45 | * |
| borlanic | 0:fbdae7e6d805 | 46 | * Change log: |
| borlanic | 0:fbdae7e6d805 | 47 | * - Version 2.0.0 |
| borlanic | 0:fbdae7e6d805 | 48 | * - Initial version |
| borlanic | 0:fbdae7e6d805 | 49 | */ |
| borlanic | 0:fbdae7e6d805 | 50 | #define FSL_BEE_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
| borlanic | 0:fbdae7e6d805 | 51 | /*@}*/ |
| borlanic | 0:fbdae7e6d805 | 52 | |
| borlanic | 0:fbdae7e6d805 | 53 | typedef enum _bee_aes_mode |
| borlanic | 0:fbdae7e6d805 | 54 | { |
| borlanic | 0:fbdae7e6d805 | 55 | kBEE_AesEcbMode = 0U, /*!< AES ECB Mode */ |
| borlanic | 0:fbdae7e6d805 | 56 | kBEE_AesCtrMode = 1U /*!< AES CTR Mode */ |
| borlanic | 0:fbdae7e6d805 | 57 | } bee_aes_mode_t; |
| borlanic | 0:fbdae7e6d805 | 58 | |
| borlanic | 0:fbdae7e6d805 | 59 | typedef enum _bee_region |
| borlanic | 0:fbdae7e6d805 | 60 | { |
| borlanic | 0:fbdae7e6d805 | 61 | kBEE_Region0 = 0U, /*!< BEE region 0 */ |
| borlanic | 0:fbdae7e6d805 | 62 | kBEE_Region1 = 1U /*!< BEE region 1 */ |
| borlanic | 0:fbdae7e6d805 | 63 | } bee_region_t; |
| borlanic | 0:fbdae7e6d805 | 64 | |
| borlanic | 0:fbdae7e6d805 | 65 | typedef enum _bee_region_enable |
| borlanic | 0:fbdae7e6d805 | 66 | { |
| borlanic | 0:fbdae7e6d805 | 67 | kBEE_RegionDisabled = 0U, /*!< BEE region disabled */ |
| borlanic | 0:fbdae7e6d805 | 68 | kBEE_RegionEnabled = 1U /*!< BEE region enabled */ |
| borlanic | 0:fbdae7e6d805 | 69 | } bee_region_enable_t; |
| borlanic | 0:fbdae7e6d805 | 70 | |
| borlanic | 0:fbdae7e6d805 | 71 | typedef enum _bee_status_flags |
| borlanic | 0:fbdae7e6d805 | 72 | { |
| borlanic | 0:fbdae7e6d805 | 73 | kBEE_DisableAbortFlag = 1U, /*!< Disable abort flag. */ |
| borlanic | 0:fbdae7e6d805 | 74 | kBEE_Reg0ReadSecViolation = 2U, /*!< Region-0 read channel security violation */ |
| borlanic | 0:fbdae7e6d805 | 75 | kBEE_ReadIllegalAccess = 4U, /*!< Read channel illegal access detected */ |
| borlanic | 0:fbdae7e6d805 | 76 | kBEE_Reg1ReadSecViolation = 8U, /*!< Region-1 read channel security violation */ |
| borlanic | 0:fbdae7e6d805 | 77 | kBEE_Reg0AccessViolation = 16U, /*!< Protected region-0 access violation */ |
| borlanic | 0:fbdae7e6d805 | 78 | kBEE_Reg1AccessViolation = 32U, /*!< Protected region-1 access violation */ |
| borlanic | 0:fbdae7e6d805 | 79 | kBEE_IdleFlag = BEE_STATUS_BEE_IDLE_MASK /*!< Idle flag */ |
| borlanic | 0:fbdae7e6d805 | 80 | } bee_status_flags_t; |
| borlanic | 0:fbdae7e6d805 | 81 | |
| borlanic | 0:fbdae7e6d805 | 82 | /*! @brief BEE region configuration structure. */ |
| borlanic | 0:fbdae7e6d805 | 83 | typedef struct _bee_region_config |
| borlanic | 0:fbdae7e6d805 | 84 | { |
| borlanic | 0:fbdae7e6d805 | 85 | bee_aes_mode_t mode; /*!< AES mode used for encryption/decryption */ |
| borlanic | 0:fbdae7e6d805 | 86 | uint32_t regionBot; /*!< Region bottom address */ |
| borlanic | 0:fbdae7e6d805 | 87 | uint32_t regionTop; /*!< Region top address */ |
| borlanic | 0:fbdae7e6d805 | 88 | uint32_t addrOffset; /*!< Region address offset */ |
| borlanic | 0:fbdae7e6d805 | 89 | bee_region_enable_t regionEn; /*!< Region enable/disable */ |
| borlanic | 0:fbdae7e6d805 | 90 | } bee_region_config_t; |
| borlanic | 0:fbdae7e6d805 | 91 | |
| borlanic | 0:fbdae7e6d805 | 92 | /******************************************************************************* |
| borlanic | 0:fbdae7e6d805 | 93 | * API |
| borlanic | 0:fbdae7e6d805 | 94 | ******************************************************************************/ |
| borlanic | 0:fbdae7e6d805 | 95 | #if defined(__cplusplus) |
| borlanic | 0:fbdae7e6d805 | 96 | extern "C" { |
| borlanic | 0:fbdae7e6d805 | 97 | #endif |
| borlanic | 0:fbdae7e6d805 | 98 | |
| borlanic | 0:fbdae7e6d805 | 99 | /*! |
| borlanic | 0:fbdae7e6d805 | 100 | * @brief Resets BEE module to factory default values. |
| borlanic | 0:fbdae7e6d805 | 101 | * |
| borlanic | 0:fbdae7e6d805 | 102 | * This function performs hardware reset of BEE module. Attributes and keys from software for both regions are cleared. |
| borlanic | 0:fbdae7e6d805 | 103 | * |
| borlanic | 0:fbdae7e6d805 | 104 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 105 | */ |
| borlanic | 0:fbdae7e6d805 | 106 | void BEE_Init(BEE_Type *base); |
| borlanic | 0:fbdae7e6d805 | 107 | |
| borlanic | 0:fbdae7e6d805 | 108 | /*! |
| borlanic | 0:fbdae7e6d805 | 109 | * @brief Resets BEE module, clears keys for both regions and disables clock to the BEE. |
| borlanic | 0:fbdae7e6d805 | 110 | * |
| borlanic | 0:fbdae7e6d805 | 111 | * This function performs hardware reset of BEE module and disables clocks. Attributes and keys from software for both |
| borlanic | 0:fbdae7e6d805 | 112 | * regions are cleared. |
| borlanic | 0:fbdae7e6d805 | 113 | * |
| borlanic | 0:fbdae7e6d805 | 114 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 115 | */ |
| borlanic | 0:fbdae7e6d805 | 116 | void BEE_Deinit(BEE_Type *base); |
| borlanic | 0:fbdae7e6d805 | 117 | |
| borlanic | 0:fbdae7e6d805 | 118 | /*! |
| borlanic | 0:fbdae7e6d805 | 119 | * @brief Enables BEE decryption. |
| borlanic | 0:fbdae7e6d805 | 120 | * |
| borlanic | 0:fbdae7e6d805 | 121 | * This function enables decryption using BEE. |
| borlanic | 0:fbdae7e6d805 | 122 | * |
| borlanic | 0:fbdae7e6d805 | 123 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 124 | */ |
| borlanic | 0:fbdae7e6d805 | 125 | static inline void BEE_Enable(BEE_Type *base) |
| borlanic | 0:fbdae7e6d805 | 126 | { |
| borlanic | 0:fbdae7e6d805 | 127 | base->CTRL |= BEE_CTRL_BEE_ENABLE_MASK | BEE_CTRL_KEY_VALID_MASK; |
| borlanic | 0:fbdae7e6d805 | 128 | } |
| borlanic | 0:fbdae7e6d805 | 129 | |
| borlanic | 0:fbdae7e6d805 | 130 | /*! |
| borlanic | 0:fbdae7e6d805 | 131 | * @brief Disables BEE decryption. |
| borlanic | 0:fbdae7e6d805 | 132 | * |
| borlanic | 0:fbdae7e6d805 | 133 | * This function disables decryption using BEE. |
| borlanic | 0:fbdae7e6d805 | 134 | * |
| borlanic | 0:fbdae7e6d805 | 135 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 136 | */ |
| borlanic | 0:fbdae7e6d805 | 137 | static inline void BEE_Disable(BEE_Type *base) |
| borlanic | 0:fbdae7e6d805 | 138 | { |
| borlanic | 0:fbdae7e6d805 | 139 | base->CTRL &= ~BEE_CTRL_BEE_ENABLE_MASK | BEE_CTRL_KEY_VALID_MASK; |
| borlanic | 0:fbdae7e6d805 | 140 | } |
| borlanic | 0:fbdae7e6d805 | 141 | |
| borlanic | 0:fbdae7e6d805 | 142 | /*! |
| borlanic | 0:fbdae7e6d805 | 143 | * @brief Loads default values to the BEE region configuration structure. |
| borlanic | 0:fbdae7e6d805 | 144 | * |
| borlanic | 0:fbdae7e6d805 | 145 | * Loads default values to the BEE region configuration structure. The default values are as follows: |
| borlanic | 0:fbdae7e6d805 | 146 | * @code |
| borlanic | 0:fbdae7e6d805 | 147 | * config->mode = kBEE_AesCbcMode; |
| borlanic | 0:fbdae7e6d805 | 148 | * config->regionBot = 0U; |
| borlanic | 0:fbdae7e6d805 | 149 | * config->regionTop = 0U; |
| borlanic | 0:fbdae7e6d805 | 150 | * config->addrOffset = 0xF0000000U; |
| borlanic | 0:fbdae7e6d805 | 151 | * config->regionEn = kBEE_RegionDisabled; |
| borlanic | 0:fbdae7e6d805 | 152 | * @endcode |
| borlanic | 0:fbdae7e6d805 | 153 | * |
| borlanic | 0:fbdae7e6d805 | 154 | * @param config Configuration structure for BEE region. |
| borlanic | 0:fbdae7e6d805 | 155 | */ |
| borlanic | 0:fbdae7e6d805 | 156 | void BEE_GetDefaultConfig(bee_region_config_t *config); |
| borlanic | 0:fbdae7e6d805 | 157 | |
| borlanic | 0:fbdae7e6d805 | 158 | /*! |
| borlanic | 0:fbdae7e6d805 | 159 | * @brief Sets BEE region configuration. |
| borlanic | 0:fbdae7e6d805 | 160 | * |
| borlanic | 0:fbdae7e6d805 | 161 | * This function sets BEE region settings accorging to given configuration structure. |
| borlanic | 0:fbdae7e6d805 | 162 | * |
| borlanic | 0:fbdae7e6d805 | 163 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 164 | * @param region Selection of the BEE region to be configured. |
| borlanic | 0:fbdae7e6d805 | 165 | * @param config Configuration structure for BEE region. |
| borlanic | 0:fbdae7e6d805 | 166 | */ |
| borlanic | 0:fbdae7e6d805 | 167 | status_t BEE_SetRegionConfig(BEE_Type *base, bee_region_t region, const bee_region_config_t *config); |
| borlanic | 0:fbdae7e6d805 | 168 | |
| borlanic | 0:fbdae7e6d805 | 169 | /*! |
| borlanic | 0:fbdae7e6d805 | 170 | * @brief Loads the AES key and nonce for selected region into BEE key registers. |
| borlanic | 0:fbdae7e6d805 | 171 | * |
| borlanic | 0:fbdae7e6d805 | 172 | * This function loads given AES key and nonce(only AES CTR mode) to BEE register for the given region. |
| borlanic | 0:fbdae7e6d805 | 173 | * |
| borlanic | 0:fbdae7e6d805 | 174 | * Please note, that eFuse BEE_KEYx_SEL must be set accordingly to be able to load and use key loaded in BEE registers. |
| borlanic | 0:fbdae7e6d805 | 175 | * Otherwise, key cannot loaded and BEE will use key from OTPMK or SW_GP2. |
| borlanic | 0:fbdae7e6d805 | 176 | * |
| borlanic | 0:fbdae7e6d805 | 177 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 178 | * @param region Selection of the BEE region to be configured. |
| borlanic | 0:fbdae7e6d805 | 179 | * @param key AES key. |
| borlanic | 0:fbdae7e6d805 | 180 | * @param keySize Size of AES key. |
| borlanic | 0:fbdae7e6d805 | 181 | * @param nonce AES nonce. |
| borlanic | 0:fbdae7e6d805 | 182 | * @param nonceSize Size of AES nonce. |
| borlanic | 0:fbdae7e6d805 | 183 | */ |
| borlanic | 0:fbdae7e6d805 | 184 | status_t BEE_SetRegionKey( |
| borlanic | 0:fbdae7e6d805 | 185 | BEE_Type *base, bee_region_t region, const uint8_t *key, size_t keySize, const uint8_t *nonce, size_t nonceSize); |
| borlanic | 0:fbdae7e6d805 | 186 | |
| borlanic | 0:fbdae7e6d805 | 187 | /*! |
| borlanic | 0:fbdae7e6d805 | 188 | * @brief Gets the BEE status flags. |
| borlanic | 0:fbdae7e6d805 | 189 | * |
| borlanic | 0:fbdae7e6d805 | 190 | * This function returns status of BEE peripheral. |
| borlanic | 0:fbdae7e6d805 | 191 | * |
| borlanic | 0:fbdae7e6d805 | 192 | * @param base BEE peripheral address. |
| borlanic | 0:fbdae7e6d805 | 193 | * |
| borlanic | 0:fbdae7e6d805 | 194 | * @return The status flags. This is the logical OR of members of the |
| borlanic | 0:fbdae7e6d805 | 195 | * enumeration ::bee_status_flags_t |
| borlanic | 0:fbdae7e6d805 | 196 | */ |
| borlanic | 0:fbdae7e6d805 | 197 | uint32_t BEE_GetStatusFlags(BEE_Type *base); |
| borlanic | 0:fbdae7e6d805 | 198 | |
| borlanic | 0:fbdae7e6d805 | 199 | /*! |
| borlanic | 0:fbdae7e6d805 | 200 | * @brief Clears the BEE status flags. |
| borlanic | 0:fbdae7e6d805 | 201 | * |
| borlanic | 0:fbdae7e6d805 | 202 | * @param base BEE peripheral base address. |
| borlanic | 0:fbdae7e6d805 | 203 | * @param mask The status flags to clear. This is a logical OR of members of the |
| borlanic | 0:fbdae7e6d805 | 204 | * enumeration ::bee_status_flags_t |
| borlanic | 0:fbdae7e6d805 | 205 | */ |
| borlanic | 0:fbdae7e6d805 | 206 | void BEE_ClearStatusFlags(BEE_Type *base, uint32_t mask); |
| borlanic | 0:fbdae7e6d805 | 207 | |
| borlanic | 0:fbdae7e6d805 | 208 | /*! |
| borlanic | 0:fbdae7e6d805 | 209 | * @brief Computes offset to be set for specifed memory location. |
| borlanic | 0:fbdae7e6d805 | 210 | * |
| borlanic | 0:fbdae7e6d805 | 211 | * This function calculates offset that must be set for BEE region to access physical memory location. |
| borlanic | 0:fbdae7e6d805 | 212 | * |
| borlanic | 0:fbdae7e6d805 | 213 | * @param addressMemory Address of physical memory location. |
| borlanic | 0:fbdae7e6d805 | 214 | */ |
| borlanic | 0:fbdae7e6d805 | 215 | static inline uint32_t BEE_GetOffset(uint32_t addressMemory) |
| borlanic | 0:fbdae7e6d805 | 216 | { |
| borlanic | 0:fbdae7e6d805 | 217 | return (addressMemory >> 16); |
| borlanic | 0:fbdae7e6d805 | 218 | } |
| borlanic | 0:fbdae7e6d805 | 219 | |
| borlanic | 0:fbdae7e6d805 | 220 | #if defined(__cplusplus) |
| borlanic | 0:fbdae7e6d805 | 221 | } |
| borlanic | 0:fbdae7e6d805 | 222 | #endif |
| borlanic | 0:fbdae7e6d805 | 223 | |
| borlanic | 0:fbdae7e6d805 | 224 | #endif /* _FSL_BEE_H_ */ |