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