TI-RTOS for SimpleLink Wireless MCUs  2.14.03.28
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  */
152 #ifndef ti_drivers_SPI__include
153 #define ti_drivers_SPI__include
154 
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158 
159 #include <stdint.h>
160 #include <stdbool.h>
161 #include <stddef.h>
162 
174 #define SPI_CMD_RESERVED 32
175 
188 #define SPI_STATUS_RESERVED -32
189 
196 #define SPI_STATUS_SUCCESS 0
197 
204 #define SPI_STATUS_ERROR -1
205 
213 #define SPI_STATUS_UNDEFINEDCMD -2
214 
218 #define SPI_WAIT_FOREVER ~(0)
219 
223 typedef struct SPI_Config *SPI_Handle;
224 
228 typedef enum SPI_Status {
234 } SPI_Status;
235 
244 typedef struct SPI_Transaction {
245  /* User input (write-only) fields */
246  size_t count;
247  void *txBuf;
248  void *rxBuf;
249  void *arg;
251  /* User output (read-only) fields */
254  /* Driver-use only fields */
256 
264 typedef void (*SPI_CallbackFxn) (SPI_Handle handle,
265  SPI_Transaction * transaction);
270 typedef enum SPI_Mode {
273 } SPI_Mode;
274 
279 typedef enum SPI_FrameFormat {
284  SPI_TI = 4,
285  SPI_MW = 5
287 
298 typedef enum SPI_TransferMode {
310 
319 typedef struct SPI_Params {
321  uint32_t transferTimeout;
326  uint32_t bitRate;
327  uint32_t dataSize;
329  void *custom;
331 } SPI_Params;
332 
337 typedef void (*SPI_CloseFxn) (SPI_Handle handle);
338 
343 typedef int (*SPI_ControlFxn) (SPI_Handle handle,
344  unsigned int cmd,
345  void *arg);
346 
351 typedef void (*SPI_InitFxn) (SPI_Handle handle);
352 
357 typedef SPI_Handle (*SPI_OpenFxn) (SPI_Handle handle,
358  SPI_Params *params);
359 
364 typedef void (*SPI_ServiceISRFxn) (SPI_Handle handle);
365 
370 typedef bool (*SPI_TransferFxn) (SPI_Handle handle,
371  SPI_Transaction *transaction);
372 
377 typedef void (*SPI_TransferCancelFxn) (SPI_Handle handle);
378 
384 typedef struct SPI_FxnTable {
387 
390 
393 
396 
399 
402 
405 } SPI_FxnTable;
406 
418 typedef struct SPI_Config {
421 
423  void *object;
424 
426  void const *hwAttrs;
427 } SPI_Config;
428 
438 extern void SPI_close(SPI_Handle handle);
439 
459 extern int SPI_control(SPI_Handle handle, unsigned int cmd, void *arg);
460 
469 extern void SPI_init(void);
470 
489 extern SPI_Handle SPI_open(unsigned int index, SPI_Params *params);
490 
506 extern void SPI_Params_init(SPI_Params *params);
507 
517 extern void SPI_serviceISR(SPI_Handle handle);
518 
548 extern bool SPI_transfer(SPI_Handle handle, SPI_Transaction *transaction);
549 
567 extern void SPI_transferCancel(SPI_Handle handle);
568 
569 #ifdef __cplusplus
570 }
571 #endif
572 
573 #endif /* ti_drivers_SPI__include */
Definition: SPI.h:284
void SPI_init(void)
This function initializes the SPI module.
SPI_ServiceISRFxn serviceISRFxn
Definition: SPI.h:404
uint32_t bitRate
Definition: SPI.h:326
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:343
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:246
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:264
SPI_FrameFormat frameFormat
Definition: SPI.h:328
void SPI_transferCancel(SPI_Handle handle)
Function to cancel SPI transactions.
uint32_t transferTimeout
Definition: SPI.h:321
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:298
SPI_TransferMode transferMode
Definition: SPI.h:320
void SPI_Params_init(SPI_Params *params)
Function to initialize the SPI_Params struct to its defaults.
SPI_CloseFxn closeFxn
Definition: SPI.h:386
struct SPI_Config SPI_Config
SPI Global configuration.
SPI_TransferCancelFxn transferCancelFxn
Definition: SPI.h:401
SPI Parameters.
Definition: SPI.h:319
SPI_Status
Status codes that are set by the SPI driver.
Definition: SPI.h:228
SPI Global configuration.
Definition: SPI.h:418
bool(* SPI_TransferFxn)(SPI_Handle handle, SPI_Transaction *transaction)
A function pointer to a driver specific implementation of SPI_transfer().
Definition: SPI.h:370
void * arg
Definition: SPI.h:249
SPI_ControlFxn controlFxn
Definition: SPI.h:389
Definition: SPI.h:303
void(* SPI_TransferCancelFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_transferCancel().
Definition: SPI.h:377
void(* SPI_ServiceISRFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_serviceISR().
Definition: SPI.h:364
void * txBuf
Definition: SPI.h:247
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:384
Definition: SPI.h:233
void(* SPI_CloseFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_close().
Definition: SPI.h:337
uint32_t dataSize
Definition: SPI.h:327
Definition: SPI.h:271
SPI_FxnTable const * fxnTablePtr
Definition: SPI.h:420
Definition: SPI.h:283
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:244
SPI_OpenFxn openFxn
Definition: SPI.h:395
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:270
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:308
Definition: SPI.h:281
Definition: SPI.h:285
void * rxBuf
Definition: SPI.h:248
void SPI_close(SPI_Handle handle)
Function to close a SPI peripheral specified by the SPI handle.
Definition: SPI.h:282
Definition: SPI.h:232
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:223
void(* SPI_InitFxn)(SPI_Handle handle)
A function pointer to a driver specific implementation of SPI_init().
Definition: SPI.h:351
SPI_TransferFxn transferFxn
Definition: SPI.h:398
SPI_Handle SPI_open(unsigned int index, SPI_Params *params)
This function opens a given SPI peripheral.
void * custom
Definition: SPI.h:329
Definition: SPI.h:230
SPI_Handle(* SPI_OpenFxn)(SPI_Handle handle, SPI_Params *params)
A function pointer to a driver specific implementation of SPI_open().
Definition: SPI.h:357
SPI_CallbackFxn transferCallbackFxn
Definition: SPI.h:324
Definition: SPI.h:229
SPI_Status status
Definition: SPI.h:252
void const * hwAttrs
Definition: SPI.h:426
Definition: SPI.h:231
SPI_FrameFormat
Definitions for various SPI data frame formats.
Definition: SPI.h:279
SPI_Mode mode
Definition: SPI.h:325
void * object
Definition: SPI.h:423
Definition: SPI.h:280
SPI_InitFxn initFxn
Definition: SPI.h:392
Definition: SPI.h:272
Copyright 2015, Texas Instruments Incorporated