summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-16 11:32:25 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-16 11:32:25 -0400
commit53b0084de1e0b3cdb94fd345a03911f80ebcb784 (patch)
treeb757518dbaf8b3845fb34d6a22cbef00301dd3fa
parent51aec80f5b733b25e0875e22f82537fd31eb4ee4 (diff)
add function to initialize Flash
-rw-r--r--dummy_functions.c20
-rw-r--r--dummy_functions.h2
-rw-r--r--globals.c50
-rw-r--r--globals.h6
-rw-r--r--instr-daemon.c2
-rw-r--r--parser.c8
6 files changed, 57 insertions, 31 deletions
diff --git a/dummy_functions.c b/dummy_functions.c
index 9f3abb3..1d36581 100644
--- a/dummy_functions.c
+++ b/dummy_functions.c
@@ -10,23 +10,3 @@ void GPIB_Set_Execution_Error() {}
void Main_update_shift_registers() { }
void Error_check(void* p) { }
-int readUserBlock(FlashStruct mem)
-{
- // read the flash.copy file into the FlashStruct
- // 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 flash.copy file exists
- // - if it does, update the requested address and
- // number of bytes
-
- // - 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
-}
diff --git a/dummy_functions.h b/dummy_functions.h
index a00569f..7c2833c 100644
--- a/dummy_functions.h
+++ b/dummy_functions.h
@@ -11,6 +11,4 @@ void GPIB_Set_Device_Dependent_Error();
void GPIB_Set_Execution_Error();
void Main_update_shift_registers();
void Error_check(void*);
-int readUserBlock(FlashStruct mem);
-void writeUserBlock(FlashStruct mem, int addr, int numbytes);
#endif
diff --git a/globals.c b/globals.c
index 8324fed..66007d3 100644
--- a/globals.c
+++ b/globals.c
@@ -2,11 +2,51 @@
GlobalStruct globals = {
.ChannelState = {0.0},
- .Flash = { .flash_start = (char) 99,
- .aux_error_message="FIXME",
- .channels = (short) 1,
- .enable_avrq_extra_ampls = (char) 12,
- .ChanKey_frequency = (char) 0 },
.error_queue = {0},
.number_of_errors = 0
};
+
+
+int readUserBlock(void)
+{
+ // read the flash.copy file into the globals.Flash struct
+ // and return the number of bytes read in
+
+ // if the file does not exist, then "return 0";
+ return 0;
+}
+
+void writeUserBlock(int addr, int numbytes)
+{
+ // check if flash.copy file exists
+ // - if it does, update the requested address and
+ // number of bytes
+
+ // - 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(void)
+{
+ if (readUserBlock() > 0) return;
+
+ // uninitialized device!
+ globals.Flash.flash_start = (char) 99;
+ strcpy(globals.Flash.aux_error_message,"FIXME");
+ globals.Flash.channels = (short) 1;
+ globals.Flash.enable_avrq_extra_ampls = (char) 12;
+ globals.Flash.ChanKey_frequency = (char) 0;
+
+ // save the default Flash config, for nonvolatile persistence
+ writeUserBlock(0, sizeof(globals.Flash));
+}
+
+
diff --git a/globals.h b/globals.h
index 51a641b..79f3362 100644
--- a/globals.h
+++ b/globals.h
@@ -399,5 +399,11 @@ typedef struct {
extern GlobalStruct globals;
+
+void initFlash(void);
+int readUserBlock(void);
+void writeUserBlock(int addr, int numbytes);
+
+
#endif
diff --git a/instr-daemon.c b/instr-daemon.c
index f4bd0b2..be023ec 100644
--- a/instr-daemon.c
+++ b/instr-daemon.c
@@ -1,6 +1,7 @@
#include "socket-common.h"
#include "response.h"
#include "lcd.h"
+#include "globals.h"
#include <stdlib.h>
#include <ctype.h>
@@ -229,6 +230,7 @@ int main(int argc, char **argv)
g_type_init ();
LCD_initialize();
+ initFlash ();
//register stdin channel
stdinChannel = g_io_channel_unix_new(0);
diff --git a/parser.c b/parser.c
index c53222c..e5466c1 100644
--- a/parser.c
+++ b/parser.c
@@ -902,7 +902,7 @@ static int Go_Str_eprom_47(gchar** response, int channel, char *loc_string,char
*(char *)(&globals.Flash.flash_start + eprom_loc+i)=store_string[i];
}
*(char *)(&globals.Flash.flash_start + eprom_loc + i)=(char) 0; /* end of string */
- writeUserBlock(globals.Flash, eprom_loc, strlen(store_string)+1);
+ writeUserBlock(eprom_loc, strlen(store_string)+1);
return OK;
} else {
return OutOfRange;
@@ -938,7 +938,7 @@ static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char
case command_param_units:
the_number=(short) atoi(store_string);
*(short *)(&globals.Flash.flash_start + eprom_loc) = the_number;
- writeUserBlock(globals.Flash, eprom_loc, sizeof (the_number));
+ writeUserBlock(eprom_loc, sizeof (the_number));
return OK;
break;
@@ -972,7 +972,7 @@ static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char
case command_param_units:
the_number=atof(store_string);
*(float *)(&globals.Flash.flash_start + eprom_loc)=the_number;
- writeUserBlock(globals.Flash, eprom_loc, sizeof(the_number));
+ writeUserBlock(eprom_loc, sizeof(the_number));
return OK;
break;
@@ -1006,7 +1006,7 @@ static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char
case command_param_units:
the_number=(char) atoi(store_string);
*(char *)(&globals.Flash.flash_start + eprom_loc)=the_number;
- writeUserBlock(globals.Flash, eprom_loc, sizeof(the_number));
+ writeUserBlock(eprom_loc, sizeof(the_number));
return OK;
break;