# HG changeset patch # User heinrichsweikamp # Date 1552638136 0 # Node ID 1bb24fd3fc9251f397ce51261a9da9876e42e2cd # Parent d365962815014f25fcd0f63c9dbe3d202947d589# Parent 8117802894a4faa1bdee5d4fd9509941a290ba9c Merged in Ideenmodellierer/ostc4/Cleanup_Compass_Wireless (pull request #4) Cleanup Compass Wireless diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Inc/i2c.h --- a/Small_CPU/Inc/i2c.h Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Inc/i2c.h Fri Mar 15 08:22:16 2019 +0000 @@ -10,7 +10,6 @@ #define DEVICE_COMPASS_HMC5883L 0x3C // Hardware gen 1 #define DEVICE_COMPASS_303D 0x3C // Hardware gen 2 (Single chip solution LSM303D) -#define DEVICE_ACCELARATOR_303DLHC 0x32 // Hardware gen 2 (Single chip solution LSM303DLHC) #define DEVICE_COMPASS_303AGR 0x3C // Hardware gen 3 (Single chip solution LSM303AGR) /* Battery Gas Gauge */ diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Inc/scheduler.h --- a/Small_CPU/Inc/scheduler.h Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Inc/scheduler.h Fri Mar 15 08:22:16 2019 +0000 @@ -29,10 +29,9 @@ #include "settings.h" /* Types -------------------------------------------------------------*/ -#define MAX_WIRELESS_BYTES 10 #define SENSOR_PRESSURE_ID 0 #define MAX_SENSORS 1 - + typedef struct { uint8_t mode; @@ -59,9 +58,6 @@ uint8_t ButtonResponsiveness[4]; uint8_t chargerStatus; uint8_t dataSendToSlaveIsNotValidCount; - uint8_t wirelessdata[MAX_WIRELESS_BYTES]; - uint8_t wirelessReceived; - uint8_t wirelessConfidenceStatus; uint8_t ButtonPICdata[4]; uint8_t accidentFlag; uint32_t accidentRemainingSeconds; @@ -81,7 +77,6 @@ uint8_t counterPressure100msec; uint8_t counterCompass100msec; uint8_t counterAmbientLight100msec; - uint16_t counterWireless1msec; uint32_t tickstart; } SScheduleCtrl; diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Inc/spi.h --- a/Small_CPU/Inc/spi.h Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Inc/spi.h Fri Mar 15 08:22:16 2019 +0000 @@ -30,6 +30,8 @@ //void SPI_Start_single_TxRx_with_Master_and_Stop_ChipSelectControl(void); void SPI_Start_single_TxRx_with_Master(void); void SPI_synchronize_with_Master(void); +void SPI_Evaluate_RX_Data(void); /*process the data received during last 100ms cycle */ + void MX_SPI_DeInit(void); /* button adjust */ diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Inc/wireless.h --- a/Small_CPU/Inc/wireless.h Wed Mar 13 20:51:50 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/** - ****************************************************************************** - * @file wireless.h - * @author heinrichs weikamp gmbh - * @date 02-July-2015 - * @version V0.0.1 - * @since 02-July-2015 - * @brief Data transfer via magnetic field using Manchester code - * - @verbatim - ============================================================================== - ##### How to use ##### - ============================================================================== - @endverbatim - ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2015 heinrichs weikamp

- * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef WIRELESS_H -#define WIRELESS_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include - -void wireless_init(void); - -void wireless_trigger_FallingEdgeSignalHigh(void); -void wireless_trigger_RisingEdgeSilence(void); - -uint8_t wireless_evaluate(uint8_t *dataOut, uint8_t maxData, uint8_t *confidence); -uint8_t wireless_evaluate_crc_error(uint8_t *dataIn, uint8_t maxData); - -#ifdef __cplusplus -} -#endif - -#endif /* WIRELESS_H */ - -/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Src/baseCPU2.c --- a/Small_CPU/Src/baseCPU2.c Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Src/baseCPU2.c Fri Mar 15 08:22:16 2019 +0000 @@ -141,7 +141,6 @@ #include "batteryGasGauge.h" #include "batteryCharger.h" #include "scheduler.h" -#include "wireless.h" #include "tm_stm32f4_otp.h" // From Common/Inc: @@ -240,18 +239,15 @@ static void EXTI_Test_Button_Init(void); static void EXTI_Test_Button_DeInit(void); -static void MX_EXTI_wireless_Init(void); -static void MX_EXTI_wireless_DeInit(void); - -//static void EXTILine01_Button_DeInit(void); static void GPIO_LED_Init(void); static void GPIO_Power_MainCPU_Init(void); static void GPIO_Power_MainCPU_ON(void); static void GPIO_Power_MainCPU_OFF(void); +#ifdef DEBUG_I2C_LINES void GPIO_test_I2C_lines(void); +#endif -//void sleep_test(void); void sleep_prepare(void); void SystemClock_Config(void); @@ -373,7 +369,7 @@ // ReInit_battery_charger_status_pins(); compass_init(0, 7); accelerator_init(); - wireless_init(); + if (global.mode == MODE_BOOT) { GPIO_Power_MainCPU_OFF(); HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); @@ -382,18 +378,9 @@ SPI_synchronize_with_Master(); MX_DMA_Init(); MX_SPI1_Init(); - MX_EXTI_wireless_Init(); SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ dohardspisync = 1; EXTI_Test_Button_Init(); - - /* - uint8_t dataWireless[64]; - while(1) - { - wireless_evaluate_and_debug(dataWireless,64); - } - */ global.mode = MODE_SURFACE; break; @@ -462,7 +449,6 @@ NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); */ EXTI_Test_Button_DeInit(); - MX_EXTI_wireless_DeInit(); if (hasExternalClock()) SystemClock_Config_HSI(); sleep_prepare(); @@ -479,11 +465,9 @@ GPIO_Power_MainCPU_ON(); compass_init(0, 7); accelerator_init(); - wireless_init(); SPI_synchronize_with_Master(); MX_DMA_Init(); MX_SPI1_Init(); - MX_EXTI_wireless_Init(); SPI_Start_single_TxRx_with_Master(); // EXTILine0_Button_DeInit(); not now, later after testing @@ -519,26 +503,12 @@ */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { - if (GPIO_Pin == WIRELSS_RISING_GPIO_PIN) { - wireless_trigger_RisingEdgeSilence(); - } - - else - - if (GPIO_Pin == WIRELSS_FALLING_GPIO_PIN) { - wireless_trigger_FallingEdgeSignalHigh(); - } - - else - if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { if (global.mode == MODE_SLEEP) { global.mode = MODE_BOOT; } } - else - if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { if (!global.demo_mode && (global.mode == MODE_SURFACE)) { global.demo_mode = 1; @@ -900,57 +870,6 @@ HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); } -static void MX_EXTI_wireless_Init(void) { - GPIO_InitTypeDef GPIO_InitStructure; - - WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); - GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; - GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStructure.Pull = GPIO_NOPULL; - HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); - HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, - GPIO_PIN_SET); - - WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); - GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; - GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStructure.Pull = GPIO_NOPULL; - HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); - - HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0); - HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn); - - WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); - GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; - GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; - GPIO_InitStructure.Pull = GPIO_NOPULL; - HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); - - HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0); - HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn); - -} - -static void MX_EXTI_wireless_DeInit(void) { - GPIO_InitTypeDef GPIO_InitStructure; - - GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; - GPIO_InitStructure.Speed = GPIO_SPEED_LOW; - GPIO_InitStructure.Pull = GPIO_NOPULL; - - GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; - HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; - HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; - HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); - - HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn); - HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn); -} - /* NUCLEO C 13 KEY_BUTTON_GPIO_CLK_ENABLE(); GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Src/compass.c --- a/Small_CPU/Src/compass.c Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Src/compass.c Fri Mar 15 08:22:16 2019 +0000 @@ -39,7 +39,6 @@ #include "stm32f4xx_hal.h" -#define MODE_LSM303DLHC #define TEST_IF_HMC5883L //#define COMPASS_DEACTIVATE @@ -112,7 +111,6 @@ #define HMC5883L (1) ///< id used with hardwareCompass #define LSM303D (2) ///< id used with hardwareCompass -#define LSM303DLHC (3) ///< id used with hardwareCompass #define COMPASS_NOT_RECOGNIZED (4) ///< id used with hardwareCompass @@ -225,12 +223,6 @@ void compass_read_LSM303D(void); void acceleration_read_LSM303D(void); -void compass_init_LSM303DLHC(uint8_t fast, uint8_t gain); -void compass_sleep_LSM303DLHC(void); -void compass_read_LSM303DLHC(void); -void acceleration_read_LSM303DLHC(void); - - int LSM303D_accel_set_onchip_lowpass_filter_bandwidth(unsigned bandwidth); int compass_calib_common(void); @@ -279,34 +271,7 @@ hardwareCompass = HMC5883L; } - -// k�nnte Probleme mit altem Chip machen -// beim 303D f�hrt dieser Code dazu, dass WHOIAM_VALUE nicht geschickt wird!!! - -#ifdef MODE_LSM303DLHC - HAL_StatusTypeDef resultOfOperation = HAL_TIMEOUT; - - if(hardwareCompass == 0) - { - uint8_t data = DLHC_CTRL_REG1_A; - resultOfOperation = I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &data, 1); - if(resultOfOperation == HAL_OK) - { - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &data, 1); - testCompassTypeDebug = data; - if((data & 0x0f) == 0x07) - { - hardwareCompass = LSM303DLHC; - } - } - else - { - testCompassTypeDebug = 0xEE; - } - } - -#endif - +/* No compass identified => Retry */ if(hardwareCompass == 0) { uint8_t data = WHO_AM_I; @@ -318,7 +283,7 @@ hardwareCompass = HMC5883L; } -// was in else before ! +/* Assume that a HMC5883L is equipped by default if detection still failed */ if(hardwareCompass == 0) hardwareCompass = HMC5883L; @@ -341,12 +306,6 @@ } #endif - - if(hardwareCompass == LSM303DLHC) - { - compass_init_LSM303DLHC(fast, gain); - } - else if(hardwareCompass == LSM303D) { compass_init_LSM303D(fast, gain); @@ -374,11 +333,6 @@ // =============================================================================== int compass_calib(void) { - if(hardwareCompass == LSM303DLHC) - { - return compass_calib_common(); // 170821 zur Zeit kein lowpass filtering gefunden, nur high pass auf dem Register ohne Erkl�rung - } - else if(hardwareCompass == LSM303D) { LSM303D_accel_set_onchip_lowpass_filter_bandwidth(773); @@ -406,11 +360,6 @@ // =============================================================================== void compass_sleep(void) { - if(hardwareCompass == LSM303DLHC) - { - compass_sleep_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { compass_sleep_LSM303D(); @@ -430,11 +379,6 @@ // =============================================================================== void compass_read(void) { - if(hardwareCompass == LSM303DLHC) - { - compass_read_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { compass_read_LSM303D(); @@ -453,7 +397,6 @@ // =============================================================================== void accelerator_init(void) { -// if((hardwareCompass != LSM303D) && (hardwareCompass != LSM303DLHC)) if(hardwareCompass == HMC5883L) accelerator_init_MMA8452Q(); } @@ -465,7 +408,6 @@ // =============================================================================== void accelerator_sleep(void) { -// if((hardwareCompass != LSM303D) && (hardwareCompass != LSM303DLHC)) if(hardwareCompass == HMC5883L) accelerator_sleep_MMA8452Q(); } @@ -477,11 +419,6 @@ // =============================================================================== void acceleration_read(void) { - if(hardwareCompass == LSM303DLHC) - { - acceleration_read_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { acceleration_read_LSM303D(); @@ -549,36 +486,6 @@ LSM303D_write_checked_reg(reg, val); } - - -// =============================================================================== -// LSM303DLHC_accelerator_read_req -/// @brief -// =============================================================================== -uint8_t LSM303DLHC_accelerator_read_req(uint8_t addr) -{ - uint8_t data; - - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &addr, 1); - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &data, 1); - return data; -} - - -// =============================================================================== -// LSM303DLHC_accelerator_write_req -/// @brief -// =============================================================================== -void LSM303DLHC_accelerator_write_req(uint8_t addr, uint8_t value) -{ - uint8_t data[2]; - - /* enable accel*/ - data[0] = addr; - data[1] = value; - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, data, 2); -} - /* // =============================================================================== // LSM303D_accel_set_range @@ -1131,204 +1038,6 @@ } -// =============================================================================== -// compass_init_LSM303DLHC -/// @brief The new ST 303DLHC 2017/2018 -/// This might be called several times with different gain values during calibration -/// but gain change is not supported at the moment. -/// parts from KOMPASS LSM303DLH-compass-app-note.pdf -/// -/// @param gain: -/// @param fast: -// =============================================================================== - - - -void compass_init_LSM303DLHC(uint8_t fast, uint8_t gain) -{ -// acceleration - // todo : BDU an (wie 303D) und high res, beides in REG4 - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - - if(fast == 0) - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x27); // 10 hz - } - else - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x57); // 100 hz - } -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x88); // 0x88: BDU + HighRes, BDU ist doof! - LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x00); // 0x00 little-endian, ist's immer -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x08); // 0x08: HighRes - //LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x80); // - - -// compass - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - - if(fast == 0) - { - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - } - else - { - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x18); // 75 Hz - } - LSM303D_write_checked_reg(DLHC_CRB_REG_M,0x20); // 0x60: 2.5 Gauss ,0x40: +/-1.9 Gauss,0x20: +/-1.3 Gauss - LSM303D_write_checked_reg(DLHC_MR_REG_M,0x00); //continuous conversation - - - - return; - - -// LSM303D_write_checked_reg(,); -// LSM303D_write_checked_reg(DLHC_CTRL_REG1_A, 0x27); // 0x27 = acc. normal mode with ODR 50Hz - passt nicht mit datenblatt!! -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x40 = full scale range �2 gauss in continuous data update mode and change the little-endian to a big-endian structure. - - if(fast == 0) - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x27); // 0x27 = acc. normal mode, all axes, with ODR 10HZ laut LSM303DLHC, page 25/42 - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - //LSM303D_write_checked_reg(DLHC_CTRL_REG3_A,0x00); // 0x00 default - // - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG4_A, 0x00); // 0x00 = ich glaube little-endian ist gut -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x00 = ich glaube little-endian ist gut - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG5_A,0x00); // 0x00 default - //LSM303D_write_checked_reg(DLHC_CTRL_REG6_A,0x00); // 0x00 default - // magnetic sensor - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - } - else - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x57); // 0x57 = acc. normal mode, all axes, with ODR 100HZ, LSM303DLHC, page 25/42 - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - //LSM303D_write_checked_reg(DLHC_CTRL_REG3_A,0x00); // 0x00 default - // - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG4_A, 0x00); // 0x00 = ich glaube little-endian ist gut -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x00 = ich glaube little-endian ist gut - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG5_A,0x00); // 0x00 default - //LSM303D_write_checked_reg(DLHC_CTRL_REG6_A,0x00); // 0x00 default - // magnetic sensor - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x18); // 75 Hz - } - LSM303D_write_checked_reg(DLHC_CRB_REG_M,0x02); // +/-1.9 Gauss - LSM303D_write_checked_reg(DLHC_MR_REG_M,0x00); //continuous conversation - - -/* -// matthias version 160620 - if(fast == 0) - { - LSM303D_write_checked_reg(ADDR_CTRL_REG0, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG1, 0x3F); // mod 12,5 Hz 3 instead of 6,25 Hz 2 - LSM303D_write_checked_reg(ADDR_CTRL_REG2, 0xC0); // anti alias 50 Hz (minimum) - LSM303D_write_checked_reg(ADDR_CTRL_REG3, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG4, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG5, 0x68); // mod 12,5 Hz 8 instead of 6,25 Hz 4 - } - else - { - LSM303D_write_checked_reg(ADDR_CTRL_REG0, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG1, 0x6F); // 100 Hz - LSM303D_write_checked_reg(ADDR_CTRL_REG2, 0xC0); - LSM303D_write_checked_reg(ADDR_CTRL_REG3, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG4, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG5, 0x74); // 100 Hz - } - LSM303D_write_checked_reg(ADDR_CTRL_REG6, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG7, 0x00); -*/ - return; -} - -// =============================================================================== -// compass_sleep_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void compass_sleep_LSM303DLHC(void) -{ - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x07); // CTRL_REG1_A: linear acceleration Power-down mode - LSM303D_write_checked_reg(DLHC_MR_REG_M, 0x02); // MR_REG_M: magnetic sensor Power-down mode -} - - -// =============================================================================== -// compass_read_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void compass_read_LSM303DLHC(void) -{ - uint8_t data; - - memset(magDataBuffer,0,6); - - compass_DX_f = 0; - compass_DY_f = 0; - compass_DZ_f = 0; - - for(int i=0;i<6;i++) - { - data = DLHC_OUT_X_L_M + i; - I2C_Master_Transmit( DEVICE_COMPASS_303D, &data, 1); - I2C_Master_Receive( DEVICE_COMPASS_303D, &magDataBuffer[i], 1); - } - - // 303DLHC new order - compass_DX_f = (((int16_t)((magDataBuffer[0] << 8) | (magDataBuffer[1])))); - compass_DZ_f = (((int16_t)((magDataBuffer[2] << 8) | (magDataBuffer[3])))); - compass_DY_f = (((int16_t)((magDataBuffer[4] << 8) | (magDataBuffer[5])))); - - // no rotation, otherwise see compass_read_LSM303D() - return; -} - - -// =============================================================================== -// acceleration_read_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void acceleration_read_LSM303DLHC(void) -{ - uint8_t data; - float xraw_f, yraw_f, zraw_f; - float accel_report_x, accel_report_y, accel_report_z; - - memset(accDataBuffer,0,6); - - accel_DX_f = 0; - accel_DY_f = 0; - accel_DZ_f = 0; - - for(int i=0;i<6;i++) - { - data = DLHC_OUT_X_L_A + i; - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &data, 1); - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &accDataBuffer[i], 1); - } - - xraw_f = ((float)( (int16_t)((accDataBuffer[1] << 8) | (accDataBuffer[0])))); - yraw_f = ((float)( (int16_t)((accDataBuffer[3] << 8) | (accDataBuffer[2])))); - zraw_f = ((float)( (int16_t)((accDataBuffer[5] << 8) | (accDataBuffer[4])))); - - rotate_accel_3f(&xraw_f, &yraw_f, &zraw_f); - - // mh f�r 303D - accel_report_x = xraw_f; - accel_report_y = yraw_f; - accel_report_z = zraw_f; - - accel_DX_f = ((int16_t)(accel_report_x)); - accel_DY_f = ((int16_t)(accel_report_y)); - accel_DZ_f = ((int16_t)(accel_report_z)); -} - - // -------------------------------------------------------------------------------- // ----------EARLIER COMPONENTS --------------------------------------------------- // -------------------------------------------------------------------------------- diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Src/i2c.c --- a/Small_CPU/Src/i2c.c Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Src/i2c.c Fri Mar 15 08:22:16 2019 +0000 @@ -105,7 +105,7 @@ global.dataSendToSlaveStopEval = 1; - global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 100 /*FIXME , 0*/); + global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 0); if(global.I2C_SystemStatus != HAL_OK) { I2C_Error_count(); @@ -128,7 +128,7 @@ 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, 2); if(global.I2C_SystemStatus != HAL_OK) { I2C_Error_count(); diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Wed Mar 13 20:51:50 2019 +0100 +++ b/Small_CPU/Src/scheduler.c Fri Mar 15 08:22:16 2019 +0000 @@ -40,7 +40,6 @@ #include "calc_crush.h" #include "stm32f4xx_hal_rtc_ex.h" #include "decom.h" -#include "wireless.h" #include "tm_stm32f4_otp.h" @@ -87,8 +86,6 @@ void copyTissueData(void); void copyVpmCrushingData(void); void copyDeviceData(void); -void changeAgeWirelessData(void); -void copyWirelessData(void); void copyPICdata(void); uint16_t schedule_update_timer_helper(int8_t thisSeconds); @@ -478,7 +475,6 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; - Scheduler.counterWireless1msec = 0; global.deviceData.diveCycles.value_int32++; scheduleSetDate(&global.deviceData.diveCycles); @@ -490,19 +486,6 @@ lasttick = HAL_GetTick(); ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); - - //Evaluate wireless data every ms, if present - if(ticksdiff > Scheduler.counterWireless1msec) - { - Scheduler.counterWireless1msec++; - changeAgeWirelessData(); - global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus); - if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived)) - { - copyWirelessData(); - } - } - if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) { SPI_Evaluate_RX_Data(); @@ -666,7 +649,6 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; - Scheduler.counterWireless1msec = 0; } } } @@ -767,7 +749,6 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; - Scheduler.counterWireless1msec = 0; global.dataSendToMaster.mode = MODE_SURFACE; global.deviceDataSendToMaster.mode = MODE_SURFACE; @@ -780,16 +761,6 @@ lasttick = HAL_GetTick(); ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); - if(ticksdiff > Scheduler.counterWireless1msec) - { - Scheduler.counterWireless1msec++; - changeAgeWirelessData(); - global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus); - if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived)) - { - copyWirelessData(); - } - } if(setButtonsNow == 1) { if(scheduleSetButtonResponsiveness()) @@ -907,7 +878,6 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; - Scheduler.counterWireless1msec = 0; } } } @@ -922,7 +892,6 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; - Scheduler.counterWireless1msec = 0; dohardspisync = 0; } } @@ -1519,40 +1488,6 @@ global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; } -void changeAgeWirelessData(void) -{ - for(int i=0;i<4;i++) - { - if(global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds) - global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds++; - } -} - -void copyWirelessData(void) -{ - uint8_t boolWirelessData = !global.dataSendToMaster.boolWirelessData; - SDataWireless *dataOld, *dataNew; - for(int i=0;i<3;i++) - { - dataNew = &global.dataSendToMaster.data[boolWirelessData].wireless_data[i+1]; - dataOld = &global.dataSendToMaster.data[!boolWirelessData].wireless_data[i]; - dataNew->ageInMilliSeconds = dataOld->ageInMilliSeconds; - dataNew->numberOfBytes = dataOld->numberOfBytes; - dataNew->status = dataOld->status; - memcpy(dataNew->data, dataOld->data,8); - } - - global.dataSendToMaster.data[boolWirelessData].wireless_data[0].ageInMilliSeconds = 1; - global.dataSendToMaster.data[boolWirelessData].wireless_data[0].numberOfBytes = global.wirelessReceived; - global.dataSendToMaster.data[boolWirelessData].wireless_data[0].status = global.wirelessConfidenceStatus; - for(int i=0;i was removed from OSTC4 code => placeholder*/ void EXTI1_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); diff -r d36596281501 -r 1bb24fd3fc92 Small_CPU/Src/wireless.c --- a/Small_CPU/Src/wireless.c Wed Mar 13 20:51:50 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,856 +0,0 @@ -/** - ****************************************************************************** - * @file wireless.c - * @author heinrichs weikamp gmbh - * @date 02-July-2015 - * @version V0.0.2 - * @since 24-March-2016 - * @brief Data transfer via magnetic field using Manchester code - * - @verbatim - ============================================================================== - ##### How to use ##### - ============================================================================== - history: - 160324 V 0.0.2 für Bonex Sender (Only in old hardware. No longer supported) - - -PA2 triggers to falling edge -PA1 triggers to rising edge -see baseCPU2.c definitions of ports for details -time base is the systick of CMSIS with SysTick->VAL for sub ms info - - -start id is 4 ms low (fall to rise time) -old: followed by 2 ms high (but can continue with high on sending '0' next (Hi->Lo) -160324: followed by bit 0: high to low of byte 1 - -even index numbers are falling edge -odd index numbers are rising edge - -first bit ('1' or '0' can be evaluated with triggerTimeDiffArray[2] (falling edge) -if it is much longer than 2ms than the first bit is '0' -if it is 2ms than it is '1' - -// Manchester code: 1 = low to high; 0 = high to low; -bits are either -rising edge at the middle of the bit transfer -> 1 -falling edge at the middle of the bit transfer -> 0 - -an array is used with even index for falling and odd for rising -the next time difference array entry is set to 0 to identify the loss of any edge -the time index is stored as microseconds -and generated by systick and SysTick->VAL (that is counting down from ->LOAD) - -old: startTime is the first falling edge, hence the ver first falling edge of the start byte) -160324: startTime is the first rising edge - -160324: total transfer time (excluding start with 8 ms) 10*8*2ms + 2ms (stop bit) = 162 ms - -Definition: first bit is always '0' -old: to recognize second start bit easily! -old: hence after 2 ms there is a falling edge! -160324: after 1 ms is a falling edge of first bit with value 0 - -160324: -Measurement of send data: length 162 ms including stop bit -81 bit - -@endverbatim - ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2016 heinrichs weikamp

