Mercurial > public > ostc4
changeset 312:e84a2486933e
Merged in janlmulder/ostc4/cleanup-4 (pull request #25)
Fix stopwatch and divetime not in sync
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Fri, 31 May 2019 06:22:50 +0000 |
parents | b70c26be71a0 (current diff) ddbe8bed5096 (diff) |
children | 49f5db6139d5 |
files | |
diffstat | 14 files changed, 110 insertions(+), 565 deletions(-) [+] |
line wrap: on
line diff
--- a/Common/Inc/data_central.h Fri May 17 06:38:56 2019 +0000 +++ b/Common/Inc/data_central.h Fri May 31 06:22:50 2019 +0000 @@ -152,13 +152,6 @@ } SDeviceState; */ -typedef struct -{ - uint32_t average_depth_meter_Count; - uint32_t average_depth_last_update_dive_time_seconds_without_surface_time; - int32_t stopwatch_start_at_this_dive_time_seconds; -} SHelper; - /* struct SLifeData * contains data all actual data (pressure, stuturation, etc. as received from second ship * and has actualGas to be send to Small CPU (second chip) @@ -213,7 +206,6 @@ float apnea_total_max_depth_meter; float apnea_last_max_depth_meter; int32_t apnea_last_dive_time_seconds; - int32_t stopwatch_seconds; uint16_t bottle_bar[2 * NUM_GASES +1]; uint16_t bottle_bar_age_MilliSeconds[2 * NUM_GASES + 1]; uint16_t apnea_total_counter; @@ -221,7 +213,6 @@ /* control of DataEX_copy_to_LifeData() */ uint8_t boolResetAverageDepth; - uint8_t boolResetStopwatch; uint8_t bool_temp1; uint8_t bool_temp2; @@ -230,10 +221,6 @@ float ppO2Sensor_bar[3]; float sensorVoltage_mV[3]; float HUD_battery_voltage_V; - - /* used by DataEX_copy_to_LifeData() - */ - SHelper internal; } SLifeData;
--- a/Discovery/Inc/data_exchange_main.h Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Inc/data_exchange_main.h Fri May 31 06:22:50 2019 +0000 @@ -48,7 +48,7 @@ uint32_t DataEX_lost_connection_count(void); void DataEX_control_connection_while_asking_for_sleep(void); uint8_t DataEX_check_RTE_version__needs_update(void); - +void setAvgDepth(SDiveState *pStateReal); SDataReceiveFromMaster * dataOutGetPointer(void);
--- a/Discovery/Src/base.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/base.c Fri May 31 06:22:50 2019 +0000 @@ -206,7 +206,6 @@ #include "display.h" #include "gfx_engine.h" #include "show_logbook.h" -//#include "test_vpm.h" #include "text_multilanguage.h" #include "tHome.h" #include "tInfo.h" @@ -215,7 +214,6 @@ #include "tMenuEdit.h" #include "tMenuEditGasOC.h" #include "tStructure.h" -//#include "gfx_specialeffects.h" #include "externLogbookFlash.h" #include "tComm.h" #include "tCCR.h" @@ -250,34 +248,26 @@ //#define QUICK_SLEEP /* Private define ------------------------------------------------------------*/ -//#define BUFFER_SIZE ((uint32_t)0x00177000) -//#define WRITE_READ_ADDR ((uint32_t)0x0000) #define REFRESH_COUNT ((uint32_t)0x0569) /**< for SDRAM refresh counter (90Mhz SD clock) */ #define INVALID_BUTTON ((uint8_t) 0xFF) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ -RTC_HandleTypeDef RtcHandle; /* used to change time and date, no RTC is running on this MCU */ +static RTC_HandleTypeDef RtcHandle; /* used to change time and date, no RTC is running on this MCU */ TIM_HandleTypeDef TimHandle; /* used in stm32f4xx_it.c too */ -TIM_HandleTypeDef TimBacklightHandle; /* used in stm32f4xx_it.c too */ +static TIM_HandleTypeDef TimBacklightHandle; #ifdef DEMOMODE TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */ #endif -uint8_t LastButtonPressed; -uint32_t LastButtonPressedTick; -uint32_t BaseTick100ms; /* Tick at last 100ms cycle */ - -/* -uint32_t time_before; -uint32_t time_between; -uint32_t time_after; -*/ +static uint8_t LastButtonPressed; +static uint32_t LastButtonPressedTick; +static uint32_t BaseTick100ms; /* Tick at last 100ms cycle */ /* SDRAM handler declaration */ -SDRAM_HandleTypeDef hsdram; -FMC_SDRAM_TimingTypeDef SDRAM_Timing; -FMC_SDRAM_CommandTypeDef command; +static SDRAM_HandleTypeDef hsdram; +static FMC_SDRAM_TimingTypeDef SDRAM_Timing; +static FMC_SDRAM_CommandTypeDef command; /* This was used for Dual Boot */ //FLASH_OBProgramInitTypeDef OBInit; @@ -285,16 +275,12 @@ /* Private variables with external access ------------------------------------*/ -uint32_t globalStateID = 0; -uint8_t globalModeID = SURFMODE; -uint32_t time_without_button_pressed_deciseconds = 0; /**< langbeschreibung (eigenes Feld) warum diese variable verwendet wird um den sleepmode zu aktivieren */ +static uint32_t globalStateID = 0; +static uint32_t time_without_button_pressed_deciseconds = 0; /**< langbeschreibung (eigenes Feld) warum diese variable verwendet wird um den sleepmode zu aktivieren */ uint8_t bootToBootloader = 0; ///< set in tComm.c to install firmware updates, calls resetToFirmwareUpdate() -//uint8_t dataEx_VPM_call = 0; -uint8_t returnFromCommCleanUpRequest = 0; ///< use this to exit bluetooth mode and call tComm_exit() +static uint8_t returnFromCommCleanUpRequest = 0; ///< use this to exit bluetooth mode and call tComm_exit() uint32_t base_tempLightLevel = 0; -uint8_t updateButtonsToDefault = 0; -uint8_t wasFirmwareUpdateCheckBattery = 0; - +static uint8_t wasFirmwareUpdateCheckBattery = 0; static uint8_t DoDisplayRefresh = 0; /* trigger to refresh display data */ /* Private function prototypes -----------------------------------------------*/ @@ -355,7 +341,6 @@ uint8_t lastsecond = 0xFF; #endif - set_globalState( StBoot0 ); LastButtonPressed = 0; @@ -382,23 +367,11 @@ } //settingsGetPointer()->bluetoothActive = 0; /* MX_Bluetooth_PowerOff(); unnecessary as part of MX_GPIO_Init() */ //settingsGetPointer()->compassBearing = 0; - set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version 161121 + set_new_settings_missing_in_ext_flash(); // includes update of firmware version 161121 GFX_init( &pLayerInvisible ); TIM_BACKLIGHT_init(); - /* - GFX_helper_font_memory_list(&FontT24); - GFX_helper_font_memory_list(&FontT42); - GFX_helper_font_memory_list(&FontT48); - GFX_helper_font_memory_list(&FontT54); - GFX_helper_font_memory_list(&FontT84); - GFX_helper_font_memory_list(&FontT105); - GFX_helper_font_memory_list(&FontT144); - */ - - - // new 170508: bluetooth on at start settingsGetPointer()->bluetoothActive = 1; MX_Bluetooth_PowerOn(); @@ -443,7 +416,6 @@ display_power_on__2_of_2__post_RGB(); GFX_use_colorscheme( settingsGetPointer()->tX_colorscheme ); -// ----------------------------- tHome_init(); tI_init(); tM_init(); @@ -490,10 +462,6 @@ if( bootToBootloader ) resetToFirmwareUpdate(); - // this will allways reset after RTE reset -> no good! -// if(DataEX_was_power_on()) // new to allow for update after RTE update -// resetToFirmwareUpdate(); - tCCR_control(); if( tComm_control() )// will stop while loop if tComm Mode started until exit from UART { @@ -932,7 +900,7 @@ } -void EvaluateButton() +static void EvaluateButton() { uint8_t action = 0; SStateList status; @@ -1012,7 +980,7 @@ } } -void gotoSleep(void) +static void gotoSleep(void) { /* not at the moment of testing */ // ext_flash_erase_firmware_if_not_empty(); @@ -1023,21 +991,6 @@ // ----------------------------- -uint8_t get_globalMode(void) -{ - return globalModeID; -} - - -void set_globalMode(uint8_t newMode) -{ - if((newMode != DIVEMODE) && (newMode != SURFMODE)) - return; - - globalModeID = newMode; -} - - uint32_t get_globalState(void) { return globalStateID; @@ -1654,7 +1607,7 @@ #endif -void deco_loop(void) +static void deco_loop(void) { typedef enum { @@ -1735,7 +1688,7 @@ counter++; } -void resetToFirmwareUpdate(void) +static void resetToFirmwareUpdate(void) { __HAL_RCC_CLEAR_RESET_FLAGS(); HAL_NVIC_SystemReset();
--- a/Discovery/Src/buehlmann.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/buehlmann.c Fri May 31 06:22:50 2019 +0000 @@ -123,7 +123,7 @@ stoplist = pDecoInfo->output_stop_length_seconds; - if(pLifeData->dive_time_seconds < 60) + if(pLifeData->dive_time_seconds_without_surface_time < 60) return; // clean stop list
--- a/Discovery/Src/data_central.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/data_central.c Fri May 31 06:22:50 2019 +0000 @@ -75,7 +75,7 @@ SDiveState stateSim = { 0 }; SDiveState stateDeco = { 0 }; -SDevice stateDevice = +static SDevice stateDevice = { /* max is 0x7FFFFFFF, min is 0x80000000 but also defined in stdint.h :-) */ @@ -94,7 +94,7 @@ .voltageMinimum.value_int32 = INT32_MAX, }; -SVpmRepetitiveData stateVPM = +static SVpmRepetitiveData stateVPM = { .repetitive_variables_not_valid = 1, .is_data_from_RTE_CPU = 0, @@ -175,65 +175,26 @@ uint8_t decoLock = DECO_CALC_undefined; -int ascent_rate_meter_per_min = 12; -int descent_rate_meter_per_min = 20; -int max_depth = 70; -int bottom_time = 10; + +static int descent_rate_meter_per_min = 20; +static int max_depth = 70; +static int bottom_time = 10; _Bool vpm_crush(SDiveState* pDiveState); void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ) { - ascent_rate_meter_per_min = _ascent_rate_meter_per_min; descent_rate_meter_per_min = _descent_rate_meter_per_min; max_depth = _max_depth; bottom_time = _bottom_time; } - - int current_second(void) { return HAL_GetTick() / 1000; - // printf("milliseconds: %lld\n", milliseconds); - //return milliseconds; } - - #define OXY_ONE_SIXTIETH_PART 0.0166667f -/*void oxygen_calculate_cns(float* oxygen_cns, float pressure_oxygen_real) -{ - int cns_no_range = 0; - _Bool not_found = 1; - //for the cns calculation - const float cns_ppo2_ranges[60][2] = { {0.50, 0.00}, {0.60, 0.14}, {0.64, 0.15}, {0.66, 0.16}, {0.68, 0.17}, {0.70, 0.18}, - {0.74, 0.19}, {0.76, 0.20}, {0.78, 0.21}, {0.80, 0.22}, {0.82, 0.23}, {0.84, 0.24}, - {0.86, 0.25}, {0.88, 0.26}, {0.90, 0.28}, {0.92, 0.29}, {0.94, 0.30}, {0.96, 0.31}, - {0.98, 0.32}, {1.00, 0.33}, {1.02, 0.35}, {1.04, 0.36}, {1.06, 0.38}, {1.08, 0.40}, - {1.10, 0.42}, {1.12, 0.43}, {1.14, 0.43}, {1.16, 0.44}, {1.18, 0.46}, {1.20, 0.47}, - {1.22, 0.48}, {1.24, 0.51}, {1.26, 0.52}, {1.28, 0.54}, {1.30, 0.56}, {1.32, 0.57}, - {1.34, 0.60}, {1.36, 0.62}, {1.38, 0.63}, {1.40, 0.65}, {1.42, 0.68}, {1.44, 0.71}, - {1.46, 0.74}, {1.48, 0.78}, {1.50, 0.83}, {1.52, 0.93}, {1.54, 1.04}, {1.56, 1.19}, - {1.58, 1.47}, {1.60, 2.22}, {1.62, 5.00}, {1.65, 6.25}, {1.67, 7.69}, {1.70, 10.0}, - {1.72,12.50}, {1.74,20.00}, {1.77,25.00}, {1.79,31.25}, {1.80,50.00}, {1.82,100.0}}; - //find the correct cns range for the corresponding ppo2 - cns_no_range = 58; - while (cns_no_range && not_found) - { - if (pressure_oxygen_real > cns_ppo2_ranges[cns_no_range][0]) - { - cns_no_range++; - not_found = 0; - } - else - cns_no_range--; - } - - //calculate cns for the actual ppo2 for 1 second - *oxygen_cns += OXY_ONE_SIXTIETH_PART * cns_ppo2_ranges[cns_no_range][1]; -}*/ - uint8_t calc_MOD(uint8_t gasId) { int16_t oxygen, maxppO2, result; @@ -261,40 +222,6 @@ return result; } -uint8_t calc_MinOD(uint8_t gasId) -{ - int16_t oxygen, minppO2, result; - SSettings *pSettings; - - pSettings = settingsGetPointer(); - - oxygen = (int16_t)(pSettings->gas[gasId].oxygen_percentage); - minppO2 =(int16_t)(pSettings->ppO2_min); - result = 10 * minppO2; - result += 9; - result /= oxygen; - result -= 10; - - if(result < 0) - return 0; - - if(result > 255) - return 255; - - return result; -} -/* -float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas) -{ - float percent_N2 = 0; - float percent_He = 0; - float percent_O2 = 0; - decom_get_inert_gases(input_ambient_pressure_bar, pGas, &percent_N2, &percent_He); - percent_O2 = 1 - percent_N2 - percent_He; - - return (input_ambient_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2; -}*/ - float get_ambiant_pressure_simulation(long dive_time_seconds, float surface_pressure_bar ) { static @@ -651,7 +578,7 @@ } -int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) +static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) { y += 2000; y -= m <= 2; @@ -663,7 +590,7 @@ } -uint8_t helper_weekday_from_days(int32_t z) +static uint8_t helper_weekday_from_days(int32_t z) { return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); } @@ -714,95 +641,12 @@ sTime->SubSeconds = 0; } - -/* -void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm) -{ - SSettings* pSettings = settingsGetPointer(); - for(int i = 0; i< NUM_GASES; i++) - { - pDiveSettings->gas[i] = pSettings->gas[i]; - pDiveSettings->gas[NUM_OFFSET_DILUENT + i] = pSettings->gas[NUM_OFFSET_DILUENT + i]; - pDiveSettings->setpoint[i] = pSettings->setpoint[i]; - } - pDiveSettings->diveMode = pSettings->dive_mode; - - pDiveSettings->gf_high = pSettings->GF_high; - pDiveSettings->gf_low = pSettings->GF_low; - pDiveSettings->last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0; - pDiveSettings->ascentRate_meterperminute = 10; - pDiveSettings->vpm_conservatism = 1; - - pDiveSettings->input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f; - - vpm_init(pVpm, pDiveSettings->vpm_conservatism, 0, 0); -} -*/ -_Bool deco_zone_reached(void) -{ - if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE) - return stateUsed->lifeData.pressure_ambient_bar <= stateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; - else - return stateUsed->vpm.deco_zone_reached; - -} - - void resetEvents(const SDiveState *pStateUsed) { memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); } -/* This is derived from crc32b but does table lookup. First the table -itself is calculated, if it has not yet been set up. -Not counting the table setup (which would probably be a separate -function), when compiled to Cyclops with GCC, this function executes in -7 + 13n instructions, where n is the number of bytes in the input -message. It should be doable in 4 + 9n instructions. In any case, two -of the 13 or 9 instrucions are load byte. - This is Figure 14-7 in the text. */ - -/* http://www.hackersdelight.org/ i guess ;-) *hw */ - -uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2) { - int i, j; - uint32_t byte, crc, mask; - static unsigned int table[256] = {0}; - - /* Set up the table, if necessary. */ - if (table[1] == 0) { - for (byte = 0; byte <= 255; byte++) { - crc = byte; - for (j = 7; j >= 0; j--) { // Do eight times. - mask = -(crc & 1); - crc = (crc >> 1) ^ (0xEDB88320 & mask); - } - table[byte] = crc; - } - } - - /* Through with table setup, now calculate the CRC. */ - i = 0; - crc = 0xFFFFFFFF; - while (length--) { - byte = message[i]; - crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF]; - i = i + 1; - } - if(length2) - { - i = 0; - while (length2--) { - byte = message2[i]; - crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF]; - i = i + 1; - } - } - return ~crc; -} - - uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) { cm_t crc_model; @@ -916,10 +760,12 @@ return (cm_crc(&crc_model)); } - +// This code is also in RTE. Keep it in sync when editing _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) { - if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.04f)) + if (lifeData->pressure_ambient_bar > 1.16) + return false; + else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) return true; else return false;
--- a/Discovery/Src/data_exchange_main.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/data_exchange_main.c Fri May 31 06:22:50 2019 +0000 @@ -860,7 +860,6 @@ //Init dive Mode decoLock = DECO_CALC_init_as_is_start_of_dive; pStateReal->lifeData.boolResetAverageDepth = 1; - pStateReal->lifeData.boolResetStopwatch = 1; } pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; @@ -890,14 +889,7 @@ pStateReal->mode = dataIn.mode; pStateReal->chargeStatus = dataIn.chargeStatus; - if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) - { - pStateReal->lifeData.depth_meter = 0; - } - else - { - pStateReal->lifeData.depth_meter = meter; - } + pStateReal->lifeData.depth_meter = meter; pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; @@ -999,48 +991,40 @@ // reset max_depth_meter, average_depth_meter and internal values pStateReal->lifeData.max_depth_meter = 0; pStateReal->lifeData.boolResetAverageDepth = 1; - pStateReal->lifeData.boolResetStopwatch = 1; } } - /* average depth - */ + setAvgDepth(pStateReal); +} + +void setAvgDepth(SDiveState *pStateReal) { + float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; float DepthNow = pStateReal->lifeData.depth_meter; - uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; - uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; + static uint32_t AvgDepthCount = 0; + static uint32_t AvgDepthTimer = 0; uint32_t AvgSecondsSinceLast; uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; - + if(pStateReal->lifeData.boolResetAverageDepth) { *AvgDepthValue = DepthNow; - *AvgDepthCount = 1; - *AvgDepthTimer = DiveTime; + AvgDepthCount = 0; + AvgDepthTimer = DiveTime; pStateReal->lifeData.boolResetAverageDepth = 0; } - else if (DiveTime > *AvgDepthTimer) + else if (DiveTime > AvgDepthTimer) { - AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; + AvgSecondsSinceLast = DiveTime - AvgDepthTimer; for(int i=0;i<AvgSecondsSinceLast;i++) { - *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); - *AvgDepthCount += 1; + *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1); + AvgDepthCount += 1; } - *AvgDepthTimer = DiveTime; + AvgDepthTimer = DiveTime; } - if(*AvgDepthCount == 0) - *AvgDepthValue = 0; - - - /* stop watch - */ - if(pStateReal->lifeData.boolResetStopwatch) - { - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; - pStateReal->lifeData.boolResetStopwatch = 0; - } - pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds; + if(AvgDepthCount == 0) + *AvgDepthValue = DepthNow; }
--- a/Discovery/Src/display.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/display.c Fri May 31 06:22:50 2019 +0000 @@ -34,7 +34,7 @@ } -void send(uint8_t *pData, uint16_t inputlength) +static void send(uint8_t *pData, uint16_t inputlength) { HAL_GPIO_WritePin(DISPLAY_CSB_GPIO_PORT,DISPLAY_CSB_PIN,GPIO_PIN_RESET); // chip select @@ -48,7 +48,7 @@ } -uint16_t convert8to9to8(uint8_t *pInput, uint8_t *pOutput,uint16_t inputlength) +static uint16_t convert8to9to8(uint8_t *pInput, uint8_t *pOutput,uint16_t inputlength) { uint16_t outputlength; uint8_t readbit = 0x80;//0b1000000; @@ -227,55 +227,6 @@ } -void display_power_off(void) -{ - uint8_t aTxBuffer[1]; - uint8_t bTxBuffer[9]; - uint16_t i,length; - - for(i=0;i<9;i++) - bTxBuffer[i] = 0; - - aTxBuffer[0] = DISPLAY_OFF; - length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); - send((uint8_t*)bTxBuffer, length); - HAL_Delay(5); - - aTxBuffer[0] = SLEEP_IN; - length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); - send((uint8_t*)bTxBuffer, length); -} - - -void display_sleep(void) -{ - uint8_t aTxBuffer[1]; - uint8_t bTxBuffer[9]; - uint16_t i,length; - - for(i=0;i<9;i++) - bTxBuffer[i] = 0; - - aTxBuffer[0] = SLEEP_IN; - length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); - send((uint8_t*)bTxBuffer, length); -} - - -void display_sleep_release(void) -{ - uint8_t aTxBuffer[1]; - uint8_t bTxBuffer[9]; - uint16_t i,length; - - for(i=0;i<9;i++) - bTxBuffer[i] = 0; - - aTxBuffer[0] = SLEEP_OUT; - length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); - send((uint8_t*)bTxBuffer, length); -} - static void Display_Error_Handler(void) { while(1)
--- a/Discovery/Src/externCPU2bootloader.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/externCPU2bootloader.c Fri May 31 06:22:50 2019 +0000 @@ -35,37 +35,26 @@ /* Exported variables --------------------------------------------------------*/ /* Private types -------------------------------------------------------------*/ -#define BOOTLOADSPITIMEOUT 5000 /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -uint8_t boot_sync_frame(void); -uint8_t boot_ack(void); -uint8_t boot_get(uint8_t *RxBuffer); -uint8_t boot_get_id(uint8_t *RxBuffer); -uint8_t boot_get_version(uint8_t *RxBuffer); -//uint8_t boot_go(uint32_t address); -uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data); -//uint8_t boot_erase_memory(uint16_t data_frame, uint16_t *page_numbers); -uint8_t boot_erase_memory(void); -uint8_t boot_write_protect(uint8_t number_of_sectors_minus_one, uint8_t *sector_codes); -/* -uint8_t boot_write_unprotect(void); -uint8_t boot_readout_protect(void); -uint8_t boot_readout_unprotect(void); -*/ -void Bootoader_send_command(uint8_t command); -void Bootloader_spi_single(uint8_t TxByte); -void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer); -void Bootloader_Error_Handler(void); +static uint8_t boot_sync_frame(void); +static uint8_t boot_ack(void); +static uint8_t boot_get_id(uint8_t *RxBuffer); +static uint8_t boot_get_version(uint8_t *RxBuffer); +static uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data); +static uint8_t boot_erase_memory(void); +static void Bootloader_send_command(uint8_t command); +static void Bootloader_spi_single(uint8_t TxByte); +static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer); +static void Bootloader_Error_Handler(void); /* Exported functions --------------------------------------------------------*/ uint8_t extCPU2bootloader_start(uint8_t *version, uint16_t *chipID) { -// uint8_t aTxBuffer[256] = { 0 }; uint8_t aRxBuffer[256] = { 0 }; HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); @@ -89,7 +78,7 @@ { uint8_t version = 0; uint16_t chipID = 0; -// uint8_t ret; + if(!extCPU2bootloader_start(&version,&chipID)) return 0; if(!boot_erase_memory()) @@ -135,28 +124,16 @@ /* Private functions --------------------------------------------------------*/ -uint8_t boot_sync_frame(void) +static uint8_t boot_sync_frame(void) { Bootloader_spi_single(0x5a); return boot_ack(); } - -uint8_t boot_get(uint8_t *RxBuffer) +static uint8_t boot_get_version(uint8_t *RxBuffer) { Bootloader_spi_single(0x5a); - Bootoader_send_command(0x00); - if(!boot_ack()) - return 0; - Bootloader_spi(14, NULL, RxBuffer); - return boot_ack(); -} - - -uint8_t boot_get_version(uint8_t *RxBuffer) -{ - Bootloader_spi_single(0x5a); - Bootoader_send_command(0x01); + Bootloader_send_command(0x01); if(!boot_ack()) return 0; Bootloader_spi(3, NULL, RxBuffer); @@ -164,23 +141,16 @@ } -uint8_t boot_get_id(uint8_t *RxBuffer) +static uint8_t boot_get_id(uint8_t *RxBuffer) { Bootloader_spi_single(0x5a); - Bootoader_send_command(0x02); + Bootloader_send_command(0x02); if(!boot_ack()) return 0; Bootloader_spi(5, NULL, RxBuffer); return boot_ack(); } -/* -uint8_t boot_go(uint32_t address) -{ - -} -*/ - uint8_t boot_write_memory(uint32_t address, uint8_t length_minus_1, uint8_t *data) { @@ -189,7 +159,7 @@ uint16_t length; Bootloader_spi_single(0x5a); - Bootoader_send_command(0x31); + Bootloader_send_command(0x31); if(!boot_ack()) return 1; HAL_Delay(5); @@ -223,13 +193,12 @@ return 1; } -//uint8_t boot_erase_memory(uint16_t data_frame, uint16_t *page_numbers) -uint8_t boot_erase_memory(void) +static uint8_t boot_erase_memory(void) { uint8_t special_erase_with_checksum[3] = {0xFF, 0xFF, 0x00}; Bootloader_spi_single(0x5a); - Bootoader_send_command(0x44); + Bootloader_send_command(0x44); if(!boot_ack()) return 0; Bootloader_spi(3, special_erase_with_checksum, NULL); @@ -243,30 +212,13 @@ uint8_t boot_write_unprotect(void) { Bootloader_spi_single(0x5a); - Bootoader_send_command(0x73); + Bootloader_send_command(0x73); if(!boot_ack()) return 0; return boot_ack(); } -/* -uint8_t boot_write_protect(uint8_t number_of_sectors_minus_one, uint8_t *sector_codes) -{ - -} - -uint8_t boot_readout_protect(void) -{ - -} - -uint8_t boot_readout_unprotect(void) -{ - -} -*/ - -uint8_t boot_ack(void) +static uint8_t boot_ack(void) { uint8_t answer = 0; @@ -287,7 +239,7 @@ return 0; } -void Bootoader_send_command(uint8_t command) +static void Bootloader_send_command(uint8_t command) { uint8_t send[2]; uint8_t receive[2]; @@ -297,13 +249,13 @@ Bootloader_spi(2, send, receive); } -void Bootloader_spi_single(uint8_t TxByte) +static void Bootloader_spi_single(uint8_t TxByte) { Bootloader_spi(1,&TxByte, 0); } -void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer) +static void Bootloader_spi(uint16_t lengthData, uint8_t *aTxBuffer, uint8_t *aRxBuffer) { uint8_t dummy[256] = { 0 }; uint8_t *tx_data; @@ -334,10 +286,7 @@ } -void Bootloader_Error_Handler(void) +static void Bootloader_Error_Handler(void) { while(1); } - - -
--- a/Discovery/Src/logbook_miniLive.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/logbook_miniLive.c Fri May 31 06:22:50 2019 +0000 @@ -32,9 +32,9 @@ */ #define MLLsize (296) -uint16_t MLLdataDepth[MLLsize]; -uint16_t MLLpointer = 0; -uint8_t MLLtickIntervallSeconds = 2; +static uint16_t MLLdataDepth[MLLsize]; +static uint16_t MLLpointer = 0; +static uint8_t MLLtickIntervallSeconds = 2; uint16_t *getMiniLiveLogbookPointerToData(void)
--- a/Discovery/Src/ostc.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/ostc.c Fri May 31 06:22:50 2019 +0000 @@ -40,7 +40,9 @@ UART_HandleTypeDef UartHandle; +#ifdef USART_PIEZO UART_HandleTypeDef UartPiezoTxHandle; +#endif UART_HandleTypeDef UartIR_HUD_Handle; __IO ITStatus UartReady = RESET; @@ -90,42 +92,6 @@ HAL_SPI_Init(&cpu2DmaSpi); } - -void MX_GPIO_Backlight_max_static_only_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStruct; - TIM_BACKLIGHT_GPIO_ENABLE(); - - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */ - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - - GPIO_InitStruct.Pin = TIM_BACKLIGHT_PIN; - HAL_GPIO_Init(TIM_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct); - - HAL_GPIO_WritePin(TIM_BACKLIGHT_GPIO_PORT,TIM_BACKLIGHT_PIN,GPIO_PIN_SET); -} - - -void MX_GPIO_One_Button_only_Init(void) -{ - GPIO_InitTypeDef GPIO_InitStruct; - BUTTON_NEXT_GPIO_ENABLE(); - - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */ - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - - GPIO_InitStruct.Pin = BUTTON_NEXT_PIN; - HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStruct); -} - - -GPIO_PinState MX_GPIO_Read_The_One_Button(void) -{ - return HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN); -} - void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; @@ -263,26 +229,6 @@ #endif } - -void MX_SmallCPU_NO_Reset_Helper(void) -{ -#ifdef SMALLCPU_NRESET_PIN - GPIO_InitTypeDef GPIO_InitStruct; - - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - - SMALLCPU_NRESET_GPIO_ENABLE(); - HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); - HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_SET); -// HAL_Delay(100); -// GPIO_InitStruct.Mode = GPIO_MODE_INPUT; -// HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); -#endif -} - - void MX_SmallCPU_Reset_To_Standard(void) { #ifdef SMALLCPU_NRESET_PIN @@ -303,23 +249,6 @@ #endif } - -uint8_t MX_UART_ButtonAdjust(uint8_t *array) -{ -#ifdef USART_PIEZO - uint8_t answer[4]; - HAL_UART_Transmit(&UartPiezoTxHandle,array,4,1000); - HAL_UART_Receive(&UartPiezoTxHandle,answer,4,2000); - if( (answer[0] == array[0]) - &&(answer[1] == array[1]) - &&(answer[2] == array[2]) - &&(answer[3] == array[3])) - return 1; -#endif - return 0; -} - - void MX_UART_Init(void) { /*##-1- Configure the UART peripheral ######################################*/ @@ -375,8 +304,6 @@ UartReady = SET; } - - //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
--- a/Discovery/Src/simulation.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/simulation.c Fri May 31 06:22:50 2019 +0000 @@ -37,6 +37,7 @@ #include "decom.h" #include "calc_crush.h" #include "data_exchange.h" +#include "data_exchange_main.h" #include "timer.h" #include "check_warning.h" #include "vpm.h" @@ -51,7 +52,7 @@ //Private functions -static float sim_get_ambiant_pressure(SDiveState * pDiveState); +static float sim_get_ambient_pressure(SDiveState * pDiveState); static void sim_reduce_deco_time_one_second(SDiveState* pDiveState); static void simulation_set_aim_depth(int depth_meter); @@ -157,12 +158,7 @@ pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2]; pDiveState->lifeData.dive_time_seconds += 1; - pDiveState->lifeData.pressure_ambient_bar = sim_get_ambiant_pressure(pDiveState); - - if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) ) - { - pDiveState->lifeData.dive_time_seconds_without_surface_time += 1; - } + pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 { @@ -185,6 +181,11 @@ pDiveState->lifeData.counterSecondsShallowDepth = 0; } + if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) ) + { + pDiveState->lifeData.dive_time_seconds_without_surface_time += 1; + } + pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; @@ -201,38 +202,10 @@ pDiveState->lifeData.dive_time_seconds = 0; pDiveState->lifeData.max_depth_meter = 0; pDiveState->lifeData.boolResetAverageDepth = 1; - pDiveState->lifeData.boolResetStopwatch = 1; } } - /* average depth - */ - float *AvgDepthValue = &pDiveState->lifeData.average_depth_meter; - float DepthNow = pDiveState->lifeData.depth_meter; - uint32_t *AvgDepthCount = &pDiveState->lifeData.internal.average_depth_meter_Count; - uint32_t *AvgDepthTimer = &pDiveState->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; - uint32_t AvgSecondsSinceLast; - uint32_t DiveTime = pDiveState->lifeData.dive_time_seconds_without_surface_time; - - if(pDiveState->lifeData.boolResetAverageDepth) - { - *AvgDepthValue = DepthNow; - *AvgDepthCount = 1; - *AvgDepthTimer = DiveTime; - pDiveState->lifeData.boolResetAverageDepth = 0; - } - else if (DiveTime > *AvgDepthTimer) - { - AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; - for(int i=0;i<AvgSecondsSinceLast;i++) - { - *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); - *AvgDepthCount += 1; - } - *AvgDepthTimer = DiveTime; - } - if(*AvgDepthCount == 0) - *AvgDepthValue = 0; + setAvgDepth(pDiveState); /* Exposure Tissues */ @@ -303,14 +276,14 @@ /** ****************************************************************************** - * @brief simulates ambiant pressure depending on aim depth + * @brief simulates ambient pressure depending on aim depth ****************************************************************************** * @note if aim_depth != actual depth, the depth change within one second * (depending on descent or ascent) rate is calculated * @param SDiveState* pDiveState: - * @return float : new ambiant pressure + * @return float : new ambient pressure */ -static float sim_get_ambiant_pressure(SDiveState * pDiveState) +static float sim_get_ambient_pressure(SDiveState * pDiveState) { //Calc next depth uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); @@ -351,7 +324,7 @@ * @param SDiveState* pDiveState: * @return void */ -void sim_reduce_deco_time_one_second(SDiveState* pDiveState) +static void sim_reduce_deco_time_one_second(SDiveState* pDiveState) { SDecoinfo* pDecoinfo; if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
--- a/Discovery/Src/timer.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/timer.c Fri May 31 06:22:50 2019 +0000 @@ -28,18 +28,17 @@ #include "data_central.h" -static long stopWatchTime_Second = 0; static _Bool bStopWatch = false; static float stopWatchAverageDepth_Meter = 0.0f; static long safetyStopCountDown_Second = 0; +static long stopWatchOffset = 0; void timer_init(void) { - stopWatchTime_Second = 0; stopWatchAverageDepth_Meter = 0.0f; bStopWatch = true; safetyStopCountDown_Second = 0; - + stopWatchOffset = 0; } void timer_UpdateSecond(_Bool checkOncePerSecond) @@ -47,6 +46,7 @@ static int last_second = -1; static _Bool bSafetyStop = false; static float last_depth_meter = 0; + long stopWatchTime_Second = 0; if(checkOncePerSecond) { @@ -57,18 +57,13 @@ } /** Stopwatch **/ - if(bStopWatch && stateUsed->lifeData.depth_meter > 1) + stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; + if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData)) { - if((stopWatchTime_Second == 0) && (stateUsed->lifeData.dive_time_seconds >= 1)) - { - stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds - 1; - stopWatchAverageDepth_Meter = stateUsed->lifeData.average_depth_meter * (stopWatchTime_Second - 1) / stopWatchTime_Second; - } + if(stopWatchTime_Second == 0) + stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; else - { stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1); - stopWatchTime_Second++; - } } /** SafetyStop **/ @@ -125,9 +120,9 @@ void timer_Stopwatch_Restart(void) { - stopWatchTime_Second = 1; stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; bStopWatch = true; + stopWatchOffset = stateUsed->lifeData.dive_time_seconds_without_surface_time; } void timer_Stopwatch_Stop(void) @@ -137,7 +132,7 @@ long timer_Stopwatch_GetTime(void) { - return stopWatchTime_Second; + return stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; } float timer_Stopwatch_GetAvarageDepth_Meter(void)
--- a/Discovery/Src/vpm.c Fri May 17 06:38:56 2019 +0000 +++ b/Discovery/Src/vpm.c Fri May 31 06:22:50 2019 +0000 @@ -240,7 +240,7 @@ pDECOINFO->output_stop_length_seconds[i] = 0; } - if(pINPUT->dive_time_seconds < 60) + if(pINPUT->dive_time_seconds_without_surface_time < 60) { vpm_calc_status = CALC_NDL; return vpm_calc_status;
--- a/Small_CPU/Src/scheduler.c Fri May 17 06:38:56 2019 +0000 +++ b/Small_CPU/Src/scheduler.c Fri May 31 06:22:50 2019 +0000 @@ -85,7 +85,6 @@ static void schedule_update_timer_helper(int8_t thisSeconds); uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); -_Bool scheduleCheck_pressure_reached_dive_mode_level(void); void scheduleSetDate(SDeviceLine *line); /* Exported functions --------------------------------------------------------*/ @@ -771,7 +770,7 @@ copyPressureData(); Scheduler.counterPressure100msec++; - if(scheduleCheck_pressure_reached_dive_mode_level()) + if (!is_ambient_pressure_close_to_surface(&global.lifeData)) global.mode = MODE_DIVE; } @@ -1029,7 +1028,7 @@ } } - if(scheduleCheck_pressure_reached_dive_mode_level()) + if (!is_ambient_pressure_close_to_surface(&global.lifeData)) global.mode = MODE_BOOT; scheduleUpdateLifeData(2000); @@ -1046,27 +1045,6 @@ /* Private functions ---------------------------------------------------------*/ - -/** - ****************************************************************************** - * @brief scheduleCheck_pressure_reached_dive_mode_level - * @author heinrichs weikamp gmbh - * @version V0.0.1 from inline code - * @date 09-Sept-2015 - ****************************************************************************** - */ -_Bool scheduleCheck_pressure_reached_dive_mode_level(void) -{ - if(get_pressure_mbar() > 1160) - return 1; - else - if((global.mode == MODE_SURFACE) && (get_pressure_mbar() > (get_surface_mbar() + 100)) && (get_surface_mbar() > 880)) - return 1; - else - return 0; -} - - /** ****************************************************************************** * @brief scheduleUpdateLifeData / calculates tissues @@ -1582,9 +1560,11 @@ } /* same as in data_central.c */ -_Bool is_ambient_pressure_close_to_surface(SLifeData *lifeDataCall) +_Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) { - if(lifeDataCall->pressure_ambient_bar < (lifeDataCall->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f + if (lifeData->pressure_ambient_bar > 1.16) + return false; + else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f return true; else return false;