mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32620C/mxc/spix.h@186:707f6e361f3e, 2018-06-22 (annotated)
- Committer:
- Anna Bridge
- Date:
- Fri Jun 22 16:45:37 2018 +0100
- Revision:
- 186:707f6e361f3e
mbed-dev library. Release version 162
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
186:707f6e361f3e | 1 | /** |
Anna Bridge |
186:707f6e361f3e | 2 | * @file |
Anna Bridge |
186:707f6e361f3e | 3 | * @brief This is the high level API for the SPI Execute in Place (SPIX) |
Anna Bridge |
186:707f6e361f3e | 4 | * module. |
Anna Bridge |
186:707f6e361f3e | 5 | * @note If using this SPIX with IAR Embedded Workbench for ARM, it is |
Anna Bridge |
186:707f6e361f3e | 6 | * required to define <tt>IAR_SPIX_PRAGMA=1</tt>. This should be |
Anna Bridge |
186:707f6e361f3e | 7 | * done under Project->Options-> C/C++ Compiler->Preprocessor in the |
Anna Bridge |
186:707f6e361f3e | 8 | * Defined Symbols input box. See the IAR documentation for |
Anna Bridge |
186:707f6e361f3e | 9 | * additional information on how to set a preprocessor define in a |
Anna Bridge |
186:707f6e361f3e | 10 | * project. |
Anna Bridge |
186:707f6e361f3e | 11 | */ |
Anna Bridge |
186:707f6e361f3e | 12 | /******************************************************************************* |
Anna Bridge |
186:707f6e361f3e | 13 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
186:707f6e361f3e | 14 | * |
Anna Bridge |
186:707f6e361f3e | 15 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
186:707f6e361f3e | 16 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
186:707f6e361f3e | 17 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
186:707f6e361f3e | 18 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
186:707f6e361f3e | 19 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
186:707f6e361f3e | 20 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
186:707f6e361f3e | 21 | * |
Anna Bridge |
186:707f6e361f3e | 22 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
186:707f6e361f3e | 23 | * in all copies or substantial portions of the Software. |
Anna Bridge |
186:707f6e361f3e | 24 | * |
Anna Bridge |
186:707f6e361f3e | 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
186:707f6e361f3e | 26 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
186:707f6e361f3e | 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
186:707f6e361f3e | 28 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
186:707f6e361f3e | 29 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
186:707f6e361f3e | 30 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
186:707f6e361f3e | 31 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
186:707f6e361f3e | 32 | * |
Anna Bridge |
186:707f6e361f3e | 33 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 34 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 35 | * Products, Inc. Branding Policy. |
Anna Bridge |
186:707f6e361f3e | 36 | * |
Anna Bridge |
186:707f6e361f3e | 37 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
186:707f6e361f3e | 38 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
186:707f6e361f3e | 39 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
186:707f6e361f3e | 40 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
186:707f6e361f3e | 41 | * ownership rights. |
Anna Bridge |
186:707f6e361f3e | 42 | * |
Anna Bridge |
186:707f6e361f3e | 43 | * $Date: 2017-02-16 12:03:11 -0600 (Thu, 16 Feb 2017) $ |
Anna Bridge |
186:707f6e361f3e | 44 | * $Revision: 26463 $ |
Anna Bridge |
186:707f6e361f3e | 45 | * |
Anna Bridge |
186:707f6e361f3e | 46 | **************************************************************************** */ |
Anna Bridge |
186:707f6e361f3e | 47 | |
Anna Bridge |
186:707f6e361f3e | 48 | |
Anna Bridge |
186:707f6e361f3e | 49 | |
Anna Bridge |
186:707f6e361f3e | 50 | #include "mxc_sys.h" |
Anna Bridge |
186:707f6e361f3e | 51 | #include "spix_regs.h" |
Anna Bridge |
186:707f6e361f3e | 52 | |
Anna Bridge |
186:707f6e361f3e | 53 | /* Define to prevent redundant inclusion */ |
Anna Bridge |
186:707f6e361f3e | 54 | #ifndef _SPIX_H_ |
Anna Bridge |
186:707f6e361f3e | 55 | #define _SPIX_H_ |
Anna Bridge |
186:707f6e361f3e | 56 | |
Anna Bridge |
186:707f6e361f3e | 57 | #ifdef __cplusplus |
Anna Bridge |
186:707f6e361f3e | 58 | extern "C" { |
Anna Bridge |
186:707f6e361f3e | 59 | #endif |
Anna Bridge |
186:707f6e361f3e | 60 | |
Anna Bridge |
186:707f6e361f3e | 61 | /** |
Anna Bridge |
186:707f6e361f3e | 62 | * @ingroup periphlibs |
Anna Bridge |
186:707f6e361f3e | 63 | * @defgroup spix SPIX |
Anna Bridge |
186:707f6e361f3e | 64 | * @brief SPI Execute In Place. |
Anna Bridge |
186:707f6e361f3e | 65 | * @{ |
Anna Bridge |
186:707f6e361f3e | 66 | */ |
Anna Bridge |
186:707f6e361f3e | 67 | |
Anna Bridge |
186:707f6e361f3e | 68 | /* **** Definitions **** */ |
Anna Bridge |
186:707f6e361f3e | 69 | /** |
Anna Bridge |
186:707f6e361f3e | 70 | * Enumeration type for the number of I/O pins to use during each fetch stage for SPIX |
Anna Bridge |
186:707f6e361f3e | 71 | */ |
Anna Bridge |
186:707f6e361f3e | 72 | typedef enum { |
Anna Bridge |
186:707f6e361f3e | 73 | SPIX_SINGLE_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_SINGLE, /**< 1 I/O pin for SPIX Fetch Cmd Data line */ |
Anna Bridge |
186:707f6e361f3e | 74 | SPIX_DUAL_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_DUAL_IO, /**< 2 I/O pins for SPIX Fetch Cmd Data line */ |
Anna Bridge |
186:707f6e361f3e | 75 | SPIX_QUAD_IO = MXC_V_SPIX_FETCH_CTRL_CMD_WIDTH_QUAD_IO /**< 4 I/O pins for SPIX Fetch Cmd Data line */ |
Anna Bridge |
186:707f6e361f3e | 76 | } spix_width_t; |
Anna Bridge |
186:707f6e361f3e | 77 | |
Anna Bridge |
186:707f6e361f3e | 78 | /** |
Anna Bridge |
186:707f6e361f3e | 79 | * Enumeration type for the number of address bytes to use during an SPIX fetch |
Anna Bridge |
186:707f6e361f3e | 80 | */ |
Anna Bridge |
186:707f6e361f3e | 81 | typedef enum { |
Anna Bridge |
186:707f6e361f3e | 82 | SPIX_3BYTE_FETCH_ADDR = 0, ///< Fetch Address of 3 Bytes |
Anna Bridge |
186:707f6e361f3e | 83 | SPIX_4BYTE_FETCH_ADDR = 1 ///< Fetch Address of 4 Bytes |
Anna Bridge |
186:707f6e361f3e | 84 | } spix_addr_size_t; |
Anna Bridge |
186:707f6e361f3e | 85 | |
Anna Bridge |
186:707f6e361f3e | 86 | /** |
Anna Bridge |
186:707f6e361f3e | 87 | * Structure type for SPIX fetch configuration |
Anna Bridge |
186:707f6e361f3e | 88 | */ |
Anna Bridge |
186:707f6e361f3e | 89 | typedef struct { |
Anna Bridge |
186:707f6e361f3e | 90 | spix_width_t cmd_width; ///< Number of I/O lines used for command SPI transaction. |
Anna Bridge |
186:707f6e361f3e | 91 | spix_width_t addr_width; ///< Number of I/O lines used for address SPI transaction. |
Anna Bridge |
186:707f6e361f3e | 92 | spix_width_t data_width; ///< Number of I/O lines used for data SPI transaction. |
Anna Bridge |
186:707f6e361f3e | 93 | spix_addr_size_t addr_size; ///< Use 3 or 4 byte addresses for fetches. |
Anna Bridge |
186:707f6e361f3e | 94 | uint8_t cmd; ///< Command value to initiate fetch. |
Anna Bridge |
186:707f6e361f3e | 95 | uint8_t mode_clocks; ///< Number of SPI clocks required during mode phase of fetch. |
Anna Bridge |
186:707f6e361f3e | 96 | uint8_t no_cmd_mode; ///< Read command sent only once. |
Anna Bridge |
186:707f6e361f3e | 97 | uint16_t mode_data; ///< Data sent with mode clocks. |
Anna Bridge |
186:707f6e361f3e | 98 | } spix_fetch_t; |
Anna Bridge |
186:707f6e361f3e | 99 | |
Anna Bridge |
186:707f6e361f3e | 100 | /* **** Globals **** */ |
Anna Bridge |
186:707f6e361f3e | 101 | |
Anna Bridge |
186:707f6e361f3e | 102 | /* **** Function Prototypes **** */ |
Anna Bridge |
186:707f6e361f3e | 103 | |
Anna Bridge |
186:707f6e361f3e | 104 | /** |
Anna Bridge |
186:707f6e361f3e | 105 | * @brief Configure SPI execute in place clocking. |
Anna Bridge |
186:707f6e361f3e | 106 | * @param sys_cfg Pointer to system level configuration structure. |
Anna Bridge |
186:707f6e361f3e | 107 | * @param baud Frequency in hertz to set the clock to. May not be able |
Anna Bridge |
186:707f6e361f3e | 108 | * to achieve with the given clock divider. |
Anna Bridge |
186:707f6e361f3e | 109 | * @param sample Number of SPIX clocks to delay the sampling of the SDIO |
Anna Bridge |
186:707f6e361f3e | 110 | * lines. Will use feedback mode if set to 0. |
Anna Bridge |
186:707f6e361f3e | 111 | * @return #E_NO_ERROR if everything is successful |
Anna Bridge |
186:707f6e361f3e | 112 | */ |
Anna Bridge |
186:707f6e361f3e | 113 | int SPIX_ConfigClock(const sys_cfg_spix_t *sys_cfg, uint32_t baud, uint8_t sample); |
Anna Bridge |
186:707f6e361f3e | 114 | |
Anna Bridge |
186:707f6e361f3e | 115 | /** |
Anna Bridge |
186:707f6e361f3e | 116 | * @brief Configure SPI execute in place slave select. |
Anna Bridge |
186:707f6e361f3e | 117 | * @param ssel Index of which slave select line to use. |
Anna Bridge |
186:707f6e361f3e | 118 | * @param pol Polarity of slave select (0 for active low, 1 for |
Anna Bridge |
186:707f6e361f3e | 119 | * active high). |
Anna Bridge |
186:707f6e361f3e | 120 | * @param act_delay SPIX clocks between slave select assert and active |
Anna Bridge |
186:707f6e361f3e | 121 | * SPI clock. |
Anna Bridge |
186:707f6e361f3e | 122 | * @param inact_delay SPIX clocks between active SPI clock and slave |
Anna Bridge |
186:707f6e361f3e | 123 | * select deassert. |
Anna Bridge |
186:707f6e361f3e | 124 | */ |
Anna Bridge |
186:707f6e361f3e | 125 | void SPIX_ConfigSlave(uint8_t ssel, uint8_t pol, uint8_t act_delay, uint8_t inact_delay); |
Anna Bridge |
186:707f6e361f3e | 126 | |
Anna Bridge |
186:707f6e361f3e | 127 | /** |
Anna Bridge |
186:707f6e361f3e | 128 | * @brief Configure how the SPIX fetches data. |
Anna Bridge |
186:707f6e361f3e | 129 | * @param fetch Pointer to configuration struct that describes how to |
Anna Bridge |
186:707f6e361f3e | 130 | * fetch data. |
Anna Bridge |
186:707f6e361f3e | 131 | */ |
Anna Bridge |
186:707f6e361f3e | 132 | void SPIX_ConfigFetch(const spix_fetch_t *fetch); |
Anna Bridge |
186:707f6e361f3e | 133 | |
Anna Bridge |
186:707f6e361f3e | 134 | /** |
Anna Bridge |
186:707f6e361f3e | 135 | * @brief Shutdown SPIX module. |
Anna Bridge |
186:707f6e361f3e | 136 | * @param spix Pointer to SPIX regs. |
Anna Bridge |
186:707f6e361f3e | 137 | * @return #E_NO_ERROR if everything is successful |
Anna Bridge |
186:707f6e361f3e | 138 | */ |
Anna Bridge |
186:707f6e361f3e | 139 | int SPIX_Shutdown(mxc_spix_regs_t *spix); |
Anna Bridge |
186:707f6e361f3e | 140 | |
Anna Bridge |
186:707f6e361f3e | 141 | /**@} end of group spix */ |
Anna Bridge |
186:707f6e361f3e | 142 | #ifdef __cplusplus |
Anna Bridge |
186:707f6e361f3e | 143 | } |
Anna Bridge |
186:707f6e361f3e | 144 | #endif |
Anna Bridge |
186:707f6e361f3e | 145 | |
Anna Bridge |
186:707f6e361f3e | 146 | #endif /* _SPIX_H */ |