changeset 221:486dddfba7ce

Merged in Ideenmodellierer/ostc4/Improve_IPC_Sync (pull request #12) Improve IPC Sync
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Mon, 01 Apr 2019 09:01:09 +0000
parents 7012a521fa95 (current diff) e524a824d8f2 (diff)
children 9b4b3decd9ba 2ae6440cb8d6
files
diffstat 7 files changed, 190 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/base.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Discovery/Src/base.c	Mon Apr 01 09:01:09 2019 +0000
@@ -292,6 +292,8 @@
 uint8_t	updateButtonsToDefault = 0;
 uint8_t	wasFirmwareUpdateCheckBattery = 0;
 
+static DoDisplayRefresh = 0;	/* trigger to refresh display data */
+
 /* Private function prototypes -----------------------------------------------*/
 static void SystemClock_Config(void);
 static void Error_Handler(void);
@@ -304,7 +306,9 @@
 static void gotoSleep(void);
 static void deco_loop(void);
 static void resetToFirmwareUpdate(void);
-void EvaluateButton(void);
+static void TriggerButtonAction(void);
+static void EvaluateButton(void);
+static void RefreshDisplay(void);
 
 /* ITM Trace-------- ---------------------------------------------------------*/
 /*
@@ -495,6 +499,12 @@
             ext_flash_write_settings();
         }
         deco_loop();
+        TriggerButtonAction();
+        if(DoDisplayRefresh)
+        {
+	        DoDisplayRefresh = 0;
+        	RefreshDisplay();
+        }
 
 #ifdef DEBUG_RUNTIME
         translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime);
@@ -756,26 +766,13 @@
 
     get_globalStateList(&status);
 
-    switch(status.base)
+    if(status.base == BaseComm) /* main loop not serviced in com mode */
     {
-    case BaseHome:
-        tHome_refresh();
-        tM_check_content();
-        break;
-    case BaseMenu:
-        tM_refresh_live_content();
-        tMenuEdit_refresh_live_content();
-        break;
-    case BaseInfo:
-        tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
-        break;
-    case BaseComm:
-         tComm_refresh();
-        break;
-    default:
-        if(get_globalState() == StStop)
-            tHome_sleepmode_fun();
-        break;
+    	tComm_refresh();
+    }
+    else
+    {
+    	DoDisplayRefresh = 1;
     }
 }
 
@@ -830,6 +827,114 @@
 #endif
 }
 
+static void RefreshDisplay()
+{
+	SStateList status;
+	get_globalStateList(&status);
+	switch(status.base)
+	{
+	case BaseHome:
+		tHome_refresh();
+		tM_check_content();
+		break;
+	case BaseMenu:
+		tM_refresh_live_content();
+		tMenuEdit_refresh_live_content();
+		break;
+	case BaseInfo:
+		tInfo_refresh(); ///< only compass at the moment 23.Feb.2015 hw
+		break;
+	case BaseComm: 		/* refresh already done in tim callback */
+		break;
+	default:
+		if(get_globalState() == StStop)
+			tHome_sleepmode_fun();
+		break;
+	}
+}
+static uint8_t ButtonAction = ACTION_END;
+
+static void StoreButtonAction(uint8_t action)
+{
+	ButtonAction = action;
+}
+
+static void TriggerButtonAction()
+{
+	uint8_t action = ButtonAction;
+	SStateList status;
+
+	if(ButtonAction != ACTION_END)
+	{
+		get_globalStateList(&status);
+
+		if (action == ACTION_BUTTON_CUSTOM) {
+			GFX_screenshot();
+		}
+
+		switch (status.base) {
+		case BaseStop:
+			if (action == ACTION_BUTTON_BACK)
+				resetToFirmwareUpdate();
+			break;
+		case BaseComm:		/* already handled in tim callback */
+			break;
+		case BaseHome:
+			if (action == ACTION_BUTTON_NEXT) {
+				if (status.page == PageSurface)
+					openMenu(1);
+				else
+					tHomeDiveMenuControl(action);
+			} else if (action == ACTION_BUTTON_BACK) {
+				if (get_globalState() == StS)
+					openInfo(StILOGLIST);
+				else if ((status.page == PageDive)
+						&& (settingsGetPointer()->design < 7)) {
+					settingsGetPointer()->design = 7; // auto switch to 9 if necessary
+				} else if ((status.page == PageDive) && (status.line != 0)) {
+					if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT)
+						settingsGetPointer()->design = 3;
+					else if (settingsGetPointer()->extraDisplay
+							== EXTRADISPLAY_DECOGAME)
+						settingsGetPointer()->design = 4;
+
+					set_globalState(StD);
+				} else
+					tHome_change_field_button_pressed();
+			} else if (action == ACTION_BUTTON_ENTER) {
+				if ((status.page == PageDive) && (status.line == 0))
+					tHome_change_customview_button_pressed();
+				else if (status.page == PageSurface)
+					tHome_change_customview_button_pressed();
+				else
+					tHomeDiveMenuControl(action);
+			}
+			break;
+
+		case BaseMenu:
+			if (status.line == 0)
+				sendActionToMenu(action);
+			else
+				sendActionToMenuEdit(action);
+			break;
+
+		case BaseInfo:
+			if (status.page == InfoPageLogList)
+				sendActionToInfoLogList(action);
+			else if (status.page == InfoPageLogShow)
+				sendActionToInfoLogShow(action);
+			else
+				sendActionToInfo(action);
+			break;
+
+		default:
+			break;
+		}
+		ButtonAction = ACTION_END;
+	}
+}
+
+
 void EvaluateButton()
 {
 	uint8_t action = 0;
@@ -894,73 +999,17 @@
 	#endif
 
 		get_globalStateList(&status);
-
-		if (action == ACTION_BUTTON_CUSTOM) {
-			GFX_screenshot();
-		}
-
-		switch (status.base) {
-		case BaseStop:
-			if (action == ACTION_BUTTON_BACK)
-				resetToFirmwareUpdate();
-			break;
-		case BaseComm:
+		if(status.base == BaseComm) /* main loop is not serviced in comm mode => react immediately */
+		{
 			if (action == ACTION_BUTTON_BACK) {
 				settingsGetPointer()->bluetoothActive = 0;
 				MX_Bluetooth_PowerOff();
 				tComm_exit();
 			}
-			break;
-		case BaseHome:
-			if (action == ACTION_BUTTON_NEXT) {
-				if (status.page == PageSurface)
-					openMenu(1);
-				else
-					tHomeDiveMenuControl(action);
-			} else if (action == ACTION_BUTTON_BACK) {
-				if (get_globalState() == StS)
-					openInfo(StILOGLIST);
-				else if ((status.page == PageDive)
-						&& (settingsGetPointer()->design < 7)) {
-					settingsGetPointer()->design = 7; // auto switch to 9 if necessary
-				} else if ((status.page == PageDive) && (status.line != 0)) {
-					if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT)
-						settingsGetPointer()->design = 3;
-					else if (settingsGetPointer()->extraDisplay
-							== EXTRADISPLAY_DECOGAME)
-						settingsGetPointer()->design = 4;
-
-					set_globalState(StD);
-				} else
-					tHome_change_field_button_pressed();
-			} else if (action == ACTION_BUTTON_ENTER) {
-				if ((status.page == PageDive) && (status.line == 0))
-					tHome_change_customview_button_pressed();
-				else if (status.page == PageSurface)
-					tHome_change_customview_button_pressed();
-				else
-					tHomeDiveMenuControl(action);
-			}
-			break;
-
-		case BaseMenu:
-			if (status.line == 0)
-				sendActionToMenu(action);
-			else
-				sendActionToMenuEdit(action);
-			break;
-
-		case BaseInfo:
-			if (status.page == InfoPageLogList)
-				sendActionToInfoLogList(action);
-			else if (status.page == InfoPageLogShow)
-				sendActionToInfoLogShow(action);
-			else
-				sendActionToInfo(action);
-			break;
-
-		default:
-			break;
+		}
+		else
+		{
+			StoreButtonAction(action);	/* Handle action in main loop */
 		}
 		LastButtonPressed = INVALID_BUTTON;
 	}
--- a/Discovery/Src/tComm.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Discovery/Src/tComm.c	Mon Apr 01 09:01:09 2019 +0000
@@ -97,16 +97,18 @@
 uint8_t bluetoothActiveLastTime = 0;
 
 uint8_t StartListeningToUART = 0;
-char display_text[256] = { 0 };
+unsigned char display_text[256] = { 0 };
 
 uint8_t setForcedBluetoothName = 0;
 
 uint8_t updateSettingsAndMenuOnExit = 0;
 
 /* Private types -------------------------------------------------------------*/
-#define BYTE_DOWNLOAD_MODE	(0xBB)
+#define BYTE_DOWNLOAD_MODE		(0xBB)
 #define BYTE_SERVICE_MODE		(0xAA)
 
+#define UART_TIMEOUT_SECONDS	(120u)		/* Timeout for keeping connection open and waiting for data */
+
 const uint8_t id_Region1_firmware = 0xFF;
 const uint8_t id_RTE = 0xFE;
 const uint8_t id_FONT = 0x10;
@@ -399,6 +401,8 @@
 
 uint8_t openComm(uint8_t aRxByte)
 {
+	SStateList status;
+	uint8_t timeoutCounter = 0;
     uint8_t answer = 0;
     uint8_t service_mode_last_three_bytes[3];
     uint8_t service_mode_response[5] =
@@ -454,10 +458,22 @@
 uint8_t dbgptr = 0;
 debug[dbgptr++] = aRxByte;
 */
-    while((answer == prompt4D4C(receiveStartByteUart)) && (HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 120000)== HAL_OK))
+    while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS * 2)) 	/* Split 120 seconds timeout into 240 iterations a 500ms */
     {
+    	if(HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 500)!= HAL_OK) 							/* Timeout half a second */
+    	{
+    		timeoutCounter++;
+    		get_globalStateList(&status);
+    		if (status.base != BaseComm)
+    		{
+    			timeoutCounter = UART_TIMEOUT_SECONDS * 2; /* Abort action triggered outside main loop => exit */
+    		}
+    	}
+    	else
+    	{
 //		debug[dbgptr++] = aRxByte;
-        answer = select_mode(aRxByte);
+    		answer = select_mode(aRxByte);
+    	}
     }
     set_returnFromComm();
     return 1;
--- a/Discovery/Src/tMenuEdit.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Discovery/Src/tMenuEdit.c	Mon Apr 01 09:01:09 2019 +0000
@@ -1070,11 +1070,12 @@
         case ACTION_TIMEOUT:
         case ACTION_MODE_CHANGE:
             exitMenuEdit(1);
-        default:
             break;
         case ACTION_IDLE_TICK:
         case ACTION_IDLE_SECOND:
+        default:
             break;
+
         }
     }
     else
@@ -1094,11 +1095,12 @@
         case ACTION_TIMEOUT:
         case ACTION_MODE_CHANGE:
             exitMenuEditField();
-        default:
             break;
         case ACTION_IDLE_TICK:
         case ACTION_IDLE_SECOND:
             break;
+        default:
+            break;
         }
     }
     else
@@ -1114,11 +1116,12 @@
         case ACTION_TIMEOUT:
         case ACTION_MODE_CHANGE:
             exitMenuEdit(1);
-        default:
             break;
         case ACTION_IDLE_TICK:
         case ACTION_IDLE_SECOND:
             break;
+        default:
+            break;
         }
     }
 }
--- a/Discovery/Src/test_vpm.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Discovery/Src/test_vpm.c	Mon Apr 01 09:01:09 2019 +0000
@@ -345,7 +345,6 @@
             decotable_minutes[i] = ((float)input.decolistVPM.output_stop_length_seconds[i]) / 60.0f;
         }
     }
-    i = i;
     return true;
 }
 
@@ -403,7 +402,6 @@
             decotable_minutes[i] = ((float)input.decolistVPM.output_stop_length_seconds[i]) / 60.0f;
         }
     }
-    i = i;
     return true;
 }
 
@@ -462,7 +460,6 @@
             decotable_minutes[i] = ((float)input.decolistVPM.output_stop_length_seconds[i]) / 60.0f;
         }
     }
-    i = i;
     return true;
 }
 
--- a/Small_CPU/Inc/scheduler.h	Thu Mar 28 13:05:29 2019 +0000
+++ b/Small_CPU/Inc/scheduler.h	Mon Apr 01 09:01:09 2019 +0000
@@ -37,6 +37,9 @@
 #define SPI_SYNC_METHOD_SOFT	(2u)	/* Scheduler shall reset adjust counters to 100ms SPI data exchange cycle */
 #define SPI_SYNC_METHOD_INVALID	(4u)
 
+#define SCHEDULER_TICK_EXE1SEC	(980u) 	/* tick count based on cycle start which is used to trigger functions which */
+										/* shall be executed once in a second (20ms before cycle restarts) */
+
 typedef struct
 {
 	uint8_t mode;
@@ -82,6 +85,7 @@
 	uint8_t counterPressure100msec;
 	uint8_t counterCompass100msec;
 	uint8_t counterAmbientLight100msec;
+	uint32_t tick_execute1second;
 	uint32_t tickstart;
 } SScheduleCtrl;
 
--- a/Small_CPU/Src/compass.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Small_CPU/Src/compass.c	Mon Apr 01 09:01:09 2019 +0000
@@ -35,6 +35,7 @@
 #include "compass_LSM303DLHC.h"
 
 #include "i2c.h"
+#include "spi.h"
 #include "RTE_FlashAccess.h" // to store compass_calib_data
 
 #include "stm32f4xx_hal.h"
