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