changeset 1000:c386ae6635e4 GasConsumption

Improve GNSS operation: during OSTC 4/5 code merge a problem with the wakeup of the gnss module showed up which has been fixed with the new verion. In addition a compile switch has been added which activated the synchronization of time between OSTC and gnss module. This my cause problems if the time is not accurate => deactivated at the moment.
author Ideenmodellierer
date Mon, 28 Apr 2025 19:51:36 +0200 (7 days ago)
parents ac25c35a3c97
children 21142f4fa968
files Common/Inc/configuration.h Small_CPU/Inc/GNSS.h Small_CPU/Inc/rtc.h Small_CPU/Inc/uartProtocol_GNSS.h Small_CPU/Src/baseCPU2.c Small_CPU/Src/gpio.c Small_CPU/Src/rtc.c Small_CPU/Src/scheduler.c Small_CPU/Src/uart.c Small_CPU/Src/uartProtocol_GNSS.c Small_CPU/Src/uart_Internal.c
diffstat 11 files changed, 166 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/configuration.h	Mon Apr 28 19:47:41 2025 +0200
+++ b/Common/Inc/configuration.h	Mon Apr 28 19:51:36 2025 +0200
@@ -73,11 +73,14 @@
 #define ENABLE_CO2_SUPPORT
 
 /* Enable to have external GPS sensor functionality available */
-/* #define ENABLE_GNSS_EXTERN */
+/*#define ENABLE_GNSS_EXTERN*/
 
 /* Enable to have internal (OSTC5) GPS sensor functionality available */
 #define ENABLE_GNSS_INTERN
 
+/* Enable to provide UTC time to GNSS module at startup. ! CAUTION ! Incorrect time will reduce performance of module */
+/* #define ENABLE_GNSS_TIME_INIT */
+
 /* Enable to have Sentinel rebreather interface available */
 /* #define ENABLE_SENTINEL_MODE */
 
--- a/Small_CPU/Inc/GNSS.h	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Inc/GNSS.h	Mon Apr 28 19:51:36 2025 +0200
@@ -101,6 +101,30 @@
 
 GNSS_StateHandle GNSS_Handle;
 
+typedef struct {
+	uint8_t header1;
+	uint8_t header2;
+    uint8_t msgClass;
+    uint8_t msgID;
+    uint16_t length;
+    uint8_t type;
+    uint8_t version;
+    uint8_t ref;
+    uint8_t leapsec;
+    uint16_t year;
+    uint8_t month;
+    uint8_t day;
+    uint8_t hour;
+    uint8_t minute;
+    uint8_t second;
+    uint8_t flags;
+    uint32_t nanoseconds;
+    uint16_t accuracy_seconds;
+    uint16_t reserved;
+    uint32_t accuracy_nano;
+
+}  __attribute__((packed)) UBX_MGA_INI_TIME_UTC_t;
+
 
 enum GNSSMode{Portable=0, Stationary=1, Pedestrian=2, Automotiv=3, Airbone1G=5, Airbone2G=6,Airbone4G=7,Wirst=8,Bike=9};
 
