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.

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?

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