changeset 939:f41974734268 Evo_2_23 tip

Resume UART com with gnss after sleep: Some changes were needed to get the communication up and running again after the gnns modul was set into power mode. The config needs to be safed at shutdown and the receiver needs to be wake up using dummy bytes before real communication may be resumed
author Ideenmodellierer
date Tue, 10 Dec 2024 21:03:04 +0100
parents df87dbfc9c21
children
files Small_CPU/Inc/GNSS.h Small_CPU/Inc/uartProtocol_GNSS.h Small_CPU/Src/uartProtocol_GNSS.c Small_CPU/Src/uart_Internal.c
diffstat 4 files changed, 47 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/GNSS.h	Tue Dec 10 21:00:55 2024 +0100
+++ b/Small_CPU/Inc/GNSS.h	Tue Dec 10 21:03:04 2024 +0100
@@ -117,7 +117,7 @@
 
 static const uint8_t setPowerLow[]={0xB5,0x62,0x06,0x86,0x08,0x00,0x00,0x02,0x78,0x00,0x14,0x00,0x00,0x00};
 
-static const uint8_t setPowerNormal[]={0xB5,0x62,0x06,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+static const uint8_t setPowerNormal[]={0xB5,0x62,0x06,0x86,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 
 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};
 
--- a/Small_CPU/Inc/uartProtocol_GNSS.h	Tue Dec 10 21:00:55 2024 +0100
+++ b/Small_CPU/Inc/uartProtocol_GNSS.h	Tue Dec 10 21:03:04 2024 +0100
@@ -41,6 +41,7 @@
 		UART_GNSS_LOADCONF_0,
 		UART_GNSS_LOADCONF_1,
 		UART_GNSS_LOADCONF_2,
+		UART_GNSS_SETMODE_MOBILE,
 		UART_GNSS_PWRDOWN,
 		UART_GNSS_PWRUP,
 		UART_GNSS_SETCONF,		/* save configuration */
@@ -72,6 +73,7 @@
   	GNSSCMD_LOADCONF_0 = 0,
 	GNSSCMD_LOADCONF_1,
 	GNSSCMD_LOADCONF_2,
+	GNSSCMD_SETMOBILE,
 	GNSSCMD_MODE_PWS,
 	GNSSCMD_MODE_NORMAL,
 	GNSSCMD_SET_CONFIG,
@@ -88,6 +90,7 @@
   } gnssRequest_s;
 
 void uartGnss_ReqPowerDown(uint8_t request);
+uint8_t uartGnss_isPowerDownRequested(void);
 uartGnssStatus_t uartGnss_GetState(void);
 void uartGnss_SetState(uartGnssStatus_t newState);
 void uartGnss_Control(void);
--- a/Small_CPU/Src/uartProtocol_GNSS.c	Tue Dec 10 21:00:55 2024 +0100
+++ b/Small_CPU/Src/uartProtocol_GNSS.c	Tue Dec 10 21:03:04 2024 +0100
@@ -66,10 +66,15 @@
 {
 	if(GnssConnected)
 	{
-		ReqPowerDown = 1;
+		ReqPowerDown = request;
 	}
 }
 
+uint8_t uartGnss_isPowerDownRequested()
+{
+	return ReqPowerDown;
+}
+
 uartGnssStatus_t uartGnss_GetState()
 {
 	return gnssState;
@@ -95,6 +100,9 @@
 		case GNSSCMD_LOADCONF_2:	pData = setGNSS;
 									txLength = sizeof(setGNSS) / sizeof(uint8_t);
 				break;
+		case GNSSCMD_SETMOBILE:		pData = setPortableMode;
+									txLength = sizeof(setPortableMode) / sizeof(uint8_t);
+				break;
 		case GNSSCMD_GET_PVT_DATA:	pData = getPVTData;
 									txLength = sizeof(getPVTData) / sizeof(uint8_t);
 			break;
@@ -157,12 +165,14 @@
 		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);
+									   rxState = GNSSRX_DETECT_ACK_0;
+				break;
 		case UART_GNSS_PWRDOWN:		UART_Gnss_SendCmd(GNSSCMD_MODE_PWS);
 									rxState = GNSSRX_DETECT_ACK_0;
 				break;
 
