| ISF 2.2 rev 5 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

isf_spi_master_adapter.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: isf_spi_master_adapter.h
4 *
5 * Copyright (c) 2015, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file isf_spi_master_adapter.h
10 * @brief \b isf_spi_master_adapter.h defines the API definitions and types for the spi master protocol adapter.
11 */
12 #ifndef ISF_SPI_MASTER_ADAPTER_H_
13 #define ISF_SPI_MASTER_ADAPTER_H_
14 #include "isf_spi_master_types.h"
15 #include "isf_comm.h"
16 #include "isf_protocol_adapter.h"
17
18
19 /*! @brief This structure defines a device endpoint encapsulation for spi handler. */
20 typedef struct spi_master_Endpoint_struct
21 {
22 busHandle_t* pBusHandle; /*!< The pointer to the bus handle. */
23 spi_master_slaveInfo_t* pSlaveInfo;
24 } spi_master_Endpoint_t;
25
26 /*! Type specifying for the spi modes */
27 enum spi_comm_flag {
28 SPI_SYNC = 0, /*!< Read/write in synchronized mode.*/
29 SPI_ASYNC = 1, /*!< Read/Write in asynchronized mode.*/
30 };
31
32 enum spi_lock_type{
33 SPI_LOCK_COMMON,
34 SPI_LOCK_READ,
35 };
36
37 typedef comm_Flags_t spi_master_writeFlags_t;
38 typedef comm_Flags_t spi_master_readFlags_t;
39 /*! @brief This function initializes a spi bus.
40 *
41 * @details A bus must be initialized prior to use. Initialization creates the bus and initializes the data structures required to manage the bus.
42 *
43 * @param[in] aBusId The ID of the bus to initialize. This is an index into the array of known spi buses that can be used.
44 * @param[out] busHandle_t The handle to the bus to be initialized.
45 *
46 * @return ::spi_master_adapter_init() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
47 * @retval ::ISF_SUCCESS is returned when the bus is initialized successfully and the apBusHandle structure reference has been
48 * populated with initialized spi bus data.
49 * @retval ::COMM_ERROR_NOEXIST is returned when the supplied bus identifier does not exist.
50 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
51 * @retval ::COMM_ERROR_INIT is returned when the bus could not be initialized.
52 *
53 *
54 * @Constraints None
55 *
56 * @Reentrant Yes
57 * @Libs None
58 */
59 isf_status_t spi_master_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle);
60 /*! @brief This function reconfigures an already initialized bus.
61 *
62 * @details A bus may be reconfigured after initialization. Calls to spi_master_adapter_configure() after initialization will override any previous
63 * configuration values and must be made while the bus state is ::COMM_STATE_STOPPED. The typical usage involves retrieving the
64 * current configuration using ::spi_master_adapter_get_config(), making modifications to the returned configuration, and then calling
65 * spi_master_adapter_configure() with the updated configuration. The bus is implicitly locked during the configuration.
66 *
67 * @param[in] busHandle_t The handle of the bus to be configured.
68 * @param[in] apBusConfig The configuration value for the bus to be configured.
69 *
70 * @return ::spi_master_adapter_configure() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
71 * @retval ::ISF_SUCCESS is returned when the bus was reconfigured successfully.
72 * @retval ::COMM_ERROR_STOP is returned when the bus was not STOPPED.
73 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
74 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
75 *
76 *
77 * @Constraints The following constraints must be observed when using this function:
78 * @li apBusHandle must be valid. A valid spi bus handler is created
79 * when the ::spi_master_adapter_init() function call is successfully returned.
80 *
81 * @Reentrant Yes
82 * @Libs None
83 */
84 isf_status_t spi_master_adapter_configure(busHandle_t *apBusHandle, spi_master_busConfig_t* apBusConfig);
85 /*! @brief This function returns the current bus state.
86 *
87 * @details A bus may be queried for its current state.
88 *
89 * @param[in] apBusHandle The handle of the bus to be queried.
90 *
91 * @return ::spi_master_adapter_get_state() returns a value of type
92 * ::comm_State_t indicating the current state of the bus.
93 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
94 *
95 * @Constraints The following constraints must be observed when using this function:
96 * @li apBusHandle must be valid. A valid spi bus handle is created when ::spi_master_adapter_init() function call returns successfully.
97 *
98 * @Reentrant Yes
99 * @Libs None.
100 */
101 comm_State_t spi_master_adapter_get_state(busHandle_t *apBusHandle);
102 /*! @brief This function returns the current bus configuration.
103 *
104 * @details A bus may be queried for the current configuration.
105 *
106 * @param[in] apBusHandle The handle of the bus to be queried.
107 * @param[out] apBusConfig The address of a bus configuration to be filled.
108 *
109 * @return ::spi_master_adapter_get_config() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
110 * @retval ::ISF_SUCCESS is returned when the bus configuration is retrieved successfully.
111 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
112 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized bus.
113
114 * @Constraints The following constraints must be observed when using this function:
115 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
116 *
117 * @Reentrant Yes
118 * @Libs None
119 */
120 isf_status_t spi_master_adapter_get_config(busHandle_t *apBusHandle, void* apBusConfig);
121 /*! @brief This function locks the bus for exclusive access.
122 *
123 * @details spi_master_adapter_acquire_lock() serializes multi-client access. While holding the bus lock,
124 * no other clients may perform any bus operations. Therefore, it is important to release the lock
125 * with ::spi_master_adapter_release_lock() as soon as practical.
126 *
127 * @param[in] apBusHandle The handle of the bus to be started.
128 * @param[in] aTimeout The time to wait for the lock before returning without the lock. The timeout parameter may be set to zero to wait for calls that fail to return without
129 * acquiring the lock, or wait as long as necessary for the lock to be acquired.
130 * @return ::dm_channel_acquire_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
131 * @retval ::ISF_SUCCESS is returned when the bus lock is acquired.
132 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
133 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
134 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
135 *
136 * @Constraints The following constraints must be observed when using this function:
137 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
138 *
139 * @Reentrant Yes
140 * @Libs None
141 */
142 isf_status_t spi_master_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout );
143 /*! @brief This function releases exclusive bus access.
144 *
145 * @details spi_master_adapter_release_lock() is used to relinquish exclusive access on a particular bus. It is the inverse of ::spi_master_adapter_acquire_lock().
146 *
147 * @param[in] apBusHandle The handle of the bus to unlock.
148 * @return ::spi_master_adapter_release_lock() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
149 * @retval ::ISF_SUCCESS is returned when the bus released successfully.
150 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
151 * @retval ::COMM_ERROR_LOCK is returned when no lock was held on the specified bus.
152 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
153 *
154 * @Constraints The following constraints must be observed when using this function:
155 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
156 *
157 * @Reentrant Yes
158 * @Libs None
159 */
160 isf_status_t spi_master_adapter_release_lock(busHandle_t *apBusHandle);
161 /*! @brief This function starts a bus.
162 *
163 * @details spi_master_adapter_start() enables communications with an initialized bus.
164 * @param[in] apBusHandle The handle of the bus to be started.
165 * @return ::spi_master_adapter_start() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
166 * @retval ::ISF_SUCCESS is returned when the bus was started successfully.
167 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
168 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
169 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
170 *
171 * @Constraints The following constraints must be observed when using this function:
172 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
173 *
174 * @Reentrant Yes
175 * @Libs None
176 */
177 isf_status_t spi_master_adapter_start(busHandle_t *apBusHandle);
178 /*! @brief This function stops the given spi bus.
179 *
180 * @details spi_master_adapter_stop() disables an initialized bus and stops communications with the channel.
181 *
182 * @param[in] apBusHandle The handle of the bus to be stopped.
183 * @return ::spi_master_adapter_stop() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
184 *
185 * @retval ::ISF_SUCCESS is returned when the bus is successfully stopped.
186 * @retval ::COMM_ERROR_INIT is returned when the bus handle refers to a non-initialized channel.
187 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
188 *
189 * @Constraints The following constraints must be observed when using this function:
190 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
191 *
192 * @Reentrant Yes
193 * @Libs None
194 */
195 isf_status_t spi_master_adapter_stop(busHandle_t *apBusHandle);
196 /*! @brief This function creates a endpoint for a device at a specified bus address.
197 *
198 * @details The spi_master_adapter_get_endpoint() function may be used to get a handle to a device at a known bus address.
199 *
200 * @param[in] apBusHandle The handle of the bus to be opened.
201 * @param[in] apDevice The known information of the device to be opened.
202 * @param[out] apEndpointHandle The address of a apEndpointHandle to be filled.
203 *
204 * @return ::spi_master_adapter_get_endpoint() returns a value of type ::isf_status_t indicating the success or failure of the function call.
205 *
206 * @retval ::ISF_SUCCESS is returned when the device is located and a valid handle is returned.
207 * @retval ::COMM_ERROR_NOEXIST is returned when a device does not exist at the specified bus.
208 * @retval ::COMM_ERROR_INIT is returned when the channel handle refers to a non-initialized channel.
209 * @retval ::COMM_ERROR_STOP is returned when the channel has not been started.
210 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
211 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
212 *
213 * @Constraints The following constraints must be observed when using this function:
214 * @li apBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
215 *
216 * @Reentrant Yes
217 * @Libs isf_core.lib
218 */
219 isf_status_t spi_master_adapter_get_endpoint(busHandle_t *apBusHandle, void *apDevice , void** apEndpointHandle);
220 /*! @brief This function closes a particular endpoint.
221 *
222 * @details The spi_master_adapter_release_endpoint() function is used when no further communication with the device is needed. A closed device should not be
223 * passed to ::spi_master_adapter_write() or ::spi_master_adapter_write().
224 *
225 * @param[in] apEndpoint The address of the end point where the endpoint is established.
226 * @return ::spi_master_adapter_release_endpoint() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
227 * @retval ::ISF_SUCCESS is returned when the device changes to closed.
228 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
229 *
230 * @Constraints The following constraints must be observed when using this function:
231 * @li pBusHandle must be valid. A valid spi bus handle is created when the ::spi_master_adapter_init() function call returns successfully.
232 *
233 * @Reentrant Yes
234 * @Libs None
235 */
236 isf_status_t spi_master_adapter_release_endpoint(spi_master_Endpoint_t *apEndpoint);
237 /*! @brief This function writes to a spi device.
238 *
239 * @details spi_master_adapter_write () writes data to the specified device. The device is implicitly locked during the write.
240 *
241 * @param[in] apEndpointHandle The handle to the device endpoint to which to write is performed.
242 * @param[in] offset The read offset/sub address from which the data to be write.
243 * @param[in] apWriteBuffer The buffer address where write data is placed.
244 * @param[in] aBuffsize The size of the buffer passed.
245 * @param[in] aNbyteRead The number of bytes to write to the device.
246 * @param[in] aFlags The write flag that change the mode of read of operation.
247 * @return ::spi_master_adapter_write() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
248 * @retval ::ISF_SUCCESS is returned when the device was written successfully.
249 * @retval ::COMM_ERROR_STOP is returned when the write is invoked on a stopped channel.
250 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
251 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
252 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
253 *
254 * @Constraints The following constraints must be observed when using this function:
255 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::spi_master_adapter_get_endpoint() function returns successfully.
256 *
257 * @Reentrant Yes
258 * @Libs isf_core.lib
259 */
260 isf_status_t spi_master_adapter_write(void* apEndpointHandle, int32 offset, void* apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, spi_master_writeFlags_t aFlags);
261 /*! @brief This function reads from a spi device.
262 *
263 * @details spi_master_adapter_read() reads data from the specified device. The supplied command is sent to the device triggering the
264 * device to return some data. Any data returned by the device is read and placed in the provided read buffer.
265 * The device is implicitly locked during the read.
266 *
267 * @param[in] apEndpointHandle The handle to the device endpoint for.
268 * @param[in] offset The read offset/sub address from which the data to be read.
269 * @param[in] apReadBuffer The buffer address where any returned data is placed.
270 * @param[in] aBuffsize The size of the buffer passed.
271 * @param[in] aNbyteRead The number of bytes to read from the device.
272 * @param[in] aFlags The read flag that change the mode of read of operation.
273
274 * @return ::spi_master_adapter_read() returns a value of type ::isf_status_t indicating whether the operation was successful or unsuccessful.
275 *
276 * @retval ::ISF_SUCCESS is returned when data from the device was read successfully.
277 * @retval ::COMM_ERROR_BUF_SIZE is returned when the provided buffer is too small to hold all the data or the number of bytes read is zero.
278 * @retval ::COMM_ERROR_NULL_PTR is returned when a NULL pointer argument was passed into the function.
279 * @retval ::COMM_ERROR_TIME_OUT is returned when the request could not be fulfilled in the specified timeout period.
280 * @retval ::COMM_ERROR_LOCK is returned when a lock could not be acquired properly.
281 *
282 * @Constraints The following constraints must be observed when using this function:
283 * @li apEndpointHandle must be valid. A valid device endpoint handle is created when the ::spi_master_adapter_get_endpoint() function returns successfully.
284 *
285 * @Reentrant Yes
286 * @Libs None
287 */
288 isf_status_t spi_master_adapter_read(void* apEndpointHandle, int32 offset, void* apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, spi_master_readFlags_t aFlags);
289
290
291 #endif /* ISF_SPI_MASTER_ADAPTER_H_ */
292
293
294
spi_master_adapter_configure
isf_status_t spi_master_adapter_configure(busHandle_t *apBusHandle, spi_master_busConfig_t *apBusConfig)
This function reconfigures an already initialized bus.
Definition: isf_spi_master_adapter.c:82
spi_master_adapter_get_config
isf_status_t spi_master_adapter_get_config(busHandle_t *apBusHandle, void *apBusConfig)
This function returns the current bus configuration.
Definition: isf_spi_master_adapter.c:125
spi_master_adapter_read
isf_status_t spi_master_adapter_read(void *apEndpointHandle, int32 offset, void *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead, spi_master_readFlags_t aFlags)
This function reads from a spi device.
Definition: isf_spi_master_adapter.c:314
spi_master_Endpoint_struct::pBusHandle
busHandle_t * pBusHandle
Definition: isf_spi_master_adapter.h:22
comm_Id_t
uint32 comm_Id_t
This type is for a numeric channel identifier- index into an array of channels in the system...
Definition: isf_comm.h:50
SPI_LOCK_COMMON
Definition: isf_spi_master_adapter.h:33
spi_mater_slaveInfo
This structure defines the slave specific spi information.
Definition: isf_spi_master_types.h:51
spi_master_BusConfig_struct
Definition: isf_spi_master_types.h:20
spi_master_Endpoint_struct::pSlaveInfo
spi_master_slaveInfo_t * pSlaveInfo
Definition: isf_spi_master_adapter.h:23
spi_master_adapter_release_endpoint
isf_status_t spi_master_adapter_release_endpoint(spi_master_Endpoint_t *apEndpoint)
This function closes a particular endpoint.
Definition: isf_spi_master_adapter.c:256
spi_master_adapter_get_state
comm_State_t spi_master_adapter_get_state(busHandle_t *apBusHandle)
This function returns the current bus state.
Definition: isf_spi_master_adapter.c:111
spi_master_adapter_init
isf_status_t spi_master_adapter_init(comm_Id_t aBusId, busHandle_t *apBusHandle)
This function initializes a spi bus.
Definition: isf_spi_master_adapter.c:40
spi_master_Endpoint_struct
This structure defines a device endpoint encapsulation for spi handler.
Definition: isf_spi_master_adapter.h:20
spi_master_readFlags_t
comm_Flags_t spi_master_readFlags_t
Definition: isf_spi_master_adapter.h:38
isf_protocol_adapter.h
isf_protocol_adapter.h defines the general interface definition for the protocol adapter.
spi_master_adapter_release_lock
isf_status_t spi_master_adapter_release_lock(busHandle_t *apBusHandle)
This function releases exclusive bus access.
Definition: isf_spi_master_adapter.c:160
spi_master_adapter_write
isf_status_t spi_master_adapter_write(void *apEndpointHandle, int32 offset, void *apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite, spi_master_writeFlags_t aFlags)
This function writes to a spi device.
Definition: isf_spi_master_adapter.c:271
spi_master_writeFlags_t
comm_Flags_t spi_master_writeFlags_t
Definition: isf_spi_master_adapter.h:37
SPI_LOCK_READ
Definition: isf_spi_master_adapter.h:34
busHandle_struct
This structure is a declaration of a BusHandle type.
Definition: isf_protocol_adapter.h:86
comm_Flags_t
uint8 comm_Flags_t
This is a bit array of flags governing device read/write behavior.
Definition: isf_comm.h:59
spi_master_adapter_stop
isf_status_t spi_master_adapter_stop(busHandle_t *apBusHandle)
This function stops the given spi bus.
Definition: isf_spi_master_adapter.c:199
SPI_SYNC
Definition: isf_spi_master_adapter.h:28
SPI_ASYNC
Definition: isf_spi_master_adapter.h:29
isf_duration_t
uint32 isf_duration_t
ISF time duration in microseconds.
Definition: isf.h:84
spi_comm_flag
spi_comm_flag
Definition: isf_spi_master_adapter.h:27
int32
signed long int int32
Definition: isf_types.h:74
spi_lock_type
spi_lock_type
Definition: isf_spi_master_adapter.h:32
isf_status_t
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
spi_master_adapter_acquire_lock
isf_status_t spi_master_adapter_acquire_lock(busHandle_t *apBusHandle, isf_duration_t aTimeout)
This function locks the bus for exclusive access.
Definition: isf_spi_master_adapter.c:143
isf_spi_master_types.h
isf_spi_master_types.h defines the spi protocol adapter structure and types.
spi_master_adapter_get_endpoint
isf_status_t spi_master_adapter_get_endpoint(busHandle_t *apBusHandle, void *apDevice, void **apEndpointHandle)
This function creates a endpoint for a device at a specified bus address.
Definition: isf_spi_master_adapter.c:223
isf_comm.h
isf_comm.h defines the common types for the Communications Service Family of the Intelligent Sensing ...
comm_State_t
enum comm_State_vals comm_State_t
This enum holds an enumerated value describing the state of a channel.
Definition: isf_comm.h:53
uint32
unsigned long int uint32
Definition: isf_types.h:78
spi_master_adapter_start
isf_status_t spi_master_adapter_start(busHandle_t *apBusHandle)
This function starts a bus.
Definition: isf_spi_master_adapter.c:176
spi_master_Endpoint_t
struct spi_master_Endpoint_struct spi_master_Endpoint_t
This structure defines a device endpoint encapsulation for spi handler.
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.