2008-12-05 14:17:04 +00:00
|
|
|
|
|
|
|
//EEPPROM compatibility support for simulator
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define EEPROM_SIZE 1024
|
|
|
|
|
|
|
|
static FILE * fp;
|
|
|
|
|
|
|
|
static uint8_t eemem[EEPROM_SIZE];
|
|
|
|
|
|
|
|
static uint8_t inited;
|
|
|
|
static void init(){
|
|
|
|
if(!inited){
|
|
|
|
inited = 1;
|
|
|
|
char* filename = ".simulated_eeprom.bin";
|
|
|
|
size_t size;
|
|
|
|
fp = fopen(filename, "r+");
|
|
|
|
if(fp == 0){
|
|
|
|
fp = fopen(filename, "w+");
|
|
|
|
if(fp == 0){
|
|
|
|
printf("Failed to open %s\n",filename );
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size = fread (eemem, 1, EEPROM_SIZE, fp);
|
|
|
|
if(size < EEPROM_SIZE){
|
|
|
|
memset(eemem, 0xff, EEPROM_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 02:18:20 +00:00
|
|
|
extern uint8_t _eeprom_start__[];
|
|
|
|
|
2010-04-22 21:49:26 +00:00
|
|
|
uint16_t conv_addr(void * p){
|
2008-12-05 14:17:04 +00:00
|
|
|
uint16_t addr;
|
2010-04-22 21:49:26 +00:00
|
|
|
addr = (unsigned long)p - (unsigned long)_eeprom_start__;
|
2008-12-05 14:17:04 +00:00
|
|
|
if(addr >= EEPROM_SIZE){
|
|
|
|
printf ("warning: eeprom write to %X\n",addr);
|
|
|
|
}
|
|
|
|
addr &= (EEPROM_SIZE-1);
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void eeprom_write_byte (uint8_t *p, uint8_t value){
|
2009-02-19 00:46:02 +00:00
|
|
|
printf("sim eeprom write [%04X]=%02X\n", conv_addr(p), value);
|
2008-12-05 14:17:04 +00:00
|
|
|
init();
|
|
|
|
eemem[conv_addr(p)] = value;
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
fwrite(eemem, 1, EEPROM_SIZE, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void eeprom_write_word (uint16_t *p, uint16_t value){
|
2009-02-19 00:46:02 +00:00
|
|
|
printf("sim eeprom write [%04X]=%04X\n", conv_addr(p), value);
|
|
|
|
|
2008-12-05 14:17:04 +00:00
|
|
|
init();
|
2009-01-02 02:18:20 +00:00
|
|
|
eemem[conv_addr((uint8_t*)p) ] = value & 0xff;
|
|
|
|
eemem[conv_addr((uint8_t*)p)+1] = value >> 8;
|
2008-12-05 14:17:04 +00:00
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
fwrite(eemem, 1, EEPROM_SIZE, fp);
|
|
|
|
fflush(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t eeprom_read_byte (uint8_t *p){
|
|
|
|
init();
|
|
|
|
return eemem[conv_addr(p)];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t eeprom_read_word (uint16_t *p){
|
|
|
|
init();
|
2009-01-02 02:18:20 +00:00
|
|
|
return eemem[conv_addr((uint8_t*)p)] | (eemem[conv_addr((uint8_t*)p)+1]<<8);
|
2008-12-05 14:17:04 +00:00
|
|
|
}
|