cc y / mbed

Fork of mbed by mbed official

Committer:
<>
Date:
Tue Nov 08 17:28:34 2016 +0000
Revision:
129:0ab6a29f35bf
Release 129 of the mbed library

Ports for Upcoming Targets

3011: Add u-blox Sara-N target. https://github.com/ARMmbed/mbed-os/pull/3011
3099: MAX32625 https://github.com/ARMmbed/mbed-os/pull/3099
3151: Add support for FRDM-K82F https://github.com/ARMmbed/mbed-os/pull/3151
3177: New mcu k22512 fixing pr 3136 https://github.com/ARMmbed/mbed-os/pull/3177

Fixes and Changes

3008: NUCLEO_F072RB: Fix wrong timer channel number on pwm PB_5 pin https://github.com/ARMmbed/mbed-os/pull/3008
3013: STM32xx - Change how the ADC internal pins are checked before pinmap_ https://github.com/ARMmbed/mbed-os/pull/3013
3041: [nRF5] - added implementation of API of serial port flow control configuration. https://github.com/ARMmbed/mbed-os/pull/3041
3084: [nrf5] fix in Digital I/O : a gpioe pin was uninitialized badly https://github.com/ARMmbed/mbed-os/pull/3084
3009: TRNG enabled. TRNG APIs implemented. REV A/B/C/D flags removed. Warnings removed https://github.com/ARMmbed/mbed-os/pull/3009
3074: Target stm init gcc alignement https://github.com/ARMmbed/mbed-os/pull/3074
2988: Update of can_api.c fixing #2987 https://github.com/ARMmbed/mbed-os/pull/2988
3173: [Exporters] Add a device_name to microbit entry in targets.json https://github.com/ARMmbed/mbed-os/pull/3173
2969: [nRF52] - switch irq priorities of driver handlers to the lowest level https://github.com/ARMmbed/mbed-os/pull/2969
3184: #3183 Compiler warning in trng_api.c with K64F https://github.com/ARMmbed/mbed-os/pull/3184
3104: [NuMaker] Support CAN and fix PWM CLK error https://github.com/ARMmbed/mbed-os/pull/3104
3186: MultiTech mDot - add back SPI3 pins https://github.com/ARMmbed/mbed-os/pull/3186
3075: nsapi - Add standardized return types for size and errors https://github.com/ARMmbed/mbed-os/pull/3075
3221: u-blox odin w2 drivers update https://github.com/ARMmbed/mbed-os/pull/3221

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 129:0ab6a29f35bf 1 /*******************************************************************************
<> 129:0ab6a29f35bf 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
<> 129:0ab6a29f35bf 3 *
<> 129:0ab6a29f35bf 4 * Permission is hereby granted, free of charge, to any person obtaining a
<> 129:0ab6a29f35bf 5 * copy of this software and associated documentation files (the "Software"),
<> 129:0ab6a29f35bf 6 * to deal in the Software without restriction, including without limitation
<> 129:0ab6a29f35bf 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
<> 129:0ab6a29f35bf 8 * and/or sell copies of the Software, and to permit persons to whom the
<> 129:0ab6a29f35bf 9 * Software is furnished to do so, subject to the following conditions:
<> 129:0ab6a29f35bf 10 *
<> 129:0ab6a29f35bf 11 * The above copyright notice and this permission notice shall be included
<> 129:0ab6a29f35bf 12 * in all copies or substantial portions of the Software.
<> 129:0ab6a29f35bf 13 *
<> 129:0ab6a29f35bf 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
<> 129:0ab6a29f35bf 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<> 129:0ab6a29f35bf 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
<> 129:0ab6a29f35bf 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
<> 129:0ab6a29f35bf 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
<> 129:0ab6a29f35bf 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
<> 129:0ab6a29f35bf 20 * OTHER DEALINGS IN THE SOFTWARE.
<> 129:0ab6a29f35bf 21 *
<> 129:0ab6a29f35bf 22 * Except as contained in this notice, the name of Maxim Integrated
<> 129:0ab6a29f35bf 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
<> 129:0ab6a29f35bf 24 * Products, Inc. Branding Policy.
<> 129:0ab6a29f35bf 25 *
<> 129:0ab6a29f35bf 26 * The mere transfer of this software does not imply any licenses
<> 129:0ab6a29f35bf 27 * of trade secrets, proprietary technology, copyrights, patents,
<> 129:0ab6a29f35bf 28 * trademarks, maskwork rights, or any other form of intellectual
<> 129:0ab6a29f35bf 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
<> 129:0ab6a29f35bf 30 * ownership rights.
<> 129:0ab6a29f35bf 31 *
<> 129:0ab6a29f35bf 32 * $Date: 2016-04-27 11:55:43 -0500 (Wed, 27 Apr 2016) $
<> 129:0ab6a29f35bf 33 * $Revision: 22541 $
<> 129:0ab6a29f35bf 34 *
<> 129:0ab6a29f35bf 35 ******************************************************************************/
<> 129:0ab6a29f35bf 36
<> 129:0ab6a29f35bf 37 /**
<> 129:0ab6a29f35bf 38 * @file spim.h
<> 129:0ab6a29f35bf 39 * @brief SPI Master driver header file.
<> 129:0ab6a29f35bf 40 */
<> 129:0ab6a29f35bf 41
<> 129:0ab6a29f35bf 42 #include "mxc_config.h"
<> 129:0ab6a29f35bf 43 #include "mxc_sys.h"
<> 129:0ab6a29f35bf 44 #include "spim_regs.h"
<> 129:0ab6a29f35bf 45
<> 129:0ab6a29f35bf 46 #ifndef _SPIM_H_
<> 129:0ab6a29f35bf 47 #define _SPIM_H_
<> 129:0ab6a29f35bf 48
<> 129:0ab6a29f35bf 49 #ifdef __cplusplus
<> 129:0ab6a29f35bf 50 extern "C" {
<> 129:0ab6a29f35bf 51 #endif
<> 129:0ab6a29f35bf 52
<> 129:0ab6a29f35bf 53 /***** Definitions *****/
<> 129:0ab6a29f35bf 54
<> 129:0ab6a29f35bf 55 /// @brief Active levels for slave select lines.
<> 129:0ab6a29f35bf 56 typedef enum {
<> 129:0ab6a29f35bf 57 SPIM_SSEL0_HIGH = (0x1 << 0),
<> 129:0ab6a29f35bf 58 SPIM_SSEL0_LOW = 0,
<> 129:0ab6a29f35bf 59 SPIM_SSEL1_HIGH = (0x1 << 1),
<> 129:0ab6a29f35bf 60 SPIM_SSEL1_LOW = 0,
<> 129:0ab6a29f35bf 61 SPIM_SSEL2_HIGH = (0x1 << 2),
<> 129:0ab6a29f35bf 62 SPIM_SSEL2_LOW = 0,
<> 129:0ab6a29f35bf 63 SPIM_SSEL3_HIGH = (0x1 << 3),
<> 129:0ab6a29f35bf 64 SPIM_SSEL3_LOW = 0,
<> 129:0ab6a29f35bf 65 SPIM_SSEL4_HIGH = (0x1 << 4),
<> 129:0ab6a29f35bf 66 SPIM_SSEL4_LOW = 0
<> 129:0ab6a29f35bf 67 }
<> 129:0ab6a29f35bf 68 spim_ssel_t;
<> 129:0ab6a29f35bf 69
<> 129:0ab6a29f35bf 70 /// @brief Number of data lines to use.
<> 129:0ab6a29f35bf 71 typedef enum {
<> 129:0ab6a29f35bf 72 SPIM_WIDTH_1 = 0,
<> 129:0ab6a29f35bf 73 SPIM_WIDTH_2 = 1,
<> 129:0ab6a29f35bf 74 SPIM_WIDTH_4 = 2
<> 129:0ab6a29f35bf 75 } spim_width_t;
<> 129:0ab6a29f35bf 76
<> 129:0ab6a29f35bf 77 /// @brief SPIM configuration type.
<> 129:0ab6a29f35bf 78 typedef struct {
<> 129:0ab6a29f35bf 79 uint8_t mode; ///< SPIM mode to use, 0-3.
<> 129:0ab6a29f35bf 80 uint32_t ssel_pol; ///< Mask of active levels for slave select signals, use spim_ssel_t.
<> 129:0ab6a29f35bf 81 uint32_t baud; ///< Baud rate in Hz.
<> 129:0ab6a29f35bf 82 } spim_cfg_t;
<> 129:0ab6a29f35bf 83
<> 129:0ab6a29f35bf 84 /// @brief SPIM Transaction request.
<> 129:0ab6a29f35bf 85 typedef struct spim_req spim_req_t;
<> 129:0ab6a29f35bf 86 struct spim_req {
<> 129:0ab6a29f35bf 87 uint8_t ssel; ///< Slave select number.
<> 129:0ab6a29f35bf 88 uint8_t deass; ///< De-assert slave select at the end of the transaction.
<> 129:0ab6a29f35bf 89 const uint8_t *tx_data; ///< TX buffer.
<> 129:0ab6a29f35bf 90 uint8_t *rx_data; ///< RX buffer.
<> 129:0ab6a29f35bf 91 spim_width_t width; ///< Number of data lines to use
<> 129:0ab6a29f35bf 92 unsigned len; ///< Number of bytes to send.
<> 129:0ab6a29f35bf 93 unsigned read_num; ///< Number of bytes read.
<> 129:0ab6a29f35bf 94 unsigned write_num; ///< Number of bytes written.
<> 129:0ab6a29f35bf 95
<> 129:0ab6a29f35bf 96 /**
<> 129:0ab6a29f35bf 97 * @brief Callback for asynchronous request.
<> 129:0ab6a29f35bf 98 * @param spim_req_t* Pointer to the transaction request.
<> 129:0ab6a29f35bf 99 * @param int Error code.
<> 129:0ab6a29f35bf 100 */
<> 129:0ab6a29f35bf 101 void (*callback)(spim_req_t*, int);
<> 129:0ab6a29f35bf 102 };
<> 129:0ab6a29f35bf 103
<> 129:0ab6a29f35bf 104 /***** Globals *****/
<> 129:0ab6a29f35bf 105
<> 129:0ab6a29f35bf 106 /***** Function Prototypes *****/
<> 129:0ab6a29f35bf 107
<> 129:0ab6a29f35bf 108 /**
<> 129:0ab6a29f35bf 109 * @brief Initialize SPIM module.
<> 129:0ab6a29f35bf 110 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 111 * @param cfg Pointer to SPIM configuration.
<> 129:0ab6a29f35bf 112 * @param sys_cfg Pointer to system configuration object
<> 129:0ab6a29f35bf 113 * @returns #E_NO_ERROR if everything is successful
<> 129:0ab6a29f35bf 114 */
<> 129:0ab6a29f35bf 115 int SPIM_Init(mxc_spim_regs_t *spim, const spim_cfg_t *cfg, const sys_cfg_spim_t *sys_cfg);
<> 129:0ab6a29f35bf 116
<> 129:0ab6a29f35bf 117 /**
<> 129:0ab6a29f35bf 118 * @brief Shutdown SPIM module.
<> 129:0ab6a29f35bf 119 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 120 * @returns #E_NO_ERROR if everything is successful
<> 129:0ab6a29f35bf 121 */
<> 129:0ab6a29f35bf 122 int SPIM_Shutdown(mxc_spim_regs_t *spim);
<> 129:0ab6a29f35bf 123
<> 129:0ab6a29f35bf 124 /**
<> 129:0ab6a29f35bf 125 * @brief Send Clock cycles on SCK without reading or writing.
<> 129:0ab6a29f35bf 126 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 127 * @param len Number of clock cycles to send.
<> 129:0ab6a29f35bf 128 * @param ssel Slave select number.
<> 129:0ab6a29f35bf 129 * @param deass De-assert slave select at the end of the transaction.
<> 129:0ab6a29f35bf 130 * @returns Cycles transacted if everything is successful, error if unsuccessful.
<> 129:0ab6a29f35bf 131 */
<> 129:0ab6a29f35bf 132 int SPIM_Clocks(mxc_spim_regs_t *spim, uint32_t len, uint8_t ssel, uint8_t deass);
<> 129:0ab6a29f35bf 133
<> 129:0ab6a29f35bf 134 /**
<> 129:0ab6a29f35bf 135 * @brief Read/write SPIM data. Will block until transaction is complete.
<> 129:0ab6a29f35bf 136 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 137 * @param req Request for a SPIM transaction.
<> 129:0ab6a29f35bf 138 * @note Callback is ignored.
<> 129:0ab6a29f35bf 139 * @returns Bytes transacted if everything is successful, error if unsuccessful.
<> 129:0ab6a29f35bf 140 */
<> 129:0ab6a29f35bf 141 int SPIM_Trans(mxc_spim_regs_t *spim, spim_req_t *req);
<> 129:0ab6a29f35bf 142
<> 129:0ab6a29f35bf 143 /**
<> 129:0ab6a29f35bf 144 * @brief Asynchronously read/write SPIM data.
<> 129:0ab6a29f35bf 145 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 146 * @param req Request for a SPIM transaction.
<> 129:0ab6a29f35bf 147 * @note Request struct must remain allocated until callback.
<> 129:0ab6a29f35bf 148 * @returns #E_NO_ERROR if everything is successful, error if unsuccessful.
<> 129:0ab6a29f35bf 149 */
<> 129:0ab6a29f35bf 150 int SPIM_TransAsync(mxc_spim_regs_t *spim, spim_req_t *req);
<> 129:0ab6a29f35bf 151
<> 129:0ab6a29f35bf 152 /**
<> 129:0ab6a29f35bf 153 * @brief Abort asynchronous request.
<> 129:0ab6a29f35bf 154 * @param req Pointer to request for a SPIM transaction.
<> 129:0ab6a29f35bf 155 * @returns #E_NO_ERROR if request aborted, error if unsuccessful.
<> 129:0ab6a29f35bf 156 */
<> 129:0ab6a29f35bf 157 int SPIM_AbortAsync(spim_req_t *req);
<> 129:0ab6a29f35bf 158
<> 129:0ab6a29f35bf 159 /**
<> 129:0ab6a29f35bf 160 * @brief SPIM interrupt handler.
<> 129:0ab6a29f35bf 161 * @details This function should be called by the application from the interrupt
<> 129:0ab6a29f35bf 162 * handler if SPIM interrupts are enabled. Alternately, this function
<> 129:0ab6a29f35bf 163 * can be periodically called by the application if SPIM interrupts are
<> 129:0ab6a29f35bf 164 * disabled.
<> 129:0ab6a29f35bf 165 * @param spim Base address of the SPIM module.
<> 129:0ab6a29f35bf 166 */
<> 129:0ab6a29f35bf 167 void SPIM_Handler(mxc_spim_regs_t *spim);
<> 129:0ab6a29f35bf 168
<> 129:0ab6a29f35bf 169 /**
<> 129:0ab6a29f35bf 170 * @brief Check the SPIM to see if it's busy.
<> 129:0ab6a29f35bf 171 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 172 * @returns #E_NO_ERROR if idle, #E_BUSY if in use.
<> 129:0ab6a29f35bf 173 */
<> 129:0ab6a29f35bf 174 int SPIM_Busy(mxc_spim_regs_t *spim);
<> 129:0ab6a29f35bf 175
<> 129:0ab6a29f35bf 176 /**
<> 129:0ab6a29f35bf 177 * @brief Attempt to prepare the SPIM for sleep.
<> 129:0ab6a29f35bf 178 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 179 * @details Checks for any ongoing transactions. Disables interrupts if the SPIM
<> 129:0ab6a29f35bf 180 is idle.
<> 129:0ab6a29f35bf 181 * @returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep.
<> 129:0ab6a29f35bf 182 */
<> 129:0ab6a29f35bf 183 int SPIM_PrepForSleep(mxc_spim_regs_t *spim);
<> 129:0ab6a29f35bf 184
<> 129:0ab6a29f35bf 185 /**
<> 129:0ab6a29f35bf 186 * @brief Enables the SPIM without overwriting existing configuration.
<> 129:0ab6a29f35bf 187 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 188 */
<> 129:0ab6a29f35bf 189 __STATIC_INLINE void SPIM_Enable(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 190 {
<> 129:0ab6a29f35bf 191 spim->gen_ctrl |= (MXC_F_SPIM_GEN_CTRL_SPI_MSTR_EN |
<> 129:0ab6a29f35bf 192 MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN | MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN);
<> 129:0ab6a29f35bf 193 }
<> 129:0ab6a29f35bf 194
<> 129:0ab6a29f35bf 195 /**
<> 129:0ab6a29f35bf 196 * @brief Drain all of the data in the RXFIFO.
<> 129:0ab6a29f35bf 197 * @param spim Pointer to UART regs.
<> 129:0ab6a29f35bf 198 */
<> 129:0ab6a29f35bf 199 __STATIC_INLINE void SPIM_DrainRX(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 200 {
<> 129:0ab6a29f35bf 201 uint32_t ctrl_save = spim->gen_ctrl;
<> 129:0ab6a29f35bf 202 spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_RX_FIFO_EN);
<> 129:0ab6a29f35bf 203 spim->gen_ctrl = ctrl_save;
<> 129:0ab6a29f35bf 204 }
<> 129:0ab6a29f35bf 205
<> 129:0ab6a29f35bf 206 /**
<> 129:0ab6a29f35bf 207 * @brief Drain all of the data in the TXFIFO.
<> 129:0ab6a29f35bf 208 * @param spim Pointer to UART regs.
<> 129:0ab6a29f35bf 209 */
<> 129:0ab6a29f35bf 210 __STATIC_INLINE void SPIM_DrainTX(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 211 {
<> 129:0ab6a29f35bf 212 uint32_t ctrl_save = spim->gen_ctrl;
<> 129:0ab6a29f35bf 213 spim->gen_ctrl = (ctrl_save & ~MXC_F_SPIM_GEN_CTRL_TX_FIFO_EN);
<> 129:0ab6a29f35bf 214 spim->gen_ctrl = ctrl_save;
<> 129:0ab6a29f35bf 215 }
<> 129:0ab6a29f35bf 216
<> 129:0ab6a29f35bf 217 /**
<> 129:0ab6a29f35bf 218 * @brief TX FIFO availability.
<> 129:0ab6a29f35bf 219 * @param spim Pointer to UART regs.
<> 129:0ab6a29f35bf 220 * @returns Number of empty bytes available in write FIFO.
<> 129:0ab6a29f35bf 221 */
<> 129:0ab6a29f35bf 222 __STATIC_INLINE unsigned SPIM_NumWriteAvail(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 223 {
<> 129:0ab6a29f35bf 224 return (MXC_CFG_SPIM_FIFO_DEPTH - ((spim->fifo_ctrl &
<> 129:0ab6a29f35bf 225 MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED) >> MXC_F_SPIM_FIFO_CTRL_TX_FIFO_USED_POS));
<> 129:0ab6a29f35bf 226 }
<> 129:0ab6a29f35bf 227
<> 129:0ab6a29f35bf 228 /**
<> 129:0ab6a29f35bf 229 * @brief RX FIFO availability.
<> 129:0ab6a29f35bf 230 * @param spim Pointer to UART regs.
<> 129:0ab6a29f35bf 231 * @returns Number of bytes in read FIFO.
<> 129:0ab6a29f35bf 232 */
<> 129:0ab6a29f35bf 233 __STATIC_INLINE unsigned SPIM_NumReadAvail(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 234 {
<> 129:0ab6a29f35bf 235 return ((spim->fifo_ctrl & MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED) >>
<> 129:0ab6a29f35bf 236 MXC_F_SPIM_FIFO_CTRL_RX_FIFO_USED_POS);
<> 129:0ab6a29f35bf 237 }
<> 129:0ab6a29f35bf 238
<> 129:0ab6a29f35bf 239 /**
<> 129:0ab6a29f35bf 240 * @brief Clear interrupt flags.
<> 129:0ab6a29f35bf 241 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 242 * @param mask Mask of interrupts to clear.
<> 129:0ab6a29f35bf 243 */
<> 129:0ab6a29f35bf 244 __STATIC_INLINE void SPIM_ClearFlags(mxc_spim_regs_t *spim, uint32_t mask)
<> 129:0ab6a29f35bf 245 {
<> 129:0ab6a29f35bf 246 spim->intfl = mask;
<> 129:0ab6a29f35bf 247 }
<> 129:0ab6a29f35bf 248
<> 129:0ab6a29f35bf 249 /**
<> 129:0ab6a29f35bf 250 * @brief Get interrupt flags.
<> 129:0ab6a29f35bf 251 * @param spim Pointer to SPIM regs.
<> 129:0ab6a29f35bf 252 * @returns Mask of active flags.
<> 129:0ab6a29f35bf 253 */
<> 129:0ab6a29f35bf 254 __STATIC_INLINE unsigned SPIM_GetFlags(mxc_spim_regs_t *spim)
<> 129:0ab6a29f35bf 255 {
<> 129:0ab6a29f35bf 256 return (spim->intfl);
<> 129:0ab6a29f35bf 257 }
<> 129:0ab6a29f35bf 258
<> 129:0ab6a29f35bf 259 #ifdef __cplusplus
<> 129:0ab6a29f35bf 260 }
<> 129:0ab6a29f35bf 261 #endif
<> 129:0ab6a29f35bf 262
<> 129:0ab6a29f35bf 263 #endif /* _SPIM_H_ */