From 05292c12ba0c374259fa2b2e99ed029e52d9af04 Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Mon, 27 Jan 2020 15:04:52 +0100 Subject: [PATCH] ADC & DMA renamed to DAQ (data acquisition) --- src/adc_dma.h | 89 ------------------ src/{adc_dma.cpp => daq.cpp} | 8 +- src/daq.h | 78 ++++++++++++++++ src/{adc_dma_mbed.cpp => daq_mbed.cpp} | 18 +++- src/{adc_dma_zephyr.c => daq_zephyr.c} | 105 +++++++++++++--------- src/device_status.h | 2 +- src/main_mbed.cpp | 19 ++-- src/main_zephyr.cpp | 25 ++---- src/pwm_switch.cpp | 2 +- test/{adc_dma_stub.h => daq_stub.h} | 4 +- test/main.cpp | 4 +- test/tests.h | 2 +- test/{tests_adc_dma.cpp => tests_daq.cpp} | 20 ++--- test/tests_load.cpp | 4 +- test/tests_power_port.cpp | 8 +- zephyr/CMakeLists.txt | 4 +- 16 files changed, 199 insertions(+), 193 deletions(-) delete mode 100644 src/adc_dma.h rename src/{adc_dma.cpp => daq.cpp} (98%) create mode 100644 src/daq.h rename src/{adc_dma_mbed.cpp => daq_mbed.cpp} (95%) rename src/{adc_dma_zephyr.c => daq_zephyr.c} (88%) rename test/{adc_dma_stub.h => daq_stub.h} (92%) rename test/{tests_adc_dma.cpp => tests_daq.cpp} (93%) diff --git a/src/adc_dma.h b/src/adc_dma.h deleted file mode 100644 index 16b368a..0000000 --- a/src/adc_dma.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** @file - * - * @brief Reads ADC via DMA and stores data into necessary structs - */ - -#ifndef ADC_DMA_H -#define ADC_DMA_H - -#ifdef __ZEPHYR__ -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define ADC_FILTER_CONST 5 // filter multiplier = 1/(2^ADC_FILTER_CONST) - -/** Struct to definie upper and lower limit alerts for any ADC channel - */ -typedef struct { - void (*callback)(); ///< Function to be called when limits are exceeded - uint16_t limit; ///< ADC reading for lower limit - int debounce_ms; ///< Milliseconds delay for triggering alert -} AdcAlert; - -/** Sets offset to actual measured value, i.e. sets zero current point. - * - * All input/output switches and consumers should be switched off before calling this function - */ -void calibrate_current_sensors(); - -/** Updates structures with data read from ADC - */ -void update_measurements(); - -#ifdef __ZEPHYR__ - -/** Restarts ADC sampling sequence (should be called by timer) - */ -void adc_trigger_conversion(struct k_timer *timer_id); - -#else - -/** Initializes registers and starts ADC timer - */ -void adc_timer_start(int freq_Hz); - -#endif /* __ZEPHYR__ */ - -/** Sets necessary ADC registers - */ -void adc_setup(void); - -/** Sets necessary DMA registers - */ -void dma_setup(void); - -/** Read, filter and check raw ADC readings stored by DMA controller - */ -void adc_update_value(unsigned int pos); - -/** Set lv side (battery) voltage limits where an alert should be triggered - * - * @param upper Upper voltage limit - * @param lower Lower voltage limit - */ -void adc_set_lv_alerts(float upper, float lower); - -/** Add an inhibit delay to the alerts to disable it temporarily - * - * @param adc_pos The position of the ADC measurement channel - * @param timeout_ms Timeout in milliseconds - */ -void adc_upper_alert_inhibit(int adc_pos, int timeout_ms); - -#ifdef __cplusplus -} -#endif - -#endif /* ADC_DMA */ diff --git a/src/adc_dma.cpp b/src/daq.cpp similarity index 98% rename from src/adc_dma.cpp rename to src/daq.cpp index 9850edf..b5360a4 100644 --- a/src/adc_dma.cpp +++ b/src/daq.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "adc_dma.h" +#include "daq.h" #include // log for thermistor calculation #include @@ -142,7 +142,7 @@ void adc_update_value(unsigned int pos) } } -void update_measurements() +void daq_update() { // reference voltage of 2.5 V at PIN_V_REF //int vcc = 2500 * 4096 / (adc_filtered[ADC_POS_V_REF] >> (4 + ADC_FILTER_CONST)); @@ -272,7 +272,7 @@ uint16_t adc_get_alert_limit(float scale, float limit) // shift 4 bits left to generate left aligned 16bit value } -void adc_set_lv_alerts(float upper, float lower) +void daq_set_lv_alerts(float upper, float lower) { int vcc = VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU); float scale = ((4096* 1000) / (ADC_GAIN_V_BAT)) / vcc; @@ -288,7 +288,7 @@ void adc_set_lv_alerts(float upper, float lower) #if defined(UNIT_TEST) -#include "../test/adc_dma_stub.h" +#include "../test/daq_stub.h" void prepare_adc_readings(AdcValues values) { diff --git a/src/daq.h b/src/daq.h new file mode 100644 index 0000000..4c7b39a --- /dev/null +++ b/src/daq.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2016 Martin Jäger / Libre Solar + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Data Acquisition (DAQ) + * + * Measurements are taken using ADC with DMA. The DAC is used to generate reference voltages + * for bi-directional current measurement. Data is stored in structs, which are afterwards + * used by the control algorithms + */ + +#ifndef DAQ_H_ +#define DAQ_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define ADC_FILTER_CONST 5 // filter multiplier = 1/(2^ADC_FILTER_CONST) + +/** + * Struct to definie upper and lower limit alerts for any ADC channel + */ +typedef struct { + void (*callback)(); ///< Function to be called when limits are exceeded + uint16_t limit; ///< ADC reading for lower limit + int debounce_ms; ///< Milliseconds delay for triggering alert +} AdcAlert; + +/** + * Set offset vs. actual measured value, i.e. sets zero current point. + * + * All input/output switches and consumers should be switched off before calling this function + */ +void calibrate_current_sensors(void); + +/** + * Updates structures with data read from ADC + */ +void daq_update(void); + +/** + * Initializes ADC, DAC and DMA + */ +void daq_setup(void); + +/** + * Read, filter and check raw ADC readings stored by DMA controller + */ +void adc_update_value(unsigned int pos); + +/** + * Set lv side (battery) voltage limits where an alert should be triggered + * + * @param upper Upper voltage limit + * @param lower Lower voltage limit + */ +void daq_set_lv_alerts(float upper, float lower); + +/** + * Add an inhibit delay to the alerts to disable it temporarily + * + * @param adc_pos The position of the ADC measurement channel + * @param timeout_ms Timeout in milliseconds + */ +void adc_upper_alert_inhibit(int adc_pos, int timeout_ms); + +#ifdef __cplusplus +} +#endif + +#endif /* DAQ_H_ */ diff --git a/src/adc_dma_mbed.cpp b/src/daq_mbed.cpp similarity index 95% rename from src/adc_dma_mbed.cpp rename to src/daq_mbed.cpp index 2a2fdc3..d1c177c 100644 --- a/src/adc_dma_mbed.cpp +++ b/src/daq_mbed.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "adc_dma.h" +#include "daq.h" #if defined(__MBED__) @@ -73,12 +73,15 @@ extern "C" void DMA1_Channel1_IRQHandler(void) DMA1->IFCR |= 0x0FFFFFFF; // clear all interrupt registers } -void adc_setup() +void dac_setup() { #ifdef PIN_REF_I_DCDC ref_i_dcdc = 0.1; // reference voltage for zero current (0.1 for buck, 0.9 for boost, 0.5 for bi-directional) #endif +} +void adc_setup() +{ #ifdef PIN_V_SOLAR_EN DigitalOut solar_en(PIN_V_SOLAR_EN); solar_en = 1; @@ -218,4 +221,15 @@ extern "C" void TIM6_IRQHandler(void) #endif +void daq_setup() +{ + dac_setup(); // for current sensor references + adc_setup(); + dma_setup(); + adc_timer_start(1000); // 1 kHz + wait(0.5); // wait for ADC to collect some measurement values + daq_update(); + calibrate_current_sensors(); +} + #endif /* __MBED__ */ \ No newline at end of file diff --git a/src/adc_dma_zephyr.c b/src/daq_zephyr.c similarity index 88% rename from src/adc_dma_zephyr.c rename to src/daq_zephyr.c index 911b62d..9ed6fe6 100644 --- a/src/adc_dma_zephyr.c +++ b/src/daq_zephyr.c @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "adc_dma.h" +#include "daq.h" -#if defined(__ZEPHYR__)// && defined(CONFIG_SOC_SERIES_STM32L0X) +#if defined(__ZEPHYR__) #include #include @@ -79,51 +79,13 @@ extern uint16_t adc_readings[]; void adc_update_value(unsigned int pos); -void DMA1_Channel1_IRQHandler(void *args) +static void dac_setup() { - if ((DMA1->ISR & DMA_ISR_TCIF1) != 0) // Test if transfer completed on DMA channel 1 - { - for (unsigned int i = 0; i < NUM_ADC_CH; i++) { - adc_update_value(i); - } - } - DMA1->IFCR |= 0x0FFFFFFF; // clear all interrupt registers + /* TODO */ } -void dma_setup() +static void adc_setup() { - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); - - LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_1, - LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA), // source address - (uint32_t)(&(adc_readings[0])), // destination address - LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - // Configure the number of DMA transfers (data length in multiples of size per transfer) - LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, NUM_ADC_CH * 2); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1); // transfer error interrupt - LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1); // transfer complete interrupt - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); - - // Configure NVIC for DMA (priority 2: second-lowest value for STM32L0/F0) - IRQ_CONNECT(DMA1_Channel1_IRQn, 2, DMA1_Channel1_IRQHandler, 0, 0); - irq_enable(DMA1_Channel1_IRQn); - - LL_ADC_REG_StartConversion(ADC1); -} - -void adc_setup() -{ -#ifdef PIN_REF_I_DCDC - //ref_i_dcdc = 0.1; // reference voltage for zero current (0.1 for buck, 0.9 for boost, 0.5 for bi-directional) -#endif - #ifdef PIN_V_SOLAR_EN //DigitalOut solar_en(PIN_V_SOLAR_EN); //solar_en = 1; @@ -174,9 +136,64 @@ void adc_setup() LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_UNLIMITED); } -void adc_trigger_conversion(struct k_timer *timer_id) +static inline void adc_trigger_conversion(struct k_timer *timer_id) { LL_ADC_REG_StartConversion(ADC1); } +static void DMA1_Channel1_IRQHandler(void *args) +{ + if ((DMA1->ISR & DMA_ISR_TCIF1) != 0) // Test if transfer completed on DMA channel 1 + { + for (unsigned int i = 0; i < NUM_ADC_CH; i++) { + adc_update_value(i); + } + } + DMA1->IFCR |= 0x0FFFFFFF; // clear all interrupt registers +} + +static void dma_setup() +{ + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); + + LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_1, + LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA), // source address + (uint32_t)(&(adc_readings[0])), // destination address + LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + + // Configure the number of DMA transfers (data length in multiples of size per transfer) + LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, NUM_ADC_CH * 2); + + LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); + LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); + LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1); // transfer error interrupt + LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1); // transfer complete interrupt + LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); + + LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); + + // Configure NVIC for DMA (priority 2: second-lowest value for STM32L0/F0) + IRQ_CONNECT(DMA1_Channel1_IRQn, 2, DMA1_Channel1_IRQHandler, 0, 0); + irq_enable(DMA1_Channel1_IRQn); + + LL_ADC_REG_StartConversion(ADC1); +} + +void daq_setup() +{ + static struct k_timer adc_trigger_timer; + + dac_setup(); + adc_setup(); + dma_setup(); + + k_timer_init(&adc_trigger_timer, adc_trigger_conversion, NULL); + k_timer_start(&adc_trigger_timer, K_MSEC(1), K_MSEC(1)); // 1 kHz + + k_sleep(500); // wait for ADC to collect some measurement values + daq_update(); + calibrate_current_sensors(); +} + #endif // __ZEPHYR__ diff --git a/src/device_status.h b/src/device_status.h index a637427..5fc4bd9 100644 --- a/src/device_status.h +++ b/src/device_status.h @@ -111,7 +111,7 @@ enum ErrorFlag { /** Charge controller internal temperature too high * - * Set and cleared by ADC update_measurements() + * Set and cleared by daq_update() */ ERR_INT_OVERTEMP = 1U << 13, diff --git a/src/main_mbed.cpp b/src/main_mbed.cpp index b1db197..f159d50 100644 --- a/src/main_mbed.cpp +++ b/src/main_mbed.cpp @@ -22,12 +22,12 @@ #include "dcdc.h" // DC/DC converter control (hardware independent) #include "pwm_switch.h" // PWM charge controller #include "bat_charger.h" // battery settings and charger state machine -#include "adc_dma.h" // ADC using DMA and conversion to measurement values -#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector +#include "daq.h" // ADC using DMA and conversion to measurement values +#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector #include "eeprom.h" // external I2C EEPROM #include "load.h" // load and USB output management #include "leds.h" // LED switching using charlieplexing -#include "device_status.h" // log data (error memory, min/max measurements, etc.) +#include "device_status.h" // log data (error memory, min/max measurements, etc.) #include "data_objects.h" // for access to internal data via ThingSet #include "bl_support.h" // Bootloader support from the application side @@ -106,13 +106,8 @@ int main() ts.set_user_password(THINGSET_USER_PASSWORD); // passwords defined in config.h (see template) ts.set_maker_password(THINGSET_MAKER_PASSWORD); - // ADC, DMA and sensor calibration - adc_setup(); - dma_setup(); - adc_timer_start(1000); // 1 kHz - wait(0.5); // wait for ADC to collect some measurement values - update_measurements(); - calibrate_current_sensors(); + // Data Acquisition (DAQ) setup + daq_setup(); // initialize all extensions and external communication interfaces ext_mgr.enable_all(); @@ -189,10 +184,10 @@ void system_control() static int counter = 0; // convert ADC readings to meaningful measurement values - update_measurements(); + daq_update(); // alerts should trigger only for transients, so update based on actual voltage - adc_set_lv_alerts(lv_terminal.voltage * 1.2, lv_terminal.voltage * 0.8); + daq_set_lv_alerts(lv_terminal.voltage * 1.2, lv_terminal.voltage * 0.8); #if CONFIG_HAS_PWM_SWITCH ports_update_current_limits(&pwm_port_int, &bat_terminal, &load_terminal); diff --git a/src/main_zephyr.cpp b/src/main_zephyr.cpp index 1883781..0e6ec9a 100644 --- a/src/main_zephyr.cpp +++ b/src/main_zephyr.cpp @@ -20,12 +20,12 @@ #include "dcdc.h" // DC/DC converter control (hardware independent) #include "pwm_switch.h" // PWM charge controller #include "bat_charger.h" // battery settings and charger state machine -#include "adc_dma.h" // ADC using DMA and conversion to measurement values -#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector +#include "daq.h" // ADC using DMA and conversion to measurement values +#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector #include "eeprom.h" // external I2C EEPROM #include "load.h" // load and USB output management #include "leds.h" // LED switching using charlieplexing -#include "device_status.h" // log data (error memory, min/max measurements, etc.) +#include "device_status.h" // log data (error memory, min/max measurements, etc.) #include "data_objects.h" // for access to internal data via ThingSet PowerPort lv_terminal; // low voltage terminal (battery for typical MPPT) @@ -100,17 +100,8 @@ void main(void) //ts.set_user_password(THINGSET_USER_PASSWORD); // passwords defined in config.h (see template) //ts.set_maker_password(THINGSET_MAKER_PASSWORD); - // ADC, DMA and sensor calibration - adc_setup(); - dma_setup(); - - struct k_timer adc_trigger_timer; - k_timer_init(&adc_trigger_timer, adc_trigger_conversion, NULL); - k_timer_start(&adc_trigger_timer, K_MSEC(1), K_MSEC(1)); // 1 kHz - - k_sleep(500); // wait for ADC to collect some measurement values - update_measurements(); - calibrate_current_sensors(); + // Data Acquisition (DAQ) setup + daq_setup(); // initialize all extensions and external communication interfaces ext_mgr.enable_all(); @@ -145,10 +136,10 @@ void control_thread() while (1) { // convert ADC readings to meaningful measurement values - update_measurements(); + daq_update(); // alerts should trigger only for transients, so update based on actual voltage - adc_set_lv_alerts(lv_terminal.voltage * 1.2, lv_terminal.voltage * 0.8); + daq_set_lv_alerts(lv_terminal.voltage * 1.2, lv_terminal.voltage * 0.8); #if CONFIG_HAS_PWM_SWITCH ports_update_current_limits(&pwm_port_int, &bat_terminal, &load_terminal); @@ -158,7 +149,7 @@ void control_thread() #if CONFIG_HAS_DCDC_CONVERTER ports_update_current_limits(&dcdc_lv_port, &bat_terminal, &load_terminal); - dcdc.control(); // control of DC/DC including MPPT algorithm + //dcdc.control(); // control of DC/DC including MPPT algorithm leds_set_charging(half_bridge_enabled()); #endif diff --git a/src/pwm_switch.cpp b/src/pwm_switch.cpp index 9bcb55a..8f638ca 100644 --- a/src/pwm_switch.cpp +++ b/src/pwm_switch.cpp @@ -8,7 +8,7 @@ #include "config.h" #include "pcb.h" -#include "adc_dma.h" +#include "daq.h" #include "debug.h" #include "helper.h" diff --git a/test/adc_dma_stub.h b/test/daq_stub.h similarity index 92% rename from test/adc_dma_stub.h rename to test/daq_stub.h index be153e1..b0357fe 100644 --- a/test/adc_dma_stub.h +++ b/test/daq_stub.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ADC_DMA_STUB_H -#define ADC_DMA_STUB_H +#ifndef DAQ_STUB_H_ +#define DAQ_STUB_H_ #include "config.h" diff --git a/test/main.cpp b/test/main.cpp index c6921f2..5e41c12 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,7 +13,7 @@ #include "dcdc.h" // DC/DC converter control (hardware independent) #include "pwm_switch.h" // PWM charge controller #include "bat_charger.h" // battery settings and charger state machine -#include "adc_dma.h" // ADC using DMA and conversion to measurement values +#include "daq.h" // ADC using DMA and conversion to measurement values #include "eeprom.h" // external I2C EEPROM #include "load.h" // load and USB output management #include "leds.h" // LED switching using charlieplexing @@ -78,7 +78,7 @@ time_t timestamp; // current unix timestamp (independent of time(NULL), as it int main() { - adc_tests(); + daq_tests(); bat_charger_tests(); power_port_tests(); half_brigde_tests(); diff --git a/test/tests.h b/test/tests.h index 64406e9..f7e77ed 100644 --- a/test/tests.h +++ b/test/tests.h @@ -9,7 +9,7 @@ void bat_charger_tests(); -void adc_tests(); +void daq_tests(); void power_port_tests(); diff --git a/test/tests_adc_dma.cpp b/test/tests_daq.cpp similarity index 93% rename from test/tests_adc_dma.cpp rename to test/tests_daq.cpp index b60d4d4..ac628a5 100644 --- a/test/tests_adc_dma.cpp +++ b/test/tests_daq.cpp @@ -5,8 +5,8 @@ */ #include "tests.h" -#include "adc_dma.h" -#include "adc_dma_stub.h" +#include "daq.h" +#include "daq_stub.h" #include "main.h" @@ -73,7 +73,7 @@ void adc_alert_undervoltage_triggering() { dev_stat.clear_error(ERR_ANY_ERROR); battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100); - adc_set_lv_alerts(bat_conf.voltage_absolute_max, bat_conf.voltage_absolute_min); + daq_set_lv_alerts(bat_conf.voltage_absolute_max, bat_conf.voltage_absolute_min); prepare_adc_filtered(); adc_update_value(ADC_POS_V_BAT); @@ -92,7 +92,7 @@ void adc_alert_undervoltage_triggering() adcval.battery_voltage = 13; prepare_adc_readings(adcval); prepare_adc_filtered(); - update_measurements(); + daq_update(); charger.discharge_control(&bat_conf); TEST_ASSERT_EQUAL(false, dev_stat.has_error(ERR_BAT_UNDERVOLTAGE)); @@ -102,7 +102,7 @@ void adc_alert_overvoltage_triggering() { dev_stat.clear_error(ERR_ANY_ERROR); battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100); - adc_set_lv_alerts(bat_conf.voltage_absolute_max, bat_conf.voltage_absolute_min); + daq_set_lv_alerts(bat_conf.voltage_absolute_max, bat_conf.voltage_absolute_min); prepare_adc_filtered(); adc_update_value(ADC_POS_V_BAT); @@ -122,7 +122,7 @@ void adc_alert_overvoltage_triggering() adcval.battery_voltage = 12; prepare_adc_readings(adcval); prepare_adc_filtered(); - update_measurements(); + daq_update(); charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1; charger.charge_control(&bat_conf); @@ -136,12 +136,12 @@ void adc_alert_overflow_prevention() TEST_ASSERT_EQUAL_HEX((uint16_t)(UINT16_MAX << 4), limit); } -/** ADC conversion test +/** Data acquisition tests * * Purpose: Check if raw data from 2 voltage and 2 current measurements are converted * to calculated voltage/current measurements of different DC buses */ -void adc_tests() +void daq_tests() { adcval.bat_temperature = 25; adcval.battery_voltage = 12; @@ -155,8 +155,8 @@ void adc_tests() RUN_TEST(check_filtering); - // call original update_measurements function - update_measurements(); + // call original daq_update function + daq_update(); RUN_TEST(check_solar_terminal_readings); RUN_TEST(check_bat_terminal_readings); diff --git a/test/tests_load.cpp b/test/tests_load.cpp index 411a3dd..c1d83c4 100644 --- a/test/tests_load.cpp +++ b/test/tests_load.cpp @@ -5,8 +5,8 @@ */ #include "tests.h" -#include "adc_dma_stub.h" -#include "adc_dma.h" +#include "daq_stub.h" +#include "daq.h" #include #include diff --git a/test/tests_power_port.cpp b/test/tests_power_port.cpp index e9ae68b..b2eff3b 100644 --- a/test/tests_power_port.cpp +++ b/test/tests_power_port.cpp @@ -5,8 +5,8 @@ */ #include "tests.h" -#include "adc_dma_stub.h" -#include "adc_dma.h" +#include "daq_stub.h" +#include "daq.h" #include #include @@ -44,7 +44,7 @@ void energy_calculation_init() // insert values into ADC functions prepare_adc_readings(adcval); prepare_adc_filtered(); - update_measurements(); + daq_update(); for (int i = 0; i < 60*60*sun_hours; i++) { hv_terminal.energy_balance(); @@ -56,7 +56,7 @@ void energy_calculation_init() adcval.dcdc_current = 0; prepare_adc_readings(adcval); prepare_adc_filtered(); - update_measurements(); + daq_update(); for (int i = 0; i < 60*60*night_hours; i++) { hv_terminal.energy_balance(); diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 74f12f8..9bfa5c5 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -12,10 +12,10 @@ add_definitions(-D__ZEPHYR__ -DDEBUG_PRINT_FLAGS=7) include_directories(../src) -target_sources(app PRIVATE ../src/adc_dma.cpp) -target_sources(app PRIVATE ../src/adc_dma_zephyr.c) target_sources(app PRIVATE ../src/bat_charger.cpp) target_sources(app PRIVATE ../src/data_objects.cpp) +target_sources(app PRIVATE ../src/daq.cpp) +target_sources(app PRIVATE ../src/daq_zephyr.c) target_sources(app PRIVATE ../src/device_status.cpp) target_sources(app PRIVATE ../src/dcdc.cpp) target_sources(app PRIVATE ../src/eeprom.cpp)