AM263Px MCU+ SDK: eeprom.h Source File

| AM263Px MCU+ SDK 26.00.00 |

eeprom.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2021 Texas Instruments Incorporated
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * 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
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
44 #ifndef EEPROM_H_
45 #define EEPROM_H_
46
47 /* ========================================================================== */
48 /* Include Files */
49 /* ========================================================================== */
50
51 #include <stdint.h>
52 #include <kernel/dpl/SystemP.h>
53 #include <kernel/dpl/SemaphoreP.h>
54 #include <drivers/i2c.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /* ========================================================================== */
61 /* Macros & Typedefs */
62 /* ========================================================================== */
63
68 #define EEPROM_PAGE_SIZE (256U)
69
73 #define EEPROM_WR_BUF_SIZE (2U + EEPROM_PAGE_SIZE)
74
76 typedef void *EEPROM_Handle;
78 typedef struct EEPROM_Config_s EEPROM_Config;
80 typedef struct EEPROM_Params_s EEPROM_Params;
81
98 typedef int32_t (*EEPROM_OpenFxn)(EEPROM_Config *config,
99 const EEPROM_Params *params);
100
111 typedef void (*EEPROM_CloseFxn)(EEPROM_Config *config);
112
126 typedef int32_t (*EEPROM_ReadFxn)(EEPROM_Config *config,
127 uint32_t offset,
128 uint8_t *buf,
129 uint32_t len);
130
144 typedef int32_t (*EEPROM_WriteFxn)(EEPROM_Config *config,
145 uint32_t offset,
146 const uint8_t *buf,
147 uint32_t len);
150 /* ========================================================================== */
151 /* Structure Declarations */
152 /* ========================================================================== */
153
157 struct EEPROM_Params_s
158 {
159 uint32_t driverInstance;
162 uint32_t i2cAddress;
164 };
165
169 typedef struct EEPROM_Fxns_s
170 {
171 EEPROM_OpenFxn openFxn;
173 EEPROM_CloseFxn closeFxn;
175 EEPROM_ReadFxn readFxn;
177 EEPROM_WriteFxn writeFxn;
179 } EEPROM_Fxns;
180
185 typedef struct EEPROM_Attrs_s
186 {
187 uint32_t size;
189 uint32_t pageCount;
191 uint32_t pageSize;
193 } EEPROM_Attrs;
194
199 struct EEPROM_Config_s
200 {
201 EEPROM_Attrs *attrs;
203 EEPROM_Fxns *fxns;
205 void *object;
207 };
208
209 /* ========================================================================== */
210 /* Function Declarations */
211 /* ========================================================================== */
212
221 void EEPROM_Params_init(EEPROM_Params *params);
222
241 EEPROM_Handle EEPROM_open(uint32_t instanceId, const EEPROM_Params *params);
242
248 void EEPROM_close(EEPROM_Handle handle);
249
260 int32_t EEPROM_read(EEPROM_Handle handle,
261 uint32_t offset,
262 uint8_t *buf,
263 uint32_t len);
264
277 int32_t EEPROM_write(EEPROM_Handle handle,
278 uint32_t offset,
279 const uint8_t *buf,
280 uint32_t len);
281
289 const EEPROM_Attrs *EEPROM_getAttrs(uint32_t instanceId);
290
291 /* ========================================================================== */
292 /* Static Function Definitions */
293 /* ========================================================================== */
294
295 /* None */
296
297 /* ========================================================================== */
298 /* Internal/Private Structure Declarations */
299 /* ========================================================================== */
300
304 typedef struct
305 {
306 I2C_Handle i2cHandle;
308 uint32_t driverInstance;
311 uint32_t i2cAddress;
313 uint8_t pageWrBuf[EEPROM_WR_BUF_SIZE];
316 void *lock;
318 SemaphoreP_Object lockObj;
320 } EEPROM_Object;
321
322 #ifdef __cplusplus
323 }
324 #endif
325
326 #endif /* #ifndef EEPROM_H_ */
327
EEPROM_Attrs
EEPROM device attributes, these are filled by SysCfg based on the device that is selected.
Definition: eeprom.h:186
EEPROM_WriteFxn
int32_t(* EEPROM_WriteFxn)(EEPROM_Config *config, uint32_t offset, const uint8_t *buf, uint32_t len)
Driver implementation to write to EEPROM using specific EEPROM driver.
Definition: eeprom.h:144
EEPROM_Params_s::driverInstance
uint32_t driverInstance
Definition: eeprom.h:159
EEPROM_Config_s::object
void * object
Definition: eeprom.h:205
EEPROM_Object::driverInstance
uint32_t driverInstance
Definition: eeprom.h:308
EEPROM_WR_BUF_SIZE
#define EEPROM_WR_BUF_SIZE
Temp write buffer to hold address offset and data for page write operation - 2 bytes for offset and r...
Definition: eeprom.h:73
EEPROM_Fxns::openFxn
EEPROM_OpenFxn openFxn
Definition: eeprom.h:171
EEPROM_Fxns::readFxn
EEPROM_ReadFxn readFxn
Definition: eeprom.h:175
EEPROM_Object::lock
void * lock
Definition: eeprom.h:316
SystemP.h
EEPROM_Config_s
EEPROM driver configuration, these are filled by SysCfg based on the device that is selected.
Definition: eeprom.h:200
EEPROM_close
void EEPROM_close(EEPROM_Handle handle)
Open EEPROM driver.
EEPROM_write
int32_t EEPROM_write(EEPROM_Handle handle, uint32_t offset, const uint8_t *buf, uint32_t len)
Write to EEPROM.
SemaphoreP.h
I2C_Handle
struct I2C_Config_s * I2C_Handle
A handle that is returned from a I2C_open() call.
Definition: i2c.h:165
EEPROM_Params_s::i2cAddress
uint32_t i2cAddress
Definition: eeprom.h:162
EEPROM_Config_s::fxns
EEPROM_Fxns * fxns
Definition: eeprom.h:203
EEPROM_Attrs::pageCount
uint32_t pageCount
Definition: eeprom.h:189
EEPROM_Object::i2cHandle
I2C_Handle i2cHandle
Definition: eeprom.h:306
EEPROM_Object
EEPROM driver object - not to be used by application.
Definition: eeprom.h:305
EEPROM_ReadFxn
int32_t(* EEPROM_ReadFxn)(EEPROM_Config *config, uint32_t offset, uint8_t *buf, uint32_t len)
Driver implementation to read from EEPROM using a specific EEPROM driver.
Definition: eeprom.h:126
EEPROM_Fxns::writeFxn
EEPROM_WriteFxn writeFxn
Definition: eeprom.h:177
EEPROM_getAttrs
const EEPROM_Attrs * EEPROM_getAttrs(uint32_t instanceId)
Return EEPROM attributes.
EEPROM_CloseFxn
void(* EEPROM_CloseFxn)(EEPROM_Config *config)
Driver implementation to close a specific EEPROM driver.
Definition: eeprom.h:111
EEPROM_Object::lockObj
SemaphoreP_Object lockObj
Definition: eeprom.h:318
EEPROM_Fxns::closeFxn
EEPROM_CloseFxn closeFxn
Definition: eeprom.h:173
EEPROM_Params_s
Parameters passed during EEPROM_open()
Definition: eeprom.h:158
EEPROM_Attrs::pageSize
uint32_t pageSize
Definition: eeprom.h:191
EEPROM_read
int32_t EEPROM_read(EEPROM_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)
Read data from EEPROM.
EEPROM_Config_s::attrs
EEPROM_Attrs * attrs
Definition: eeprom.h:201
EEPROM_OpenFxn
int32_t(* EEPROM_OpenFxn)(EEPROM_Config *config, const EEPROM_Params *params)
Driver implementation to open a specific EEPROM driver.
Definition: eeprom.h:98
EEPROM_Params_init
void EEPROM_Params_init(EEPROM_Params *params)
Set default parameters in the EEPROM_Params_s structure.
EEPROM_Object::i2cAddress
uint32_t i2cAddress
Definition: eeprom.h:311
EEPROM_open
EEPROM_Handle EEPROM_open(uint32_t instanceId, const EEPROM_Params *params)
Open EEPROM driver.
EEPROM_Attrs::size
uint32_t size
Definition: eeprom.h:187
EEPROM_Fxns
Driver implementation callbacks.
Definition: eeprom.h:170
EEPROM_Handle
void * EEPROM_Handle
Handle to the EEPROM driver returned by EEPROM_open()
Definition: eeprom.h:76