changeset 728:5143e927219f

Added sensor map to Firmware <=> RTE inferface: The sensor map contains a list of up to five sensors which may be connected to the external interface. The update includes the definition of the type as well as the data structure. to ensure compatibility the RTE and needed RTE version has been set to 3.0
author Ideenmodellierer
date Sat, 14 Jan 2023 20:41:36 +0100
parents 1dca3bb187d7
children d646a0f724a7
files Common/Inc/data_central.h Common/Inc/data_exchange.h Common/Inc/settings.h Discovery/Src/data_exchange_main.c Discovery/Src/settings.c Small_CPU/Src/baseCPU2.c
diffstat 6 files changed, 91 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Sat Jan 14 20:37:20 2023 +0100
+++ b/Common/Inc/data_central.h	Sat Jan 14 20:41:36 2023 +0100
@@ -40,6 +40,9 @@
 #define false  0
 #define true 1
 
+#define EXT_INTERFACE_SENSOR_CNT	(5u)		/* 5 sensors may be connected to the external interface */
+
+
 /* Helper structs ------------------------------------------------------------*/
 
 //struct SGas
@@ -200,7 +203,7 @@
 	uint8_t extIf_sensor_Id;
 	uint8_t UINT64ALIGNMENT;					/* If your program crash check if you changed something in the life data structure ! The external sensor may contain a 64 bit ID */
 	uint8_t extIf_sensor_data[32];
-
+	uint8_t extIf_sensor_map[EXT_INTERFACE_SENSOR_CNT];
 
 	/* by create DiveSettings() and by setActualGas()
 	 * is send to Small CPU2 for nitrogen calculation
@@ -418,6 +421,16 @@
 		DECO_CALC_undefined
 };
 
+typedef enum
+{
+	 SENSOR_NONE,
+	 SENSOR_ANALOG,
+	 SENSOR_DIGO2,
+	 SENSOR_CO2,
+	 SENSOR_END
+} externalInterfaceSensorType;
+
+
 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
 
 void set_stateUsedToSim(void);
--- a/Common/Inc/data_exchange.h	Sat Jan 14 20:37:20 2023 +0100
+++ b/Common/Inc/data_exchange.h	Sat Jan 14 20:41:36 2023 +0100
@@ -43,11 +43,11 @@
 #define EXT_INTERFACE_UART_SENTINEL (0x0200u)	/* Activate Sentinel Backup monitor protocol */
 #define EXT_INTERFACE_UART_O2		(0x0400u)	/* Activate digital o2 sensor protocol (DiveO2) */
 
-/* Command subset for CO2 sensor */
-#define EXT_INTERFACE_CO2_CALIB 	(0x0001u)	/* Request calibration of CO2Sensor */
-
-/* Command subset for O2 sensor */
-#define EXT_INTERFACE_O2_INDICATE	(0x0001u)	/* Request LED to blink*/
+/* Command subset */
+#define EXT_INTERFACE_AUTODETECT 	(0x0001u)	/* Start auto detection of connected sensors	*/
+#define EXT_INTERFACE_COPY_SENSORMAP (0x0002u)	/* Use the sensor map provided by master for internal operations */
+#define EXT_INTERFACE_CO2_CALIB 	(0x0010u)	/* Request calibration of CO2Sensor */
+#define EXT_INTERFACE_O2_INDICATE	(0x0020u)	/* Request LED to blink*/
 
 #define DATA_BUFFER_ADC				(0x01u)
 #define DATA_BUFFER_CO2				(0x02u)
@@ -60,18 +60,18 @@
 	MODE_DIVE 		= 1,
 	MODE_CALIB 		= 2,
 	MODE_SLEEP 		= 3,
-	MODE_SHUTDOWN = 4,
+	MODE_SHUTDOWN   = 4,
 	MODE_ENDDIVE	= 5,
-	MODE_BOOT			= 6,
+	MODE_BOOT		= 6,
 	MODE_CHARGESTART = 7,
-	MODE_TEST			= 8,
+	MODE_TEST		= 8,
 	MODE_POWERUP 	= 9,
 };
 
 enum ACCIDENT_BITS
 {
-	ACCIDENT_DECOSTOP = 0x01,
-	ACCIDENT_CNS			= 0x02,
+	ACCIDENT_DECOSTOP 	= 0x01,
+	ACCIDENT_CNS		= 0x02,
 	ACCIDENT_CNSLVL2	= 0x02 + 0x04,
 	ACCIDENT_SPARE2		= 0x08,
 	ACCIDENT_SPARE3		= 0x10,
@@ -80,6 +80,7 @@
 	ACCIDENT_SPARE6		= 0x80
 };
 
