From 6ce6b78ebee21e75a3aaf53969ff95aeaa5e7773 Mon Sep 17 00:00:00 2001 From: Anders Sandstrom Date: Tue, 18 Jan 2022 11:25:10 +0100 Subject: [PATCH] WIP: settings to file (eeprom) seems to work --- ecmc_plugin_grbl/ecmcPluginGrbl.c | 6 ++++-- grbl/eeprom.c | 22 +++++++++++----------- grbl/eeprom.h | 2 ++ grbl/protocol.c | 2 ++ grbl/settings.c | 3 ++- iocsh/ecmc_grbl_eeprom.txt | Bin 0 -> 1024 bytes 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ecmc_plugin_grbl/ecmcPluginGrbl.c b/ecmc_plugin_grbl/ecmcPluginGrbl.c index bc7d338..dbb17a3 100644 --- a/ecmc_plugin_grbl/ecmcPluginGrbl.c +++ b/ecmc_plugin_grbl/ecmcPluginGrbl.c @@ -52,7 +52,9 @@ int grblConstruct(char *configStr) lastConfStr = strdup(configStr); // Initialize system upon power-up. - serial_init(); // Setup serial baud rate and interrupts + //serial_init(); // Setup serial baud rate and interrupts + ecmc_init_file(); // create and clear file (simulated eeprom) + settings_restore(0b1111); // restore all to defaults settings_init(); // Load Grbl settings from EEPROM stepper_init(); // Configure stepper pins and interrupt timers system_init(); // Configure pinout pins and pin-change interrupt @@ -115,7 +117,7 @@ int grblConstruct(char *configStr) report_init_message(); // Start Grbl main loop. Processes program inputs and executes them. - protocol_main_loop(); + //protocol_main_loop(); This is for serial interface use.. comment out for now.. //} return 0; //createSocketCAN(configStr,getEcmcSampleTimeMS()); diff --git a/grbl/eeprom.c b/grbl/eeprom.c index 0807c3c..c254687 100644 --- a/grbl/eeprom.c +++ b/grbl/eeprom.c @@ -30,7 +30,7 @@ #include #include #define EEPROM_DUMMY_FILE "./ecmc_grbl_eeprom.txt" -#define EEPROM_MEM_SIZE 512 +#define EEPROM_MEM_SIZE 1024 char buffer[EEPROM_MEM_SIZE]; @@ -50,7 +50,7 @@ char buffer[EEPROM_MEM_SIZE]; unsigned char ecmc_mem_to_file(); // Init file void ecmc_init_file() { - printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); + printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); memset(&buffer[0],0,EEPROM_MEM_SIZE); ecmc_mem_to_file(); } @@ -58,7 +58,7 @@ void ecmc_init_file() { // Read file to buffer[] unsigned char ecmc_file_to_mem() { - printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); + //printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd"); @@ -80,7 +80,7 @@ unsigned char ecmc_file_to_mem() // Write buffer[] to file unsigned char ecmc_mem_to_file() { - printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); +// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); FILE* fh = fopen(EEPROM_DUMMY_FILE, "w"); @@ -110,9 +110,9 @@ unsigned char ecmc_mem_to_file() */ unsigned char eeprom_get_char( unsigned int addr ) { - printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); - ecmc_file_to_mem(); + //printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,buffer[addr]); + return buffer[addr]; //do {} while( EECR & (1< 0; size--) { checksum = (checksum << 1) || (checksum >> 7); diff --git a/grbl/eeprom.h b/grbl/eeprom.h index 6760262..671e847 100644 --- a/grbl/eeprom.h +++ b/grbl/eeprom.h @@ -29,4 +29,6 @@ void eeprom_put_char(unsigned int addr, unsigned char new_value); void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); + + #endif diff --git a/grbl/protocol.c b/grbl/protocol.c index 08ea48b..a5c3a8e 100644 --- a/grbl/protocol.c +++ b/grbl/protocol.c @@ -37,6 +37,8 @@ static void protocol_exec_rt_suspend(); */ void protocol_main_loop() { + printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); + // Perform some machine checks to make sure everything is good to go. #ifdef CHECK_LIMITS_AT_INIT if (bit_istrue(settings.flags, BITFLAG_HARD_LIMIT_ENABLE)) { diff --git a/grbl/settings.c b/grbl/settings.c index 6e34cc8..e2ce9f3 100644 --- a/grbl/settings.c +++ b/grbl/settings.c @@ -104,7 +104,7 @@ void write_global_settings() void settings_restore(uint8_t restore_flag) { if (restore_flag & SETTINGS_RESTORE_DEFAULTS) { settings = defaults; - write_global_settings(); + write_global_settings(); } if (restore_flag & SETTINGS_RESTORE_PARAMETERS) { @@ -129,6 +129,7 @@ void settings_restore(uint8_t restore_flag) { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); eeprom_put_char(EEPROM_ADDR_BUILD_INFO+1 , 0); // Checksum } + printf("%s:%s:%d settings_restore complete!!!..\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/iocsh/ecmc_grbl_eeprom.txt b/iocsh/ecmc_grbl_eeprom.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2a0b79cb9291cfe234e6a6b4c697b8cbae6298a0 100644 GIT binary patch literal 1024 zcmd;LV5o9N;9o#C6ffX$XMkY_kHZX5%*DVU$;iOKz;#{OCSQoz8mQL=$c2Ivjv)QN Vz`O=~2bl0EJsJX|Aut$20001q6B7Uc literal 0 HcmV?d00001