@@ -125,11 +149,13 @@
 
 static const uint8_t setPowerNormal[]={0xB5,0x62,0x06,0x86,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 
+/* UBX-CFG-NAV5 */
 static const uint8_t setPortableMode[]={0xB5,0x62,0x06,0x24,0x24,0x00,0xFF,0xFF,0x00,0x03,0x00,0x00,0x00,0x00,0x10,0x27,0x00,0x00,0x05,0x00,0xFA,0x00,0xFA,0x00,0x64,0x00,0x5E,0x01,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
 static const uint8_t setPedestrianMode[]={0xB5,0x62,0x06,0x24,0x24,0x00,0xFF,0xFF,0x03,0x03,0x00,0x00,0x00,0x00,0x10,0x27,0x00,0x00,0x05,0x00,0xFA,0x00,0xFA,0x00,0x64,0x00,0x5E,0x01,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 
 static const uint8_t setConfig[]={0xB5,0x62,0x06,0x09,0x0D,0x00, 0x00,0x00,0x00,0x00, 0x18,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x01};
+/* UBX-MGA-INI-TIME_UTC */
+static const uint8_t setDateTime[] = {0xB5,0x62,0x13,0x40,0x18,0x00,0x10,0x00,0x00,0x80,0x07,0xE9,0x01,0x02,0x03,0x04,0x05,0x00,0x01,0x02,0x03,0x04,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00};
 
 static const uint8_t setPortableType[]={};
 void GNSS_Init(GNSS_StateHandle *GNSS, UART_HandleTypeDef *huart);
--- a/Small_CPU/Inc/rtc.h	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Inc/rtc.h	Mon Apr 28 19:51:36 2025 +0200
@@ -41,6 +41,7 @@
 void RTC_SetDate(RTC_DateTypeDef sdatestructure);
 
 void RTC_GetTime(RTC_TimeTypeDef* pstimestructure);
+void RTC_GetDate(RTC_DateTypeDef* psdatestructure);
 
 #ifdef __cplusplus
 }
--- a/Small_CPU/Inc/uartProtocol_GNSS.h	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Inc/uartProtocol_GNSS.h	Mon Apr 28 19:51:36 2025 +0200
@@ -42,6 +42,7 @@
 		UART_GNSS_LOADCONF_1,
 		UART_GNSS_LOADCONF_2,
 		UART_GNSS_SETMODE_MOBILE,
+		UART_GNSS_SETDATE_TIME,
 		UART_GNSS_PWRDOWN,
 		UART_GNSS_PWRUP,
 		UART_GNSS_SETCONF,		/* save configuration */
@@ -74,6 +75,7 @@
 	GNSSCMD_LOADCONF_1,
 	GNSSCMD_LOADCONF_2,
 	GNSSCMD_SETMOBILE,
+	GNSSCMD_SETDATETIME,
 	GNSSCMD_MODE_PWS,
 	GNSSCMD_MODE_NORMAL,
 	GNSSCMD_SET_CONFIG,
--- a/Small_CPU/Src/baseCPU2.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/baseCPU2.c	Mon Apr 28 19:51:36 2025 +0200
@@ -483,7 +483,10 @@
 
 			MX_SPI3_Init();
 
-#if defined ENABLE_GNSS_INTERN || ENABLE_GNSS_EXTERN
+#if defined ENABLE_GNSS_INTERN || defined ENABLE_GNSS_EXTERN
+
+		do
+		{
 			if(GPIO_GetVersion() > 0)
 			{
 				if(shutdownTick == 0)
@@ -504,16 +507,18 @@
 #endif
 #endif
 #if defined ENABLE_GNSS_INTERN || defined ENABLE_GNSS_EXTERN
-			if((uartGnss_GetState() == UART_GNSS_INACTIVE) || (time_elapsed_ms(shutdownTick,HAL_GetTick()) > 3000))
+			if((uartGnss_GetState() == UART_GNSS_INACTIVE) || (time_elapsed_ms(shutdownTick,HAL_GetTick()) > 4000))
 			{
 				global.mode = MODE_SLEEP;
 				uartGnss_ReqPowerDown(0);	/* release power down request */
+				uartGnss_SetState(UART_GNSS_INACTIVE);
 			}
+
 #else
 			global.mode = MODE_SLEEP;
 #endif
 
-
+		}while (global.mode == MODE_SHUTDOWN);
 			break;
 
 		case MODE_SLEEP:
@@ -549,6 +554,8 @@
 				externalInterface_SwitchPower33(true);
 			}
 			externalInterface_InitDatastruct();
+			MX_USART6_UART_Init();
+			GNSS_Init(&GNSS_Handle, &huart6);
 			// EXTILine0_Button_DeInit(); not now, later after testing
 			break;
 		}
--- a/Small_CPU/Src/gpio.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/gpio.c	Mon Apr 28 19:51:36 2025 +0200
@@ -181,6 +181,8 @@
 
 void GPIO_Activate_V2(void)
 {
+	if(GPIO_Version == 0)
+	{
 	GPIO_Version = 1;
 	GPIO_LEDs_VIBRATION_Init();
 
@@ -191,6 +193,7 @@
 	MX_USART6_UART_Init();
 	GNSS_Init(&GNSS_Handle, &huart6);
 #endif
+	}
 }
 /* Private functions ---------------------------------------------------------*/
 
--- a/Small_CPU/Src/rtc.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/rtc.c	Mon Apr 28 19:51:36 2025 +0200
@@ -35,6 +35,11 @@
 	HAL_RTC_GetTime(&RTCHandle, pstimestructure, RTC_FORMAT_BIN);
 }
 
