diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index f4c2f1800..9f63f9d97 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -28,7 +28,7 @@ #include "menus.h" volatile uint8_t pinb=0, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0; -uint8_t portb, portc, dummyport; +uint8_t portb, portc, porth=0, dummyport; uint16_t dummyport16; const char *eepromFile; @@ -93,26 +93,39 @@ void *eeprom_write_function(void *) } uint8_t main_thread_running = 0; +char * main_thread_error = NULL; void *main_thread(void *) { - g_menuStack[0] = menuMainView; - g_menuStack[1] = menuProcModelSelect; +#ifdef SIMU_EXCEPTIONS + signal(SIGFPE, sig); + signal(SIGSEGV, sig); - eeReadAll(); //load general setup and selected model + try { +#endif + g_menuStack[0] = menuMainView; + g_menuStack[1] = menuProcModelSelect; - if (main_thread_running == 1) { - doSplash(); - checkLowEEPROM(); - checkTHR(); - checkSwitches(); - checkAlarm(); + eeReadAll(); //load general setup and selected model + + if (main_thread_running == 1) { + doSplash(); + checkLowEEPROM(); + checkTHR(); + checkSwitches(); + checkAlarm(); + } + + while (main_thread_running) { + perMain(); + usleep(1000); + } + return NULL; +#ifdef SIMU_EXCEPTIONS } - - while (main_thread_running) { - perMain(); - usleep(1000); + catch (...) { + main_thread_running = 0; } - return NULL; +#endif } pthread_t main_thread_pid; diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 3207ed9f4..dafd0478f 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -22,7 +22,40 @@ #ifndef simpgmspace_h #define simpgmspace_h +#ifdef SIMU_EXCEPTIONS +extern char * main_thread_error; +#include +#include +#include +#ifdef WIN32 +#define write_backtrace(output) +#else +#include +inline void write_backtrace(char *output) +{ + + void *buf[16]; + char **s; + int n = backtrace(buf,16); + s = backtrace_symbols(buf, n); + if (s) { + for(int i=0; i +#endif + #include #include #include @@ -64,7 +97,7 @@ extern sem_t eeprom_write_sem; #define PORTE dummyport #define PORTF dummyport #define PORTG dummyport -#define PORTH dummyport +#define PORTH porth #define DDRA dummyport #define DDRB dummyport #define DDRC dummyport @@ -131,7 +164,7 @@ extern sem_t eeprom_write_sem; #define INP_P_KEY_DWN 0 extern volatile unsigned char pinb,pinc,pind,pine,ping,pinh,pinj,pinl; -extern uint8_t portb, portc, dummyport; +extern uint8_t portb, portc, porth, dummyport; extern uint16_t dummyport16; extern uint8_t main_thread_running;