mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32620C/mxc/spim.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 Registers, Bit Masks and Bit Positions for the SPI Master module. |
Anna Bridge |
186:707f6e361f3e | 4 | */ |
Anna Bridge |
186:707f6e361f3e | 5 | /* **************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 6 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
186:707f6e361f3e | 7 | * |
Anna Bridge |
186:707f6e361f3e | 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
186:707f6e361f3e | 9 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
186:707f6e361f3e | 10 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
186:707f6e361f3e | 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
186:707f6e361f3e | 12 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
186:707f6e361f3e | 13 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
186:707f6e361f3e | 14 | * |
Anna Bridge |
186:707f6e361f3e | 15 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
186:707f6e361f3e | 16 | * in all copies or substantial portions of the Software. |
Anna Bridge |
186:707f6e361f3e | 17 | * |
Anna Bridge |
186:707f6e361f3e | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
186:707f6e361f3e | 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
186:707f6e361f3e | 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
186:707f6e361f3e | 21 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
186:707f6e361f3e | 22 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
186:707f6e361f3e | 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
186:707f6e361f3e | 24 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
186:707f6e361f3e | 25 | * |
Anna Bridge |
186:707f6e361f3e | 26 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 27 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 28 | * Products, Inc. Branding Policy. |
Anna Bridge |
186:707f6e361f3e | 29 | * |
Anna Bridge |
186:707f6e361f3e | 30 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
186:707f6e361f3e | 31 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
186:707f6e361f3e | 32 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
186:707f6e361f3e | 33 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
186:707f6e361f3e | 34 | * ownership rights. |
Anna Bridge |
186:707f6e361f3e | 35 | * |
Anna Bridge |
186:707f6e361f3e | 36 | * $Date: 2017-02-16 12:03:47 -0600 (Thu, 16 Feb 2017) $ |
Anna Bridge |
186:707f6e361f3e | 37 | * $Revision: 26464 $ |
Anna Bridge |
186:707f6e361f3e | 38 | * |
Anna Bridge |
186:707f6e361f3e | 39 | **************************************************************************** */ |
Anna Bridge |
186:707f6e361f3e | 40 | |
Anna Bridge |
186:707f6e361f3e | 41 | /* **** Includes **** */ |
Anna Bridge |
186:707f6e361f3e | 42 | #include "mxc_config.h" |
Anna Bridge |
186:707f6e361f3e | 43 | #include "mxc_sys.h" |
Anna Bridge |
186:707f6e361f3e | 44 | #include "spim_regs.h" |
Anna Bridge |
186:707f6e361f3e | 45 | |
Anna Bridge |
186:707f6e361f3e | 46 | /* Define to prevent redundant inclusion */ |
Anna Bridge |
186:707f6e361f3e | 47 | #ifndef _SPIM_H_ |
Anna Bridge |
186:707f6e361f3e | 48 | #define _SPIM_H_ |
Anna Bridge |
186:707f6e361f3e | 49 | |
Anna Bridge |
186:707f6e361f3e | 50 | #ifdef __cplusplus |
Anna Bridge |
186:707f6e361f3e | 51 | extern "C" { |
Anna Bridge |
186:707f6e361f3e | 52 | #endif |
Anna Bridge |
186:707f6e361f3e | 53 | |
Anna Bridge |
186:707f6e361f3e | 54 | /** |
Anna Bridge |
186:707f6e361f3e | 55 | * @ingroup periphlibs |
Anna Bridge |
186:707f6e361f3e | 56 | * @defgroup spim SPI Master |
Anna Bridge |
186:707f6e361f3e | 57 | * @brief Serial Peripheral Interface Master (SPIM) API. |
Anna Bridge |
186:707f6e361f3e | 58 | * @{ |
Anna Bridge |
186:707f6e361f3e | 59 | */ |
Anna Bridge |
186:707f6e361f3e | 60 | |
Anna Bridge |
186:707f6e361f3e | 61 | /* **** Definitions **** */ |
Anna Bridge |
186:707f6e361f3e | 62 | |
Anna Bridge |
186:707f6e361f3e | 63 | /** |
Anna Bridge |
186:707f6e361f3e | 64 | * Enumeration type for selecting the active levels for the SPI Master Slave Select (SS) lines. |
Anna Bridge |
186:707f6e361f3e | 65 | */ |
Anna Bridge |
186:707f6e361f3e | 66 | typedef enum { |
Anna Bridge |
186:707f6e361f3e | 67 | SPIM_SSEL0_HIGH = (0x1 << 0), /**< Slave Select 0 High. */ |
Anna Bridge |
186:707f6e361f3e | 68 | SPIM_SSEL0_LOW = 0, /**< Slave Select 0 Low. */ |
Anna Bridge |
186:707f6e361f3e | 69 | SPIM_SSEL1_HIGH = (0x1 << 1), /**< Slave Select 1 High. */ |
Anna Bridge |
186:707f6e361f3e | 70 | SPIM_SSEL1_LOW = 0, /**< Slave Select 1 Low. */ |
Anna Bridge |
186:707f6e361f3e | 71 | SPIM_SSEL2_HIGH = (0x1 << 2), /**< Slave Select 2 High. */ |
Anna Bridge |
186:707f6e361f3e | 72 | SPIM_SSEL2_LOW = 0, /**< Slave Select 2 Low. */ |
Anna Bridge |
186:707f6e361f3e | 73 | SPIM_SSEL3_HIGH = (0x1 << 3), /**< Slave Select 3 High. */ |
Anna Bridge |
186:707f6e361f3e | 74 | SPIM_SSEL3_LOW = 0, /**< Slave Select 3 Low. */ |
Anna Bridge |
186:707f6e361f3e | 75 | SPIM_SSEL4_HIGH = (0x1 << 4), /**< Slave Select 4 High. */ |
Anna Bridge |
186:707f6e361f3e | 76 | SPIM_SSEL4_LOW = 0 /**< Slave Select 4 Low. */ |
Anna Bridge |
186:707f6e361f3e | 77 | } |
Anna Bridge |
186:707f6e361f3e | 78 | spim_ssel_t; |
Anna Bridge |
186:707f6e361f3e | 79 | |
Anna Bridge |
186:707f6e361f3e | 80 | /** |
Anna Bridge |
186:707f6e361f3e | 81 | * Enumeration type for setting the number data lines to use for communication. |
Anna Bridge |
186:707f6e361f3e | 82 | */ |
Anna Bridge |
186:707f6e361f3e | 83 | typedef enum { |
Anna Bridge |
186:707f6e361f3e | 84 | SPIM_WIDTH_1 = 0, /**< 1 Data Line. */ |
Anna Bridge |
186:707f6e361f3e | 85 | SPIM_WIDTH_2 = 1, /**< 2 Data Lines (x2). */ |
Anna Bridge |
186:707f6e361f3e | 86 | SPIM_WIDTH_4 = 2 /**< 4 Data Lines (x4). */ |
Anna Bridge |
186:707f6e361f3e | 87 | } spim_width_t; |
Anna Bridge |
186:707f6e361f3e | 88 | |
Anna Bridge |
186:707f6e361f3e | 89 | /** |
Anna Bridge |
186:707f6e361f3e | 90 | * Structure type for configuring a SPIM port. |
Anna Bridge |
186:707f6e361f3e | 91 | */ |
Anna Bridge |
186:707f6e361f3e | 92 | typedef struct { |
Anna Bridge |
186:707f6e361f3e | 93 | uint8_t mode; /**< SPIM mode selection, 0 to 3. */ |
Anna Bridge |
186:707f6e361f3e | 94 | uint32_t ssel_pol; /**< Mask of active levels for the slave select signals, see #spim_ssel_t. */ |
Anna Bridge |
186:707f6e361f3e | 95 | uint32_t baud; /**< Baud rate in Hz. */ |
Anna Bridge |
186:707f6e361f3e | 96 | } spim_cfg_t; |
Anna Bridge |
186:707f6e361f3e | 97 | |
Anna Bridge |
186:707f6e361f3e | 98 | /** |
Anna Bridge |
186:707f6e361f3e | 99 | * Structure type representing a SPI Master Transaction request. |
Anna Bridge |
186:707f6e361f3e | 100 | */ |
Anna Bridge |
186:707f6e361f3e | 101 | typedef struct spim_req spim_req_t; |
Anna Bridge |
186:707f6e361f3e | 102 | |
Anna Bridge |
186:707f6e361f3e | 103 | /** |
Anna Bridge |
186:707f6e361f3e | 104 | * @brief Callback function type used in asynchromous SPIM communications requests. |
Anna Bridge |
186:707f6e361f3e | 105 | * @details The function declaration for the SPIM callback is: |
Anna Bridge |
186:707f6e361f3e | 106 | * @code |
Anna Bridge |
186:707f6e361f3e | 107 | * void callback(spim_req_t * req, int error_code); |
Anna Bridge |
186:707f6e361f3e | 108 | * @endcode |
Anna Bridge |
186:707f6e361f3e | 109 | * | | | |
Anna Bridge |
186:707f6e361f3e | 110 | * | -----: | :----------------------------------------- | |
Anna Bridge |
186:707f6e361f3e | 111 | * | \p req | Pointer to a #spim_req object representing the active SPIM active transaction. | |
Anna Bridge |
186:707f6e361f3e | 112 | * | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. | |
Anna Bridge |
186:707f6e361f3e | 113 | * @addtogroup spim_async |
Anna Bridge |
186:707f6e361f3e | 114 | */ |
Anna Bridge |
186:707f6e361f3e | 115 | typedef void (*spim_callback_fn)(spim_req_t * req, int error_code); |
Anna Bridge |
186:707f6e361f3e | 116 | |
Anna Bridge |
186:707f6e361f3e | 117 | /** |
Anna Bridge |
186:707f6e361f3e | 118 | * @brief Structure definition for an SPI Master Transaction request. |
Anna Bridge |
186:707f6e361f3e | 119 | * @note When using this structure for an asynchronous operation, the |
Anna Bridge |
186:707f6e361f3e | 120 | * structure must remain allocated until the callback is completed. |
Anna Bridge |
186:707f6e361f3e | 121 | * @addtogroup spim_async |
Anna Bridge |
186:707f6e361f3e | 122 | */ |
Anna Bridge |
186:707f6e361f3e | 123 | struct spim_req { |
Anna Bridge |
186:707f6e361f3e | 124 | uint8_t ssel; /**< Number of the Slave Select to use. */ |
Anna Bridge |
186:707f6e361f3e | 125 | uint8_t deass; /**< Set to de-assert slave select at the completions of the transaction.*/ |
Anna Bridge |
186:707f6e361f3e | 126 | const uint8_t *tx_data; /**< Pointer to a buffer to transmit data from. */ |
Anna Bridge |
186:707f6e361f3e | 127 | uint8_t *rx_data; /**< Pointer to a buffer to store data received. */ |
Anna Bridge |
186:707f6e361f3e | 128 | spim_width_t width; /**< Number of data lines to use, see #spim_width_t. */ |
Anna Bridge |
186:707f6e361f3e | 129 | unsigned len; /**< Number of bytes to send from the \p tx_data buffer. */ |
Anna Bridge |
186:707f6e361f3e | 130 | unsigned read_num; /**< Number of bytes read and stored in \p rx_data buffer. */ |
Anna Bridge |
186:707f6e361f3e | 131 | unsigned write_num; /**< Number of bytes sent from the \p tx_data buffer, this will be filled by the driver after up to \p len bytes have been transmitted. */ |
Anna Bridge |
186:707f6e361f3e | 132 | spim_callback_fn callback; /**< Function pointer to a callback function if desired, NULL otherwise */ |
Anna Bridge |
186:707f6e361f3e | 133 | }; |
Anna Bridge |
186:707f6e361f3e | 134 | |
Anna Bridge |
186:707f6e361f3e | 135 | /* **** Globals **** */ |
Anna Bridge |
186:707f6e361f3e | 136 | |
Anna Bridge |
186:707f6e361f3e | 137 | /* **** Function Prototypes **** */ |
Anna Bridge |
186:707f6e361f3e | 138 | |
Anna Bridge |
186:707f6e361f3e | 139 | /** |
Anna Bridge |
186:707f6e361f3e | 140 | * @brief Initialize the SPIM peripheral module. |
Anna Bridge |
186:707f6e361f3e | 141 | * |
Anna Bridge |
186:707f6e361f3e | 142 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 143 | * @param cfg Pointer to an SPIM configuration object. |
Anna Bridge |
186:707f6e361f3e | 144 | * @param sys_cfg Pointer to a system configuration object to select the |
Anna Bridge |
186:707f6e361f3e | 145 | * peripheral clock rate and assign the requested GPIO. |
Anna Bridge |
186:707f6e361f3e | 146 | * |
Anna Bridge |
186:707f6e361f3e | 147 | * @return #E_NO_ERROR if the SPIM port is initialized successfully, @ref MXC_Error_Codes |
Anna Bridge |
186:707f6e361f3e | 148 | * "error" if unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 149 | */ |
Anna Bridge |
186:707f6e361f3e | 150 | int SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *cfg, const sys_cfg_spim_t *sys_cfg); |
Anna Bridge |
186:707f6e361f3e | 151 | |
Anna Bridge |
186:707f6e361f3e | 152 | /** |
Anna Bridge |
186:707f6e361f3e | 153 | * @brief Shutdown the SPIM peripheral module instance represented by the |
Anna Bridge |
186:707f6e361f3e | 154 | * @p spim parameter. |
Anna Bridge |
186:707f6e361f3e | 155 | * |
Anna Bridge |
186:707f6e361f3e | 156 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 157 | * |
Anna Bridge |
186:707f6e361f3e | 158 | * @return #E_NO_ERROR if the SPIM is shutdown successfully, @ref |
Anna Bridge |
186:707f6e361f3e | 159 | * MXC_Error_Codes "error" if unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 160 | */ |
Anna Bridge |
186:707f6e361f3e | 161 | int SPIM_Shutdown(mxc_spim_regs_t *spim); |
Anna Bridge |
186:707f6e361f3e | 162 | |
Anna Bridge |
186:707f6e361f3e | 163 | /** |
Anna Bridge |
186:707f6e361f3e | 164 | * @brief Send Clock cycles on SCK without reading or writing. |
Anna Bridge |
186:707f6e361f3e | 165 | * |
Anna Bridge |
186:707f6e361f3e | 166 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 167 | * @param len Number of clock cycles to send. |
Anna Bridge |
186:707f6e361f3e | 168 | * @param ssel Slave select number. |
Anna Bridge |
186:707f6e361f3e | 169 | * @param deass De-assert slave select at the end of the transaction. |
Anna Bridge |
186:707f6e361f3e | 170 | * |
Anna Bridge |
186:707f6e361f3e | 171 | * @return Cycles transacted if everything is successful, @ref |
Anna Bridge |
186:707f6e361f3e | 172 | * MXC_Error_Codes "error" if unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 173 | */ |
Anna Bridge |
186:707f6e361f3e | 174 | int SPIM_Clocks(mxc_spim_regs_t *spim, uint32_t len, uint8_t ssel, uint8_t deass); |
Anna Bridge |
186:707f6e361f3e | 175 | |
Anna Bridge |
186:707f6e361f3e | 176 | /** |
Anna Bridge |
186:707f6e361f3e | 177 | * @brief Read/write SPIM data. This function will block until the |
Anna Bridge |
186:707f6e361f3e | 178 | * transaction is complete. |
Anna Bridge |
186:707f6e361f3e | 179 | * |
Anna Bridge |
186:707f6e361f3e | 180 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 181 | * @param req Request for a SPIM transaction. |
Anna Bridge |
186:707f6e361f3e | 182 | * @note If a callback function is registered it will not be called when using a blocking function. |
Anna Bridge |
186:707f6e361f3e | 183 | * |
Anna Bridge |
186:707f6e361f3e | 184 | * @return Bytes transacted if everything is successful, error if |
Anna Bridge |
186:707f6e361f3e | 185 | * unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 186 | */ |
Anna Bridge |
186:707f6e361f3e | 187 | int SPIM_Trans(mxc_spim_regs_t *spim, spim_req_t *req); |
Anna Bridge |
186:707f6e361f3e | 188 | /** |
Anna Bridge |
186:707f6e361f3e | 189 | * @defgroup spim_async SPIM Asynchrous Functions |
Anna Bridge |
186:707f6e361f3e | 190 | * @{ |
Anna Bridge |
186:707f6e361f3e | 191 | */ |
Anna Bridge |
186:707f6e361f3e | 192 | /** |
Anna Bridge |
186:707f6e361f3e | 193 | * @brief Asynchronously read/write SPIM data. |
Anna Bridge |
186:707f6e361f3e | 194 | * |
Anna Bridge |
186:707f6e361f3e | 195 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 196 | * @param req Request for a SPIM transaction. |
Anna Bridge |
186:707f6e361f3e | 197 | * @note Request struct must remain allocated until callback. |
Anna Bridge |
186:707f6e361f3e | 198 | * |
Anna Bridge |
186:707f6e361f3e | 199 | * @return #E_NO_ERROR if everything is successful, @ref MXC_Error_Codes |
Anna Bridge |
186:707f6e361f3e | 200 | * "error" if unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 201 | */ |
Anna Bridge |
186:707f6e361f3e | 202 | int SPIM_TransAsync(mxc_spim_regs_t *spim, spim_req_t *req); |
Anna Bridge |
186:707f6e361f3e | 203 | |
Anna Bridge |
186:707f6e361f3e | 204 | /** |
Anna Bridge |
186:707f6e361f3e | 205 | * @brief Abort asynchronous request. |
Anna Bridge |
186:707f6e361f3e | 206 | * |
Anna Bridge |
186:707f6e361f3e | 207 | * @param req Pointer to a request structure for a SPIM transaction. |
Anna Bridge |
186:707f6e361f3e | 208 | * |
Anna Bridge |
186:707f6e361f3e | 209 | * @return #E_NO_ERROR if request aborted, , @ref MXC_Error_Codes "error" if |
Anna Bridge |
186:707f6e361f3e | 210 | * unsuccessful. |
Anna Bridge |
186:707f6e361f3e | 211 | */ |
Anna Bridge |
186:707f6e361f3e | 212 | int SPIM_AbortAsync(spim_req_t *req); |
Anna Bridge |
186:707f6e361f3e | 213 | |
Anna Bridge |
186:707f6e361f3e | 214 | /** |
Anna Bridge |
186:707f6e361f3e | 215 | * @brief SPIM interrupt handler. |
Anna Bridge |
186:707f6e361f3e | 216 | * @details This function should be called by the application from the |
Anna Bridge |
186:707f6e361f3e | 217 | * interrupt handler if SPIM interrupts are enabled. Alternately, |
Anna Bridge |
186:707f6e361f3e | 218 | * this function can be periodically polled by the application if |
Anna Bridge |
186:707f6e361f3e | 219 | * SPIM interrupts are disabled. |
Anna Bridge |
186:707f6e361f3e | 220 | * |
Anna Bridge |
186:707f6e361f3e | 221 | * @param spim Base address of the SPIM module. |
Anna Bridge |
186:707f6e361f3e | 222 | */ |
Anna Bridge |
186:707f6e361f3e | 223 | void SPIM_Handler(mxc_spim_regs_t *spim); |
Anna Bridge |
186:707f6e361f3e | 224 | |
Anna Bridge |
186:707f6e361f3e | 225 | /** |
Anna Bridge |
186:707f6e361f3e | 226 | * @brief Check the SPIM to see if it's busy. |
Anna Bridge |
186:707f6e361f3e | 227 | * |
Anna Bridge |
186:707f6e361f3e | 228 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 229 | * |
Anna Bridge |
186:707f6e361f3e | 230 | * @retval #E_NO_ERROR if idle. |
Anna Bridge |
186:707f6e361f3e | 231 | * @retval #E_BUSY if in use. |
Anna Bridge |
186:707f6e361f3e | 232 | */ |
Anna Bridge |
186:707f6e361f3e | 233 | int SPIM_Busy(mxc_spim_regs_t *spim); |
Anna Bridge |
186:707f6e361f3e | 234 | /**@} end of spim_async define group */ |
Anna Bridge |
186:707f6e361f3e | 235 | |
Anna Bridge |
186:707f6e361f3e | 236 | /** |
Anna Bridge |
186:707f6e361f3e | 237 | * @brief Attempts to prepare the SPIM for Low Power Sleep Modes. |
Anna Bridge |
186:707f6e361f3e | 238 | * @details Checks for any ongoing transactions. Disables interrupts if the |
Anna Bridge |
186:707f6e361f3e | 239 | * SPIM is idle. |
Anna Bridge |
186:707f6e361f3e | 240 | * |
Anna Bridge |
186:707f6e361f3e | 241 | * @param spim The spim |
Anna Bridge |
186:707f6e361f3e | 242 | * |
Anna Bridge |
186:707f6e361f3e | 243 | * @return #E_NO_ERROR if ready to sleep. |
Anna Bridge |
186:707f6e361f3e | 244 | * @return #E_BUSY if not able to sleep at this time. |
Anna Bridge |
186:707f6e361f3e | 245 | */ |
Anna Bridge |
186:707f6e361f3e | 246 | int SPIM_PrepForSleep(mxc_spim_regs_t *spim); |
Anna Bridge |
186:707f6e361f3e | 247 | |
Anna Bridge |
186:707f6e361f3e | 248 | /** |
Anna Bridge |
186:707f6e361f3e | 249 | * @brief Enables the SPIM without overwriting the existing configuration. |
Anna Bridge |
186:707f6e361f3e | 250 | * |
Anna Bridge |
186:707f6e361f3e | 251 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 252 | */ |
Anna Bridge |
186:707f6e361f3e | 253 | __STATIC_INLINE void SPIM_Enable(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 254 | { |
Anna Bridge |
186:707f6e361f3e | 255 | spim->gen_ctrl |= (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN | |
Anna Bridge |
186:707f6e361f3e | 256 | MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); |
Anna Bridge |
186:707f6e361f3e | 257 | } |
Anna Bridge |
186:707f6e361f3e | 258 | |
Anna Bridge |
186:707f6e361f3e | 259 | /** |
Anna Bridge |
186:707f6e361f3e | 260 | * @brief Drains/empties the data in the RX FIFO. |
Anna Bridge |
186:707f6e361f3e | 261 | * |
Anna Bridge |
186:707f6e361f3e | 262 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 263 | */ |
Anna Bridge |
186:707f6e361f3e | 264 | __STATIC_INLINE void SPIM_DrainRX(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 265 | { |
Anna Bridge |
186:707f6e361f3e | 266 | uint32_t ctrl_save = spim->gen_ctrl; |
Anna Bridge |
186:707f6e361f3e | 267 | spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN); |
Anna Bridge |
186:707f6e361f3e | 268 | spim->gen_ctrl = ctrl_save; |
Anna Bridge |
186:707f6e361f3e | 269 | } |
Anna Bridge |
186:707f6e361f3e | 270 | |
Anna Bridge |
186:707f6e361f3e | 271 | /** |
Anna Bridge |
186:707f6e361f3e | 272 | * @brief Drains/empties the data in the TX FIFO. |
Anna Bridge |
186:707f6e361f3e | 273 | * |
Anna Bridge |
186:707f6e361f3e | 274 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 275 | */ |
Anna Bridge |
186:707f6e361f3e | 276 | __STATIC_INLINE void SPIM_DrainTX(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 277 | { |
Anna Bridge |
186:707f6e361f3e | 278 | uint32_t ctrl_save = spim->gen_ctrl; |
Anna Bridge |
186:707f6e361f3e | 279 | spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN); |
Anna Bridge |
186:707f6e361f3e | 280 | spim->gen_ctrl = ctrl_save; |
Anna Bridge |
186:707f6e361f3e | 281 | } |
Anna Bridge |
186:707f6e361f3e | 282 | |
Anna Bridge |
186:707f6e361f3e | 283 | /** |
Anna Bridge |
186:707f6e361f3e | 284 | * @brief Returns the number of bytes free in the TX FIFO. |
Anna Bridge |
186:707f6e361f3e | 285 | * |
Anna Bridge |
186:707f6e361f3e | 286 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 287 | * |
Anna Bridge |
186:707f6e361f3e | 288 | * @return Number of bytes free in Transmit FIFO. |
Anna Bridge |
186:707f6e361f3e | 289 | */ |
Anna Bridge |
186:707f6e361f3e | 290 | __STATIC_INLINE unsigned SPIM_NumWriteAvail(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 291 | { |
Anna Bridge |
186:707f6e361f3e | 292 | return (MXC_CFG_SPIM_FIFO_DEPTH - ((spim->fifo_ctrl & |
Anna Bridge |
186:707f6e361f3e | 293 | MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) >> MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS)); |
Anna Bridge |
186:707f6e361f3e | 294 | } |
Anna Bridge |
186:707f6e361f3e | 295 | |
Anna Bridge |
186:707f6e361f3e | 296 | /** |
Anna Bridge |
186:707f6e361f3e | 297 | * @brief Returns the number of bytes available to read in the RX FIFO. |
Anna Bridge |
186:707f6e361f3e | 298 | * |
Anna Bridge |
186:707f6e361f3e | 299 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 300 | * |
Anna Bridge |
186:707f6e361f3e | 301 | * @return Number of bytes in RX FIFO. |
Anna Bridge |
186:707f6e361f3e | 302 | */ |
Anna Bridge |
186:707f6e361f3e | 303 | __STATIC_INLINE unsigned SPIM_NumReadAvail(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 304 | { |
Anna Bridge |
186:707f6e361f3e | 305 | return ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED) >> |
Anna Bridge |
186:707f6e361f3e | 306 | MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS); |
Anna Bridge |
186:707f6e361f3e | 307 | } |
Anna Bridge |
186:707f6e361f3e | 308 | |
Anna Bridge |
186:707f6e361f3e | 309 | /** |
Anna Bridge |
186:707f6e361f3e | 310 | * @brief Clear the SPIM interrupt flags. |
Anna Bridge |
186:707f6e361f3e | 311 | * |
Anna Bridge |
186:707f6e361f3e | 312 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 313 | * @param mask Mask of the SPIM interrupt flags to clear, see @ref |
Anna Bridge |
186:707f6e361f3e | 314 | * SPIM_INTFL_Register Register for the SPIM interrupt flag |
Anna Bridge |
186:707f6e361f3e | 315 | * bit masks. |
Anna Bridge |
186:707f6e361f3e | 316 | */ |
Anna Bridge |
186:707f6e361f3e | 317 | __STATIC_INLINE void SPIM_ClearFlags(mxc_spim_regs_t *spim, uint32_t mask) |
Anna Bridge |
186:707f6e361f3e | 318 | { |
Anna Bridge |
186:707f6e361f3e | 319 | spim->intfl = mask; |
Anna Bridge |
186:707f6e361f3e | 320 | } |
Anna Bridge |
186:707f6e361f3e | 321 | |
Anna Bridge |
186:707f6e361f3e | 322 | /** |
Anna Bridge |
186:707f6e361f3e | 323 | * @brief Read the current SPIM interrupt flags. |
Anna Bridge |
186:707f6e361f3e | 324 | * |
Anna Bridge |
186:707f6e361f3e | 325 | * @param spim Pointer to the SPIM register structure. |
Anna Bridge |
186:707f6e361f3e | 326 | * |
Anna Bridge |
186:707f6e361f3e | 327 | * @return Mask of currently set SPIM interrupt flags, see @ref |
Anna Bridge |
186:707f6e361f3e | 328 | * SPIM_INTFL_Register Register for the SPIM interrupt flag bit |
Anna Bridge |
186:707f6e361f3e | 329 | * masks. |
Anna Bridge |
186:707f6e361f3e | 330 | */ |
Anna Bridge |
186:707f6e361f3e | 331 | __STATIC_INLINE unsigned SPIM_GetFlags(mxc_spim_regs_t *spim) |
Anna Bridge |
186:707f6e361f3e | 332 | { |
Anna Bridge |
186:707f6e361f3e | 333 | return (spim->intfl); |
Anna Bridge |
186:707f6e361f3e | 334 | } |
Anna Bridge |
186:707f6e361f3e | 335 | |
Anna Bridge |
186:707f6e361f3e | 336 | /**@} end of group spim_comm */ |
Anna Bridge |
186:707f6e361f3e | 337 | #ifdef __cplusplus |
Anna Bridge |
186:707f6e361f3e | 338 | } |
Anna Bridge |
186:707f6e361f3e | 339 | #endif |
Anna Bridge |
186:707f6e361f3e | 340 | |
Anna Bridge |
186:707f6e361f3e | 341 | #endif /* _SPIM_H_ */ |