+void RTC_GetDate(RTC_DateTypeDef* psdatestructure)
+{
+	HAL_RTC_GetDate(&RTCHandle, psdatestructure, RTC_FORMAT_BIN);
+}
+
 void RTC_SetTime(RTC_TimeTypeDef stimestructure)
 {
 
--- a/Small_CPU/Src/scheduler.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/scheduler.c	Mon Apr 28 19:51:36 2025 +0200
@@ -1204,7 +1204,7 @@
 			global.mode = MODE_BOOT;
 		}
 		scheduleUpdateLifeData(2000);
-#ifdef ENABLE_GNSS_INTER
+#ifdef ENABLE_GNSS_INTERN
 		if(GPIO_GetVersion() > 0)
 		{
 			if(deepSleepCntDwn)
@@ -1250,6 +1250,10 @@
 		{
 			GPIO_GNSS_Init();
 		}
+		else
+		{
+			GNSS_IO_init();
+		}
 	}
 #endif
 }
--- a/Small_CPU/Src/uart.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/uart.c	Mon Apr 28 19:51:36 2025 +0200
@@ -26,6 +26,7 @@
 #include "uartProtocol_GNSS.h"
 #include "externalInterface.h"
 #include "data_exchange.h"
+#include "gpio.h"
 #include <string.h>	/* memset */
 
 #ifdef ENABLE_GNSS_INTERN
--- a/Small_CPU/Src/uartProtocol_GNSS.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/uartProtocol_GNSS.c	Mon Apr 28 19:51:36 2025 +0200
@@ -26,6 +26,7 @@
 #include "GNSS.h"
 #include "configuration.h"
 #include "externalInterface.h"
+#include "rtc.h"
 
 
 #if defined ENABLE_GNSS_INTERN || defined ENABLE_GNSS_EXTERN