+
 typedef struct{
 uint8_t button:1;
 uint8_t date:1;
@@ -190,7 +191,8 @@
 		uint8_t	alignmentdummy;
 		uint8_t externalInterface_SensorID;						/* Used to identify how to read the sensor data array */
 		uint8_t sensor_data[EXTIF_SENSOR_INFO_SIZE];			/* sensor specific data array. Content may vary from sensor type to sensor type */
-		uint8_t SPARE_OldWireless[10]; 							/* 64 - 12 for extADC - 6 for CO2 - 34 for sensor (+dummmy)*/
+		uint8_t sensor_map[EXT_INTERFACE_SENSOR_CNT];
+		uint8_t SPARE_OldWireless[5]; 							/* 64 - 12 for extADC - 6 for CO2 - 34 for sensor (+dummmy) - sensor map*/
 		// PIC data
 		uint8_t button_setting[4]; /* see dependency to SLiveData->buttonPICdata */
 		uint8_t SPARE1;
@@ -210,6 +212,8 @@
 
 		uint16_t externalInterface_Cmd;
 
+		uint8_t externalInterface_SensorMap[EXT_INTERFACE_SENSOR_CNT];
+
 		float UNUSED1[16-1];//VPM_adjusted_critical_radius_he[16];
 		float UNUSED2[16];//VPM_adjusted_critical_radius_n2[16];
 		float UNUSED3[16];//VPM_adjusted_crushing_pressure_he[16];
--- a/Common/Inc/settings.h	Sat Jan 14 20:37:20 2023 +0100
+++ b/Common/Inc/settings.h	Sat Jan 14 20:41:36 2023 +0100
@@ -85,7 +85,7 @@
 
 #define UART_MAX_PROTOCOL		(2u)
 
-#define FUTURE_SPARE_SIZE		(10u)		/* Applied for reuse of old, not used, scooter block (was 32 bytes)*/
+#define FUTURE_SPARE_SIZE		(5u)		/* Applied for reuse of old, not used, scooter block (was 32 bytes)*/
 
 typedef enum
 {
@@ -234,7 +234,7 @@
 
 	uint8_t scubberActiveId;									/* redefined in 0xFFFF0023 */
 	SScrubberData scrubberData[2];
-
+	uint8_t ext_sensor_map[5];
 	uint8_t Future_SPARE[FUTURE_SPARE_SIZE];					/* redefined in 0xFFFF0020 (old scooter Block was 32 byte)*/
 	// new in 0xFFFF0006
 	uint8_t ppo2sensors_deactivated;
--- a/Discovery/Src/data_exchange_main.c	Sat Jan 14 20:37:20 2023 +0100
+++ b/Discovery/Src/data_exchange_main.c	Sat Jan 14 20:41:36 2023 +0100
@@ -373,6 +373,10 @@
 	const SDiveState * pStateReal = stateRealGetPointer();
 	SSettings *settings = settingsGetPointer();
 
+	uint8_t SensorActive[SENSOR_END];
+	uint8_t index = 0;
+
+
 	if(get_globalState() == StStop)
 		dataOut.mode = MODE_SHUTDOWN;
 	else
@@ -392,15 +396,35 @@
 	dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad;
 
 
+	memcpy(dataOut.data.externalInterface_SensorMap, settings->ext_sensor_map, 5);
 
-	if((settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG) || (settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANADIG))
+	memset(SensorActive, 0, sizeof(SensorActive));
+	for (index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++)
 	{
-			externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON;
+		switch(settings->ext_sensor_map[index])
+		{
+			case SENSOR_ANALOG:	SensorActive[SENSOR_ANALOG] = 1;
+				break;
+			case SENSOR_DIGO2:	SensorActive[SENSOR_DIGO2] = 1;
+				break;
+			case SENSOR_CO2:	SensorActive[SENSOR_CO2] = 1;
+				break;
+			default:
+				break;
+		}
 	}
 
-	if((settings->ppo2sensors_source == O2_SENSOR_SOURCE_DIGITAL) || (settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANADIG))
+	if(SensorActive[SENSOR_ANALOG])
+	{
+		externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON;
+	}
+	if(SensorActive[SENSOR_DIGO2])
 	{
-			externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_O2;
+		externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_O2;
+	}
+	else if(SensorActive[SENSOR_CO2])		/* TODO: at the moment only one serial sensor is supported => else condition. to be changed once multiplexing is available */
+	{
+		externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2;		/* CO2 sensor has to be activated via auto detection */
 	}
 
 #ifdef ENABLE_SENTINEL_MODE
@@ -411,14 +435,6 @@
 	}
 #endif
 
-	if(settings->ext_uart_protocol)
-	{
-		externalInterface_Cmd |= (settings->ext_uart_protocol << 8);
-	}
-	if(settings->co2_sensor_active)
-	{
-		externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2;
-	}
 	dataOut.data.externalInterface_Cmd = externalInterface_Cmd;
 	externalInterface_Cmd = 0;
 
@@ -452,6 +468,7 @@
 		
 		settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness);
 		setButtonResponsiveness(settings->ButtonResponsiveness);
