Mercurial > public > ostc4
changeset 104:22a1094545f3 kittz
Tested and alive.
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Mon, 24 Dec 2018 16:15:02 +0300 |
parents | f5d2f02dc73f |
children | 68181cd61f20 |
files | Common/Inc/global_constants.h Discovery/Src/base.c Discovery/Src/data_exchange_main.c Discovery/Src/ostc.c Discovery/Src/settings.c Discovery/Src/tHome.c Small_CPU/Inc/spi.h Small_CPU/Src/baseCPU2.c Small_CPU/Src/compass.c Small_CPU/Src/i2c.c Small_CPU/Src/scheduler.c Small_CPU/Src/spi.c Small_CPU/Src/stm32f4xx_it_v3.c ostc4pack/OSTC4_Firmware.bin ostc4pack/OSTC4_RTE.bin ostc4pack/OSTC4_RTE_upload.bin ostc4pack/OSTC4_firmware_upload.bin |
diffstat | 17 files changed, 115 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/Common/Inc/global_constants.h Wed Nov 28 09:36:33 2018 +0300 +++ b/Common/Inc/global_constants.h Mon Dec 24 16:15:02 2018 +0300 @@ -38,7 +38,7 @@ //Spi sync data debug #define SPI_SHOW_SYNC_STATS 1 -#define SPI_MIN_ERROR_SHOW 2 +#define SPI_MIN_ERROR_SHOW 10 //Text data
--- a/Discovery/Src/base.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Discovery/Src/base.c Mon Dec 24 16:15:02 2018 +0300 @@ -656,21 +656,20 @@ switch (status.base) { case BaseHome: // added hw 161027 - if (!(stateRealGetPointer()->warnings.lowBattery) - && (stateRealGetPointer()->lifeData.battery_charge > 9)) { - stateRealGetPointerWrite()->lastKnownBatteryPercentage = - stateRealGetPointer()->lifeData.battery_charge; - } else if ((wasFirmwareUpdateCheckBattery) - && (timeout_in_seconds > 3)) { + if (!(stateRealGetPointer()->warnings.lowBattery) && (stateRealGetPointer()->lifeData.battery_charge > 9)) { + stateRealGetPointerWrite()->lastKnownBatteryPercentage =stateRealGetPointer()->lifeData.battery_charge; + } else if ((wasFirmwareUpdateCheckBattery) && (timeout_in_seconds > 3)) { wasFirmwareUpdateCheckBattery = 0; - setButtonResponsiveness( - settingsGetPointer()->ButtonResponsiveness); // added 170306 - if ((settingsGetPointer()->lastKnownBatteryPercentage > 0) - && (settingsGetPointer()->lastKnownBatteryPercentage - <= 100) - && (stateRealGetPointer()->warnings.lowBattery)) { - setBatteryPercentage( - settingsGetPointer()->lastKnownBatteryPercentage); + setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); // added 170306 + if ((settingsGetPointer()->lastKnownBatteryPercentage > 0) && + (settingsGetPointer()->lastKnownBatteryPercentage <= 100) && + (stateRealGetPointer()->warnings.lowBattery)) + { +// If PowerOff, and battery is <=100, and lifeData.battery_charge < 10 - ALWAYS!!! set DataOutnewBatteryGaugePercentageFloat +// Need to fix in smallCPU handled. Compeled. + //upd.Fixed. + setBatteryPercentage(settingsGetPointer()->lastKnownBatteryPercentage); + } } // stuff before and new @161121 CCR-sensor limit 10 minutes
--- a/Discovery/Src/data_exchange_main.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Discovery/Src/data_exchange_main.c Mon Dec 24 16:15:02 2018 +0300 @@ -306,7 +306,7 @@ uint8_t SPI_DMA_answer = 0; HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); - delayMicros(50); //~exchange time(+20% reserve) + delayMicros(20); //~exchange time(+20% reserve) HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); /* one cycle with NotChipSelect true to clear slave spi buffer */ @@ -330,6 +330,7 @@ // HAL_Delay(3); if(SPI_DMA_answer != HAL_OK) DataEX_Error_Handler(SPI_DMA_answer); +// HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); //HAL_Delay(3); //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */
--- a/Discovery/Src/ostc.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Discovery/Src/ostc.c Mon Dec 24 16:15:02 2018 +0300 @@ -81,7 +81,7 @@ cpu2DmaSpi.Init.CLKPolarity = SPI_POLARITY_LOW; cpu2DmaSpi.Init.CLKPhase = SPI_PHASE_1EDGE; cpu2DmaSpi.Init.NSS = SPI_NSS_SOFT;//SPI_NSS_HARD_OUTPUT;//SPI_NSS_SOFT; - cpu2DmaSpi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; + cpu2DmaSpi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; cpu2DmaSpi.Init.FirstBit = SPI_FIRSTBIT_MSB; cpu2DmaSpi.Init.TIMode = SPI_TIMODE_DISABLED; cpu2DmaSpi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
--- a/Discovery/Src/settings.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Discovery/Src/settings.c Mon Dec 24 16:15:02 2018 +0300 @@ -55,7 +55,7 @@ { .versionFirst = 1, .versionSecond = 4, - .versionThird = 2, + .versionThird = 4, .versionBeta = 1, /* 4 bytes with trailing 0 */
--- a/Discovery/Src/tHome.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Discovery/Src/tHome.c Mon Dec 24 16:15:02 2018 +0300 @@ -446,8 +446,8 @@ snprintf(text,32,"spi err:\002 %i/%i",DataEX_lost_connection_count(),get_num_SPI_CALLBACKS()); Gfx_write_label_var(ScreenToWriteOn, 100,300, 0,&FontT24,CLUT_ButtonSymbols,text); - snprintf(text,32,"header:\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, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); +// snprintf(text,32,"header:\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, 350,550, 0,&FontT24,CLUT_ButtonSymbols,text); snprintf(text,32,"footer:\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, 0,&FontT24,CLUT_ButtonSymbols,text);
--- a/Small_CPU/Inc/spi.h Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Inc/spi.h Mon Dec 24 16:15:02 2018 +0300 @@ -36,7 +36,9 @@ void MX_SPI3_Init(void); void MX_SPI3_DeInit(void); uint8_t SPI3_ButtonAdjust(uint8_t *arrayInput, uint8_t *arrayOutput); - +void MX_SPI_DeInit(void); + + #ifdef __cplusplus } #endif
--- a/Small_CPU/Src/baseCPU2.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/baseCPU2.c Mon Dec 24 16:15:02 2018 +0300 @@ -370,7 +370,7 @@ MX_DMA_Init(); MX_SPI1_Init(); MX_EXTI_wireless_Init(); - SPI_Start_single_TxRx_with_Master(); +// SPI_Start_single_TxRx_with_Master(); EXTI_Test_Button_Init(); /* @@ -466,11 +466,11 @@ compass_init(0, 7); accelerator_init(); wireless_init(); - SPI_synchronize_with_Master(); + SPI_synchronize_with_Master(); //one manual start cycle. MX_DMA_Init(); MX_SPI1_Init(); MX_EXTI_wireless_Init(); - SPI_Start_single_TxRx_with_Master(); +// SPI_Start_single_TxRx_with_Master(); // EXTILine0_Button_DeInit(); not now, later after testing break; @@ -1079,7 +1079,25 @@ /** * @} */ +/** + * @brief This function handles SysTick Handler. + * @param None + * @retval None + */ +/*TxRx only here. Every 100 ms.*/ +uint8_t ticks100ms=0; +void SysTick_Handler(void) +{ + HAL_IncTick(); + if(ticks100ms<100){ + ticks100ms++; + }else + { + ticks100ms=0; + SPI_Start_single_TxRx_with_Master(); + } +} /** * @} */
--- a/Small_CPU/Src/compass.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/compass.c Mon Dec 24 16:15:02 2018 +0300 @@ -1853,7 +1853,6 @@ while((ticks) < 60 * 1000) { compass_read(); - acceleration_read(); compass_calc_roll_pitch_only(); @@ -1873,15 +1872,16 @@ } copyCompassDataDuringCalibration(compass_DX_f,compass_DY_f,compass_DZ_f); - compass_add_calibration(&g); + compass_add_calibration(&g); HAL_Delay(1); lasttick = HAL_GetTick(); if(lasttick == 0) { tickstart = -ticks; } + HAL_Delay(1); ticks = lasttick - tickstart; - } + } compass_solve_calibration(&g);
--- a/Small_CPU/Src/i2c.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/i2c.c Mon Dec 24 16:15:02 2018 +0300 @@ -69,9 +69,9 @@ { I2cHandle.Instance = I2Cx; I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - I2cHandle.Init.ClockSpeed = 400000;//400000; + I2cHandle.Init.ClockSpeed = 100000;//400000; REDUCED for compatibility with HMC5583L + MMA8452Q I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; - I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_16_9; + I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; I2cHandle.Init.OwnAddress1 = 0x01; @@ -120,6 +120,7 @@ I2C_Error_count(); } global.dataSendToSlaveStopEval = 0; + //TODO: REMOVE. // if(global.dataSendToSlavePending) // { // scheduleSpecial_Evaluate_DataSendToSlave(); @@ -136,13 +137,14 @@ global.dataSendToSlaveStopEval = 1; - global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 100 /*FIXME , 1*/); + global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size,100 /*FIXME , 1*/); if(global.I2C_SystemStatus != HAL_OK) { I2C_Error_count(); } global.dataSendToSlaveStopEval = 0; + //TODO: REMOVE. // if(global.dataSendToSlavePending) // { // scheduleSpecial_Evaluate_DataSendToSlave(); @@ -161,13 +163,14 @@ global.dataSendToSlaveStopEval = 1; - localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 100); + localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); if(localHALstatusReturn != HAL_OK) { I2C_Error_count(); } global.dataSendToSlaveStopEval = 0; + //TODO: REMOVE. // if(global.dataSendToSlavePending) // { // scheduleSpecial_Evaluate_DataSendToSlave();
--- a/Small_CPU/Src/scheduler.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/scheduler.c Mon Dec 24 16:15:02 2018 +0300 @@ -181,6 +181,11 @@ void scheduleSpecial_Evaluate_DataSendToSlave(void) { + //TEMPORARY fix for compass calibration. + //TODO: Fix I2C timeout for complete solving problem. + if(global.mode==MODE_CALIB){ + return; + } global.dataSendToSlavePending = 0; if(!global.dataSendToSlaveIsValid) return; @@ -243,8 +248,10 @@ if(global.dataSendToSlave.setBatteryGaugeNow) { + if(global.mode!=MODE_CALIB){ global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); + } } if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) @@ -272,30 +279,26 @@ deviceDataFlashValid = 1; - //TODO: (kittz) split by current mode. -// new hw 170523 -// if (global.I2C_SystemStatus != HAL_OK) { -// MX_I2C1_TestAndClear(); -// MX_I2C1_Init(); -// if (!is_init_pressure_done()) { -// init_pressure(); -// } -// } - - -// pressure_update(); -// -// compass_read(); -// acceleration_read(); -// compass_calc(); -// -// + //TODO: Temporary placed here. Duration ~210 ms. + if (global.I2C_SystemStatus != HAL_OK) { + MX_I2C1_TestAndClear(); + MX_I2C1_Init(); +// init_pressure(); +// compass_init(0, 7); +// accelerator_init(); + } +//Collect and copy sensor data just in one place. +//TODO: compass_calib_common needs big refactor. + compass_read(); + acceleration_read(); + compass_calc(); + pressure_update(); copyPressureData(); battery_gas_gauge_get_data(); copyCompassData(); - copyCnsAndOtuData(); +// copyCnsAndOtuData(); //TODO: move here. copyTimeData(); - copyBatteryData(); +// copyBatteryData(); // TODO: move here. copyDeviceData(); copyVpmCrushingData(); // @@ -438,7 +441,7 @@ */ void schedule_check_resync(void) { - //TODO: (kittz) test for stability + //TODO: убрать к хуям if((global.check_sync_not_running >= 2)) { // global.dataSendToSlaveIsNotValidCount = 0; @@ -448,7 +451,7 @@ // HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ // MX_DMA_Init(); // MX_SPI1_Init(); - SPI_Start_single_TxRx_with_Master(); +// SPI_Start_single_TxRx_with_Master(); } } @@ -509,8 +512,8 @@ if(ticksdiff >= counterPressure100msec * 100 + 20) { global.check_sync_not_running++; - pressure_update(); - scheduleUpdateDeviceData(); +// pressure_update(); +// scheduleUpdateDeviceData(); if(global.demo_mode) { turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar); @@ -541,18 +544,18 @@ // if(global.demo_mode) // global.lifeData.ascent_rate_meter_per_min /= 4; } - copyPressureData(); +// copyPressureData(); counterPressure100msec++; } //evaluate compass data at 50 ms, 150 ms, 250 ms,.... - if(ticksdiff >= counterCompass100msec * 100 + 50) - { - compass_read(); - acceleration_read(); - compass_calc(); - copyCompassData(); - counterCompass100msec++; - } +// if(ticksdiff >= counterCompass100msec * 100 + 50) +// { +// compass_read(); +// acceleration_read(); +// compass_calc(); +// copyCompassData(); +// counterCompass100msec++; +// } if(ticksdiff >= counterAmbientLight100msec * 100 + 70) { @@ -719,10 +722,10 @@ { global.check_sync_not_running++; -pressure_update(); -scheduleUpdateDeviceData(); +//pressure_update(); +//scheduleUpdateDeviceData(); global.lifeData.ascent_rate_meter_per_min = 0; -copyPressureData(); +//copyPressureData(); if(temperature_carousel > 20.0f) { @@ -801,10 +804,10 @@ if(ticksdiff >= counterPressure100msec * 100 + 20) { global.check_sync_not_running++; - pressure_update(); - scheduleUpdateDeviceData(); +// pressure_update(); +// scheduleUpdateDeviceData(); global.lifeData.ascent_rate_meter_per_min = 0; - copyPressureData(); +// copyPressureData(); counterPressure100msec++; if(scheduleCheck_pressure_reached_dive_mode_level()) @@ -813,14 +816,14 @@ //evaluate compass data at 50 ms, 150 ms, 250 ms,... - if(ticksdiff >= counterCompass100msec * 100 + 50) - { - compass_read(); - acceleration_read(); - compass_calc(); - copyCompassData(); - counterCompass100msec++; - } +// if(ticksdiff >= counterCompass100msec * 100 + 50) +// { +//// compass_read(); +//// acceleration_read(); +// compass_calc(); +// copyCompassData(); +// counterCompass100msec++; +// } //evaluate compass data at 70 ms, 170 ms, 270 ms,... if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
--- a/Small_CPU/Src/spi.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/spi.c Mon Dec 24 16:15:02 2018 +0300 @@ -124,7 +124,7 @@ hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_HARD_INPUT; //SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLED; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; //_DISABLED; _ENABLED; @@ -325,16 +325,20 @@ // GPIO_new_DEBUG_LOW(); //For debug. global.dataSendToSlaveIsValid = 0; global.dataSendToSlaveIsNotValidCount++; + MX_SPI_DeInit(); + HAL_Delay(30); + MX_DMA_Init(); + MX_SPI1_Init(); } 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(); + SPI_Start_single_TxRx_with_Master(); //Send data always. } }
--- a/Small_CPU/Src/stm32f4xx_it_v3.c Wed Nov 28 09:36:33 2018 +0300 +++ b/Small_CPU/Src/stm32f4xx_it_v3.c Mon Dec 24 16:15:02 2018 +0300 @@ -159,10 +159,10 @@ * @param None * @retval None */ -void SysTick_Handler(void) -{ - HAL_IncTick(); -} +//void SysTick_Handler(void) +//{ +// HAL_IncTick(); +//} /******************************************************************************/