@@ -88,6 +89,10 @@
 {
 	const uint8_t* pData;
 	uint8_t txLength = 0;
+	RTC_TimeTypeDef time;
+	RTC_DateTypeDef date;
+
+	UBX_MGA_INI_TIME_UTC_t msg_DateTime;
 
 	switch (GnssCmd)
 	{
@@ -121,6 +126,40 @@
 		case GNSSCMD_SET_CONFIG:	pData = setConfig;
 						  	  	  	txLength = sizeof(setConfig) / sizeof(uint8_t);
 				     break;
+		case GNSSCMD_SETDATETIME:
+		  							RTC_GetDate(&date);
+		  							RTC_GetTime(&time);
+
+									memset(&msg_DateTime, 0, sizeof(UBX_MGA_INI_TIME_UTC_t));
+									msg_DateTime.header1 = 0xB5;
+									msg_DateTime.header2 = 0x62;
+									msg_DateTime.msgClass = 0x13;
+									msg_DateTime.msgID = 0x40;
+									msg_DateTime.length = sizeof(UBX_MGA_INI_TIME_UTC_t) - 6;
+									msg_DateTime.type = 0x00;
+									msg_DateTime.version = 0x00;
+									msg_DateTime.year = date.Year + 2000;
+									msg_DateTime.month = date.Month;
+									msg_DateTime.day = date.Date;
+									if((time.Hours - 2) < 0)
+									{
+										msg_DateTime.hour = time.Hours + 24 - 2;
+									}
+									else
+									{
+										msg_DateTime.hour = time.Hours - 2;
+									}
+									msg_DateTime.minute = time.Minutes;
+									msg_DateTime.second =  time.Seconds;
+									msg_DateTime.accuracy_seconds = 60;
+									msg_DateTime.accuracy_nano = 0x0;
+									msg_DateTime.flags = 0x00;
+									msg_DateTime.leapsec = 0x80;
+
+									pData = (uint8_t*)&msg_DateTime;
+								  	txLength = sizeof(msg_DateTime) / sizeof(uint8_t);
+
+						     break;
 		default:
 			break;
 	}
@@ -165,9 +204,13 @@
 		case UART_GNSS_LOADCONF_2:	UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
 									rxState = GNSSRX_DETECT_ACK_0;
 				break;
-		case UART_GNSS_SETMODE_MOBILE: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
+		case UART_GNSS_SETMODE_MOBILE: UART_Gnss_SendCmd(GNSSCMD_SETMOBILE);
 									   rxState = GNSSRX_DETECT_ACK_0;
 				break;
+		case UART_GNSS_SETDATE_TIME: UART_Gnss_SendCmd(GNSSCMD_SETDATETIME);
+		   	   	   	   	   	   	   	// rxState = GNSSRX_DETECT_ACK_0;	/* aiding function will not acknoledge receiption (until config to do so) */
+									gnssState = UART_GNSS_PWRUP;
+				break;
 		case UART_GNSS_PWRDOWN:		UART_Gnss_SendCmd(GNSSCMD_MODE_PWS);
 									rxState = GNSSRX_DETECT_ACK_0;
 				break;
@@ -289,10 +332,18 @@
 													break;
 												case UART_GNSS_LOADCONF_2:	gnssState = UART_GNSS_SETMODE_MOBILE;
 													break;
-												case UART_GNSS_SETMODE_MOBILE:	rxState = GNSSRX_DETECT_ACK_0;
+												case UART_GNSS_SETMODE_MOBILE:
+#ifdef ENABLE_GNSS_TIME_INIT
+																				gnssState = UART_GNSS_SETDATE_TIME;
+#else
+																				rxState = GNSSRX_DETECT_ACK_0;
 																				UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL);
 																				gnssState = UART_GNSS_PWRUP;
+#endif
 													break;
+												case UART_GNSS_SETDATE_TIME: rxState = GNSSRX_DETECT_ACK_0;
+																				UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL);
+																				gnssState = UART_GNSS_PWRUP;
 												default:
 													break;
 											}
--- a/Small_CPU/Src/uart_Internal.c	Mon Apr 28 19:47:41 2025 +0200
+++ b/Small_CPU/Src/uart_Internal.c	Mon Apr 28 19:51:36 2025 +0200
@@ -64,6 +64,56 @@
 	GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
 	GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
 	HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+}