- * - ****************************************************************************** - */ -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" -#include "wireless.h" -#include "scheduler.h" - -/* array starts with first falling edge - * old: beginning of first start byte, - * old: data starts on 3 - * new: beginning of first bit that is always 0 -> high->low - * new: data starts on 0 - */ - -#define ttdaSize (1200) - -#define TIMEOUTSIZE (20000) - -#define WIRELESS_OK (0) -#define WIRELESS_FAIL (1) - -#define FALLING (0) -#define RISING (1) - -//#define STEP_HALFBIT (1010) -#define STEP_HALFBIT (1000) -#define LIMIT_STARTBIT (5000) -#define MIN_TIME_STARTBIT (3800) -#define MAX_TIME_FIRST_STARTBIT (5200) -#define MIN_TIME_BOTH_STARTBITS (MIN_TIME_STARTBIT + MIN_TIME_STARTBIT) -#define MAX_TIME_BOTH_STARTBITS (MAX_TIME_FIRST_STARTBIT + 4200) -// includes necessary start bit (2000 us) and timing issues -#define HELPER_MAX_DATA_LENGTH_TOLERANCE (10*STEP_HALFBIT) -#define HELPER_MAX_DATA_BYTES (10) ///< 160324: 10, before 8 -#define MAX_DATA_BITS (HELPER_MAX_DATA_BYTES*8) -#define MAX_DATA_LENGTH ((STEP_HALFBIT*2*MAX_DATA_BITS) + HELPER_MAX_DATA_LENGTH_TOLERANCE) - -#define MAX_DIFF_IN_MS ((MAX_DATA_LENGTH+999)/1000) - -void wireless_reset(uint32_t timeMain, uint32_t timeSub); - -/* triggerTimeDiffArray in us with max 65 ms */ - -int32_t triggerNewArray[ttdaSize][2]; - -int32_t triggerNewArrayDebugStartBits[20][2]; - -//uint16_t triggerTimeDiffArray[ttdaSize]; -uint16_t ttdaPointer; -uint32_t startTimeMain; - -uint32_t subDivisorX1000; -uint8_t blockDataCapture = 0; -uint8_t evaluateRequest = 0; ///< - -uint8_t found_first_4ms_high = 0; ///< -uint8_t found_second_4ms_low = 0; ///< - - - - -// =============================================================================== -// wireless_init -/// @brief has to be called once to initialize the variables -// =============================================================================== -void wireless_init(void) -{ - subDivisorX1000 = SysTick->LOAD; ///< never changes - wireless_reset(0,0); - ttdaPointer = 0; ///< is set back again by timeout or on error - blockDataCapture = 0; - //triggerTimeDiffArray[0] = 0; -} - - -/** - ****************************************************************************** - * @brief RECORDING functions - * @author heinrichs weikamp gmbh - * @date 03-July-2015 - * @version V0.0.1 - * @since 03-July-2015 - ****************************************************************************** - */ - - -// =============================================================================== -// wireless_getTime -/// @brief RECORDING -/// -/// @param -// =============================================================================== -void wireless_getTime(uint32_t *timeMain, uint32_t *timeSub) -{ - uint32_t timeSub2, timeMain2; - - *timeSub = SysTick->VAL; - *timeMain = HAL_GetTick(); - timeSub2 = SysTick->VAL; - timeMain2 = HAL_GetTick(); - -/* - static uint32_t difference = 0; - if(ttdaPointer == 1) - difference = 7; //& breakpoint -*/ - - if((timeSub2 > *timeSub) && (timeMain2 == *timeMain)) - *timeMain -= 1; - - *timeSub = subDivisorX1000 - *timeSub; - *timeSub *= 1000; - *timeSub /= subDivisorX1000; -} - - - -/* stored value _could be_ in multiples of 2 us - * to have 1000 for each byte - * 0000 is beginning of start bit (always 1) - * 1000 is beginning of first bit (if timing is perfect, otherwise less or more) - * ... - * XXXX000 is beginning of XXXX bit - * - */ - -// =============================================================================== -// wireless_time0keeper -/// @brief RECORDING -/// -/// @param -/// @return still in us -// =============================================================================== -int32_t wireless_time0keeper(uint8_t store1_or_diffOut0, uint32_t timeMain, uint32_t timeSub) -{ - static uint32_t storeMain = 0, storeSub = 0; - - /* store time0 */ - if(store1_or_diffOut0) - { - storeMain = timeMain; - storeSub = timeSub; - return 0; - } - - /* evaluate time difference */ - int32_t diff = 0; - - if((timeMain < storeMain) || ((timeMain - storeMain) > MAX_DIFF_IN_MS)) - return -1; - - diff = timeMain - storeMain; - diff *= 1000; - diff += timeSub; - diff -= storeSub; - - return diff; -} - - -// =============================================================================== -// wireless_save_time0 -/// @brief RECORDING -/// -/// @param -// =============================================================================== -void wireless_save_time0(uint32_t timeMain, uint32_t timeSub) -{ - wireless_time0keeper(1, timeMain, timeSub); -} - - -// =============================================================================== -// wireless_get_time_since_time0 -/// @brief RECORDING -/// -/// @param -/// @return -// =============================================================================== -int32_t wireless_get_time_since_time0(uint32_t timeMain, uint32_t timeSub) -{ - return wireless_time0keeper(0, timeMain, timeSub); -} - - -// =============================================================================== -// wireless_get_time_since_previous -/// @brief RECORDING -/// -/// @param -/// @return -// =============================================================================== -int32_t wireless_get_time_since_previous(uint8_t fallingOrRising, uint32_t timeMain, uint32_t timeSub) -{ - int32_t absoluteTimeDiff = wireless_time0keeper(0, timeMain, timeSub); - - if(fallingOrRising == FALLING) // same array - { - return (absoluteTimeDiff - triggerNewArray[ttdaPointer][FALLING]); - } - else - if(ttdaPointer > 0) - { - return (absoluteTimeDiff - triggerNewArray[ttdaPointer - 1][RISING]); - } - else // not possible - return -1; -} - - -// =============================================================================== -// wireless_reset -/// @brief RECORDING -/// -/// @param -// =============================================================================== -void wireless_reset(uint32_t timeMain, uint32_t timeSub) -{ - found_first_4ms_high = 0; - found_second_4ms_low = 0; - ttdaPointer = 0; - startTimeMain = 0; - evaluateRequest = 0; - wireless_save_time0(timeMain, timeSub); - triggerNewArray[ttdaPointer][FALLING] = 0; - triggerNewArray[ttdaPointer][RISING] = 0; -} - - - - -// =============================================================================== -// wireless_trigger_FallingEdgeSignalHigh -/// @brief RECORDING -/// -// =============================================================================== -void wireless_trigger_FallingEdgeSignalHigh(void) -{ - uint32_t timeSub, timeMain; - int32_t timeDifference; - - wireless_getTime(&timeMain, &timeSub); - - if((blockDataCapture) || (evaluateRequest == 1)) - return; - - if(evaluateRequest == 2) - wireless_reset(0, 0); - - if(!found_first_4ms_high) // trying to get first start 4ms - { - if(ttdaPointer == 0) - { - wireless_reset(timeMain, timeSub); - } - else - { - timeDifference = wireless_get_time_since_time0(timeMain, timeSub); - if((timeDifference > 0) && (timeDifference <= LIMIT_STARTBIT)) - { - triggerNewArray[ttdaPointer][0] = timeDifference; - } - else - { - wireless_reset(timeMain, timeSub); - } - } - } - else // here comes the very important time0 for all following data - if(!found_second_4ms_low) ///< the beginning of the very first is recorded here :-) - { - timeDifference = wireless_get_time_since_time0(timeMain, timeSub); - if((timeDifference > 0) && (timeDifference >= MIN_TIME_BOTH_STARTBITS) && (timeDifference <= MAX_TIME_BOTH_STARTBITS)) - { - // now we are ready for data - for(int i=0;i<20;i++) - { - if(i <= ttdaPointer) - { - triggerNewArrayDebugStartBits[i][FALLING] = triggerNewArray[i][FALLING]; - triggerNewArrayDebugStartBits[i][RISING] = triggerNewArray[i][FALLING]; - } - else - { - triggerNewArrayDebugStartBits[i][FALLING] = 0; - triggerNewArrayDebugStartBits[i][RISING] = 0; - } - } - wireless_reset(timeMain, timeSub); ///< reset all including ttdaPointer and more - startTimeMain = timeMain; ///< set again - found_first_4ms_high = 1; ///< set again - found_second_4ms_low = 1; ///< set now: ready for recording - } - } - else - { - timeDifference = wireless_get_time_since_time0(timeMain, timeSub); - - if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2))) - { - evaluateRequest = 1; - } - else - { - triggerNewArray[ttdaPointer][FALLING] = timeDifference; - triggerNewArray[ttdaPointer][RISING] = 0; - } - } -} - - -// =============================================================================== -// wireless_trigger_RisingEdgeSilence -/// @brief RECORDING -/// -// =============================================================================== -void wireless_trigger_RisingEdgeSilence(void) -{ - uint32_t timeSub, timeMain; - int32_t timeDifference; - - wireless_getTime(&timeMain, &timeSub); - - if((blockDataCapture) || (evaluateRequest == 1)) - return; - - if(evaluateRequest == 2) - { - wireless_reset(0, 0); - return; // Falling Edge first - } - - timeDifference = wireless_get_time_since_time0(timeMain, timeSub); - - if(!found_first_4ms_high) - { - if((timeDifference > 0) && (timeDifference <= MAX_TIME_FIRST_STARTBIT)) - { - triggerNewArray[ttdaPointer++][RISING] = timeDifference; - triggerNewArray[ttdaPointer][FALLING] = 0; - - if(timeDifference >= MIN_TIME_STARTBIT) ///< start bit is the 4 ms - { - found_first_4ms_high = 1; - found_second_4ms_low = 0; - } - } - } - else - { - if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2))) - { - evaluateRequest = 1; - } - else - { - triggerNewArray[ttdaPointer++][RISING] = timeDifference; - triggerNewArray[ttdaPointer][FALLING] = 0; - } - } -} - - -// =============================================================================== -// wireless_position_next -/// @brief RECORDING -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_position_next(uint16_t *ttdaPointerNow, uint8_t *typeNow) -{ - if(*typeNow == FALLING) - *typeNow = RISING; - else if(*ttdaPointerNow < (ttdaSize - 1)) - { - *ttdaPointerNow += 1; - *typeNow = FALLING; - } - else - { - return WIRELESS_FAIL; - } - return WIRELESS_OK; - -} - - -// =============================================================================== -// wireless_position_previous -/// @brief RECORDING -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_position_previous(uint16_t *ttdaPointerNow, uint8_t *typeNow) -{ - if(*typeNow == RISING) - *typeNow = FALLING; - else if(*ttdaPointerNow > 0) - { - *ttdaPointerNow -= 1; - *typeNow = RISING; - } - else - { - return WIRELESS_FAIL; - } - return WIRELESS_OK; -} - - -// =============================================================================== -// wireless_position_compare -/// @brief RECORDING -/// -/// @param -/// @return -// =============================================================================== -int8_t wireless_position_compare(uint16_t ttdaPointerLeft, uint8_t typeLeft, uint16_t ttdaPointerRight, uint8_t typeRight) -{ - if(ttdaPointerLeft < ttdaPointerRight) - return -1; - else - if(ttdaPointerLeft > ttdaPointerRight) - return 1; - else - if(typeLeft < typeRight) - return -1; - else - if(typeLeft > typeRight) - return 1; - else - return 0; -} - - -// =============================================================================== -// wireless_debug -/// @brief -/// -/// @param -/// @return -// =============================================================================== -/* outlined because of errors while compiling -void wireless_debug(int8_t *adcData, uint16_t max_size_adc) -{ - // debug - uint32_t dataVisual[201]; - uint8_t dataVisualValue[201]; - int8_t dataVisualResult[201]; - - dataVisualValue[0] = 1; - - for(int i=0;i<201;i++) - dataVisualResult[i] = -1; - - for(int i=0;i<201-4;i +=4) - { - dataVisualValue[i] = 1; - dataVisualValue[i+1] = 1; - dataVisualValue[i+2] = 0; - dataVisualValue[i+3] = 0; - } - - dataVisual[0] = triggerNewArray[0][FALLING]; - - int j = 1; - uint32_t valueStore = 0; - for(int i=0;i<50;i++) - { - valueStore = triggerNewArray[i][FALLING]; - dataVisual[j++] = valueStore; - dataVisual[j++] = valueStore + 1; - valueStore = triggerNewArray[i][RISING]; - dataVisual[j++] = valueStore; - dataVisual[j++] = valueStore + 1; - } - - - if(max_size_adc > 0) - { - int jStep = 0; - int jData = 0; - for(int i=0;i<201;i++) - { - if(dataVisual[i] >= jStep) - { - if(adcData[jData] > 0) - dataVisualResult[i] = 1; - else - dataVisualResult[i] = 0; - jStep += STEP_HALFBIT + STEP_HALFBIT; - jData++; - if(jData >= max_size_adc) - break; - } - } - } -} -*/ - -// =============================================================================== -// wireless_debug_test_failed_AACCF1010203 -/// @brief -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_debug_test_failed_AACCF1010203(uint8_t *data) -{ - if(data[0] != 0xAA) - return 1; - if(data[1] != 0xCC) - return 1; - if(data[2] != 0xF1) - return 1; - if(data[3] != 0x01) - return 1; - if(data[4] != 0x02) - return 0; - if(data[5] != 0x03) - return 1; - - return 0; -} - - -// =============================================================================== -// wireless_check_crc_failed -/// @brief -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_check_crc_failed(uint8_t *dataOut, uint8_t maxData) -{ - return (wireless_debug_test_failed_AACCF1010203(dataOut)); -} - - -/** - ****************************************************************************** - * @brief EVALUATION functions - * @author heinrichs weikamp gmbh - * @date 03-July-2015 - * @version V0.0.2 - * @since 14-July-2015 - ****************************************************************************** - */ - -// =============================================================================== -// wireless_time0keeper -/// @brief EVALUATION -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_evaluate_internal_loop(uint8_t *dataOut, uint8_t maxData, int32_t shift, uint8_t *confidence) -{ - // variables - int iOut = 0; - int jAdc = 0; - - int8_t adcData[MAX_DATA_BITS]; - uint16_t adcPointer = 0; - - int8_t bitLeft = 0; - int8_t bitRight = 0; - - uint16_t ttdaPointerStart = 0; - uint16_t ttdaPointerEnd = 0; - uint8_t typeStart = RISING; - uint8_t typeEnd = RISING; - int32_t startTimeHalfBit = 0; - int32_t endTimeHalfBit = 0; - int32_t startOfThisPeak = 0; - int32_t endOfThisPeak = 0; - uint8_t wirelessErrorStatus = 0; - uint8_t timeToStop = 0; - int32_t valueSingle = 0; - int32_t halfbitTemp = 0; - int confidenceTemp = 0; - - // safety end for all loops coming - triggerNewArray[ttdaPointer][RISING] = INT32_MAX; - - ttdaPointerStart = 0; - ttdaPointerEnd = 0; - typeStart = RISING; - typeEnd = RISING; - startTimeHalfBit = 0; - endTimeHalfBit = shift; - adcPointer = 0; - - while(!timeToStop) - { - // start is latest start - ttdaPointerEnd = ttdaPointerStart; - typeEnd = typeStart; - for(int doItTwice=0;doItTwice<2;doItTwice++) - { - startTimeHalfBit = endTimeHalfBit; - endTimeHalfBit += STEP_HALFBIT; - // find the end for this half bit; this will include values that continue to the next halfbit and negative values - while(triggerNewArray[ttdaPointerEnd][typeEnd] < endTimeHalfBit) - wireless_position_next(&ttdaPointerEnd,&typeEnd); - - if(triggerNewArray[ttdaPointerEnd][typeEnd] == INT32_MAX) - { - timeToStop = 1; - break; - } - startOfThisPeak = startTimeHalfBit; - wirelessErrorStatus = 0; - halfbitTemp = 0; - while(!wirelessErrorStatus && (wireless_position_compare(ttdaPointerStart,typeStart, ttdaPointerEnd,typeEnd) <= 0)) - { - endOfThisPeak = triggerNewArray[ttdaPointerStart][typeStart]; - if(endOfThisPeak <= startOfThisPeak) - { - wireless_position_next(&ttdaPointerStart,&typeStart); - } - else - { - // TODO: what about time difference errors? - if(endOfThisPeak >= endTimeHalfBit) - valueSingle = endTimeHalfBit - startOfThisPeak; - else - valueSingle = endOfThisPeak - startOfThisPeak; - - if(typeStart == RISING) - { - halfbitTemp += valueSingle; - } - // next, also valid for every next halfbit - if(endOfThisPeak <= endTimeHalfBit) - { - startOfThisPeak = endOfThisPeak; - wireless_position_next(&ttdaPointerStart,&typeStart); - } - else - { - startOfThisPeak = endTimeHalfBit; - } - // should not be necessary, anyway - if(startOfThisPeak == endTimeHalfBit) - break; - } - } - // store - halfbitTemp *= 100; - halfbitTemp /= STEP_HALFBIT; - if(halfbitTemp > 100) halfbitTemp = 100; - if(doItTwice == 0) - { - bitLeft = halfbitTemp; - } - else - { - bitRight = halfbitTemp; - } - } - // Gewichtung und Bit Generierung - adcData[adcPointer++] = (int8_t)((bitLeft - bitRight)); // possitive value - if(adcPointer >= MAX_DATA_BITS) - timeToStop = 1; - } - - // Auswertung - jAdc = 0; - iOut = 0; - - for(int i=0;i 0)) - dataOut[i] |= 1; - if(jAdc >= adcPointer) - { - j++; - while(j<8) - { - jAdc = adcPointer + 1; // end signal - dataOut[i] *= 2; - j++; - } - break; - } - } - if(jAdc > adcPointer) - break; - iOut++; - } - - confidenceTemp = 0; - for(int i=0;i= 5) && wireless_debug_test_failed_AACCF1010203(dataOut)) - wireless_debug(adcData,MAX_DATA_BITS); -*/ - return iOut; - -} - - -// =============================================================================== -// wireless_evaluate_crc_error -/// @brief EVALUATION -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_evaluate_crc_error(uint8_t *dataIn, uint8_t maxData) -{ - uint8_t crcTest = 0; - for(int i=0; i< maxData; i++) - crcTest ^= dataIn[i]; - - return crcTest; -} - - -// =============================================================================== -// wireless_evaluate -/// @brief EVALUATION -/// -/// @param -/// @return -// =============================================================================== -uint8_t wireless_evaluate(uint8_t *dataOut, uint8_t maxData, uint8_t *confidence) -{ - uint32_t timeTick; - uint32_t timeElapsed; - - timeTick = HAL_GetTick(); - timeElapsed = time_elapsed_ms(startTimeMain,timeTick); - - uint8_t start = 0; - int iOut = 0; - - // check condition for start - if(evaluateRequest == 2) - return 0; - - if(evaluateRequest == 1) - start = 1; - - if((ttdaPointer > 10) && (timeElapsed > (MAX_DATA_LENGTH/1000))) - start = 1; - - if(!start) - return 0; - - // start - blockDataCapture = 1; - - // evaluate - iOut = wireless_evaluate_internal_loop(dataOut, maxData, 0, confidence); - - - /* - for(int i=0; i>=-500; i -= 100) - { - iOut = wireless_evaluate_internal_loop(dataOut, maxData, i, confidence); - if(iOut < 5) - break; - if(wireless_check_crc_failed(dataOut,iOut) == 0) - break; - } -*/ - // end - evaluateRequest = 2; - blockDataCapture = 0; - - return iOut; -} - -/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/