I2CCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2023, 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 /*!****************************************************************************
33  * @file I2CCC26XX.h
34  *
35  * @brief I2C driver implementation for a CC26XX I2C controller.
36  *
37  * # Driver Include #
38  * The I2C header file should be included in an application as follows:
39  * @code
40  * #include <ti/drivers/I2C.h>
41  * #include <ti/drivers/i2c/I2CCC26XX.h>
42  * @endcode
43  *
44  * Refer to @ref I2C.h for a complete description of APIs.
45  *
46  * # Overview #
47  * Refer to @ref I2C.h for a complete description of APIs.
48  *
49  * ## General Behavior #
50  * Before using the I2C in CC26XX:
51  * - The I2C driver is initialized by calling I2C_init().
52  * - The I2C HW is configured and system dependencies are declared (e.g. IOs,
53  * power, etc.) by calling I2C_open().
54  * .
55  * The following is true for receive operation:
56  * - RX is enabled by calling I2C_transfer().
57  * The readCount of the ::I2C_Transaction must be set to a non-zero value.
58  * - If the I2C_transfer() succeeds, the I2C remains enabled.
59  * - The application must check the return value from I2C_transfer()
60  * to verify that the transfer succeeded.
61  * .
62  * The following apply for transmit operation:
63  * - TX is enabled by calling I2C_transfer().
64  * The writeCount of the ::I2C_Transaction must be set to a non-zero value.
65  * - If the I2C_transfer() succeeds, the I2C remains enabled.
66  * - The application must check the return value from I2C_transfer()
67  * to verify that the transfer succeeded.
68  * .
69  * After I2C operation has ended:
70  * - Release system dependencies for I2C by calling I2C_close().
71  *
72  * ### Known Issue #
73  * @warning The I2C will transmit a single data byte in the event that the
74  * I2C target address is not acknowledged (NACK'd). This is due to a known
75  * hardware bug.
76  *
77  * ## Error handling #
78  * If an error occurs during operation:
79  * - The I2C Controller transmits a stop bit and remains enabled.
80  * .
81  *
82  * ## Power Management #
83  * The I2CCC26XX driver sets a power constraint during transactions to keep
84  * the device out of standby; so when all tasks are blocked, the device will
85  * enter idle mode instead of standby. When the transactions have finished,
86  * the power constraint to prohibit standby is released.
87  * The following statements are valid:
88  * - After I2C_open() call: I2C is enabled, there are no active I2C
89  * transactions, the device can enter standby.
90  * - After I2C_transfer() call: active I2C transactions exist, the device
91  * might enter idle, but not standby.
92  * - When I2C_transfer() completes, either after success or error, I2C
93  * remains enabled, and the device can enter standby.
94  * - After I2C_close() call: I2C is disabled
95  * - If the device goes into idle during a transaction, the state of
96  * SDA is undefined in the time between the transaction completing and
97  * the device waking up. SCL will go low until the device wakes up and
98  * starts another transaction or releases the bus. If this is a problem
99  * for another device on the I2C bus, you can set a power constraint for
100  * #PowerCC26XX_DISALLOW_IDLE before the transaction and release it
101  * when the transaction completes.
102  *
103  * ## Supported Functions ##
104  * | Generic API Function | Description |
105  * |------------------------|---------------------------------------------------|
106  * | #I2C_init() | Initialize I2C driver |
107  * | #I2C_Params_init() | Initialize an #I2C_Params structure |
108  * | #I2C_open() | Initialize I2C HW and set system dependencies |
109  * | #I2C_close() | Disable I2C HW and release system dependencies |
110  * | #I2C_transfer() | Start I2C transfer |
111  * | #I2C_transferTimeout() | Start I2C transfer with a timeout |
112  * | #I2C_cancel() | Cancels all I2C transfers |
113  *
114  * ## Supported Bit Rates ##
115  * - #I2C_100kHz
116  * - #I2C_400kHz
117  *
118  * ## Supported Address Modes ##
119  * - #I2C_ADDRESS_MODE_7_BIT
120  *
121  * ## Unsupported Functionality #
122  * The CC26XX I2C driver currently does not support:
123  * - Multi-controller mode
124  * - I2C target mode
125  *
126  * # Instrumentation #
127  * The I2C driver interface produces log statements if instrumentation is
128  * enabled.
129  *
130  * Diagnostics Mask | Log details |
131  * ---------------- | ----------- |
132  * Diags_USER1 | basic I2C operations performed |
133  * Diags_USER2 | detailed I2C operations performed |
134  *
135  ******************************************************************************
136  */
137 
138 #ifndef ti_drivers_i2c_I2CCC26XX__include
139 #define ti_drivers_i2c_I2CCC26XX__include
140 
141 #include <stdint.h>
142 #include <stdbool.h>
143 
144 #include <ti/drivers/I2C.h>
145 #include <ti/drivers/Power.h>
147 
148 #include <ti/drivers/dpl/SwiP.h>
149 
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
153 
175 typedef struct
176 {
177  uint8_t pinSDA;
178  uint8_t pinSCL;
180 
225 typedef struct
226 {
227  I2C_BASE_HWATTRS
228 
229  /*
230  * I2C Swi priority.
231  * The higher the number, the higher the priority.
232  * The minimum is 0 and the maximum is 15 by default.
233  * The maximum can be reduced to save RAM by adding or modifying
234  * Swi.numPriorities in the kernel configuration file.
235  */
236  uint32_t swiPriority;
237 
238  /* I2C peripheral's Power driver ID */
239  PowerCC26XX_Resource powerMngrId;
240 
241  /* SDA pin index and mux */
242  uint8_t sdaPin;
243  uint8_t sdaPinMux;
244  /* SCL pin index and mux */
245  uint8_t sclPin;
246  uint8_t sclPinMux;
248 
254 typedef struct
255 {
256  I2C_BASE_OBJECT
257 
258  /* Swi object */
260 
261  /* Bitrate of the I2C module */
262  uint32_t bitRate;
263 
264  /* Pin indexes. We need to cache these because we might have custom pins */
265  uint8_t sdaPin;
266  uint8_t sclPin;
267 
268  /* I2C power notification */
269  void *i2cPostFxn;
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif /* ti_drivers_i2c_I2CCC26XX__include */
I2C_BASE_OBJECT SwiP_Struct swi
Definition: I2CCC26XX.h:259
uint8_t pinSDA
Definition: I2CCC26XX.h:177
I2CCC26XX Pin Configuration.
Definition: I2CCC26XX.h:175
uint32_t bitRate
Definition: I2CCC26XX.h:262
Power Manager.
I2C_BASE_HWATTRS uint32_t swiPriority
Definition: I2CCC26XX.h:236
Power manager interface for CC26XX/CC13XX.
PowerCC26XX_Resource powerMngrId
Definition: I2CCC26XX.h:239
I2CCC26XX Hardware attributes.
Definition: I2CCC26XX.h:225
Power_NotifyObj i2cPostObj
Definition: I2CCC26XX.h:270
uint8_t sclPin
Definition: I2CCC26XX.h:245
uint8_t sclPin
Definition: I2CCC26XX.h:266
Software Interrupt module for the RTOS Porting Interface.
Power notify object structure.
Definition: Power.h:441
uint8_t sdaPin
Definition: I2CCC26XX.h:265
uint8_t sclPinMux
Definition: I2CCC26XX.h:246
uint8_t pinSCL
Definition: I2CCC26XX.h:178
I2CCC26XX Object.
Definition: I2CCC26XX.h:254
uint8_t sdaPin
Definition: I2CCC26XX.h:242
uint8_t sdaPinMux
Definition: I2CCC26XX.h:243
SemaphoreP structure.
Definition: SwiP.h:68
Inter-Integrated Circuit (I2C) Controller Driver.
void * i2cPostFxn
Definition: I2CCC26XX.h:269
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale