ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_spi_master_driver.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_spi_master_driver.h
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_spi_master_driver.h
10 * @brief \b fsl_spi_master_driver.h defines structures and types for the spi master driver.
11 */
12 #ifndef FSL_MASTER_SPI_DRIVER_H_
13 #define FSL_MASTER_SPI_DRIVER_H_
14 
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include "PE_Types.h"
18 #include "mqxlite.h"
19 #include "lwevent.h"
20 #include "fsl_spi_hal.h"
21 //*! @addtogroup spi_master_driver*/
22 /*! @{*/
23 
24 /*******************************************************************************
25  * Definitions
26  ******************************************************************************/
27 
29 {
30  /*! Wait forever for a transfer to complete.*/
31  kSpiWaitForever = 0xffffffffU
32 };
33 
34 /*! @brief Information about a device on the SPI bus.*/
35 typedef struct SPIUserConfig {
36  uint32_t busFrequencyKHz;
41 
42 typedef struct SPIHandle{
43  uint32_t instance;
45 
46 typedef struct SPI_Master_State {
47  uint32_t instance; /*!< UART module instance number. */
48  LDD_TDeviceData* pDeviceHandle; /*!< Pointer to the device handle.*/
49  LWEVENT_STRUCT eventHandler;
51 
52 /*! @brief event macros for the lld components.*/
53 #define SPI_PEX_WRITE_EVENT_SUCCESS (1)
54 #define SPI_PEX_WRITE_EVENT_ERROR (SPI_PEX_WRITE_EVENT_SUCCESS << 1)
55 #define SPI_PEX_READ_EVENT_SUCCESS (SPI_PEX_WRITE_EVENT_ERROR << 1)
56 #define SPI_PEX_READ_EVENT_ERROR (SPI_PEX_READ_EVENT_SUCCESS << 1)
57 /*******************************************************************************
58  * API
59  ******************************************************************************/
60 
61 #if defined(__cplusplus)
62 extern "C" {
63 #endif
64 
65 /*! @name Init and shutdown*/
66 /*@{*/
67 
68 /*!
69  * @brief Initialize a SPI instance for master mode operation.
70  *
71  * @param instance The instance number of the SPI peripheral.
72  */
73 void spi_master_init(uint32_t instance);
74 
75 
76 /*@}*/
77 
78 /*! @name Bus configuration*/
79 /*@{*/
80 
81 /*!
82  * @brief Configure the SPI port to access a device on the bus.
83  *
84  * @param instance The instance number of the SPI peripheral.
85  * @param device Pointer to the device information struct. This struct contains the settings
86  * for how the SPI bus will be configured.
87  */
88 void spi_master_configure_bus(uint32_t instance, const spi_user_config_t * device);
89 
90 /*@}*/
91 
92 /*! @name Blocking transfers*/
93 /*@{*/
94 
95 /*!
96  * @brief Perform a blocking SPI master mode transfer.
97  *
98  * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally
99  * a full-duplex bus.
100  *
101  * @param instance The instance number of the SPI peripheral.
102  * @param device Pointer to the device information struct. This struct contains the settings
103  * for how the SPI bus will be configured for this transfer. You may pass NULL for this
104  * parameter, in which case the current bus configuration is used unmodified.
105  * @param sendBuffer Buffer of data to send. You may pass NULL for this parameter, in which case
106  * bytes with a value of 0 (zero) will be sent.
107  * @param receiveBuffer Buffer where received bytes are stored. If you pass NULL for this parameter,
108  * the received bytes are ignored.
109  * @param transferByteCount The number of bytes to send and receive.
110  * @param timeout A timeout for the transfer in microseconds. If the transfer takes longer than
111  * this amount of time, the transfer will be aborted and a #kStatus_SPI_Timeout error will be
112  * returned.
113  *
114  * @retval #kStatus_Success The transfer was succesful.
115  * @retval #kStatus_SPI_Busy Cannot perform another transfer because one is already in progress.
116  * @retval #kStatus_SPI_Timeout The transfer timed out and was aborted.
117  */
118 spi_status_t spi_master_transfer(uint32_t instance,
119  const spi_user_config_t * device,
120  const uint8_t * sendBuffer,
121  uint8_t * receiveBuffer,
122  uint16_t transferByteCount,
123  uint32_t timeout);
124 
125 /*@}*/
126 
127 /*! @name Non-blocking transfers*/
128 /*@{*/
129 
130 /*!
131  * @brief Perform an non-blocking SPI master mode transfer.
132  *
133  * @param instance The instance number of the SPI peripheral.
134  * @param device Pointer to the device information struct. This struct contains the settings
135  * for how the SPI bus will be configured for this transfer. You may pass NULL for this
136  * parameter, in which case the current bus configuration is used unmodified.
137  * @param sendBuffer Buffer of data to send. You may pass NULL for this parameter, in which case
138  * bytes with a value of 0 (zero) will be sent.
139  * @param receiveBuffer Buffer where received bytes are stored. If you pass NULL for this parameter,
140  * the received bytes are ignored.
141  * @param transferByteCount The number of bytes to send and receive.
142  *
143  * @retval #kStatus_Success The transfer was succesful.
144  * @retval #kStatus_SPI_Busy Cannot perform another transfer because one is already in progress.
145  * @retval #kStatus_SPI_Timeout The transfer timed out and was aborted.
146  */
147 spi_status_t spi_master_transfer_async(uint32_t instance,
148  const spi_user_config_t * device,
149  const uint8_t * sendBuffer,
150  uint8_t * receiveBuffer,
151  uint16_t transferByteCount);
152 
153 
154 /*@}*/
155 
156 /*******************************************************************************
157  * EOF
158  ******************************************************************************/
159 
160 /*! @}*/
161 #endif /* FSL_SPI_MASTER_DRIVER_H_ */
162 
163 
164 
enum _spi_errors spi_status_t
Error codes for the SPI driver.
struct SPIUserConfig spi_user_config_t
Information about a device on the SPI bus.
spi_clock_polarity_t polarity
struct SPIHandle spi_handle_t
LWEVENT_STRUCT eventHandler
struct SPI_Master_State spi_master_state_t
enum _spi_shift_direction spi_shift_direction_t
SPI data shifter direction options.
fsl_spi_hal.h defines structures and types for the spi master HAL layer.
void spi_master_init(uint32_t instance)
Initialize a SPI instance for master mode operation.
spi_clock_phase_t phase
spi_status_t spi_master_transfer_async(uint32_t instance, const spi_user_config_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount)
Perform an non-blocking SPI master mode transfer.
spi_status_t spi_master_transfer(uint32_t instance, const spi_user_config_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount, uint32_t timeout)
Perform a blocking SPI master mode transfer.
enum _spi_clock_phase spi_clock_phase_t
SPI clock phase configuration.
void spi_master_configure_bus(uint32_t instance, const spi_user_config_t *device)
Configure the SPI port to access a device on the bus.
spi_shift_direction_t direction
enum _spi_clock_polarity spi_clock_polarity_t
SPI clock polarity configuration.
LDD_TDeviceData * pDeviceHandle
Information about a device on the SPI bus.