LPC11U24 internal EEPROM

Dependents:   ver1_2_2_1

Committer:
okini3939
Date:
Sat Aug 04 11:36:21 2012 +0000
Revision:
0:c32514e75196
Child:
1:724b44e46ecf
bugfix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:c32514e75196 1 /**
okini3939 0:c32514e75196 2 * @file
okini3939 0:c32514e75196 3 */
okini3939 0:c32514e75196 4
okini3939 0:c32514e75196 5 #include "mbed.h"
okini3939 0:c32514e75196 6 #include "eeprom.h"
okini3939 0:c32514e75196 7
okini3939 0:c32514e75196 8 enum command_code
okini3939 0:c32514e75196 9 {
okini3939 0:c32514e75196 10 IAPCommand_EEPROM_Write = 61,
okini3939 0:c32514e75196 11 IAPCommand_EEPROM_Read,
okini3939 0:c32514e75196 12 };
okini3939 0:c32514e75196 13
okini3939 0:c32514e75196 14 #define IAP_LOCATION 0x1fff1ff1
okini3939 0:c32514e75196 15 typedef void (*IAP_call)(unsigned int [], unsigned int []);
okini3939 0:c32514e75196 16
okini3939 0:c32514e75196 17 IAP_call iap_entry = reinterpret_cast<IAP_call>(IAP_LOCATION);
okini3939 0:c32514e75196 18 unsigned int IAP_command[ 5 ];
okini3939 0:c32514e75196 19 unsigned int IAP_result[ 5 ];
okini3939 0:c32514e75196 20 int cclk_kHz = SystemCoreClock / 1000;
okini3939 0:c32514e75196 21
okini3939 0:c32514e75196 22 /** Copy RAM to EEPROM (LPC11U24)
okini3939 0:c32514e75196 23 *
okini3939 0:c32514e75196 24 * @param source_addr Source RAM address from which data bytes are to be read.
okini3939 0:c32514e75196 25 * @param target_addr Destination EEPROM address where data bytes are to be written.
okini3939 0:c32514e75196 26 * @param size Number of bytes to be written.
okini3939 0:c32514e75196 27 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
okini3939 0:c32514e75196 28 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
okini3939 0:c32514e75196 29 */
okini3939 0:c32514e75196 30 int write_eeprom( char *source_addr, char *target_addr, int size ) {
okini3939 0:c32514e75196 31 IAP_command[ 0 ] = IAPCommand_EEPROM_Write;
okini3939 0:c32514e75196 32 IAP_command[ 1 ] = (unsigned int)target_addr; // Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary.
okini3939 0:c32514e75196 33 IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary.
okini3939 0:c32514e75196 34 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
okini3939 0:c32514e75196 35 IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.
okini3939 0:c32514e75196 36
okini3939 0:c32514e75196 37 iap_entry( IAP_command, IAP_result );
okini3939 0:c32514e75196 38
okini3939 0:c32514e75196 39 return ( (int)IAP_result[ 0 ] );
okini3939 0:c32514e75196 40 }
okini3939 0:c32514e75196 41
okini3939 0:c32514e75196 42 /** Copy EEPROM to RAM (LPC11U24)
okini3939 0:c32514e75196 43 *
okini3939 0:c32514e75196 44 * @param source_addr Source EEPROM address from which data bytes are to be read.
okini3939 0:c32514e75196 45 * @param target_addr Destination RAM address where data bytes are to be written.
okini3939 0:c32514e75196 46 * @param size Number of bytes to be written.
okini3939 0:c32514e75196 47 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
okini3939 0:c32514e75196 48 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
okini3939 0:c32514e75196 49 */
okini3939 0:c32514e75196 50 int read_eeprom( char *source_addr, char *target_addr, int size ) {
okini3939 0:c32514e75196 51 IAP_command[ 0 ] = IAPCommand_EEPROM_Read;
okini3939 0:c32514e75196 52 IAP_command[ 1 ] = (unsigned int)source_addr; // Source EEPROM address from which data bytes are to be read. This address should be a word boundary.
okini3939 0:c32514e75196 53 IAP_command[ 2 ] = (unsigned int)target_addr; // Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary.
okini3939 0:c32514e75196 54 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
okini3939 0:c32514e75196 55 IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.
okini3939 0:c32514e75196 56
okini3939 0:c32514e75196 57 iap_entry( IAP_command, IAP_result );
okini3939 0:c32514e75196 58
okini3939 0:c32514e75196 59 return ( (int)IAP_result[ 0 ] );
okini3939 0:c32514e75196 60 }