-		case UART_GNSS_PWRUP:
-		case UART_GNSS_INACTIVE:	UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL);
+		case UART_GNSS_PWRUP:		UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL);
 									rxState = GNSSRX_DETECT_ACK_0;
 									gnssState = UART_GNSS_PWRUP;
 				break;
@@ -264,30 +274,25 @@
 		case GNSSRX_DETECT_ACK_3:		if((data == 0x01))
 										{
 											rxState = GNSSRX_READY;
-											if(gnssState == UART_GNSS_PWRUP)
-											{
-												gnssState = UART_GNSS_IDLE;
-											}
-											else if(gnssState == UART_GNSS_PWRDOWN)
-											{
-												rxState = GNSSRX_DETECT_ACK_0;
-												UART_Gnss_SendCmd(GNSSCMD_SET_CONFIG);
-												gnssState = UART_GNSS_SETCONF;
-											}
-											else if(gnssState == UART_GNSS_SETCONF)
+											switch(gnssState)
 											{
-												gnssState = UART_GNSS_INACTIVE;
-											}
-											else if((gnssState >= UART_GNSS_LOADCONF_0) && (gnssState <= UART_GNSS_LOADCONF_2))
-											{
-												if(gnssState == UART_GNSS_LOADCONF_2)
-												{
-													gnssState = UART_GNSS_IDLE;
-												}
-												else
-												{
-													gnssState++;
-												}
+												case UART_GNSS_PWRUP: gnssState = UART_GNSS_IDLE;
+													break;
+												case UART_GNSS_PWRDOWN:	rxState = GNSSRX_DETECT_ACK_0;
+																		UART_Gnss_SendCmd(GNSSCMD_SET_CONFIG);
+																		gnssState = UART_GNSS_SETCONF;
+													break;
+												case UART_GNSS_SETCONF:	gnssState = UART_GNSS_INACTIVE;
+													break;
+												case UART_GNSS_LOADCONF_0:
+												case UART_GNSS_LOADCONF_1:	gnssState++;
+													break;
+												case UART_GNSS_LOADCONF_2:	gnssState = UART_GNSS_SETMODE_MOBILE;
+													break;
+												case UART_GNSS_SETMODE_MOBILE: gnssState = UART_GNSS_IDLE;
+													break;
+												default:
+													break;
 											}
 											GnssConnected = 1;
 										}
--- a/Small_CPU/Src/uart_Internal.c	Tue Dec 10 21:00:55 2024 +0100
+++ b/Small_CPU/Src/uart_Internal.c	Tue Dec 10 21:03:04 2024 +0100
@@ -158,7 +158,7 @@
 	static uint8_t retryRequest = 0;
 	static uint32_t lastRequestTick = 0;
 	static uint32_t TriggerTick = 0;
-	static uint8_t timeToTrigger = 0;
+	static uint16_t timeToTrigger = 0;
 	uint32_t tick =  HAL_GetTick();
 
 	uartGnssStatus_t gnssState = uartGnss_GetState();
@@ -175,6 +175,16 @@
 			timeToTrigger = 1;
 			retryRequest = 0;
 		}
+		else if((gnssState == UART_GNSS_INACTIVE) && (!uartGnss_isPowerDownRequested()))		/* send dummy bytes to wakeup receiver */
+		{
+			txBufferUart6[0] = 0xFF;
+			txBufferUart6[1] = 0xFF;
+			HAL_UART_Transmit_DMA(Uart6Ctrl.pHandle, Uart6Ctrl.pTxBuffer,2);
+			timeToTrigger = 500;						/* receiver needs 500ms for wakeup */
+			lastRequestTick = tick;
+			gnssState = UART_GNSS_PWRUP;
+			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 */
 					|| (gnssState == UART_GNSS_ERROR))))
@@ -194,7 +204,7 @@
 			retryRequest = 0;
 			timeToTrigger = 1;
 
-			if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT))	/* timeout */
+			if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT) || (gnssState == UART_GNSS_PWRUP))	/* timeout */
 			{
 				gnssState = UART_GNSS_IDLE;
 				uartGnss_SetState(gnssState);