LPC1549 EEPROM
Embed:
(wiki syntax)
Show/hide line numbers
eeprom.cpp
Go to the documentation of this file.
00001 // OKANO's IAP code from 00002 // http://mbed.org/users/okano/notebook/iap-in-application-programming-internal-flash-eras/ 00003 /** 00004 * @file 00005 */ 00006 00007 #include "mbed.h" 00008 #include "eeprom.h " 00009 00010 enum command_code 00011 { 00012 IAPCommand_EEPROM_Write = 61, 00013 IAPCommand_EEPROM_Read, 00014 }; 00015 00016 #define IAP_LOCATION 0x3000205 00017 typedef void (*IAP_call)(unsigned int [], unsigned int []); 00018 00019 IAP_call iap_entry = reinterpret_cast<IAP_call>(IAP_LOCATION); 00020 unsigned int IAP_command[ 5 ]; 00021 unsigned int IAP_result[ 5 ]; 00022 int cclk_kHz = SystemCoreClock / 1000; 00023 00024 /** Copy RAM to EEPROM (LPC11U24) 00025 * 00026 * @param source_addr Source RAM address from which data bytes are to be read. 00027 * @param target_addr Destination EEPROM address where data bytes are to be written. 00028 * @param size Number of bytes to be written. 00029 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED 00030 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to. 00031 */ 00032 int write_eeprom( char *source_addr, char *target_addr, int size ) { 00033 IAP_command[ 0 ] = IAPCommand_EEPROM_Write; 00034 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. 00035 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. 00036 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. 00037 IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz. 00038 00039 iap_entry( IAP_command, IAP_result ); 00040 00041 return ( (int)IAP_result[ 0 ] ); 00042 } 00043 00044 /** Copy EEPROM to RAM (LPC11U24) 00045 * 00046 * @param source_addr Source EEPROM address from which data bytes are to be read. 00047 * @param target_addr Destination RAM address where data bytes are to be written. 00048 * @param size Number of bytes to be written. 00049 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED 00050 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to. 00051 */ 00052 int read_eeprom( char *source_addr, char *target_addr, int size ) { 00053 IAP_command[ 0 ] = IAPCommand_EEPROM_Read; 00054 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. 00055 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. 00056 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. 00057 IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz. 00058 00059 iap_entry( IAP_command, IAP_result ); 00060 00061 return ( (int)IAP_result[ 0 ] ); 00062 }
Generated on Tue Aug 30 2022 00:28:04 by
1.7.2