Index: webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c =================================================================== --- webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 37) +++ webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 39) @@ -104,4 +104,9 @@ +portTickType xLastSolarStateChangeTime; + + +int solarReadErrors = 0; + /* pototype section */ @@ -134,4 +139,5 @@ void initSolarFSM(void) { + xLastSolarStateChangeTime = xTaskGetTickCount(); xLastReadTime = xTaskGetTickCount(); solarState = SOL_NO_INIT; @@ -315,4 +321,14 @@ getUart3RxData(); + /* did the SolarFSM get stuck during reading? */ + if (xTaskGetTickCount() > xLastSolarStateChangeTime + 5000) + { + /* something has gone wrong (possible Rx Timeout). restart, state SOL_NO_INIT */ + xLastSolarStateChangeTime = xTaskGetTickCount(); + initSolarFSM(); + solarReadErrors++; + } + + switch (solarState) { @@ -323,4 +339,5 @@ /* send init 1 */ send_uart3((unsigned char *)init1, sizeof(init1)); + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_SENT_INIT; /* now wait for reply */ break; @@ -341,4 +358,5 @@ /* now ready to query channel 0 data in next state */ + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_CHAN; } @@ -377,4 +395,5 @@ case 6: /* we are through with all the channels, ready to send next init for next query round */ + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_FINISHED; break; @@ -384,4 +403,5 @@ if (solarState != SOL_FINISHED) { + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_CHAN_WAIT_REPLY; /* wait for reply if not finished */ } /* if */ @@ -443,4 +463,5 @@ currentChannel++; /* now ready to query channel data for next channel */ + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_CHAN; } @@ -448,4 +469,5 @@ { /* we received the finishing sequence */ + xLastSolarStateChangeTime = xTaskGetTickCount(); solarState = SOL_NO_INIT; /* restart the measurement cycle */ }