PDK API Guide for AM64x
SPI.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
38 /* @} */
39 
61 #ifndef SPI_H
62 #define SPI_H
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 #include <stdint.h>
69 #include <stdbool.h>
70 #include <stddef.h>
71 
83 #define SPI_CMD_RESERVED (32U)
84 
97 #define SPI_STATUS_RESERVED (-((int32_t)32))
98 
105 #define SPI_STATUS_SUCCESS (int32_t)(0)
106 
113 #define SPI_STATUS_ERROR (-((int32_t)1))
114 
122 #define SPI_STATUS_UNDEFINEDCMD (-((int32_t)2))
123 
127 #define SPI_WAIT_FOREVER (~(0U))
128 
132 typedef struct SPI_Config_s *SPI_Handle;
133 
137 typedef enum SPI_Status_s {
144 } SPI_Status;
145 
154 typedef struct SPI_Transaction_s {
155  /* User input (write-only) fields */
156  size_t count;
157  void *txBuf;
158  void *rxBuf;
159  void *arg;
161  /* User output (read-only) fields */
164  /* Driver-use only fields */
166 
174 typedef void (*SPI_CallbackFxn) (SPI_Handle handle,
175  SPI_Transaction * transaction);
180 typedef enum SPI_Mode_s {
183 } SPI_Mode;
184 
189 typedef enum SPI_FrameFormat_s {
194  SPI_TI = 4,
195  SPI_MW = 5
197 
208 typedef enum SPI_TransferMode_s {
220 
229 typedef struct SPI_Params_s {
231  uint32_t transferTimeout;
236  uint32_t bitRate;
237  uint32_t dataSize;
239  void *custom;
241 } SPI_Params;
242 
247 typedef void (*SPI_CloseFxn) (SPI_Handle handle);
248 
253 typedef int32_t (*SPI_ControlFxn) (SPI_Handle handle,
254  uint32_t cmd,
255  const void *arg);
256 
261 typedef void (*SPI_InitFxn) (SPI_Handle handle);
262 
267 typedef SPI_Handle (*SPI_OpenFxn) (SPI_Handle handle,
268  const SPI_Params *params);
269 
274 typedef void (*SPI_ServiceISRFxn) (SPI_Handle handle);
275 
280 typedef bool (*SPI_TransferFxn) (SPI_Handle handle,
281  SPI_Transaction *transaction);
282 
287 typedef void (*SPI_TransferCancelFxn) (SPI_Handle handle);
288 
294 typedef struct SPI_FxnTable_s {
297 
300 
303 
306 
309 
312 
315 } SPI_FxnTable;
316 
328 typedef struct SPI_Config_s {
331 
333  void *object;
334 
336  void const *hwAttrs;
337 } SPI_Config;
338 
339 #define SPI_MAX_CONFIG_CNT (8U)
341 
342 
352 extern void SPI_close(SPI_Handle handle);
353 
373 extern int32_t SPI_control(SPI_Handle handle, uint32_t cmd, void *arg);
374 
383 extern void SPI_init(void);
384 
403 extern SPI_Handle SPI_open(uint32_t idx, SPI_Params *params);
404 
420 extern void SPI_Params_init(SPI_Params *params);
421 
427 extern void SPI_serviceISR(SPI_Handle handle);
428 
458 extern bool SPI_transfer(SPI_Handle handle, SPI_Transaction *spiTrans);
459 
477 extern void SPI_transferCancel(SPI_Handle handle);
478 
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 #endif /* _SPI_H */
484 
485 /* @} */
void(* SPI_TransferCancelFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_transferCancel().
Definition: SPI.h:287
Definition: SPI.h:218
bool(* SPI_TransferFxn)(SPI_Handle handle, SPI_Transaction *transaction)
A function pointer to a driver specific implementation of SPI_transfer().
Definition: SPI.h:280
Definition: SPI.h:181
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:294
SPI_FxnTable const * fxnTablePtr
Definition: SPI.h:330
Definition: SPI.h:139
uint32_t dataSize
Definition: SPI.h:237
Definition: SPI.h:138
void SPI_init(void)
This function initializes the SPI module.
Definition: SPI.h:140
uint32_t transferTimeout
Definition: SPI.h:231
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:180
SPI_CallbackFxn transferCallbackFxn
Definition: SPI.h:234
SPI_FrameFormat frameFormat
Definition: SPI.h:238
SPI_FrameFormat
Definitions for various SPI data frame formats.
Definition: SPI.h:189
void SPI_Params_init(SPI_Params *params)
Function to initialize the SPI_Params struct to its defaults.
SPI_Status status
Definition: SPI.h:162
SPI Parameters.
Definition: SPI.h:229
SPI_Handle(* SPI_OpenFxn)(SPI_Handle handle, const SPI_Params *params)
A function pointer to a driver specific implementation of SPI_open().
Definition: SPI.h:267
Definition: SPI.h:191
Definition: SPI.h:190
struct SPI_Config_s * SPI_Handle
A handle that is returned from a SPI_open() call.
Definition: SPI.h:132
void(* SPI_CloseFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_close().
Definition: SPI.h:247
SPI_CloseFxn closeFxn
Definition: SPI.h:296
SPI_TransferMode transferMode
Definition: SPI.h:230
SPI_TransferFxn transferFxn
Definition: SPI.h:308
#define SPI_MAX_CONFIG_CNT
Definition: SPI.h:339
void(* SPI_CallbackFxn)(SPI_Handle handle, SPI_Transaction *transaction)
The definition of a callback function used by the SPI driver when used in SPI_MODE_CALLBACK.
Definition: SPI.h:174
uint32_t bitRate
Definition: SPI.h:236
Definition: SPI.h:213
void(* SPI_InitFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_init().
Definition: SPI.h:261
SPI_Handle SPI_open(uint32_t idx, SPI_Params *params)
This function opens a given SPI peripheral.
void SPI_close(SPI_Handle handle)
Function to close a SPI peripheral specified by the SPI handle.
void * arg
Definition: SPI.h:159
Definition: SPI.h:192
Definition: SPI.h:182
void * rxBuf
Definition: SPI.h:158
Definition: SPI.h:141
SPI_TransferCancelFxn transferCancelFxn
Definition: SPI.h:311
SPI_ControlFxn controlFxn
Definition: SPI.h:299
SPI_OpenFxn openFxn
Definition: SPI.h:305
void * object
Definition: SPI.h:333
SPI_ServiceISRFxn serviceISRFxn
Definition: SPI.h:314
void SPI_transferCancel(SPI_Handle handle)
Function to cancel SPI transactions.
Definition: SPI.h:193
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously....
Definition: SPI.h:208
SPI_InitFxn spiInitFxn
Definition: SPI.h:302
void * custom
Definition: SPI.h:239
SPI_Status
Status codes that are set by the SPI driver.
Definition: SPI.h:137
Definition: SPI.h:194
Definition: SPI.h:195
SPI_Mode mode
Definition: SPI.h:235
Definition: SPI.h:143
bool SPI_transfer(SPI_Handle handle, SPI_Transaction *spiTrans)
Function to perform SPI transactions.
void SPI_serviceISR(SPI_Handle handle)
Function to service the SPI module's interrupt service routine.
int32_t(* SPI_ControlFxn)(SPI_Handle handle, uint32_t cmd, const void *arg)
A function pointer to a driver specific implementation of SPI_control().
Definition: SPI.h:253
SPI_Config SPI_config_list[SPI_MAX_CONFIG_CNT]
Definition: SPI.h:340
void(* SPI_ServiceISRFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_serviceISR().
Definition: SPI.h:274
size_t count
Definition: SPI.h:156
void const * hwAttrs
Definition: SPI.h:336
Definition: SPI.h:142
void * txBuf
Definition: SPI.h:157
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:154
SPI Global configuration.
Definition: SPI.h:328
int32_t SPI_control(SPI_Handle handle, uint32_t cmd, void *arg)
Function performs implementation specific features on a given SPI_Handle.