+		DataEX_setExtInterface_Cmd(EXT_INTERFACE_COPY_SENSORMAP);
 	}
 }
 
@@ -953,7 +970,7 @@
 				}
 				else
 				{
-					if((idx == 0) && ((pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_DIGITAL) || (pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_ANADIG)))
+					if(dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_map[idx] == SENSOR_DIGO2)
 					{
 						pStateReal->lifeData.ppO2Sensor_bar[idx] = pStateReal->lifeData.sensorVoltage_mV[idx] / 100.0;
 					}
@@ -968,6 +985,7 @@
 			{
 				memcpy(pStateReal->lifeData.extIf_sensor_data, dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_data, 32);
 			}
+			memcpy(pStateReal->lifeData.extIf_sensor_map, dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].sensor_map, EXT_INTERFACE_SENSOR_CNT);
 		}
 	}
 
--- a/Discovery/Src/settings.c	Sat Jan 14 20:37:20 2023 +0100
+++ b/Discovery/Src/settings.c	Sat Jan 14 20:41:36 2023 +0100
@@ -40,8 +40,8 @@
 
 SSettings Settings;
 
-const uint8_t RTErequiredHigh = 2;
-const uint8_t RTErequiredLow = 9;
+const uint8_t RTErequiredHigh = 3;
+const uint8_t RTErequiredLow = 0;
 
 const uint8_t FONTrequiredHigh = 1;
 const uint8_t FONTrequiredLow =	0;
@@ -87,7 +87,7 @@
  * There might even be entries with fixed values that have no range
  */
 const SSettings SettingsStandard = {
-    .header = 0xFFFF0023,
+    .header = 0xFFFF0024,
     .warning_blink_dsec = 8 * 2,
     .lastDiveLogId = 0,
     .logFlashNextSampleStartAddress = SAMPLESTART,
@@ -325,6 +325,11 @@
 	.scrubTimerMax_Obsolete = 0,
 	.scrubTimerCur_Obsolete = 0,
 	.scrubTimerMode = SCRUB_TIMER_OFF,
+	.ext_sensor_map[0] = SENSOR_ANALOG,
+	.ext_sensor_map[1] = SENSOR_ANALOG,
+	.ext_sensor_map[2] = SENSOR_ANALOG,
+	.ext_sensor_map[3] = SENSOR_NONE,
+	.ext_sensor_map[4] = SENSOR_NONE,
 };
 
 /* Private function prototypes -----------------------------------------------*/
@@ -518,6 +523,12 @@
     	pSettings->scrubberData[1].lastDive.Date = 0;
     	pSettings->scrubberData[1].lastDive.Year = 0;
     	// no break;
+    case 0xFFFF0023: pSettings->ext_sensor_map[0] = SENSOR_ANALOG;
+    				 pSettings->ext_sensor_map[1] = SENSOR_ANALOG;
+    				 pSettings->ext_sensor_map[2] = SENSOR_ANALOG;
+    				 pSettings->ext_sensor_map[3] = SENSOR_NONE;
+    				 pSettings->ext_sensor_map[4] = SENSOR_NONE;
+    	// no break;
     default:
         pSettings->header = pStandard->header;
         break; // no break before!!
@@ -1522,6 +1533,19 @@
     	Settings.ext_uart_protocol = 0;
     	corrections++;
     }
+    if((Settings.ext_sensor_map[0] >= SENSOR_END)
+    		|| (Settings.ext_sensor_map[1] >= SENSOR_END)
+			|| (Settings.ext_sensor_map[2] >= SENSOR_END)
+			|| (Settings.ext_sensor_map[3] >= SENSOR_END)
+			|| (Settings.ext_sensor_map[4] >= SENSOR_END))
+    {
+    	Settings.ext_sensor_map[0] = SENSOR_ANALOG;
+    	Settings.ext_sensor_map[1] = SENSOR_ANALOG;
+    	Settings.ext_sensor_map[2] = SENSOR_ANALOG;
+    	Settings.ext_sensor_map[3] = SENSOR_NONE;
+    	Settings.ext_sensor_map[4] = SENSOR_NONE;
+       	corrections++;
+    }
 
     if(corrections)
     {
--- a/Small_CPU/Src/baseCPU2.c	Sat Jan 14 20:37:20 2023 +0100
+++ b/Small_CPU/Src/baseCPU2.c	Sat Jan 14 20:41:36 2023 +0100
@@ -165,8 +165,8 @@
 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000.
 // See CPU2-RTE.ld
 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= {
-		.versionFirst = 2,
-		.versionSecond = 9,
+		.versionFirst = 3,
+		.versionSecond = 0,
 		.versionThird = 1,
 		.versionBeta = 1,