EEPROM Library Overview  1.0.0.x
eeprom_emulation_type_b.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 eeprom_emulation_type_b.h
34  * @brief EEPROM Emulation Type B
35  * @defgroup EEPROM_TYPE_B EEPROM Emulation Type B
36  *
37  * @anchor EEPROM_EMULATION_TYPE_B_H__Overview
38  * # Overview
39  *
40  * MSPM0 support EEPROM emulation through its internal Flash. Compared to using
41  * an external serial EEPROM, EEPROM emulation using the internal Flash saves
42  * pin usage and cost.
43  * The EEPROM emulation Type B solution is suitable if the user application
44  * needs to store small "variable" data.
45  *
46  * <hr>
47  ******************************************************************************/
51 #include <stdbool.h>
52 #include <stdint.h>
53 
54 #include <ti/devices/msp/msp.h>
55 #include <ti/driverlib/driverlib.h>
56 #include <ti/driverlib/m0p/dl_core.h>
57 
58 #ifndef EEPROM_EMULATION_TYPE_B_H_
59 #define EEPROM_EMULATION_TYPE_B_H_
60 
61 /* clang-format off */
62 
71 #ifndef EEPROM_EMULATION_ADDRESS
72 #define EEPROM_EMULATION_ADDRESS (0x00001400)
73 #endif
74 
77 #define EEPROM_EMULATION_GROUP_ACCOUNT (3)
78 
81 #define EEPROM_EMULATION_SECTOR_INGROUP_ACCOUNT (2)
82 
85 #define EEPROM_EMULATION_REPAIR_ENABLE (0)
86 
97 #define EEPROM_EMULATION_DATAITEM_ACCOUNT \
98  (EEPROM_EMULATION_SECTOR_INGROUP_ACCOUNT * 128 - 1)
99 
102 #define EEPROM_EMULATION_ACTIVE_DATAITEM_NUM_MIN (0)
103 
106 #define EEPROM_EMULATION_ACTIVE_DATAITEM_NUM_MAX \
107  (EEPROM_EMULATION_DATAITEM_ACCOUNT)
108 
111 #define EEPROM_EMULATION_ACTIVE_GROUP_NUM_MIN (1)
112 
115 #define EEPROM_EMULATION_ACTIVE_GROUP_NUM_MAX (EEPROM_EMULATION_GROUP_ACCOUNT)
116 
126 #define EEPROM_EMULATION_WRITE_OK ((uint32_t) 0x00000000U)
127 
130 #define EEPROM_EMULATION_WRITE_ERROR ((uint32_t) 0x00000001U)
131 
134 #define EEPROM_EMULATION_FORMAT_ERROR ((uint32_t) 0x00000010U)
135 
139 #define EEPROM_EMULATION_TRANSFER_OK ((uint32_t) 0x00000000U)
140 
143 #define EEPROM_EMULATION_TRANSFER_ERROR ((uint32_t) 0x00000002U)
144 
148 #define EEPROM_EMULATION_INIT_OK ((uint32_t) 0x00000000U)
149 
152 #define EEPROM_EMULATION_INIT_OK_FORMAT_REPAIR ((uint32_t) 0x00000004U)
153 
156 #define EEPROM_EMULATION_INIT_OK_ALL_ERASE ((uint32_t) 0x00000040U)
157 
160 #define EEPROM_EMULATION_INIT_ERROR ((uint32_t) 0x00000400U)
161 
164 #define EEPROM_EMULATION_FINDITEM_NOT_FOUND ((uint32_t) 0x00000000U)
165 
168 #define CHECK_ONE_ACTIVE_GROUP ((uint32_t) 0x00000000U)
169 
172 #define CHECK_NO_ACTIVE_ONE_ERROR_GROUP ((uint32_t) 0x00000001U)
173 
176 #define CHECK_NO_ACTIVE_NO_ERROR_GROUP ((uint32_t) 0x00000002U)
177 
179 /* clang-format on */
180 
182 extern uint16_t gActiveDataItemNum;
184 extern uint16_t gActiveGroupNum;
185 
187 extern bool gEEPROMTypeBSearchFlag;
189 extern bool gEEPROMTypeBEraseFlag;
190 
207 uint32_t EEPROM_TypeB_write(uint16_t identifier, uint32_t data);
208 
226 uint32_t EEPROM_TypeB_writeDataItem(uint16_t identifier, uint32_t data,
227  uint16_t groupNum, uint16_t dataItemNum);
228 
247 uint32_t EEPROM_TypeB_transferDataItem(uint16_t groupNum);
248 
261 uint32_t EEPROM_TypeB_readDataItem(uint16_t identifier);
262 
278  uint16_t identifier, uint16_t groupNum, uint16_t dataItemNum);
279 
299 uint32_t EEPROM_TypeB_init(void);
300 
316 uint32_t EEPROM_TypeB_checkFormat(void);
317 
330 bool EEPROM_TypeB_eraseGroup(void);
331 
341 
350 bool EEPROM_TypeB_eraseAllGroups(void);
351 
352 #endif /* EEPROM_EMULATION_TYPE_B_H_ */
353 
bool EEPROM_TypeB_eraseNonActiveGroups(void)
Erases groups other than the active group.
uint16_t gActiveDataItemNum
Store the number of active data items.
bool EEPROM_TypeB_eraseGroup(void)
Erases the &#39;Erasing&#39; group.
uint32_t EEPROM_TypeB_readDataItem(uint16_t identifier)
Read the latest data item based on the identifier.
uint32_t EEPROM_TypeB_writeDataItem(uint16_t identifier, uint32_t data, uint16_t groupNum, uint16_t dataItemNum)
Store provided data and identifier to the specified data item.
uint32_t EEPROM_TypeB_findDataItem(uint16_t identifier, uint16_t groupNum, uint16_t dataItemNum)
Find the latest data item based on the identifier.
uint32_t EEPROM_TypeB_checkFormat(void)
Search the active group and check the format.
uint32_t EEPROM_TypeB_write(uint16_t identifier, uint32_t data)
Write provided data and identifier to the Flash.
bool gEEPROMTypeBEraseFlag
Indicate when the group is full nad needs to be erased.
uint32_t EEPROM_TypeB_init(void)
Initialize the specified area in flash.
uint16_t gActiveGroupNum
Store the number of active groups.
uint32_t EEPROM_TypeB_transferDataItem(uint16_t groupNum)
Transfer the data items to next group.
bool EEPROM_TypeB_eraseAllGroups(void)
Erase all groups used by EEPROM emulation.
bool gEEPROMTypeBSearchFlag
Indicate when the data item is found.
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale