changeset 82:a6f0881074a4 kittz

+i2c analog noise filtering spi more stable
author Dmitry Romanov <kitt@bk.ru>
date Tue, 20 Nov 2018 12:08:19 +0300
parents cc2bb7bb8456
children ef4f45df70c1
files Discovery/Inc/data_exchange_main.h Discovery/Src/data_exchange_main.c Discovery/Src/settings.c Discovery/Src/tHome.c Small_CPU/Src/baseCPU2.c Small_CPU/Src/i2c.c Small_CPU/Src/scheduler.c Small_CPU/Src/spi.c ostc4pack/OSTC4_Firmware.bin ostc4pack/OSTC4_RTE.bin ostc4pack/OSTC4_RTE_upload.bin ostc4pack/OSTC4_firmware_upload.bin ostc4pack/step0_copy_bins.bat
diffstat 13 files changed, 79 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/data_exchange_main.h	Sat Oct 06 15:02:11 2018 +0200
+++ b/Discovery/Inc/data_exchange_main.h	Tue Nov 20 12:08:19 2018 +0300
@@ -39,6 +39,9 @@
 void DataEX_init(void);
 uint8_t DataEX_call(void);
 uint32_t DataEX_time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
+
+uint32_t get_num_SPI_CALLBACKS(void);
+SDataExchangeSlaveToMaster* get_dataInPointer(void);
 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag);
 void DataEX_copy_to_deco(void);
 void DateEx_copy_to_dataOut(void);
--- a/Discovery/Src/data_exchange_main.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Discovery/Src/data_exchange_main.c	Tue Nov 20 12:08:19 2018 +0300
@@ -327,6 +327,7 @@
 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */
 
 	SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE+1);
+	HAL_Delay(3);
 	if(SPI_DMA_answer != HAL_OK)
     DataEX_Error_Handler(SPI_DMA_answer);
 //HAL_Delay(3);
@@ -335,6 +336,31 @@
 	return 1;
 }
 
+
+uint32_t SPI_CALLBACKS;
+uint32_t get_num_SPI_CALLBACKS(void){
+	return SPI_CALLBACKS;
+}
+
+SDataExchangeSlaveToMaster* get_dataInPointer(void){
+	return &dataIn;
+}
+
+
+void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
+{
+
+
+	if(hspi == &cpu2DmaSpi)
+	{
+		SPI_CALLBACKS+=1;
+	}
+}
+
+
+
+
+
 void DateEx_copy_to_dataOut(void)
 {
 	const SDiveState * pStateReal = stateRealGetPointer();
--- a/Discovery/Src/settings.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Discovery/Src/settings.c	Tue Nov 20 12:08:19 2018 +0300
@@ -55,7 +55,7 @@
 {
     .versionFirst   = 1,
     .versionSecond 	= 4,
-    .versionThird   = 0,
+    .versionThird   = 1,
     .versionBeta    = 0,
 
     /* 4 bytes with trailing 0 */
--- a/Discovery/Src/tHome.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Discovery/Src/tHome.c	Tue Nov 20 12:08:19 2018 +0300
@@ -436,15 +436,33 @@
 
 uint8_t tHome_show_lost_connection_count(GFX_DrawCfgScreen *ScreenToWriteOn)
 {
-    return 0;
+//    return 0;
 
-    if(!DataEX_lost_connection_count())
-        return 0;
+//    if(!DataEX_lost_connection_count()) return 0;
 
     char text[10];
+//    if(get_DataEX_Error_place()) last_place=get_DataEX_Error_place();
 
-    snprintf(text,10,"\002   %i",DataEX_lost_connection_count());
-    Gfx_write_label_var(ScreenToWriteOn,  600,800, 0,&FontT48,CLUT_ButtonSymbols,text);
+//    if(get_DataEX_Error_Handler()) last_err=get_DataEX_Error_Handler();
+    SDataExchangeSlaveToMaster* dataIn=get_dataInPointer();
+
+    snprintf(text,10,"spi:\002%i",DataEX_lost_connection_count());
+    Gfx_write_label_var(ScreenToWriteOn,  600,800, 0,&FontT24,CLUT_ButtonSymbols,text);
+
+    snprintf(text,10,"\002%X%X%X%X",dataIn->header.checkCode[0],dataIn->header.checkCode[1],dataIn->header.checkCode[2],dataIn->header.checkCode[3]);
+    Gfx_write_label_var(ScreenToWriteOn,  600,800, 30,&FontT24,CLUT_ButtonSymbols,text);
+
+    snprintf(text,10,"\002%X%X%X%X",dataIn->footer.checkCode[0],dataIn->footer.checkCode[1],dataIn->footer.checkCode[2],dataIn->footer.checkCode[3]);
+    Gfx_write_label_var(ScreenToWriteOn,  600,800, 60,&FontT24,CLUT_ButtonSymbols,text);
+
+    snprintf(text,10,"---");
+       Gfx_write_label_var(ScreenToWriteOn,  600,800, 90,&FontT24,CLUT_ButtonSymbols,text);
+
+       snprintf(text,10,"cpt:\002%i",get_num_SPI_CALLBACKS());
+          Gfx_write_label_var(ScreenToWriteOn,  600,800, 120,&FontT24,CLUT_ButtonSymbols,text);
+
+//    snprintf(text,10,"i2c:\002%i",get_DataEX_Error_place());
+//    Gfx_write_label_var(ScreenToWriteOn,  600,800, 90,&FontT24,CLUT_ButtonSymbols,text);
 
     return DataEX_lost_connection_count();
 }
--- a/Small_CPU/Src/baseCPU2.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/baseCPU2.c	Tue Nov 20 12:08:19 2018 +0300
@@ -167,8 +167,8 @@
     =
     {
       .versionFirst = 1,
-      .versionSecond = 6,
-      .versionThird = 0,
+      .versionSecond = 5,
+      .versionThird = 2,
       .versionBeta = 0,
 
       /* 4 bytes with trailing 0 */
--- a/Small_CPU/Src/i2c.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/i2c.c	Tue Nov 20 12:08:19 2018 +0300
@@ -69,7 +69,7 @@
 {
 	I2cHandle.Instance             = I2Cx;
   I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
-  I2cHandle.Init.ClockSpeed      = 100000;//400000;
+  I2cHandle.Init.ClockSpeed      = 400000;//400000;
   I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
   I2cHandle.Init.DutyCycle       = I2C_DUTYCYCLE_16_9;
   I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
@@ -79,6 +79,8 @@
 	global.dataSendToSlaveStopEval = 1;
 
 	global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle);
+	HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED);
+
 
 	global.dataSendToSlaveStopEval = 0;
 	if(global.dataSendToSlavePending)
--- a/Small_CPU/Src/scheduler.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/scheduler.c	Tue Nov 20 12:08:19 2018 +0300
@@ -406,7 +406,8 @@
   */
 void schedule_check_resync(void)
 {
-	if((global.check_sync_not_running >= 10) || (global.dataSendToSlaveIsNotValidCount >= 2))
+	//TODO: (kittz) test for stability
+	if((global.check_sync_not_running >= 10))
 	{
 		global.dataSendToSlaveIsNotValidCount = 0;
 		global.check_sync_not_running = 0;
--- a/Small_CPU/Src/spi.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/spi.c	Tue Nov 20 12:08:19 2018 +0300
@@ -82,7 +82,7 @@
 			arrayInput[i] = 0xFE;
 		if(arrayInput[i] >= 15)
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = arrayInput[i];
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = arrayInput[i] - 10;
@@ -90,14 +90,14 @@
 		else
 		if(arrayInput[i] >= 10)
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = arrayInput[i];
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = arrayInput[i] - 5;
 		}
 		else
 		{
-			// copy - auslöse-schwelle
+			// copy - ausl�se-schwelle
 			rework[i+1] = 7;
 			// wieder-scharf-schalte-schwelle
 			rework[i+3+1] = 6;
@@ -339,6 +339,10 @@
 
 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
 {
+	/* restart SPI */
+if(hspi == &hspi1)
+	{
+
 	global.check_sync_not_running = 0;
 	/* stop data exchange? */
 	if(global.mode == MODE_SHUTDOWN)
@@ -353,41 +357,24 @@
 	/* data consistent? */
 	if(SPI_check_header_and_footer_ok())
 	{
-		GPIO_new_DEBUG_HIGH();
+//		GPIO_new_DEBUG_HIGH(); //For debug.
 		global.dataSendToSlaveIsValid = 1;
 		global.dataSendToSlaveIsNotValidCount = 0;
 	}
 	else
 	{
-		GPIO_new_DEBUG_LOW();
+//		GPIO_new_DEBUG_LOW(); //For debug.
 		global.dataSendToSlaveIsValid = 0;
 		global.dataSendToSlaveIsNotValidCount++;
 	}
 	global.dataSendToMaster.power_on_reset = 0;
 	global.deviceDataSendToMaster.power_on_reset = 0;
-	/* no i2c or other time critical threads? */
-	if(global.dataSendToSlaveIsValid)
-	{
-		if(!global.dataSendToSlaveStopEval)
+	if(!global.dataSendToSlaveStopEval)
 		{
-			scheduleSpecial_Evaluate_DataSendToSlave();
-		}
-		else
-		{
-			global.dataSendToSlavePending = 1;
+		scheduleSpecial_Evaluate_DataSendToSlave();
 		}
-	}
-	else
-	{
-		global.dataSendToSlavePending = 0;
-	}
-	
-	/* restart SPI */
-	if(hspi == &hspi1)
-	{
-		if(global.dataSendToSlaveIsValid)
-			SPI_Start_single_TxRx_with_Master();
-	}
+	SPI_Start_single_TxRx_with_Master();
+  }
 }
 
 
@@ -415,9 +402,10 @@
 
 static void SPI_Error_Handler(void)
 {
-  while(1)
-  {
-  }
+	//The device is locks. Hard to recover.
+//  while(1)
+//  {
+//  }
 }
 
 /**
Binary file ostc4pack/OSTC4_Firmware.bin has changed
Binary file ostc4pack/OSTC4_RTE.bin has changed
Binary file ostc4pack/OSTC4_RTE_upload.bin has changed
Binary file ostc4pack/OSTC4_firmware_upload.bin has changed
--- a/ostc4pack/step0_copy_bins.bat	Sat Oct 06 15:02:11 2018 +0200
+++ b/ostc4pack/step0_copy_bins.bat	Tue Nov 20 12:08:19 2018 +0300
@@ -1,3 +1,3 @@
-copy ..\RefPrj\Firmware\Release\OSTC4_Firmware.bin OSTC4_Firmware.bin /V /Y
-copy ..\RefPrj\RTE\Release\OSTC4_RTE.bin OSTC4_RTE.bin /V /Y
+copy D:\Kitt\Coding\AC6-workspace\OSTC4_Firmware\Debug\OSTC4_Firmware.bin OSTC4_Firmware.bin /V /Y
+copy D:\Kitt\Coding\AC6-workspace\OSTC4_RTE\Debug\OSTC4_RTE.bin OSTC4_RTE.bin /V /Y