EEPROM in TG-LPC11U35-501

Dependents:   mbed_EEPROM USBMSD_step1 USBMSD_step1_5 picossd_step1_2cs

See https://mbed.org/users/yasuyuki/notebook/EEPROM/

Committer:
yasuyuki
Date:
Thu Jun 26 13:45:34 2014 +0000
Revision:
0:25e5bc71e65f
first revision

Who changed what in which revision?

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