2 * @brief EEPROM registers and driver functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __EEPROM_001_H_
\r
33 #define __EEPROM_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_EEPROM_001 IP: EEPROM register block and driver
\r
43 * @ingroup IP_Drivers
\r
44 * Supports 4032 byte EEPROM devices.
\r
49 * @brief EEPROM register block structure
\r
51 typedef struct { /* EEPROM Structure */
\r
52 __IO uint32_t CMD; /*!< EEPROM command register */
\r
53 __IO uint32_t ADDR; /*!< EEPROM address register */
\r
54 __O uint32_t WDATA; /*!< EEPROM write data register */
\r
55 __I uint32_t RDATA; /*!< EEPROM read data register */
\r
56 __IO uint32_t WSTATE; /*!< EEPROM wait state register */
\r
57 __IO uint32_t CLKDIV; /*!< EEPROM clock divider register */
\r
58 __IO uint32_t PWRDWN; /*!< EEPROM power-down register */
\r
59 uint32_t RESERVED0[975];
\r
60 __O uint32_t INTENCLR; /*!< EEPROM interrupt enable clear */
\r
61 __O uint32_t INTENSET; /*!< EEPROM interrupt enable set */
\r
62 __I uint32_t INTSTAT; /*!< EEPROM interrupt status */
\r
63 __I uint32_t INTEN; /*!< EEPROM interrupt enable */
\r
64 __O uint32_t INTSTATCLR; /*!< EEPROM interrupt status clear */
\r
65 __O uint32_t INTSTATSET; /*!< EEPROM interrupt status set */
\r
68 #define EEPROM_PAGE_SIZE 64 /*!< EEPROM byes per page */
\r
69 #define EEPROM_PAGE_NUM 63 /*!< EEPROM pages */
\r
72 * @brief Macro defines for EEPROM command register
\r
74 #define EEPROM_CMD_8BITS_READ (0) /*!< EEPROM 8-bit read command */
\r
75 #define EEPROM_CMD_16BITS_READ (1) /*!< EEPROM 16-bit read command */
\r
76 #define EEPROM_CMD_32BITS_READ (2) /*!< EEPROM 32-bit read command */
\r
77 #define EEPROM_CMD_8BITS_WRITE (3) /*!< EEPROM 8-bit write command */
\r
78 #define EEPROM_CMD_16BITS_WRITE (4) /*!< EEPROM 16-bit write command */
\r
79 #define EEPROM_CMD_32BITS_WRITE (5) /*!< EEPROM 32-bit write command */
\r
80 #define EEPROM_CMD_ERASE_PRG_PAGE (6) /*!< EEPROM erase/program command */
\r
81 #define EEPROM_CMD_RDPREFETCH (1 << 3)/*!< EEPROM read pre-fetch enable */
\r
84 * @brief Macro defines for EEPROM power down register
\r
86 #define EEPROM_PWRDWN (1 << 0)
\r
89 * @brief Macro defines for EEPROM interrupt related registers
\r
91 #define EEPROM_INT_ENDOFRW (1 << 26)
\r
92 #define EEPROM_INT_ENDOFPROG (1 << 28)
\r
95 * @brief EEPROM Mode type definition
\r
97 typedef enum IP_EEPROM_RWSIZE {
\r
98 EEPROM_RWSIZE_8BITS = 1,
\r
99 EEPROM_RWSIZE_16BITS = 2,
\r
100 EEPROM_RWSIZE_32BITS = 4
\r
101 } IP_EEPROM_RWSIZE_T;
\r
104 * @brief Select an EEPROM command
\r
105 * @param pEEPROM : pointer to EEPROM peripheral block
\r
106 * @param cmd : EEPROM command.
\r
108 * @note cmd is or-ed bits value of EEPROM_CMD_[8|16|32]BITS_READ/EEPROM_CMD_[8|16|32]BITS_WRITE
\r
109 * with EEPROM_CMD_RDPREFETCH flag.
\r
110 * Read and erase/program operations are started on the EEPROM device as a side-effect of calling this function.
\r
111 * Write operations are started as a side-effect of writing data to data register.
\r
113 STATIC INLINE void IP_EEPROM_SetCmd(IP_EEPROM_001_T *pEEPROM, uint32_t cmd)
\r
115 pEEPROM->CMD = cmd;
\r
119 * @brief Set EEPROM address
\r
120 * @param pEEPROM : pointer to EEPROM peripheral block
\r
121 * @param pageAddr : Page address.
\r
122 * @param pageOffset : Page address.
\r
125 STATIC INLINE void IP_EEPROM_SetAddr(IP_EEPROM_001_T *pEEPROM, uint32_t pageAddr, uint32_t pageOffset)
\r
127 pEEPROM->ADDR = (pageAddr << 6) | pageOffset;
\r
131 * @brief Write EEPROM data
\r
132 * @param pEEPROM : pointer to EEPROM peripheral block
\r
133 * @param data : EEPROM data.
\r
136 STATIC INLINE void IP_EEPROM_WriteData(IP_EEPROM_001_T *pEEPROM, uint32_t data)
\r
138 pEEPROM->WDATA = data;
\r
142 * @brief Read EEPROM data
\r
143 * @param pEEPROM : pointer to EEPROM peripheral block
\r
146 STATIC INLINE uint32_t IP_EEPROM_ReadData(IP_EEPROM_001_T *pEEPROM)
\r
148 return pEEPROM->RDATA;
\r
152 * @brief Set EEPROM wait state
\r
153 * @param pEEPROM : pointer to EEPROM peripheral block
\r
154 * @param ws : Wait State value.
\r
157 STATIC INLINE void IP_EEPROM_SetWaitState(IP_EEPROM_001_T *pEEPROM, uint32_t ws)
\r
159 pEEPROM->WSTATE = ws;
\r
163 * @brief Put EEPROM device in power down mode
\r
164 * @param pEEPROM : pointer to EEPROM peripheral block
\r
167 STATIC INLINE void IP_EEPROM_EnablePowerDown(IP_EEPROM_001_T *pEEPROM)
\r
169 pEEPROM->PWRDWN = EEPROM_PWRDWN;
\r
173 * @brief Bring EEPROM device out of power down mode
\r
174 * @param pEEPROM : pointer to EEPROM peripheral block
\r
176 * @note Any EEPROM operation has to be suspended for 100us while the EEPROM wakes up.
\r
178 STATIC INLINE void IP_EEPROM_DisablePowerDown(IP_EEPROM_001_T *pEEPROM)
\r
180 pEEPROM->PWRDWN = 0;
\r
184 * @brief Enable EEPROM interrupt
\r
185 * @param pEEPROM : pointer to EEPROM peripheral block
\r
186 * @param mask : interrupt mask (or-ed bits value of EEPROM_INT_*)
\r
189 STATIC INLINE void IP_EEPROM_EnableInt(IP_EEPROM_001_T *pEEPROM, uint32_t mask)
\r
191 pEEPROM->INTENSET = mask;
\r
195 * @brief Disable EEPROM interrupt
\r
196 * @param pEEPROM : pointer to EEPROM peripheral block
\r
197 * @param mask : interrupt mask (or-ed bits value of EEPROM_INT_*)
\r
200 STATIC INLINE void IP_EEPROM_DisableInt(IP_EEPROM_001_T *pEEPROM, uint32_t mask)
\r
202 pEEPROM->INTENCLR = mask;
\r
206 * @brief Get the value of the EEPROM interrupt enable register
\r
207 * @param pEEPROM : pointer to EEPROM peripheral block
\r
208 * @return Or-ed bits value of EEPROM_INT_*
\r
210 STATIC INLINE uint32_t IP_EEPROM_GetIntEnable(IP_EEPROM_001_T *pEEPROM)
\r
212 return pEEPROM->INTEN;
\r
216 * @brief Get EEPROM interrupt status
\r
217 * @param pEEPROM : pointer to EEPROM peripheral block
\r
218 * @return Or-ed bits value of EEPROM_INT_*
\r
220 STATIC INLINE uint32_t IP_EEPROM_GetIntStatus(IP_EEPROM_001_T *pEEPROM)
\r
222 return pEEPROM->INTSTAT;
\r
226 * @brief Set EEPROM interrupt status
\r
227 * @param pEEPROM : pointer to EEPROM peripheral block
\r
228 * @param mask : interrupt mask (or-ed bits value of EEPROM_INT_*)
\r
231 STATIC INLINE void IP_EEPROM_SetIntStatus(IP_EEPROM_001_T *pEEPROM, uint32_t mask)
\r
233 pEEPROM->INTSTATSET = mask;
\r
237 * @brief Clear EEPROM interrupt status
\r
238 * @param pEEPROM : pointer to EEPROM peripheral block
\r
239 * @param mask : interrupt mask (or-ed bits value of EEPROM_INT_*)
\r
242 STATIC INLINE void IP_EEPROM_ClearIntStatus(IP_EEPROM_001_T *pEEPROM, uint32_t mask)
\r
244 pEEPROM->INTSTATCLR = mask;
\r
248 * @brief Initializes EEPROM
\r
249 * @param pEEPROM : pointer to EEPROM peripheral block
\r
250 * @param div : clock divide value (pre-minus 1)
\r
253 void IP_EEPROM_Init(IP_EEPROM_001_T *pEEPROM, uint32_t div);
\r
256 * @brief De-initializes EEPROM
\r
257 * @param pEEPROM : pointer to EEPROM peripheral block
\r
260 STATIC INLINE void IP_EEPROM_DeInit(IP_EEPROM_001_T *pEEPROM)
\r
262 /* Enable EEPROM power down mode */
\r
263 IP_EEPROM_EnablePowerDown(pEEPROM);
\r
267 * @brief Erase data in page register
\r
268 * @param pEEPROM : pointer to EEPROM peripheral block
\r
271 void IP_EEPROM_ErasePageRegister(IP_EEPROM_001_T *pEEPROM);
\r
274 * @brief Write data to page register
\r
275 * @param pEEPROM : pointer to EEPROM peripheral block
\r
276 * @param pageOffset : offset of data in page register(0 -> EEPROM_PAGE_SIZE-1)
\r
277 * @param pData : buffer that contain data that will be written to buffer
\r
278 * @param wsize : The number of bytes in each writting (1/2/4 bytes)
\r
279 * @param byteNum : number written data (bytes)
\r
280 * @return The bumber of byte written
\r
281 * @note The pageOffset must be aligned following selected mode.
\r
283 uint32_t IP_EEPROM_WritePageRegister(IP_EEPROM_001_T *pEEPROM, uint16_t pageOffset,
\r
284 uint8_t *pData, uint8_t wsize, uint32_t byteNum);
\r
287 * @brief Read data from non-volatile memory
\r
288 * @param pEEPROM : pointer to EEPROM peripheral block
\r
289 * @param pageOffset : offset of data in page register(0 -> EEPROM_PAGE_SIZE-1)
\r
290 * @param pageAddr : page address (0 ->EEPROM_PAGE_NUM -1 )
\r
291 * @param pData : buffer that contain data read from read data register
\r
292 * @param rsize : The number of bytes in each reading (1/2/4 bytes)
\r
293 * @param byteNum : number of read data (bytes)
\r
294 * @return The bumber of byte read
\r
295 * @note The pageOffset must be aligned following selected mode.
\r
297 uint32_t IP_EEPROM_ReadPage(IP_EEPROM_001_T *pEEPROM,
\r
298 uint16_t pageOffset,
\r
305 * @brief Erase/Program an EEPROM page
\r
306 * @param pEEPROM : pointer to EEPROM peripheral block
\r
307 * @param pageAddr : EEPROM page address (0-62)
\r
310 void IP_EEPROM_EraseProgramPage(IP_EEPROM_001_T *pEEPROM, uint16_t pageAddr);
\r
313 * @brief Wait for interrupt occurs
\r
314 * @param pEEPROM : pointer to EEPROM peripheral block
\r
315 * @param mask : expected interrupt
\r
318 void IP_EEPROM_WaitForIntStatus(IP_EEPROM_001_T *pEEPROM, uint32_t mask);
\r
321 * @brief Write data to EEPROM at specific address
\r
322 * @param pEEPROM : pointer to EEPROM peripheral block
\r
323 * @param pageOffset : offset of data in page register(0 -> EEPROM_PAGE_SIZE-1)
\r
324 * @param pageAddr : page address (0 ->EEPROM_PAGE_NUM -1 )
\r
325 * @param pData : buffer that contain data that will be written to buffer
\r
326 * @param wsize : Write size:<br>
\r
327 * - EEPROM_RWSIZE_8BITS : 8-bit read/write mode<br>
\r
328 * - EEPROM_RWSIZE_16BITS : 16-bit read/write mode<br>
\r
329 * - EEPROM_RWSIZE_32BITS : 32-bit read/write mode<br>
\r
330 * @param byteNum : number written data (bytes)
\r
331 * @return SUCCESS on successful write of data, or ERROR
\r
332 * @note The pageOffset must be aligned following selected mode. <br>
\r
333 * This function actually write data into EEPROM memory and automatically
\r
334 * write into next page if current page is overflowed
\r
336 Status IP_EEPROM_Write(IP_EEPROM_001_T *pEEPROM,
\r
337 uint16_t pageOffset,
\r
340 IP_EEPROM_RWSIZE_T wsize,
\r
344 * @brief Read data to EEPROM at specific address
\r
345 * @param pEEPROM : pointer to EEPROM peripheral block
\r
346 * @param pageOffset : offset of data in page register(0 -> EEPROM_PAGE_SIZE-1)
\r
347 * @param pageAddr : page address (0 ->EEPROM_PAGE_NUM -1 )
\r
348 * @param pData : buffer that contain data read from read data register
\r
349 * @param rsize : Read size:<br>
\r
350 * - EEPROM_RWSIZE_8BITS : 8-bit read/write mode<br>
\r
351 * - EEPROM_RWSIZE_16BITS : 16-bit read/write mode<br>
\r
352 * - EEPROM_RWSIZE_32BITS : 32-bit read/write mode<br>
\r
353 * @param byteNum : number read data (bytes)
\r
354 * @return SUCCESS on successful write of data, or ERROR
\r
355 * @note The pageOffset must be aligned following selected mode.
\r
357 Status IP_EEPROM_Read(IP_EEPROM_001_T *pEEPROM,
\r
358 uint16_t pageOffset,
\r
361 IP_EEPROM_RWSIZE_T rsize,
\r
365 * @brief Erase a page at the specific address
\r
366 * @param pEEPROM : pointer to EEPROM peripheral block
\r
367 * @param pageAddr : EEPROM page address (0-62)
\r
370 void IP_EEPROM_Erase(IP_EEPROM_001_T *pEEPROM, uint16_t pageAddr);
\r
380 #endif /* __EEPROM_001_H_ */
\r