+
+void MX_USART6_DMA_Init() {
+	  /* DMA controller clock enable */
+	  __HAL_RCC_DMA2_CLK_ENABLE();
+
+	  /* DMA interrupt init */
+	  /* DMA2_Stream2_IRQn interrupt configuration */
+	  HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
+	  HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
+	  /* DMA2_Stream6_IRQn interrupt configuration */
+	  HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
+	  HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
+}
+
+
+void MX_USART6_UART_DeInit(void)
+{
+	HAL_DMA_Abort(&hdma_usart6_rx);
+	HAL_DMA_DeInit(&hdma_usart6_rx);
+	HAL_DMA_Abort(&hdma_usart6_tx);
+	HAL_DMA_DeInit(&hdma_usart6_tx);
+	HAL_UART_DeInit(&huart6);
+	//HAL_UART_DeInit(&huart6);
+	Uart6Ctrl.dmaRxActive = 0;
+	Uart6Ctrl.dmaTxActive = 0;
+}
+
+void MX_USART6_UART_Init(void) {
+	huart6.Instance = USART6;
+	huart6.Init.BaudRate = 9600;
+	huart6.Init.WordLength = UART_WORDLENGTH_8B;
+	huart6.Init.StopBits = UART_STOPBITS_1;
+	huart6.Init.Parity = UART_PARITY_NONE;
+	huart6.Init.Mode = UART_MODE_TX_RX;
+	huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+	huart6.Init.OverSampling = UART_OVERSAMPLING_16;
+	HAL_UART_Init(&huart6);
+
+	Uart6Ctrl.pHandle = &huart6;
+	Uart6Ctrl.dmaRxActive = 0;
+	Uart6Ctrl.dmaTxActive = 0;
+	Uart6Ctrl.pRxBuffer = rxBufferUart6;
+	Uart6Ctrl.pTxBuffer = txBufferUart6;
+	Uart6Ctrl.rxReadIndex = 0;
+	Uart6Ctrl.rxWriteIndex = 0;
+	Uart6Ctrl.txBufferQueLen = 0;
+
+	UART_clearRxBuffer(&Uart6Ctrl);
+	UART_SetGnssCtrl(&Uart6Ctrl);
 
 	/* USART6 DMA Init */
 	/* USART6_RX Init */
@@ -101,56 +151,6 @@
 	HAL_NVIC_EnableIRQ(USART6_IRQn);
 
 	MX_USART6_DMA_Init();
-
-}
-
-void MX_USART6_DMA_Init() {
-	  /* DMA controller clock enable */
-	  __HAL_RCC_DMA2_CLK_ENABLE();
-
-	  /* DMA interrupt init */
-	  /* DMA2_Stream2_IRQn interrupt configuration */
-	  HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
-	  HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
-	  /* DMA2_Stream6_IRQn interrupt configuration */
-	  HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
-	  HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
-}
-
-
-void MX_USART6_UART_DeInit(void)
-{
-	HAL_DMA_Abort(&hdma_usart6_rx);
-	HAL_DMA_DeInit(&hdma_usart6_rx);
-	HAL_DMA_Abort(&hdma_usart6_tx);
-	HAL_DMA_DeInit(&hdma_usart6_tx);
-	HAL_UART_DeInit(&huart6);
-	HAL_UART_DeInit(&huart6);
-}
-
-void MX_USART6_UART_Init(void) {
-	huart6.Instance = USART6;
-	huart6.Init.BaudRate = 9600;
-	huart6.Init.WordLength = UART_WORDLENGTH_8B;
-	huart6.Init.StopBits = UART_STOPBITS_1;
-	huart6.Init.Parity = UART_PARITY_NONE;
-	huart6.Init.Mode = UART_MODE_TX_RX;
-	huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
-	huart6.Init.OverSampling = UART_OVERSAMPLING_16;
-	HAL_UART_Init(&huart6);
-
-	UART_clearRxBuffer(&Uart6Ctrl);
-
-	Uart6Ctrl.pHandle = &huart6;
-	Uart6Ctrl.dmaRxActive = 0;
-	Uart6Ctrl.dmaTxActive = 0;
-	Uart6Ctrl.pRxBuffer = rxBufferUart6;
-	Uart6Ctrl.pTxBuffer = txBufferUart6;
-	Uart6Ctrl.rxReadIndex = 0;
-	Uart6Ctrl.rxWriteIndex = 0;
-	Uart6Ctrl.txBufferQueLen = 0;
-
-	UART_SetGnssCtrl(&Uart6Ctrl);
 }
 
 void UART6_HandleUART()
@@ -163,7 +163,9 @@
 
 	uartGnssStatus_t gnssState = uartGnss_GetState();
 
-		if(gnssState != UART_GNSS_INIT)
+	if(Uart6Ctrl.pHandle != 0)
+	{
+		if((gnssState != UART_GNSS_INIT) && (gnssState != UART_GNSS_PWRUP))
 		{
 			UART_ReadData(SENSOR_GNSS, 0);
 			UART_WriteData(&Uart6Ctrl);
@@ -186,7 +188,7 @@
 			uartGnss_SetState(gnssState);
 		}
 		else if(((retryRequest == 0)		/* timeout or error */
-				&& (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE))	/* retry if no answer after half request interval */
+				&& (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE) && (gnssState != UART_GNSS_PWRUP))	/* retry if no answer after half request interval */
 					|| (gnssState == UART_GNSS_ERROR))))
 		{
 			/* The channel switch will cause the sensor to respond with an error message. */
@@ -216,7 +218,7 @@
 			timeToTrigger = 0;
 			uartGnss_Control();
 		}
-
+	}
 }