| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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
28 enum _spi_timeouts
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;
37 spi_clock_polarity_t polarity;
38 spi_clock_phase_t phase;
39 spi_shift_direction_t direction;
40 } spi_user_config_t;
41
42 typedef struct SPIHandle{
43 uint32_t instance;
44 }spi_handle_t;
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;
50 } spi_master_state_t;
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
spi_status_t
enum _spi_errors spi_status_t
Error codes for the SPI driver.
spi_user_config_t
struct SPIUserConfig spi_user_config_t
Information about a device on the SPI bus.
SPIUserConfig::polarity
spi_clock_polarity_t polarity
Definition: fsl_spi_master_driver.h:37
spi_handle_t
struct SPIHandle spi_handle_t
SPI_Master_State::instance
uint32_t instance
Definition: fsl_spi_master_driver.h:47
kSpiWaitForever
Definition: fsl_spi_master_driver.h:31
SPI_Master_State::eventHandler
LWEVENT_STRUCT eventHandler
Definition: fsl_spi_master_driver.h:49
SPIUserConfig::busFrequencyKHz
uint32_t busFrequencyKHz
Definition: fsl_spi_master_driver.h:36
spi_master_state_t
struct SPI_Master_State spi_master_state_t
SPI_Master_State
Definition: fsl_spi_master_driver.h:46
spi_shift_direction_t
enum _spi_shift_direction spi_shift_direction_t
SPI data shifter direction options.
fsl_spi_hal.h
fsl_spi_hal.h defines structures and types for the spi master HAL layer.
SPIHandle::instance
uint32_t instance
Definition: fsl_spi_master_driver.h:43
spi_master_init
void spi_master_init(uint32_t instance)
Initialize a SPI instance for master mode operation.
Definition: fsl_spi_master_driver.c:43
SPIUserConfig::phase
spi_clock_phase_t phase
Definition: fsl_spi_master_driver.h:38
spi_master_transfer_async
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.
Definition: fsl_spi_master_driver.c:105
spi_master_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.
Definition: fsl_spi_master_driver.c:70
spi_clock_phase_t
enum _spi_clock_phase spi_clock_phase_t
SPI clock phase configuration.
spi_master_configure_bus
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.
Definition: fsl_spi_master_driver.c:60
SPIUserConfig::direction
spi_shift_direction_t direction
Definition: fsl_spi_master_driver.h:39
spi_clock_polarity_t
enum _spi_clock_polarity spi_clock_polarity_t
SPI clock polarity configuration.
SPI_Master_State::pDeviceHandle
LDD_TDeviceData * pDeviceHandle
Definition: fsl_spi_master_driver.h:48
SPIHandle
Definition: fsl_spi_master_driver.h:42
SPIUserConfig
Information about a device on the SPI bus.
Definition: fsl_spi_master_driver.h:35
_spi_timeouts
_spi_timeouts
Definition: fsl_spi_master_driver.h:28
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.