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