TI-RTOS Drivers  tidrivers_full_2_20_00_08
SPI.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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  */
142 #ifndef ti_drivers_SPI__include
143 #define ti_drivers_SPI__include
144 
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148 
149 #include <stdint.h>
150 #include <stdbool.h>
151 #include <stddef.h>
152 
170 #define SPI_CMD_RESERVED 32
171 
184 #define SPI_STATUS_RESERVED -32
185 
199 #define SPI_STATUS_SUCCESS 0
200 
207 #define SPI_STATUS_ERROR -1
208 
216 #define SPI_STATUS_UNDEFINEDCMD -2
217 
227 /* Add SPI_CMD_<commands> here */
228 
236 #define SPI_WAIT_FOREVER ~(0)
237 
241 typedef struct SPI_Config *SPI_Handle;
242 
246 typedef enum SPI_Status {
252 } SPI_Status;
253 
262 typedef struct SPI_Transaction {
263  /* User input (write-only) fields */
264  size_t count;
265  void *txBuf;
266  void *rxBuf;
267  void *arg;
269  /* User output (read-only) fields */
272  /* Driver-use only fields */
274 
282 typedef void (*SPI_CallbackFxn) (SPI_Handle handle,
283  SPI_Transaction * transaction);
288 typedef enum SPI_Mode {
291 } SPI_Mode;
292 
297 typedef enum SPI_FrameFormat {
302  SPI_TI = 4,
303  SPI_MW = 5
305 
316 typedef enum SPI_TransferMode {
328 
337 typedef struct SPI_Params {
339  uint32_t transferTimeout;
344  uint32_t bitRate;
345  uint32_t dataSize;
347  uintptr_t custom;
349 } SPI_Params;
350 
355 typedef void (*SPI_CloseFxn) (SPI_Handle handle);
356 
361 typedef int (*SPI_ControlFxn) (SPI_Handle handle,
362  unsigned int cmd,
363  void *arg);
364 
369 typedef void (*SPI_InitFxn) (SPI_Handle handle);
370 
375 typedef SPI_Handle (*SPI_OpenFxn) (SPI_Handle handle,
376  SPI_Params *params);
377 
382 typedef void (*SPI_ServiceISRFxn) (SPI_Handle handle);
383 
388 typedef bool (*SPI_TransferFxn) (SPI_Handle handle,
389  SPI_Transaction *transaction);
390 
395 typedef void (*SPI_TransferCancelFxn) (SPI_Handle handle);
396 
402 typedef struct SPI_FxnTable {
405 
408 
411 
414 
417 
420 
423 } SPI_FxnTable;
424 
436 typedef struct SPI_Config {
439 
441  void *object;
442 
444  void const *hwAttrs;
445 } SPI_Config;
446 
456 extern void SPI_close(SPI_Handle handle);
457 
495 extern int SPI_control(SPI_Handle handle, unsigned int cmd, void *arg);
496 
505 extern void SPI_init(void);
506 
525 extern SPI_Handle SPI_open(unsigned int index, SPI_Params *params);
526 
542 extern void SPI_Params_init(SPI_Params *params);
543 
552 extern void SPI_serviceISR(SPI_Handle handle);
553 
583 extern bool SPI_transfer(SPI_Handle handle, SPI_Transaction *transaction);
584 
602 extern void SPI_transferCancel(SPI_Handle handle);
603 
604 #ifdef __cplusplus
605 }
606 #endif
607 
608 #endif /* ti_drivers_SPI__include */
Definition: SPI.h:302
void SPI_init(void)
This function initializes the SPI module.
SPI_ServiceISRFxn serviceISRFxn
Definition: SPI.h:422
uint32_t bitRate
Definition: SPI.h:344
struct SPI_Params SPI_Params
SPI Parameters.
int(* SPI_ControlFxn)(SPI_Handle handle, unsigned int cmd, void *arg)
A function pointer to a driver specific implementation of SPI_control().
Definition: SPI.h:361
struct SPI_Transaction SPI_Transaction
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
size_t count
Definition: SPI.h:264
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:282
SPI_FrameFormat frameFormat
Definition: SPI.h:346
void SPI_transferCancel(SPI_Handle handle)
Function to cancel SPI transactions.
uint32_t transferTimeout
Definition: SPI.h:339
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:316
SPI_TransferMode transferMode
Definition: SPI.h:338
void SPI_Params_init(SPI_Params *params)
Function to initialize the SPI_Params struct to its defaults.
SPI_CloseFxn closeFxn
Definition: SPI.h:404
struct SPI_Config SPI_Config
SPI Global configuration.
SPI_TransferCancelFxn transferCancelFxn
Definition: SPI.h:419
SPI Parameters.
Definition: SPI.h:337
SPI_Status
Status codes that are set by the SPI driver.
Definition: SPI.h:246
SPI Global configuration.
Definition: SPI.h:436
bool(* SPI_TransferFxn)(SPI_Handle handle, SPI_Transaction *transaction)
A function pointer to a driver specific implementation of SPI_transfer().
Definition: SPI.h:388
void * arg
Definition: SPI.h:267
SPI_ControlFxn controlFxn
Definition: SPI.h:407
Definition: SPI.h:321
void(* SPI_TransferCancelFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_transferCancel().
Definition: SPI.h:395
void(* SPI_ServiceISRFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_serviceISR().
Definition: SPI.h:382
void * txBuf
Definition: SPI.h:265
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:402
Definition: SPI.h:251
void(* SPI_CloseFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_close().
Definition: SPI.h:355
uint32_t dataSize
Definition: SPI.h:345
uintptr_t custom
Definition: SPI.h:347
Definition: SPI.h:289
SPI_FxnTable const * fxnTablePtr
Definition: SPI.h:438
Definition: SPI.h:301
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:262
SPI_OpenFxn openFxn
Definition: SPI.h:413
bool SPI_transfer(SPI_Handle handle, SPI_Transaction *transaction)
Function to perform SPI transactions.
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:288
struct SPI_FxnTable SPI_FxnTable
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:326
Definition: SPI.h:299
Definition: SPI.h:303
void * rxBuf
Definition: SPI.h:266
void SPI_close(SPI_Handle handle)
Function to close a SPI peripheral specified by the SPI handle.
Definition: SPI.h:300
Definition: SPI.h:250
void SPI_serviceISR(SPI_Handle handle)
Function to service the SPI module's interrupt service routine.
int SPI_control(SPI_Handle handle, unsigned int cmd, void *arg)
Function performs implementation specific features on a given SPI_Handle.
struct SPI_Config * SPI_Handle
A handle that is returned from a SPI_open() call.
Definition: SPI.h:241
void(* SPI_InitFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_init().
Definition: SPI.h:369
SPI_TransferFxn transferFxn
Definition: SPI.h:416
SPI_Handle SPI_open(unsigned int index, SPI_Params *params)
This function opens a given SPI peripheral.
Definition: SPI.h:248
SPI_Handle(* SPI_OpenFxn)(SPI_Handle handle, SPI_Params *params)
A function pointer to a driver specific implementation of SPI_open().
Definition: SPI.h:375
SPI_CallbackFxn transferCallbackFxn
Definition: SPI.h:342
Definition: SPI.h:247
SPI_Status status
Definition: SPI.h:270
void const * hwAttrs
Definition: SPI.h:444
Definition: SPI.h:249
SPI_FrameFormat
Definitions for various SPI data frame formats.
Definition: SPI.h:297
SPI_Mode mode
Definition: SPI.h:343
void * object
Definition: SPI.h:441
Definition: SPI.h:298
SPI_InitFxn initFxn
Definition: SPI.h:410
Definition: SPI.h:290
Copyright 2016, Texas Instruments Incorporated