Thank you, mobyfab.
I actually did exactliy that and i now have the driver patially working but still have some questions.
First: this is my code for writing my variabls to eeprom:
i made a struct with arrays of pointer to whatever and sizes of the array elements:
Code: Select all
typedef struct {
void* ptr[3];
uint16_t sz[3];
} eeprom_data_t;
the three pointers point to the following:
Code: Select all
#define LENGTH 11
typedef struct{
float in[LENGTH]; // Array of x-coordinates
float out[LENGTH]; // Array of y-coordinates
uint8_t t_length; // Number of data points
} table_1d_t ;
typedef struct {
uint8_t screen; // screen
uint8_t bl; // backlight
uint8_t con; // contrast
} DisplayData_t;
typedef struct {
float corr_mult; // ADC Factors
int16_t corr_add;
uint8_t principle;
} correction_t;
And this are the values:
Code: Select all
correction_t corr_val[6] = {
{1.2, 0, 1},
{1.5, 0, 1},
{0.876, 0, 1},
{1.0, 0, 3},
{1.9, 0, 2},
{0.5, 12, 3}
};
table_1d_t tables[4] = {
{
{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, //in
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, //out
11 //length
},
{
{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, //in
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, //out
11 //length
},
{
{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, //in
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, //out
11, //length
},
{
{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}, //in
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, //out
11 //length
}
};
DisplayData_t DisplayData = {
0, //screen
127, //backlight
50 //contrast
};
eeprom_data_t ee_data = {
{tables, &DisplayData, corr_val}, //pointers to structs, array of structs,...
{sizeof(table_1d_t)*4, sizeof(DisplayData_t), sizeof(correction_t)*6} //sizes
};
Code: Select all
void cmd_dumpvar(BaseSequentialStream *chp, int argc, char *argv[]){
(void)argc;
(void)* argv;
uint16_t sz, bs, szc;
uint16_t i, idx, adr;
int16_t pos;
uint8_t* p;
uint8_t* b;
uint8_t buf[EEPROM_PAGE_SIZE];
uint8_t temp;
b=buf;
chprintf(chp, "Dumps Struct Variable\r\n");
sz = sizeof(ee_data.ptr)/sizeof(void*); //How many pointers are there
chprintf(chp, "Pointers: %d\r\n", sz);
szc = 0; //reset total size
adr = EEPROM_SETTINGS_START; //set start address
pos = eepfs_lseek(&EepromFile, adr);
if (pos != eepfs_getposition(&EepromFile)){
chprintf(chp, "EEPROM fseek Error\r\n");
return;
}
for (idx = 0; idx<sz; idx++){ //go through all the pointers
bs = ee_data.sz[idx]; //size of this data
szc += bs;
chprintf(chp, "size of ptr: %d\r\n", bs);
}
chprintf(chp, "size complete: %d\r\n", szc);
chprintf(chp, "%d pages\r\n", szc/EEPROM_PAGE_SIZE);
chprintf(chp, "%d rest\r\n", szc%EEPROM_PAGE_SIZE);
if (szc > EEPROM_SETTINGS_SIZE){
chprintf(chp, "size too big for eeprom!\r\n");
return;
}
idx = 0;
bs = ee_data.sz[idx]; //reusing variable
p=(uint8_t*)ee_data.ptr[idx]; //move pointer to first data bloc
for (i=0; i<szc; i++){ //go through ALL the bytes
if (i >= bs){ //we are at the end of one bloc
chprintf(chp, "old val: %x\r\n", temp);
p=(uint8_t*)ee_data.ptr[idx++]; //move pointer to next data bloc
bs += ee_data.sz[idx]; //calculate next boundary
chprintf(chp, "next bloc: %d\r\n", i);
chprintf(chp, "new val: %x\r\n", *p);
}
if ((i % EEPROM_PAGE_SIZE == 0) && (i>0)){ //if buffer is full...
fileStreamWrite(&EepromFile, buf, EEPROM_PAGE_SIZE);
b=buf; //reset buffer
chThdSleepMilliseconds(100);
chprintf(chp, "Page written\r\n");
adr += EEPROM_PAGE_SIZE; //next page
pos = eepfs_lseek(&EepromFile, adr);
if (pos != eepfs_getposition(&EepromFile)){
chprintf(chp, "EEPROM fseek Error\r\n");
return;
}
}
if (i%8 == 0){ //beautyfy the output a little
cli_println("");
}
chprintf(chp, "%x ", *p); //print val
*b = *p; //copy to buffer
temp = *p;
b++;
p++;
}
cli_println("");
if (szc > adr){
chprintf(chp, "More Data to write, szc: %d, adr: %d, pos: %d\r\n", szc, adr, eepfs_getposition(&EepromFile));
}
fileStreamWrite(&EepromFile, buf, (szc-adr));
for (i=0;i<szc-adr; i++){
chprintf(chp, "%x ", buf[i]); //print val
}
cli_println("");
}
my Questions:
do i have to take care of the time the eprom needs to write or can i dump the whole buffer to fileStreamWrite?
do i have to read first and compare to avoid uneccessary writes or does the driver do that?
is fileStreamWrite the correct function to write many bytes and do i have to take care of the page size?
Thats all for now.
When i manage to finish the eprom read i will post the code on bitbucket:
https://bitbucket.org/100prozent/rob-rt-stm32f100-discovery-shell-eeprom/src/default/