How to use EEPROM in TG-LPC11U35-501
Dependencies: AQM0802 EEPROM mbed
EEPROM.h@0:8dfee9f6df54, 2014-06-22 (annotated)
- Committer:
- yasuyuki
- Date:
- Sun Jun 22 09:57:23 2014 +0000
- Revision:
- 0:8dfee9f6df54
first revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:8dfee9f6df54 | 1 | //********************** |
yasuyuki | 0:8dfee9f6df54 | 2 | // EEPROM.h for TG-LPC11U35-501 |
yasuyuki | 0:8dfee9f6df54 | 3 | // |
yasuyuki | 0:8dfee9f6df54 | 4 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:8dfee9f6df54 | 5 | // http://einstlab.web.fc2.com |
yasuyuki | 0:8dfee9f6df54 | 6 | //********************** |
yasuyuki | 0:8dfee9f6df54 | 7 | |
yasuyuki | 0:8dfee9f6df54 | 8 | #ifndef __ROMAPI_11U35_H_ |
yasuyuki | 0:8dfee9f6df54 | 9 | #define __ROMAPI_11U35_H_ |
yasuyuki | 0:8dfee9f6df54 | 10 | |
yasuyuki | 0:8dfee9f6df54 | 11 | #include "mbed.h" |
yasuyuki | 0:8dfee9f6df54 | 12 | |
yasuyuki | 0:8dfee9f6df54 | 13 | typedef enum { |
yasuyuki | 0:8dfee9f6df54 | 14 | CMD_SUCCESS = 0, // Command is executed successfully. |
yasuyuki | 0:8dfee9f6df54 | 15 | INVALID_COMMAND = 1, // Invalid command. |
yasuyuki | 0:8dfee9f6df54 | 16 | SRC_ADDR_ERROR = 2, // Source address is not on a word boundary. |
yasuyuki | 0:8dfee9f6df54 | 17 | DST_ADDR_ERROR = 3, // Destination address is not on a correct boundary. |
yasuyuki | 0:8dfee9f6df54 | 18 | SRC_ADDR_NOT_MAPPED = 4, // Source address is not mapped in the memory map. |
yasuyuki | 0:8dfee9f6df54 | 19 | DST_ADDR_NOT_MAPPED = 5, // Destination address is not mapped in the memory map. |
yasuyuki | 0:8dfee9f6df54 | 20 | COUNT_ERROR = 6, // Byte count is not multiple of 4 or is not a permitted value. |
yasuyuki | 0:8dfee9f6df54 | 21 | INVALID_SECTOR = 7, // Sector number is invalid. |
yasuyuki | 0:8dfee9f6df54 | 22 | SECTOR_NOT_BLANK = 8, // Sector is not blank. |
yasuyuki | 0:8dfee9f6df54 | 23 | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION = 9, // Command to prepare sector for write operation was not executed. |
yasuyuki | 0:8dfee9f6df54 | 24 | COMPARE_ERROR =10, // Source and destination data is not same. |
yasuyuki | 0:8dfee9f6df54 | 25 | BUSY = 11 // flash programming hardware interface is busy. |
yasuyuki | 0:8dfee9f6df54 | 26 | } IAPstatus; |
yasuyuki | 0:8dfee9f6df54 | 27 | |
yasuyuki | 0:8dfee9f6df54 | 28 | |
yasuyuki | 0:8dfee9f6df54 | 29 | typedef enum { |
yasuyuki | 0:8dfee9f6df54 | 30 | Prepare_sector = 50, |
yasuyuki | 0:8dfee9f6df54 | 31 | Copy_RAM_flash = 51, |
yasuyuki | 0:8dfee9f6df54 | 32 | Erase_sector = 52, |
yasuyuki | 0:8dfee9f6df54 | 33 | Blank_check_sector = 53, |
yasuyuki | 0:8dfee9f6df54 | 34 | Read_Part_ID = 54, |
yasuyuki | 0:8dfee9f6df54 | 35 | Read_Boot_version = 55, |
yasuyuki | 0:8dfee9f6df54 | 36 | Compare = 56, |
yasuyuki | 0:8dfee9f6df54 | 37 | Reinvoke_ISP = 57, |
yasuyuki | 0:8dfee9f6df54 | 38 | Read_UID = 58, |
yasuyuki | 0:8dfee9f6df54 | 39 | Erase_page = 59, |
yasuyuki | 0:8dfee9f6df54 | 40 | EEPROM_Write = 61, |
yasuyuki | 0:8dfee9f6df54 | 41 | EEPROM_Read = 62 |
yasuyuki | 0:8dfee9f6df54 | 42 | } IAPcommand; |
yasuyuki | 0:8dfee9f6df54 | 43 | |
yasuyuki | 0:8dfee9f6df54 | 44 | |
yasuyuki | 0:8dfee9f6df54 | 45 | #define IAP_LOCATION (0x1FFF1FF1UL) |
yasuyuki | 0:8dfee9f6df54 | 46 | typedef void (*IAP)(unsigned int[], unsigned int[]); |
yasuyuki | 0:8dfee9f6df54 | 47 | |
yasuyuki | 0:8dfee9f6df54 | 48 | |
yasuyuki | 0:8dfee9f6df54 | 49 | class EEPROM { |
yasuyuki | 0:8dfee9f6df54 | 50 | public: |
yasuyuki | 0:8dfee9f6df54 | 51 | EEPROM() : iap_entry( reinterpret_cast<IAP>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {} |
yasuyuki | 0:8dfee9f6df54 | 52 | |
yasuyuki | 0:8dfee9f6df54 | 53 | int write( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ); |
yasuyuki | 0:8dfee9f6df54 | 54 | int read( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ); |
yasuyuki | 0:8dfee9f6df54 | 55 | int put( unsigned int EEPROM_addr, char data ); |
yasuyuki | 0:8dfee9f6df54 | 56 | char get( unsigned int EEPROM_addr ); |
yasuyuki | 0:8dfee9f6df54 | 57 | |
yasuyuki | 0:8dfee9f6df54 | 58 | private: |
yasuyuki | 0:8dfee9f6df54 | 59 | IAP iap_entry; |
yasuyuki | 0:8dfee9f6df54 | 60 | unsigned int command[5]; |
yasuyuki | 0:8dfee9f6df54 | 61 | unsigned int status[4]; |
yasuyuki | 0:8dfee9f6df54 | 62 | char dat[1]; |
yasuyuki | 0:8dfee9f6df54 | 63 | int cclk_kHz; |
yasuyuki | 0:8dfee9f6df54 | 64 | }; |
yasuyuki | 0:8dfee9f6df54 | 65 | |
yasuyuki | 0:8dfee9f6df54 | 66 | |
yasuyuki | 0:8dfee9f6df54 | 67 | #endif /* __ROMAPI_11U35_H_ */ |