--- a/Small_CPU/Src/scheduler.c	Thu Mar 28 13:05:29 2019 +0000
+++ b/Small_CPU/Src/scheduler.c	Mon Apr 01 09:01:09 2019 +0000
@@ -458,7 +458,6 @@
 {
 	uint32_t ticksdiff = 0; 
 	uint32_t lasttick = 0;
-
 	uint8_t counterAscentRate = 0;
 	float lastPressure_bar = 0.0f;
 	global.dataSendToMaster.mode = MODE_DIVE;
@@ -471,6 +470,7 @@
 	Scheduler.counterCompass100msec = 0;
 	Scheduler.counterPressure100msec = 0;
 	Scheduler.counterAmbientLight100msec = 0;
+	Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
 	
 	global.deviceData.diveCycles.value_int32++;
 	scheduleSetDate(&global.deviceData.diveCycles);
@@ -542,12 +542,10 @@
 			Scheduler.counterAmbientLight100msec++;
 		}
 
-		//Evaluate tissues, toxic data, vpm, etc. once a second 
-		if(ticksdiff >= 1000)
+		//Evaluate tissues, toxic data, vpm, etc. once a second
+		if(ticksdiff >= Scheduler.tick_execute1second)
 		{
-			/* reset counter */
-			Scheduler.tickstart = HAL_GetTick();
-
+			Scheduler.tick_execute1second = 0xFFFFFFFF;	/* execute once only in the second cycle */
 			if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea)
 			{
 				scheduleUpdateLifeData(0); // includes tissues
@@ -642,10 +640,16 @@
 					init_pressure();
 				}
 			}
+		}
+		if(ticksdiff >= 1000)
+		{
+			/* reset counter */
+			Scheduler.tickstart = HAL_GetTick();
 			Scheduler.counterSPIdata100msec = 0;
 			Scheduler.counterCompass100msec = 0;
 			Scheduler.counterPressure100msec = 0;
 			Scheduler.counterAmbientLight100msec = 0;
+			Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
 		}
 	}
 }
@@ -735,7 +739,6 @@
 
 
 
-
 void scheduleSurfaceMode(void)
 {
 
@@ -746,6 +749,7 @@
 	Scheduler.counterCompass100msec = 0;
 	Scheduler.counterPressure100msec = 0;
 	Scheduler.counterAmbientLight100msec = 0;
+	Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
 
 	global.dataSendToMaster.mode = MODE_SURFACE;
 	global.deviceDataSendToMaster.mode = MODE_SURFACE;
@@ -762,14 +766,14 @@
 				setButtonsNow = 0;
 		}
 		
-		//Evaluate received data at 10 ms, 110 ms, 210 ms,...
+		/* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */
 		if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
 		{
 			SPI_Evaluate_RX_Data();
 			Scheduler.counterSPIdata100msec++;
 		}
 
-		//Evaluate pressure at 20 ms, 120 ms, 220 ms,...
+		/* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */
 		if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
 		{
 				global.check_sync_not_running++;
@@ -783,7 +787,7 @@
 					global.mode = MODE_DIVE;
 		}
 		
-		//Evaluate compass data at 50 ms, 150 ms, 250 ms,...
+		/* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */
 		if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50)
 		{
 			compass_read();
@@ -793,19 +797,20 @@
 			Scheduler.counterCompass100msec++;
 		}
 
-		//evaluate compass data at 70 ms, 170 ms, 270 ms,...
+		/* evaluate compass data at 70 ms, 170 ms, 270 ms,... duration <1ms */
 		if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70)
 		{
 			adc_ambient_light_sensor_get_data();
 			copyAmbientLightData();
 			Scheduler.counterAmbientLight100msec++;
 		}
-		//Evaluate tissues, toxic data, etc. once a second
-		if(ticksdiff >= 1000)
+
+
+
+		/*  Evaluate tissues, toxic data, etc. once a second... duration ~1ms */
+		if(ticksdiff >= Scheduler.tick_execute1second)
 		{
-			//Set back tick counter
-			Scheduler.tickstart = HAL_GetTick();
-
+			Scheduler.tick_execute1second = 0xFFFFFFFF;
 			if(clearDecoNow)
 			{
 				decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time
@@ -867,10 +872,17 @@
 					init_pressure();
 				}
 			}
+		}
+
+		if(ticksdiff >= 1000)
+		{
+			//Set back tick counter
+			Scheduler.tickstart = HAL_GetTick();
 			Scheduler.counterSPIdata100msec = 0;
 			Scheduler.counterCompass100msec = 0;
 			Scheduler.counterPressure100msec = 0;
 			Scheduler.counterAmbientLight100msec = 0;
+			Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
 		}
 	}
 }