1 //*****************************************************************************
2 //
3 // eeprom.h - Prototypes for the EEPROM driver.
4 //
5 // Copyright (c) 2010-2020 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __DRIVERLIB_EEPROM_H__
41 #define __DRIVERLIB_EEPROM_H__
42 
43 //*****************************************************************************
44 //
45 // If building with a C++ compiler, make all of the definitions in this header
46 // have a C binding.
47 //
48 //*****************************************************************************
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54 //*****************************************************************************
55 //
56 //! \addtogroup eeprom_api
57 //! @{
58 //
59 //*****************************************************************************
60 
61 //*****************************************************************************
62 //
63 // Values returned by EEPROMInit.
64 //
65 //*****************************************************************************
66 
67 //
68 //! This value may be returned from a call to EEPROMInit().  It indicates that
69 //! no previous write operations were interrupted by a reset event and that the
70 //! EEPROM peripheral is ready for use.
71 //
72 #define EEPROM_INIT_OK      0
73 
74 //
75 //! This value may be returned from a call to EEPROMInit().  It indicates that
76 //! a previous data or protection write operation was interrupted by a reset
77 //! event and that the EEPROM peripheral was unable to clean up after the
78 //! problem.  This situation may be resolved with another reset or may be fatal
79 //! depending upon the cause of the problem.  For example, if the voltage to
80 //! the part is unstable, retrying once the voltage has stabilized may clear
81 //! the error.
82 //
83 #define EEPROM_INIT_ERROR   2
84 
85 //*****************************************************************************
86 //
87 // Error indicators returned by various EEPROM API calls.  These will be ORed
88 // together into the final return code.
89 //
90 //*****************************************************************************
91 
92 //
93 //! This return code bit indicates that an attempt was made to read from
94 //! the EEPROM while a write operation was in progress.
95 //
96 #define EEPROM_RC_WRBUSY            0x00000020
97 
98 //
99 //! This return code bit indicates that an attempt was made to write a
100 //! value but the destination permissions disallow write operations.  This
101 //! may be due to the destination block being locked, access protection set
102 //! to prohibit writes or an attempt to write a password when one is already
103 //! written.
104 //
105 #define EEPROM_RC_NOPERM            0x00000010
106 
107 //
108 //! This return code bit indicates that the EEPROM programming state machine
109 //! is currently copying to or from the internal copy buffer to make room for
110 //! a newly written value.  It is provided as a status indicator and does not
111 //! indicate an error.
112 //
113 #define EEPROM_RC_WKCOPY            0x00000008
114 
115 //
116 //! This return code bit indicates that the EEPROM programming state machine
117 //! is currently erasing the internal copy buffer.  It is provided as a
118 //! status indicator and does not indicate an error.
119 //
120 #define EEPROM_RC_WKERASE           0x00000004
121 
122 //
123 //! This return code bit indicates that the EEPROM programming state machine
124 //! is currently working.  No new write operations should be attempted until
125 //! this bit is clear.
126 //
127 #define EEPROM_RC_WORKING           0x00000001
128 
129 //*****************************************************************************
130 //
131 // Values that can be passed to EEPROMBlockProtectSet() in the ui32Protect
132 // parameter, and returned by EEPROMBlockProtectGet().
133 //
134 //*****************************************************************************
135 
136 //
137 //! This bit may be ORed with the protection option passed to
138 //! EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet().  It
139 //! restricts EEPROM access to threads running in supervisor mode and prevents
140 //! access to an EEPROM block when the CPU is in user mode.
141 //
142 #define EEPROM_PROT_SUPERVISOR_ONLY 0x00000008
143 
144 //
145 //! This value may be passed to EEPROMBlockProtectSet() or returned from
146 //! EEPROMBlockProtectGet().  It indicates that the block should offer
147 //! read/write access when no password is set or when a password is set and
148 //! the block is unlocked, and read-only access when a password is set but
149 //! the block is locked.
150 //
151 #define EEPROM_PROT_RW_LRO_URW      0x00000000
152 
153 //
154 //! This value may be passed to EEPROMBlockProtectSet() or returned from
155 //! EEPROMBlockProtectGet().  It indicates that the block should offer neither
156 //! read nor write access unless it is protected by a password and unlocked.
157 //
158 #define EEPROM_PROT_NA_LNA_URW      0x00000001
159 
160 //
161 //! This value may be passed to EEPROMBlockProtectSet() or returned from
162 //! EEPROMBlockProtectGet().  It indicates that the block should offer
163 //! read-only access when no password is set or when a password is set and the
164 //! block is unlocked.  When a password is set and the block is locked, neither
165 //! read nor write access is permitted.
166 //
167 #define EEPROM_PROT_RO_LNA_URO      0x00000002
168 
169 //*****************************************************************************
170 //
171 //! This value may be passed to EEPROMIntEnable() and EEPROMIntDisable() and is
172 //! returned by EEPROMIntStatus() if an EEPROM interrupt is currently being
173 //! signaled.
174 //
175 //*****************************************************************************
176 #define EEPROM_INT_PROGRAM          0x00000004
177 
178 //*****************************************************************************
179 //
180 //! Returns the EEPROM block number containing a given offset address.
181 //!
182 //! \param ui32Addr is the linear, byte address of the EEPROM location whose
183 //! block number is to be returned.  This is a zero-based offset from the start
184 //! of the EEPROM storage.
185 //!
186 //! This macro may be used to translate an EEPROM address offset into a
187 //! block number suitable for use in any of the driver's block protection
188 //! functions.  The address provided is expressed as a byte offset from the
189 //! base of the EEPROM.
190 //!
191 //! \return Returns the zero-based block number which contains the passed
192 //! address.
193 //
194 //*****************************************************************************
195 #define EEPROMBlockFromAddr(ui32Addr) ((ui32Addr) >> 6)
196 
197 //*****************************************************************************
198 //
199 //! Returns the offset address of the first word in an EEPROM block.
200 //!
201 //! \param ui32Block is the index of the EEPROM block whose first word address
202 //! is to be returned.
203 //!
204 //! This macro may be used to determine the address of the first word in a
205 //! given EEPROM block.  The address returned is expressed as a byte offset
206 //! from the base of EEPROM storage.
207 //!
208 //! \return Returns the address of the first word in the given EEPROM block.
209 //
210 //*****************************************************************************
211 #define EEPROMAddrFromBlock(ui32Block) ((ui32Block) << 6)
212 
213 //*****************************************************************************
214 //
215 // Close the Doxygen group.
216 //! @}
217 //
218 //*****************************************************************************
219 
220 //*****************************************************************************
221 //
222 // Prototypes for the APIs.
223 //
224 //*****************************************************************************
225 extern uint32_t EEPROMInit(void);
226 extern uint32_t EEPROMSizeGet(void);
227 extern uint32_t EEPROMBlockCountGet(void);
228 extern void EEPROMRead(uint32_t *pui32Data, uint32_t ui32Address,
229                        uint32_t ui32Count);
230 extern uint32_t EEPROMProgram(uint32_t *pui32Data,
231                               uint32_t ui32Address,
232                               uint32_t ui32Count);
233 extern uint32_t EEPROMProgramNonBlocking(uint32_t ui32Data,
234                                          uint32_t ui32Address);
235 extern uint32_t EEPROMStatusGet(void);
236 extern uint32_t EEPROMMassErase(void);
237 extern uint32_t EEPROMBlockProtectGet(uint32_t ui32Block);
238 extern uint32_t EEPROMBlockProtectSet(uint32_t ui32Block,
239                                       uint32_t ui32Protect);
240 extern uint32_t EEPROMBlockPasswordSet(uint32_t ui32Block,
241                                        uint32_t *pui32Password,
242                                        uint32_t ui32Count);
243 extern uint32_t EEPROMBlockLock(uint32_t ui32Block);
244 extern uint32_t EEPROMBlockUnlock(uint32_t ui32Block,
245                                   uint32_t *pui32Password,
246                                   uint32_t ui32Count);
247 extern void EEPROMBlockHide(uint32_t ui32Block);
248 extern void EEPROMIntEnable(uint32_t ui32IntFlags);
249 extern void EEPROMIntDisable(uint32_t ui32IntFlags);
250 extern uint32_t EEPROMIntStatus(bool bMasked);
251 extern void EEPROMIntClear(uint32_t ui32IntFlags);
252 
253 #ifndef DEPRECATED
254 //*****************************************************************************
255 //
256 // The following definitions appeared in previous revisions of this file
257 // but have been deprecated and should not be used by applications.
258 //
259 //*****************************************************************************
260 
261 //
262 // This value used to be one of those which could be returned from a call to
263 // EEPROMInit().  It transpires that it is was incorrect and has been removed
264 // after EEPROMInit() was reworked for TivaWare 2.1.
265 //
266 #define EEPROM_INIT_RETRY   1
267 
268 //
269 // This return code is not available from any Tiva part and has been removed.
270 //
271 #define EEPROM_RC_INVPL             0x00000100
272 
273 #endif
274 
275 //*****************************************************************************
276 //
277 // Mark the end of the C bindings section for C++ compilers.
278 //
279 //*****************************************************************************
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif // __DRIVERLIB_EEPROM_H__
285