The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT32625B/TOOLCHAIN_IAR/maa.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
169:a7c7b631e539 | 1 | /** |
Anna Bridge |
169:a7c7b631e539 | 2 | * @file maa.h |
Anna Bridge |
169:a7c7b631e539 | 3 | * @brief Registers, Bit Masks and Bit Positions for the Modular Math |
Anna Bridge |
169:a7c7b631e539 | 4 | * Accelerator (MAA) module. |
Anna Bridge |
169:a7c7b631e539 | 5 | */ |
Anna Bridge |
169:a7c7b631e539 | 6 | /* ***************************************************************************** |
Anna Bridge |
169:a7c7b631e539 | 7 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
169:a7c7b631e539 | 8 | * |
Anna Bridge |
169:a7c7b631e539 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
169:a7c7b631e539 | 10 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
169:a7c7b631e539 | 11 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
169:a7c7b631e539 | 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
169:a7c7b631e539 | 13 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
169:a7c7b631e539 | 14 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
169:a7c7b631e539 | 15 | * |
Anna Bridge |
169:a7c7b631e539 | 16 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
169:a7c7b631e539 | 17 | * in all copies or substantial portions of the Software. |
Anna Bridge |
169:a7c7b631e539 | 18 | * |
Anna Bridge |
169:a7c7b631e539 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
169:a7c7b631e539 | 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
169:a7c7b631e539 | 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
169:a7c7b631e539 | 22 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
169:a7c7b631e539 | 23 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
169:a7c7b631e539 | 24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
169:a7c7b631e539 | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
169:a7c7b631e539 | 26 | * |
Anna Bridge |
169:a7c7b631e539 | 27 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
169:a7c7b631e539 | 28 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
169:a7c7b631e539 | 29 | * Products, Inc. Branding Policy. |
Anna Bridge |
169:a7c7b631e539 | 30 | * |
Anna Bridge |
169:a7c7b631e539 | 31 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
169:a7c7b631e539 | 32 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
169:a7c7b631e539 | 33 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
169:a7c7b631e539 | 34 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
169:a7c7b631e539 | 35 | * ownership rights. |
Anna Bridge |
169:a7c7b631e539 | 36 | * |
Anna Bridge |
169:a7c7b631e539 | 37 | * $Date: 2016-08-15 11:28:30 -0500 (Mon, 15 Aug 2016) $ |
Anna Bridge |
169:a7c7b631e539 | 38 | * $Revision: 24064 $ |
Anna Bridge |
169:a7c7b631e539 | 39 | * |
Anna Bridge |
169:a7c7b631e539 | 40 | **************************************************************************** */ |
Anna Bridge |
169:a7c7b631e539 | 41 | |
Anna Bridge |
169:a7c7b631e539 | 42 | /* Define to prevent redundant inclusion */ |
Anna Bridge |
169:a7c7b631e539 | 43 | #ifndef _MAA_H |
Anna Bridge |
169:a7c7b631e539 | 44 | #define _MAA_H |
Anna Bridge |
169:a7c7b631e539 | 45 | |
Anna Bridge |
169:a7c7b631e539 | 46 | /* **** Includes **** */ |
Anna Bridge |
169:a7c7b631e539 | 47 | #include <stdint.h> |
Anna Bridge |
169:a7c7b631e539 | 48 | |
Anna Bridge |
169:a7c7b631e539 | 49 | #include "maa_regs.h" |
Anna Bridge |
169:a7c7b631e539 | 50 | |
Anna Bridge |
169:a7c7b631e539 | 51 | #ifdef __cplusplus |
Anna Bridge |
169:a7c7b631e539 | 52 | extern "C" { |
Anna Bridge |
169:a7c7b631e539 | 53 | #endif |
Anna Bridge |
169:a7c7b631e539 | 54 | |
Anna Bridge |
169:a7c7b631e539 | 55 | /** |
Anna Bridge |
169:a7c7b631e539 | 56 | * @defgroup maa MAA |
Anna Bridge |
169:a7c7b631e539 | 57 | * @ingroup periphlibs |
Anna Bridge |
169:a7c7b631e539 | 58 | * @details The API only supports synchronous operations due to the sensitive |
Anna Bridge |
169:a7c7b631e539 | 59 | * nature of the input and output data. |
Anna Bridge |
169:a7c7b631e539 | 60 | * @{ |
Anna Bridge |
169:a7c7b631e539 | 61 | */ |
Anna Bridge |
169:a7c7b631e539 | 62 | |
Anna Bridge |
169:a7c7b631e539 | 63 | /* **** Definitions **** */ |
Anna Bridge |
169:a7c7b631e539 | 64 | |
Anna Bridge |
169:a7c7b631e539 | 65 | /** |
Anna Bridge |
169:a7c7b631e539 | 66 | * Definition for the maximum MAA register size on this device in bytes, 128. |
Anna Bridge |
169:a7c7b631e539 | 67 | */ |
Anna Bridge |
169:a7c7b631e539 | 68 | #define MXC_MAA_REG_SIZE 0x80 |
Anna Bridge |
169:a7c7b631e539 | 69 | /** |
Anna Bridge |
169:a7c7b631e539 | 70 | * Definition for the maximum MAA register size on this device in bits, 1024. |
Anna Bridge |
169:a7c7b631e539 | 71 | */ |
Anna Bridge |
169:a7c7b631e539 | 72 | #define MXC_MAA_REG_SIZE_BITS (MXC_MAA_REG_SIZE << 3) |
Anna Bridge |
169:a7c7b631e539 | 73 | |
Anna Bridge |
169:a7c7b631e539 | 74 | /** |
Anna Bridge |
169:a7c7b631e539 | 75 | * @define Sub-register ("half size"), allowing 2x more operands in MAA at a time when MAWS <= MAX_SIZE/2 |
Anna Bridge |
169:a7c7b631e539 | 76 | */ |
Anna Bridge |
169:a7c7b631e539 | 77 | #define MXC_MAA_HALF_SIZE (MXC_MAA_REG_SIZE/2) |
Anna Bridge |
169:a7c7b631e539 | 78 | |
Anna Bridge |
169:a7c7b631e539 | 79 | /** Flags for MAA_Load() and MAA_Unload() */ |
Anna Bridge |
169:a7c7b631e539 | 80 | #define MXC_MAA_F_MEM_VERBATIM 0 |
Anna Bridge |
169:a7c7b631e539 | 81 | /** Flags for MAA_Load() and MAA_Unload() */ |
Anna Bridge |
169:a7c7b631e539 | 82 | #define MXC_MAA_F_MEM_REVERSE 1 |
Anna Bridge |
169:a7c7b631e539 | 83 | |
Anna Bridge |
169:a7c7b631e539 | 84 | /** |
Anna Bridge |
169:a7c7b631e539 | 85 | * Enumeration type for Segment and Sub-segment selection |
Anna Bridge |
169:a7c7b631e539 | 86 | */ |
Anna Bridge |
169:a7c7b631e539 | 87 | /* Warning: Do not change the assigned numbers/ordering without associated changes to UMAA_REGFILE_TO_ADDR(x) */ |
Anna Bridge |
169:a7c7b631e539 | 88 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 89 | /* Register names when MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 90 | MXC_E_REG_0 = 0, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 91 | MXC_E_REG_1 = 2, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 92 | MXC_E_REG_2 = 4, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 93 | MXC_E_REG_3 = 6, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 94 | MXC_E_REG_4 = 8, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 95 | MXC_E_REG_5 = 10, /**< Register name if MAA_MAWS > 512 */ |
Anna Bridge |
169:a7c7b631e539 | 96 | /* Register names when MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 97 | MXC_E_REG_00 = 0, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 98 | MXC_E_REG_01 = 1, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 99 | MXC_E_REG_10 = 2, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 100 | MXC_E_REG_11 = 3, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 101 | MXC_E_REG_20 = 4, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 102 | MXC_E_REG_21 = 5, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 103 | MXC_E_REG_30 = 6, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 104 | MXC_E_REG_31 = 7, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 105 | MXC_E_REG_40 = 8, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 106 | MXC_E_REG_41 = 9, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 107 | MXC_E_REG_50 = 10, /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 108 | MXC_E_REG_51 = 11 /**< Register name if MAA_MAWS < 512 */ |
Anna Bridge |
169:a7c7b631e539 | 109 | } mxc_maa_reg_select_t; |
Anna Bridge |
169:a7c7b631e539 | 110 | |
Anna Bridge |
169:a7c7b631e539 | 111 | /** |
Anna Bridge |
169:a7c7b631e539 | 112 | * Enumeration type for MAA operation select. |
Anna Bridge |
169:a7c7b631e539 | 113 | */ |
Anna Bridge |
169:a7c7b631e539 | 114 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 115 | MXC_E_MAA_EXP = 0, /**< Exponentiate */ |
Anna Bridge |
169:a7c7b631e539 | 116 | MXC_E_MAA_SQR = 1, /**< Square */ |
Anna Bridge |
169:a7c7b631e539 | 117 | MXC_E_MAA_MUL = 2, /**< Multiply */ |
Anna Bridge |
169:a7c7b631e539 | 118 | MXC_E_MAA_SQRMUL = 3, /**< Square followed by Multiply */ |
Anna Bridge |
169:a7c7b631e539 | 119 | MXC_E_MAA_ADD = 4, /**< Addition */ |
Anna Bridge |
169:a7c7b631e539 | 120 | MXC_E_MAA_SUB = 5 /**< Subtraction */ |
Anna Bridge |
169:a7c7b631e539 | 121 | } mxc_maa_operation_t; |
Anna Bridge |
169:a7c7b631e539 | 122 | |
Anna Bridge |
169:a7c7b631e539 | 123 | /** |
Anna Bridge |
169:a7c7b631e539 | 124 | * Enumeration type to set special flags for loading & unloading data. |
Anna Bridge |
169:a7c7b631e539 | 125 | */ |
Anna Bridge |
169:a7c7b631e539 | 126 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 127 | |
Anna Bridge |
169:a7c7b631e539 | 128 | MXC_E_MAA_VERBATIM = 0, /**< Copy bytes without reversal and right-justification */ |
Anna Bridge |
169:a7c7b631e539 | 129 | MXC_E_MAA_REVERSE /**< Reverse bytes and right-justify (bytes are loaded at the highest address, then descending) */ |
Anna Bridge |
169:a7c7b631e539 | 130 | } mxc_maa_endian_select_t; |
Anna Bridge |
169:a7c7b631e539 | 131 | |
Anna Bridge |
169:a7c7b631e539 | 132 | /** |
Anna Bridge |
169:a7c7b631e539 | 133 | * Enumeration type for MAA module specific return codes. |
Anna Bridge |
169:a7c7b631e539 | 134 | */ |
Anna Bridge |
169:a7c7b631e539 | 135 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 136 | MXC_E_MAA_ERR = -1, /**< Error */ |
Anna Bridge |
169:a7c7b631e539 | 137 | MXC_E_MAA_OK = 0, /**< No Error */ |
Anna Bridge |
169:a7c7b631e539 | 138 | MXC_E_MAA_BUSY /**< MAA engine busy, try again later */ |
Anna Bridge |
169:a7c7b631e539 | 139 | } mxc_maa_ret_t; |
Anna Bridge |
169:a7c7b631e539 | 140 | |
Anna Bridge |
169:a7c7b631e539 | 141 | /** |
Anna Bridge |
169:a7c7b631e539 | 142 | * @brief Initialize the required clocks and enable the MAA peripheral |
Anna Bridge |
169:a7c7b631e539 | 143 | * module. |
Anna Bridge |
169:a7c7b631e539 | 144 | */ |
Anna Bridge |
169:a7c7b631e539 | 145 | mxc_maa_ret_t MAA_Init(void); |
Anna Bridge |
169:a7c7b631e539 | 146 | |
Anna Bridge |
169:a7c7b631e539 | 147 | /** |
Anna Bridge |
169:a7c7b631e539 | 148 | * @brief Erase all MAA register RAM |
Anna Bridge |
169:a7c7b631e539 | 149 | */ |
Anna Bridge |
169:a7c7b631e539 | 150 | mxc_maa_ret_t MAA_WipeRAM(void); |
Anna Bridge |
169:a7c7b631e539 | 151 | |
Anna Bridge |
169:a7c7b631e539 | 152 | |
Anna Bridge |
169:a7c7b631e539 | 153 | /** |
Anna Bridge |
169:a7c7b631e539 | 154 | * @brief Load the selected MAA register. |
Anna Bridge |
169:a7c7b631e539 | 155 | * |
Anna Bridge |
169:a7c7b631e539 | 156 | * @param regfile Selects the register to load. |
Anna Bridge |
169:a7c7b631e539 | 157 | * @param data Pointer to a data buffer to load into the register. |
Anna Bridge |
169:a7c7b631e539 | 158 | * @param size Size of the data to load. |
Anna Bridge |
169:a7c7b631e539 | 159 | * @param flag Reverse the data so that it will unload properly on |
Anna Bridge |
169:a7c7b631e539 | 160 | * little endian machines, see #mxc_maa_endian_select_t. |
Anna Bridge |
169:a7c7b631e539 | 161 | * |
Anna Bridge |
169:a7c7b631e539 | 162 | * @return #MXC_E_MAA_ERR if any parameter out of range. |
Anna Bridge |
169:a7c7b631e539 | 163 | * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. |
Anna Bridge |
169:a7c7b631e539 | 164 | * @return #MXC_E_MAA_OK if the selected register is loaded correctly. |
Anna Bridge |
169:a7c7b631e539 | 165 | */ |
Anna Bridge |
169:a7c7b631e539 | 166 | mxc_maa_ret_t MAA_Load(mxc_maa_reg_select_t regfile, const uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag); |
Anna Bridge |
169:a7c7b631e539 | 167 | |
Anna Bridge |
169:a7c7b631e539 | 168 | /** |
Anna Bridge |
169:a7c7b631e539 | 169 | * @brief Unload (copy from) the selected MAA register |
Anna Bridge |
169:a7c7b631e539 | 170 | * |
Anna Bridge |
169:a7c7b631e539 | 171 | * @param regfile Selects the register to unload. |
Anna Bridge |
169:a7c7b631e539 | 172 | * @param data Pointer to a buffer to store the unloaded data. |
Anna Bridge |
169:a7c7b631e539 | 173 | * @param size Maximum size of the data to unload. |
Anna Bridge |
169:a7c7b631e539 | 174 | * @param flag Reverse the data so that it will unload properly on |
Anna Bridge |
169:a7c7b631e539 | 175 | * little endian machines, see #mxc_maa_endian_select_t. |
Anna Bridge |
169:a7c7b631e539 | 176 | * @return #MXC_E_MAA_ERR if any parameter out of range. |
Anna Bridge |
169:a7c7b631e539 | 177 | * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. |
Anna Bridge |
169:a7c7b631e539 | 178 | * @return #MXC_E_MAA_OK if the requested register data is copied correctly |
Anna Bridge |
169:a7c7b631e539 | 179 | * to @p data. |
Anna Bridge |
169:a7c7b631e539 | 180 | */ |
Anna Bridge |
169:a7c7b631e539 | 181 | mxc_maa_ret_t MAA_Unload(mxc_maa_reg_select_t regfile, uint8_t *data, unsigned int size, mxc_maa_endian_select_t flag); |
Anna Bridge |
169:a7c7b631e539 | 182 | |
Anna Bridge |
169:a7c7b631e539 | 183 | /** |
Anna Bridge |
169:a7c7b631e539 | 184 | * @brief Execute an MAA operation specified. |
Anna Bridge |
169:a7c7b631e539 | 185 | * |
Anna Bridge |
169:a7c7b631e539 | 186 | * @param op Operation to perform, see #mxc_maa_operation_t. |
Anna Bridge |
169:a7c7b631e539 | 187 | * @param al Segment to use for operand A, see #mxc_maa_reg_select_t. |
Anna Bridge |
169:a7c7b631e539 | 188 | * @param bl Segment to use for operand B. |
Anna Bridge |
169:a7c7b631e539 | 189 | * @param rl Segment which will hold result R after the operation is |
Anna Bridge |
169:a7c7b631e539 | 190 | * complete. |
Anna Bridge |
169:a7c7b631e539 | 191 | * @param tl Segment to use for temporary storage T. |
Anna Bridge |
169:a7c7b631e539 | 192 | * |
Anna Bridge |
169:a7c7b631e539 | 193 | * @return #MXC_E_MAA_ERR if any parameter out of range. |
Anna Bridge |
169:a7c7b631e539 | 194 | * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. |
Anna Bridge |
169:a7c7b631e539 | 195 | * @return #MXC_E_MAA_OK if the operation completed. |
Anna Bridge |
169:a7c7b631e539 | 196 | */ |
Anna Bridge |
169:a7c7b631e539 | 197 | mxc_maa_ret_t MAA_Run(mxc_maa_operation_t op, \ |
Anna Bridge |
169:a7c7b631e539 | 198 | mxc_maa_reg_select_t al, mxc_maa_reg_select_t bl, \ |
Anna Bridge |
169:a7c7b631e539 | 199 | mxc_maa_reg_select_t rl, mxc_maa_reg_select_t tl); |
Anna Bridge |
169:a7c7b631e539 | 200 | |
Anna Bridge |
169:a7c7b631e539 | 201 | /** |
Anna Bridge |
169:a7c7b631e539 | 202 | * @brief Set the bit length of the modulus. |
Anna Bridge |
169:a7c7b631e539 | 203 | * |
Anna Bridge |
169:a7c7b631e539 | 204 | * @param len Modulus size in bits (ie. \f$ ln_2(modulus) \f$ ) |
Anna Bridge |
169:a7c7b631e539 | 205 | * |
Anna Bridge |
169:a7c7b631e539 | 206 | * @return #MXC_E_MAA_ERR if any parameter out of range. |
Anna Bridge |
169:a7c7b631e539 | 207 | * @return #MXC_E_MAA_BUSY if MAA registers are not currently accessible. |
Anna Bridge |
169:a7c7b631e539 | 208 | * @return #MXC_E_MAA_OK if the length is set as requested. |
Anna Bridge |
169:a7c7b631e539 | 209 | */ |
Anna Bridge |
169:a7c7b631e539 | 210 | mxc_maa_ret_t MAA_SetWordSize(unsigned int len); |
Anna Bridge |
169:a7c7b631e539 | 211 | |
Anna Bridge |
169:a7c7b631e539 | 212 | /** |
Anna Bridge |
169:a7c7b631e539 | 213 | * @} |
Anna Bridge |
169:a7c7b631e539 | 214 | */ |
Anna Bridge |
169:a7c7b631e539 | 215 | |
Anna Bridge |
169:a7c7b631e539 | 216 | #ifdef __cplusplus |
Anna Bridge |
169:a7c7b631e539 | 217 | } |
Anna Bridge |
169:a7c7b631e539 | 218 | #endif |
Anna Bridge |
169:a7c7b631e539 | 219 | |
Anna Bridge |
169:a7c7b631e539 | 220 | #endif |