TI-RTOS Drivers  tidrivers_tivac_2_16_00_08
I2CTiva.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  */
48 #ifndef ti_drivers_i2c_I2CTiva__include
49 #define ti_drivers_i2c_I2CTiva__include
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #include <stdint.h>
56 #include <stdbool.h>
57 #include <ti/drivers/I2C.h>
58 
59 #include <ti/sysbios/knl/Semaphore.h>
60 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
61 #include <ti/sysbios/family/arm/m3/Hwi.h>
62 
73 /* Add I2CTiva_STATUS_* macros here */
74 
87 /* Add I2CTiva_CMD_* macros here */
88 
91 /* I2C function table pointer */
92 extern const I2C_FxnTable I2CTiva_fxnTable;
93 
100 typedef enum I2CTiva_Mode {
101  I2CTiva_IDLE_MODE = 0, /* I2C is not performing a transaction */
102  I2CTiva_WRITE_MODE, /* I2C is currently performing write operations */
103  I2CTiva_READ_MODE, /* I2C is currently performing read operations */
104  I2CTiva_ERROR = 0xFF /* I2C error has occurred, exit gracefully */
105 } I2CTiva_Mode;
106 
142 typedef struct I2CTiva_HWAttrs {
144  unsigned int baseAddr;
146  unsigned int intNum;
148  unsigned int intPriority;
150 
156 typedef struct I2CTiva_Object {
157  Semaphore_Struct mutex; /* Grants exclusive access to I2C */
158  Semaphore_Struct transferComplete; /* Notify finished I2C transfer */
159 
160  I2C_TransferMode transferMode; /* Blocking or Callback mode */
161  I2C_CallbackFxn transferCallbackFxn; /* Callback function pointer */
162 
163  ti_sysbios_family_arm_m3_Hwi_Struct hwi; /* Hwi object handle */
164 
165  volatile I2CTiva_Mode mode; /* Stores the I2C state */
166 
167  I2C_Transaction *currentTransaction; /* Pointer to current I2C transaction */
168 
169  uint8_t *writeBufIdx; /* Internal inc. writeBuf index */
170  size_t writeCountIdx; /* Internal dec. writeCounter */
171 
172  uint8_t *readBufIdx; /* Internal inc. readBuf index */
173  size_t readCountIdx; /* Internal dec. readCounter */
174 
175  /* I2C transaction pointers for I2C_MODE_CALLBACK */
176  I2C_Transaction *headPtr; /* Head ptr for queued transactions */
177  I2C_Transaction *tailPtr; /* Tail ptr for queued transactions */
178 
179  bool isOpen; /* flag to indicate module is open */
181 
182 /* Do not interfere with the app if they include the family Hwi module */
183 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* ti_drivers_i2c_I2CTiva__include */
bool isOpen
Definition: I2CTiva.h:179
Definition: I2CTiva.h:103
void(* I2C_CallbackFxn)(I2C_Handle, I2C_Transaction *, bool)
I2C callback function.
Definition: I2C.h:268
struct I2CTiva_HWAttrs I2CTiva_HWAttrs
I2CTiva Hardware attributes.
Semaphore_Struct transferComplete
Definition: I2CTiva.h:158
I2CTiva_Mode
I2CTiva mode.
Definition: I2CTiva.h:100
unsigned int intNum
Definition: I2CTiva.h:146
I2C_CallbackFxn transferCallbackFxn
Definition: I2CTiva.h:161
I2C_Transaction * currentTransaction
Definition: I2CTiva.h:167
const I2C_FxnTable I2CTiva_fxnTable
I2CTiva Object.
Definition: I2CTiva.h:156
I2C_Transaction * headPtr
Definition: I2CTiva.h:176
I2C_TransferMode
I2C transfer mode.
Definition: I2C.h:250
I2C_Transaction * tailPtr
Definition: I2CTiva.h:177
The definition of a I2C function table that contains the required set of functions to control a speci...
Definition: I2C.h:348
Definition: I2CTiva.h:104
I2C_TransferMode transferMode
Definition: I2CTiva.h:160
I2CTiva Hardware attributes.
Definition: I2CTiva.h:142
unsigned int baseAddr
Definition: I2CTiva.h:144
struct I2CTiva_Object I2CTiva_Object
I2CTiva Object.
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: I2CTiva.h:163
size_t writeCountIdx
Definition: I2CTiva.h:170
uint8_t * writeBufIdx
Definition: I2CTiva.h:169
Definition: I2CTiva.h:101
size_t readCountIdx
Definition: I2CTiva.h:173
I2C transaction.
Definition: I2C.h:230
Definition: I2CTiva.h:102
volatile I2CTiva_Mode mode
Definition: I2CTiva.h:165
unsigned int intPriority
Definition: I2CTiva.h:148
I2C driver interface.
uint8_t * readBufIdx
Definition: I2CTiva.h:172
Semaphore_Struct mutex
Definition: I2CTiva.h:157
Copyright 2016, Texas Instruments Incorporated