1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "globals.h"
int readUserBlock(FlashStruct *mem)
{
// read the /root/flash.copy file into the mem struct
// and return the number of bytes read in
// if the file does not exist, then "return 0";
return 0;
}
void writeUserBlock(FlashStruct *mem, int addr, int numbytes)
{
// check if /root/flash.copy file exists
// - if it does, update the requested address and
// number of bytes, use fseek / fwrite / fflush
// - if does not, create the file and
// set addr = 0, numbytes = sizeof (mem)
// so that entire struct will be written,
// instead of just the requested range
// All writing should be done in a super-safe
// way. Non-corruption, even during a power-off transient,
// is the priority here. We do not want instruments
// losing configuration data ever, because that
// means expensive repairs.
}
void initFlash(FlashStruct *mem)
{
if (readUserBlock(mem) > 0) {
return;
}
// uninitialized device!
mem->flash_start = (char) 99;
strcpy(mem->aux_error_message,"FIXME");
mem->channels = (short) 1;
mem->enable_avrq_extra_ampls = (char) 12;
mem->ChanKey_frequency = (char) 0;
// much more needs to be added here - later
// save the default Flash config, for nonvolatile persistence
writeUserBlock(mem, 0, sizeof(*mem));
}
|