diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | flash.c | 45 | ||||
-rw-r--r-- | flash.h | 11 | ||||
-rw-r--r-- | globals.c | 45 | ||||
-rw-r--r-- | globals.h | 5 | ||||
-rw-r--r-- | instr-daemon.c | 3 | ||||
-rw-r--r-- | parser.c | 9 |
7 files changed, 64 insertions, 55 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 882db13..9155bb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(instr-daemon instr-daemon.c globals.c i2c.c lcd.c + flash.c dummy_functions.c ) add_executable(instr-client instr-client.c) @@ -0,0 +1,45 @@ +#include "globals.h" + +int readUserBlock(FlashStruct *mem) +{ + // 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(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 + + // 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; + + // save the default Flash config, for nonvolatile persistence + writeUserBlock(mem, 0, sizeof(mem)); +} + + @@ -0,0 +1,11 @@ +#ifndef FLASH_H_ +#define FLASH_H_ + +#include "globals.h" + +void initFlash(FlashStruct *mem); +int readUserBlock(FlashStruct *mem); +void writeUserBlock(FlashStruct *mem, int addr, int numbytes); + +#endif + @@ -5,48 +5,3 @@ GlobalStruct globals = { .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)); -} - - @@ -400,10 +400,5 @@ 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 be023ec..ad63329 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -1,6 +1,7 @@ #include "socket-common.h" #include "response.h" #include "lcd.h" +#include "flash.h" #include "globals.h" #include <stdlib.h> #include <ctype.h> @@ -230,7 +231,7 @@ int main(int argc, char **argv) g_type_init (); LCD_initialize(); - initFlash (); + initFlash (&globals.Flash); //register stdin channel stdinChannel = g_io_channel_unix_new(0); @@ -10,6 +10,7 @@ END DESCRIPTION **********************************************************/ #include "parser.h" +#include "flash.h" #include <glib/gprintf.h> //STATICS @@ -902,7 +903,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(eprom_loc, strlen(store_string)+1); + writeUserBlock(&globals.Flash, eprom_loc, strlen(store_string)+1); return OK; } else { return OutOfRange; @@ -937,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(eprom_loc, sizeof (the_number)); + writeUserBlock(&globals.Flash, eprom_loc, sizeof (the_number)); return OK; break; @@ -970,7 +971,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(eprom_loc, sizeof(the_number)); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(the_number)); return OK; break; @@ -1003,7 +1004,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(eprom_loc, sizeof(the_number)); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(the_number)); return OK; break; |