1 //*****************************************************************************
2 //
3 // eeprom.h - Prototypes for the EEPROM driver.
4 //
5 // Copyright (c) 2010-2017 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 //*****************************************************************************
37 
38 #ifndef __DRIVERLIB_EEPROM_H__
39 #define __DRIVERLIB_EEPROM_H__
40 
41 #include <stdint.h>
42 #include <stdbool.h>
43 
44 //*****************************************************************************
45 //
46 // If building with a C++ compiler, make all of the definitions in this header
47 // have a C binding.
48 //
49 //*****************************************************************************
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 //*****************************************************************************
56 //
57 //! \addtogroup eeprom_api
58 //! @{
59 //
60 //*****************************************************************************
61 
62 //*****************************************************************************
63 //
64 // Values returned by EEPROMInit.
65 //
66 //*****************************************************************************
67 
68 //
69 //! This value may be returned from a call to EEPROMInit().  It indicates that
70 //! no previous write operations were interrupted by a reset event and that the
71 //! EEPROM peripheral is ready for use.
72 //
73 #define EEPROM_INIT_OK      0
74 
75 //
76 //! This value may be returned from a call to EEPROMInit().  It indicates that
77 //! a previous data or protection write operation was interrupted by a reset
78 //! event and that the EEPROM peripheral was unable to clean up after the
79 //! problem.  This situation may be resolved with another reset or may be fatal
80 //! depending upon the cause of the problem.  For example, if the voltage to
81 //! the part is unstable, retrying once the voltage has stabilized may clear
82 //! the error.
83 //
84 #define EEPROM_INIT_ERROR   2
85 
86 //*****************************************************************************
87 //
88 // Error indicators returned by various EEPROM API calls.  These will be ORed
89 // together into the final return code.
90 //
91 //*****************************************************************************
92 
93 //
94 //! This return code bit indicates that an attempt was made to read from
95 //! the EEPROM while a write operation was in progress.
96 //
97 #define EEPROM_RC_WRBUSY            0x00000020
98 
99 //
100 //! This return code bit indicates that an attempt was made to write a
101 //! value but the destination permissions disallow write operations.  This
102 //! may be due to the destination block being locked, access protection set
103 //! to prohibit writes or an attempt to write a password when one is already
104 //! written.
105 //
106 #define EEPROM_RC_NOPERM            0x00000010
107 
108 //
109 //! This return code bit indicates that the EEPROM programming state machine
110 //! is currently copying to or from the internal copy buffer to make room for
111 //! a newly written value.  It is provided as a status indicator and does not
112 //! indicate an error.
113 //
114 #define EEPROM_RC_WKCOPY            0x00000008
115 
116 //
117 //! This return code bit indicates that the EEPROM programming state machine
118 //! is currently erasing the internal copy buffer.  It is provided as a
119 //! status indicator and does not indicate an error.
120 //
121 #define EEPROM_RC_WKERASE           0x00000004
122 
123 //
124 //! This return code bit indicates that the EEPROM programming state machine
125 //! is currently working.  No new write operations should be attempted until
126 //! this bit is clear.
127 //
128 #define EEPROM_RC_WORKING           0x00000001
129 
130 //*****************************************************************************
131 //
132 // Values that can be passed to EEPROMBlockProtectSet() in the ui32Protect
133 // parameter, and returned by EEPROMBlockProtectGet().
134 //
135 //*****************************************************************************
136 
137 //
138 //! This bit may be ORed with the protection option passed to
139 //! EEPROMBlockProtectSet() or returned from EEPROMBlockProtectGet().  It
140 //! restricts EEPROM access to threads running in supervisor mode and prevents
141 //! access to an EEPROM block when the CPU is in user mode.
142 //
143 #define EEPROM_PROT_SUPERVISOR_ONLY 0x00000008
144 
145 //
146 //! This value may be passed to EEPROMBlockProtectSet() or returned from
147 //! EEPROMBlockProtectGet().  It indicates that the block should offer
148 //! read/write access when no password is set or when a password is set and
149 //! the block is unlocked, and read-only access when a password is set but
150 //! the block is locked.
151 //
152 #define EEPROM_PROT_RW_LRO_URW      0x00000000
153 
154 //
155 //! This value may be passed to EEPROMBlockProtectSet() or returned from
156 //! EEPROMBlockProtectGet().  It indicates that the block should offer neither
157 //! read nor write access unless it is protected by a password and unlocked.
158 //
159 #define EEPROM_PROT_NA_LNA_URW      0x00000001
160 
161 //
162 //! This value may be passed to EEPROMBlockProtectSet() or returned from
163 //! EEPROMBlockProtectGet().  It indicates that the block should offer
164 //! read-only access when no password is set or when a password is set and the
165 //! block is unlocked.  When a password is set and the block is locked, neither
166 //! read nor write access is permitted.
167 //
168 #define EEPROM_PROT_RO_LNA_URO      0x00000002
169 
170 //*****************************************************************************
171 //
172 //! This value may be passed to EEPROMIntEnable() and EEPROMIntDisable() and is
173 //! returned by EEPROMIntStatus() if an EEPROM interrupt is currently being
174 //! signaled.
175 //
176 //*****************************************************************************
177 #define EEPROM_INT_PROGRAM          0x00000004
178 
179 //*****************************************************************************
180 //
181 //! Returns the EEPROM block number containing a given offset address.
182 //!
183 //! \param ui32Addr is the linear, byte address of the EEPROM location whose
184 //! block number is to be returned.  This is a zero-based offset from the start
185 //! of the EEPROM storage.
186 //!
187 //! This macro may be used to translate an EEPROM address offset into a
188 //! block number suitable for use in any of the driver's block protection
189 //! functions.  The address provided is expressed as a byte offset from the
190 //! base of the EEPROM.
191 //!
192 //! \return Returns the zero-based block number which contains the passed
193 //! address.
194 //
195 //*****************************************************************************
196 #define EEPROMBlockFromAddr(ui32Addr) ((ui32Addr) >> 6)
197 
198 //*****************************************************************************
199 //
200 //! Returns the offset address of the first word in an EEPROM block.
201 //!
202 //! \param ui32Block is the index of the EEPROM block whose first word address
203 //! is to be returned.
204 //!
205 //! This macro may be used to determine the address of the first word in a
206 //! given EEPROM block.  The address returned is expressed as a byte offset
207 //! from the base of EEPROM storage.
208 //!
209 //! \return Returns the address of the first word in the given EEPROM block.
210 //
211 //*****************************************************************************
212 #define EEPROMAddrFromBlock(ui32Block) ((ui32Block) << 6)
213 
214 //*****************************************************************************
215 //
216 // Close the Doxygen group.
217 //! @}
218 //
219 //*****************************************************************************
220 
221 //*****************************************************************************
222 //
223 // Prototypes for the APIs.
224 //
225 //*****************************************************************************
226 extern uint32_t EEPROMInit(void);
227 extern uint32_t EEPROMSizeGet(void);
228 extern uint32_t EEPROMBlockCountGet(void);
229 extern void EEPROMRead(uint32_t *pui32Data, uint32_t ui32Address,
230                        uint32_t ui32Count);
231 extern uint32_t EEPROMProgram(uint32_t *pui32Data,
232                               uint32_t ui32Address,
233                               uint32_t ui32Count);
234 extern uint32_t EEPROMProgramNonBlocking(uint32_t ui32Data,
235         uint32_t ui32Address);
236 extern uint32_t EEPROMStatusGet(void);
237 extern uint32_t EEPROMMassErase(void);
238 extern uint32_t EEPROMBlockProtectGet(uint32_t ui32Block);
239 extern uint32_t EEPROMBlockProtectSet(uint32_t ui32Block,
240                                       uint32_t ui32Protect);
241 extern uint32_t EEPROMBlockPasswordSet(uint32_t ui32Block,
242                                        uint32_t *pui32Password,
243                                        uint32_t ui32Count);
244 extern uint32_t EEPROMBlockLock(uint32_t ui32Block);
245 extern uint32_t EEPROMBlockUnlock(uint32_t ui32Block,
246                                   uint32_t *pui32Password,
247                                   uint32_t ui32Count);
248 extern void EEPROMBlockHide(uint32_t ui32Block);
249 extern void EEPROMIntEnable(uint32_t ui32IntFlags);
250 extern void EEPROMIntDisable(uint32_t ui32IntFlags);
251 extern uint32_t EEPROMIntStatus(bool bMasked);
252 extern void EEPROMIntClear(uint32_t ui32IntFlags);
253 
254 //*****************************************************************************
255 //
256 // Mark the end of the C bindings section for C++ compilers.
257 //
258 //*****************************************************************************
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif // __DRIVERLIB_EEPROM_H__
264