# HG changeset patch # User heinrichsweikamp # Date 1554799964 0 # Node ID c20c73b0d0346c7cb09e2b1d1a45aa535740e61d # Parent ad6ddc4aabcd57012ef8e7531c746cd6700a5fa4# Parent b7b481df4f22d9ebf0356b0984a6fe6f90da08ef Merged in janlmulder/ostc4/div-fixes-5 (pull request #15) Improvement SPI stability/recoverability and cleanup, and trivial bugfixes diff -r ad6ddc4aabcd -r c20c73b0d034 Discovery/Inc/tInfoCompass.h --- a/Discovery/Inc/tInfoCompass.h Sat Apr 06 09:41:14 2019 +0200 +++ b/Discovery/Inc/tInfoCompass.h Tue Apr 09 08:52:44 2019 +0000 @@ -30,7 +30,7 @@ /* Exported functions --------------------------------------------------------*/ void openInfo_Compass(void); -void refreshInfo_Compass(void); +void refreshInfo_Compass(GFX_DrawCfgScreen s); #endif /* TINFO_COMPASS_H */ diff -r ad6ddc4aabcd -r c20c73b0d034 Discovery/Src/t3.c --- a/Discovery/Src/t3.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Discovery/Src/t3.c Tue Apr 09 08:52:44 2019 +0000 @@ -37,7 +37,7 @@ #include "timer.h" #include "unit.h" -//* Importend function prototypes ---------------------------------------------*/ +//* Imported function prototypes ---------------------------------------------*/ extern uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium); /* Exported variables --------------------------------------------------------*/ @@ -799,7 +799,7 @@ t3_basics_colorscheme_mod(text); GFX_write_string(&FontT105,tXc1,text,1); } - else // NDL + else if(pDecoinfo->output_ndl_seconds) // NDL { snprintf(text,TEXTSIZE,"\032\f%c",TXT_Nullzeit); GFX_write_string(&FontT42,tXc1,text,0); diff -r ad6ddc4aabcd -r c20c73b0d034 Discovery/Src/tInfo.c --- a/Discovery/Src/tInfo.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Discovery/Src/tInfo.c Tue Apr 09 08:52:44 2019 +0000 @@ -210,7 +210,7 @@ if(inDebugMode()) tDebug_refresh(); else - refreshInfo_Compass(); + refreshInfo_Compass(tIscreen); if(inDebugMode() || (get_globalState() == StICOMPASS)) /* could be timeout and exitInfo */ GFX_SetFramesTopBottom(tIscreen.FBStartAdress, 0,480); diff -r ad6ddc4aabcd -r c20c73b0d034 Discovery/Src/tInfoCompass.c --- a/Discovery/Src/tInfoCompass.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Discovery/Src/tInfoCompass.c Tue Apr 09 08:52:44 2019 +0000 @@ -27,11 +27,13 @@ ////////////////////////////////////////////////////////////////////////////// /* Includes ------------------------------------------------------------------*/ + +#include "gfx_engine.h" +#include "gfx_fonts.h" +#include "tHome.h" +#include "tInfo.h" #include "tInfoCompass.h" -#include "gfx_fonts.h" -#include "tInfo.h" - #include /* Private variables ---------------------------------------------------------*/ @@ -59,8 +61,10 @@ /// @brief there is only compass_DX_f, compass_DY_f, compass_DZ_f output during this mode /// the accel is not called during this process // =============================================================================== -void refreshInfo_Compass(void) +void refreshInfo_Compass(GFX_DrawCfgScreen s) { + + tHome_show_lost_connection_count(&s); tInfoCompassTimeout--; if(tInfoCompassTimeout == 0) { @@ -94,7 +98,7 @@ } snprintf(text,80,"Time left: %u s",(tInfoCompassTimeout+9)/10); - tInfo_write_content_simple( 20,800, 20, &FontT42, text, CLUT_InfoCompass); + tInfo_write_content_simple( 20,800, 25, &FontT42, text, CLUT_InfoCompass); for(int i = 0; i<3;i ++) { diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Inc/scheduler.h --- a/Small_CPU/Inc/scheduler.h Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Inc/scheduler.h Tue Apr 09 08:52:44 2019 +0000 @@ -60,7 +60,6 @@ _Bool demo_mode; uint8_t dataSendToSlaveIsValid; uint8_t dataSendToSlavePending; - uint8_t dataSendToSlaveStopEval; uint32_t sync_error_count; uint32_t check_sync_not_running; uint8_t ButtonResponsiveness[4]; @@ -70,7 +69,7 @@ uint8_t accidentFlag; uint32_t accidentRemainingSeconds; uint8_t sensorError[MAX_SENSORS]; - uint8_t I2C_SystemStatus; + HAL_StatusTypeDef I2C_SystemStatus; } SGlobal; typedef struct diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/baseCPU2.c --- a/Small_CPU/Src/baseCPU2.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/baseCPU2.c Tue Apr 09 08:52:44 2019 +0000 @@ -48,7 +48,7 @@ [..] HAL_SPI_TxRxCpltCallback() restarts DMA and will call scheduleSpecial_Evaluate_DataSendToSlave() only if it is not blocked - by I2C for example by setting global.dataSendToSlaveStopEval to 0. + by I2C. If the evaluation is blocked it has to be tested and executed afterwards. I2C is executed _without_ the usage of interrupts. diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/batteryGasGauge.c --- a/Small_CPU/Src/batteryGasGauge.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/batteryGasGauge.c Tue Apr 09 08:52:44 2019 +0000 @@ -71,6 +71,21 @@ I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); } +static void disable_adc(void) +{ + uint8_t buffer[2]; + buffer[0] = 0x01; + + // according to the datasheet of the LTC2942, the adc shall + // be disabled when writing to the gauge registers + + // 0xF9 = 11111001: + // see init_battery_gas_gauge() + // Shutdown (1) + buffer[1] = 0xF9; + I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); +} + void battery_gas_gauge_get_data(void) { @@ -104,6 +119,7 @@ void battery_gas_gauge_set_charge_full(void) { + disable_adc(); #ifdef OSTC_ON_DISCOVERY_HARDWARE return; #endif @@ -113,11 +129,14 @@ bufferSend[1] = 0xFF; bufferSend[2] = 0xFF; I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); + init_battery_gas_gauge(); } void battery_gas_gauge_set(float percentage) { + + disable_adc(); #ifdef OSTC_ON_DISCOVERY_HARDWARE return; #endif @@ -135,6 +154,7 @@ bufferSend[1] = (uint8_t)(mAhSend / 256); bufferSend[2] = (uint8_t)(mAhSend & 0xFF); I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); + init_battery_gas_gauge(); } diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/i2c.c --- a/Small_CPU/Src/i2c.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/i2c.c Tue Apr 09 08:52:44 2019 +0000 @@ -23,12 +23,6 @@ } */ -HAL_StatusTypeDef I2C1_Status(void) -{ -return (HAL_StatusTypeDef)global.I2C_SystemStatus; -} - - GPIO_PinState HAL_I2C_Read_Data_PIN(void) { return HAL_GPIO_ReadPin(I2Cx_SDA_GPIO_PORT,I2Cx_SDA_PIN); @@ -66,21 +60,16 @@ I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; I2cHandle.Init.OwnAddress1 = 0x01; - - global.dataSendToSlaveStopEval = 1; global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED); HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F); - - - global.dataSendToSlaveStopEval = 0; if(global.dataSendToSlavePending) { scheduleSpecial_Evaluate_DataSendToSlave(); } - return (HAL_StatusTypeDef)global.I2C_SystemStatus; + return global.I2C_SystemStatus; } @@ -89,84 +78,37 @@ HAL_I2C_DeInit(&I2cHandle); } - -uint8_t i2c_errors = 0; +static uint8_t i2c_errors = 0; void I2C_Error_count(void) { i2c_errors++; } - -HAL_StatusTypeDef I2C_Master_TransmitNoStop( uint16_t DevAddress, uint8_t *pData, uint16_t Size) -{ - if(global.I2C_SystemStatus != HAL_OK) - return (HAL_StatusTypeDef)global.I2C_SystemStatus; - - global.dataSendToSlaveStopEval = 1; - - global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 0); - if(global.I2C_SystemStatus != HAL_OK) - { - I2C_Error_count(); - } - global.dataSendToSlaveStopEval = 0; - //TODO: REMOVE. -// if(global.dataSendToSlavePending) -// { -// scheduleSpecial_Evaluate_DataSendToSlave(); -// } - return (HAL_StatusTypeDef)global.I2C_SystemStatus; -} - - HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) { if(global.I2C_SystemStatus != HAL_OK) - return (HAL_StatusTypeDef)(global.I2C_SystemStatus & 0x03); - - - global.dataSendToSlaveStopEval = 1; + return global.I2C_SystemStatus; global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 2); if(global.I2C_SystemStatus != HAL_OK) { I2C_Error_count(); } - - global.dataSendToSlaveStopEval = 0; - //TODO: REMOVE. -// if(global.dataSendToSlavePending) -// { -// scheduleSpecial_Evaluate_DataSendToSlave(); -// } - return (HAL_StatusTypeDef)global.I2C_SystemStatus; + return global.I2C_SystemStatus; } - HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size) { if(global.I2C_SystemStatus != HAL_OK) - return (HAL_StatusTypeDef)global.I2C_SystemStatus; - - uint8_t localHALstatusReturn = 0xFF; + return global.I2C_SystemStatus; - global.dataSendToSlaveStopEval = 1; - - localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); - if(localHALstatusReturn != HAL_OK) + global.I2C_SystemStatus = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); + if(global.I2C_SystemStatus != HAL_OK) { I2C_Error_count(); } - global.dataSendToSlaveStopEval = 0; - //TODO: REMOVE. -// if(global.dataSendToSlavePending) -// { -// scheduleSpecial_Evaluate_DataSendToSlave(); -// } - - return (HAL_StatusTypeDef)localHALstatusReturn; + return global.I2C_SystemStatus; } - diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/pressure.c --- a/Small_CPU/Src/pressure.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/pressure.c Tue Apr 09 08:52:44 2019 +0000 @@ -29,7 +29,7 @@ at the beginning of a dive the oldest value will be used */ - +#include "scheduler.h" #include "pressure.h" #include "i2c.h" #include "rtc.h" @@ -261,7 +261,7 @@ C2_x_2p16 = C[2] * 65536; C1_x_2p15 = C[1] * 32768; - if(I2C1_Status() == HAL_OK) + if(global.I2C_SystemStatus == HAL_OK) { pressureSensorInitSuccess = 1; } @@ -360,7 +360,7 @@ void pressure_calculation(void) { - if(I2C1_Status() != HAL_OK) + if(global.I2C_SystemStatus != HAL_OK) return; pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Tue Apr 09 08:52:44 2019 +0000 @@ -48,10 +48,6 @@ /* Private types -------------------------------------------------------------*/ const SGas Air = {79,0,0,0,0}; -uint8_t testarrayindex = 0; -uint32_t testarray[256]; -uint32_t testarrayMain[256]; - /* Exported variables --------------------------------------------------------*/ SGlobal global; SDevice DeviceDataFlash; @@ -121,7 +117,7 @@ global.ButtonPICdata[2] = 0xFF; global.ButtonPICdata[3] = 0xFF; - global.I2C_SystemStatus = 0xFF; // 0x00 would be everything working + global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; @@ -415,8 +411,8 @@ /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the * function error handler */ + Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); SPI_Start_single_TxRx_with_Master(); - Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); } } @@ -437,10 +433,8 @@ float lastPressure_bar = 0.0f; global.dataSendToMaster.mode = MODE_DIVE; global.deviceDataSendToMaster.mode = MODE_DIVE; - //uint16_t counterSecondsShallowDepth = 0; uint8_t counter_exit = 0; - Scheduler.tickstart = HAL_GetTick() - 1000; Scheduler.counterSPIdata100msec = 0; Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; @@ -451,6 +445,7 @@ scheduleSetDate(&global.deviceData.diveCycles); global.lifeData.counterSecondsShallowDepth = 0; + Scheduler.tickstart = HAL_GetTick(); while(global.mode == MODE_DIVE) { schedule_check_resync(); @@ -1335,8 +1330,7 @@ //Supports threadsave copying!!! void copyPressureData(void) { - global.dataSendToMaster.sensorErrors = I2C1_Status(); - //uint8_t dataSendToMaster. + global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); diff -r ad6ddc4aabcd -r c20c73b0d034 Small_CPU/Src/spi.c --- a/Small_CPU/Src/spi.c Sat Apr 06 09:41:14 2019 +0200 +++ b/Small_CPU/Src/spi.c Tue Apr 09 08:52:44 2019 +0000 @@ -382,10 +382,6 @@ global.dataSendToMaster.power_on_reset = 0; global.deviceDataSendToMaster.power_on_reset = 0; - //TODO:REMOVE - // if ( !global.dataSendToSlaveStopEval ) { - // scheduleSpecial_Evaluate_DataSendToSlave(); - // } scheduleSpecial_Evaluate_DataSendToSlave(); SPI_Start_single_TxRx_with_Master();