From fa833c73c677a3f8d1ff038d3a290650277559f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucher?= <cfoucher@laas.fr> Date: Tue, 7 Feb 2023 11:21:55 +0100 Subject: [PATCH] Small improvements to Data Acquisition, Scheduling and GPIO modules. Data Acquisition module: - Get rid of static qualifiers that add complexity to code and are useless if user use the module correctly (i.e. does not instantiate its own object). - Add guards to prevent accessing module functions when it is not started. - Rewrite functions comments to ease API understanding. - Corrected voltage offsets that were invalidated by conversion formula change. Scheduling module: - Add an initial value of "uninitialized" for interrupt source. - Use typedef enum instead of enum class: prefix not mandatory any more. GPIO module: - Just add small comments to public include file to better understand file sections. --- .../zephyr/data_conversion/data_conversion.c | 2 +- .../zephyr/public_api/DataAcquisition.cpp | 405 +++++++++++++----- .../zephyr/public_api/DataAcquisition.h | 166 +++---- .../zephyr/public_api/GpioApi.h | 12 + .../zephyr/public_api/Scheduling.h | 8 +- .../src/uninterruptible_synchronous_task.cpp | 14 +- 6 files changed, 407 insertions(+), 200 deletions(-) diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.c b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.c index b02b73b..6bb2143 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.c +++ b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.c @@ -45,7 +45,7 @@ static float32_t offset_currents[3] = {25.9, 29.28, 0}; //i1_low, i2_low o // Voltages static float32_t gain_voltages[3] = {0.0462, 0.0462, 0.0640}; //v1_low, v2_low and v_high -static float32_t offset_voltages[3] = {94.04, 94.04, 4.408}; //v1_low, v2_low and v_high +static float32_t offset_voltages[3] = {-94.04, -94.04, 4.408}; //v1_low, v2_low and v_high static float32_t gain_extra = 1.0; //gain for the extra static float32_t offset_extra = 1.0; //offset for the extra diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp index 77580c4..aea7cb1 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp +++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp @@ -45,21 +45,6 @@ DataAcquisition dataAcquisition; -///// -// Initialize static members - -DataAcquisition::channel_assignment_t DataAcquisition::v1_low_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::v2_low_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::v_high_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::i1_low_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::i2_low_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::i_high_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::temp_sensor_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::extra_sensor_assignement = {0}; -DataAcquisition::channel_assignment_t DataAcquisition::analog_comm_assignement = {0}; - -bool DataAcquisition::is_started = false; - ///// // Public static configuration functions @@ -132,7 +117,6 @@ void DataAcquisition::start() break; } } - } // Initialize data dispatch @@ -141,12 +125,12 @@ void DataAcquisition::start() // Launch ADC conversion adc_start(); - DataAcquisition::is_started = true; + this->is_started = true; } bool DataAcquisition::started() { - return DataAcquisition::is_started; + return this->is_started; } @@ -155,231 +139,422 @@ bool DataAcquisition::started() uint16_t* DataAcquisition::getV1LowRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(v1_low_assignement.adc_number, v1_low_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(v1_low_assignement.adc_number, v1_low_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getV2LowRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(v2_low_assignement.adc_number, v2_low_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(v2_low_assignement.adc_number, v2_low_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getVHighRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(v_high_assignement.adc_number, v_high_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(v_high_assignement.adc_number, v_high_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getI1LowRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(i1_low_assignement.adc_number, i1_low_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(i1_low_assignement.adc_number, i1_low_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getI2LowRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(i2_low_assignement.adc_number, i2_low_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(i2_low_assignement.adc_number, i2_low_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getIHighRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(i_high_assignement.adc_number, i_high_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(i_high_assignement.adc_number, i_high_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getTemperatureRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(temp_sensor_assignement.adc_number, temp_sensor_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(temp_sensor_assignement.adc_number, temp_sensor_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getExtraRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(extra_sensor_assignement.adc_number, extra_sensor_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(extra_sensor_assignement.adc_number, extra_sensor_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } uint16_t* DataAcquisition::getAnalogCommRawValues(uint32_t& number_of_values_acquired) { - return data_dispatch_get_acquired_values(analog_comm_assignement.adc_number, analog_comm_assignement.channel_rank, &number_of_values_acquired); + if (this->is_started == true) + { + return data_dispatch_get_acquired_values(analog_comm_assignement.adc_number, analog_comm_assignement.channel_rank, &number_of_values_acquired); + } + else + { + number_of_values_acquired = 0; + return nullptr; + } } float32_t DataAcquisition::peekV1Low() { - uint16_t rawValue = data_dispatch_peek_acquired_value(v1_low_assignement.adc_number, v1_low_assignement.channel_rank); - return data_conversion_convert_v1_low(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(v1_low_assignement.adc_number, v1_low_assignement.channel_rank); + return data_conversion_convert_v1_low(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekV2Low() { - uint16_t rawValue = data_dispatch_peek_acquired_value(v2_low_assignement.adc_number, v2_low_assignement.channel_rank); - return data_conversion_convert_v2_low(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(v2_low_assignement.adc_number, v2_low_assignement.channel_rank); + return data_conversion_convert_v2_low(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekVHigh() { - uint16_t rawValue = data_dispatch_peek_acquired_value(v_high_assignement.adc_number, v_high_assignement.channel_rank); - return data_conversion_convert_v_high(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(v_high_assignement.adc_number, v_high_assignement.channel_rank); + return data_conversion_convert_v_high(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekI1Low() { - uint16_t rawValue = data_dispatch_peek_acquired_value(i1_low_assignement.adc_number, i1_low_assignement.channel_rank); - return data_conversion_convert_i1_low(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(i1_low_assignement.adc_number, i1_low_assignement.channel_rank); + return data_conversion_convert_i1_low(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekI2Low() { - uint16_t rawValue = data_dispatch_peek_acquired_value(i2_low_assignement.adc_number, i2_low_assignement.channel_rank); - return data_conversion_convert_i2_low(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(i2_low_assignement.adc_number, i2_low_assignement.channel_rank); + return data_conversion_convert_i2_low(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekIHigh() { - uint16_t rawValue = data_dispatch_peek_acquired_value(i_high_assignement.adc_number, i_high_assignement.channel_rank); - return data_conversion_convert_i_high(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(i_high_assignement.adc_number, i_high_assignement.channel_rank); + return data_conversion_convert_i_high(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekTemperature() { - uint16_t rawValue = data_dispatch_peek_acquired_value(temp_sensor_assignement.adc_number, temp_sensor_assignement.channel_rank); - return data_conversion_convert_temp(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(temp_sensor_assignement.adc_number, temp_sensor_assignement.channel_rank); + return data_conversion_convert_temp(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::peekExtra() { - uint16_t rawValue = data_dispatch_peek_acquired_value(extra_sensor_assignement.adc_number, extra_sensor_assignement.channel_rank); - return data_conversion_convert_extra(rawValue); + if (this->is_started == true) + { + uint16_t rawValue = data_dispatch_peek_acquired_value(extra_sensor_assignement.adc_number, extra_sensor_assignement.channel_rank); + return data_conversion_convert_extra(rawValue); + } + else + { + return 0; + } } float32_t DataAcquisition::getV1Low() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getV1LowRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getV1LowRawValues(data_count); + + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_v1_low(raw_value); + } - if (data_count > 0) // If data was received it gets converted + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_v1_low(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getV2Low() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getV2LowRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getV2LowRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_v2_low(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_v2_low(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getVHigh() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getVHighRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getVHighRawValues(data_count); + + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_v_high(raw_value); + } - if (data_count > 0) // If data was received it gets converted + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_v_high(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getI1Low() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getI1LowRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getI1LowRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_i1_low(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_i1_low(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getI2Low() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getI2LowRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getI2LowRawValues(data_count); + + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_i2_low(raw_value); + } - if (data_count > 0) // If data was received it gets converted + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_i2_low(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getIHigh() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getIHighRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getIHighRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_i_high(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_i_high(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getTemperature() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getTemperatureRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getTemperatureRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_temp(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_temp(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getExtra() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getExtraRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getExtraRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_extra(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_extra(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::getAnalogComm() { - uint32_t data_count; - static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet - uint16_t* buffer = getAnalogCommRawValues(data_count); + if (this->is_started == true) + { + uint32_t data_count; + static float32_t converted_data = -10000; // Return an impossible value if no data has been acquired yet + uint16_t* buffer = getAnalogCommRawValues(data_count); - if (data_count > 0) // If data was received it gets converted + if (data_count > 0) // If data was received it gets converted + { + uint16_t raw_value = buffer[data_count - 1]; + converted_data = data_conversion_convert_analog_comm(raw_value); + } + + return converted_data; + } + else { - uint16_t raw_value = buffer[data_count - 1]; - converted_data = data_conversion_convert_analog_comm(raw_value); + return -10000; // Return an impossible value if no data has been acquired yet } - - return converted_data; } float32_t DataAcquisition::convertV1Low(uint16_t raw_value) diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h index a323846..4e758cf 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h +++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 LAAS-CNRS + * Copyright (c) 2022-2023 LAAS-CNRS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -18,7 +18,7 @@ */ /** - * @date 2022 + * @date 2023 * * @author Clément Foucher <clement.foucher@laas.fr> */ @@ -35,8 +35,6 @@ #include <arm_math.h> - - ///// // Static class definition @@ -51,24 +49,40 @@ private: * @param channel_name Channel name * @param channel_rannk Channel rank */ - static void setChannnelAssignment(uint8_t adc_number, const char* channel_name, uint8_t channel_rank); + void setChannnelAssignment(uint8_t adc_number, const char* channel_name, uint8_t channel_rank); public: /** * This functions starts the acquisition chain. It must be called - * after all module configuration has been carried out. No ADC + * after ADC module configuration has been fully carried out. No ADC * configuration change is allowed after module has been started. + * If you're not sure how to initialize ADC, just use the Hardware + * Configuration module API: hwConfig.configureAdcDefaultAllMeasurements() + * + * NOTE: This function must be called before accessing any dataAcquisition.get*() + * or dataAcquisition.peek*() function. Other functions are safe to + * use before starting the module. + * + * @return 0 if everything went well, -1 if there was an error. + * Error is triggered when dispatch method is set to + * uninterruptible task start, but the task has not been + * defined yet. */ - static void start(); + void start(); /** * Check if the module is already started. - * For auto-spawning threads, please make sure - * the module has already been started before - * trying to access measures. + * + * For auto-spawning threads, this allows to make sure the module + * has already been started before trying to access measures. + * + * If you don't use (or don't know what are) auto-spawning threads, + * just make sure you call dataAcquisition.start() before accessing + * any dataAcquisition.get*() or dataAcquisition.peek*() function, + * and ignore this one. */ - static bool started(); + bool started(); ///// @@ -86,9 +100,10 @@ public: * * NOTE 1: When calling one of these functions, it invalidates * the buffer returned by a previous call to the same function. - * NOTE 2: All function buffers are independent. - * NOTE 3: When using these functions, the user is responsible for - * data conversion. Use convert***() functions for this purpose. + * NOTE 2: All function buffers are independent from each other. + * NOTE 3: When using these functions, the user is responsible for data + * conversion. Use dataAcquisition.convert*() functions for this + * purpose. * NOTE 4: When using these functions for a channel, DO NOT use the * functions to get the latest converted value for the same channel * as these functions clear the buffer and disregard all values @@ -101,15 +116,15 @@ public: * If number_of_values_acquired is 0, do not try to access the * buffer as it may be NULL. */ - static uint16_t* getV1LowRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getV2LowRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getVHighRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getI1LowRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getI2LowRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getIHighRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getTemperatureRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getExtraRawValues(uint32_t& number_of_values_acquired); - static uint16_t* getAnalogCommRawValues(uint32_t& number_of_values_acquired); + uint16_t* getV1LowRawValues(uint32_t& number_of_values_acquired); + uint16_t* getV2LowRawValues(uint32_t& number_of_values_acquired); + uint16_t* getVHighRawValues(uint32_t& number_of_values_acquired); + uint16_t* getI1LowRawValues(uint32_t& number_of_values_acquired); + uint16_t* getI2LowRawValues(uint32_t& number_of_values_acquired); + uint16_t* getIHighRawValues(uint32_t& number_of_values_acquired); + uint16_t* getTemperatureRawValues(uint32_t& number_of_values_acquired); + uint16_t* getExtraRawValues(uint32_t& number_of_values_acquired); + uint16_t* getAnalogCommRawValues(uint32_t& number_of_values_acquired); /** * Functions to access the latest value available from a channel expressed @@ -119,63 +134,64 @@ public: * * @return Latest available value available from the given channel. */ - static float32_t peekV1Low(); - static float32_t peekV2Low(); - static float32_t peekVHigh(); - static float32_t peekI1Low(); - static float32_t peekI2Low(); - static float32_t peekIHigh(); - static float32_t peekTemperature(); - static float32_t peekExtra(); + float32_t peekV1Low(); + float32_t peekV2Low(); + float32_t peekVHigh(); + float32_t peekI1Low(); + float32_t peekI2Low(); + float32_t peekIHigh(); + float32_t peekTemperature(); + float32_t peekExtra(); /** * These functions return the latest acquired measure expressed * in the relevant unit for the data: Volts, Amperes, Degree Celcius. * - * @return Latest acquired measure for the channel. - * * NOTE: When using these functions for a channel, you loose the - * ability to access raw values using get***RawValues() functions, - * as get***() functions clear the buffers on each call. + * ability to access raw values using dataAcquisition.get*RawValues() + * functions, as dataAcquisition.get*() functions clear the buffers + * on each call. + * + * @return Latest acquired measure for the channel. */ - static float32_t getV1Low(); - static float32_t getV2Low(); - static float32_t getVHigh(); - static float32_t getI1Low(); - static float32_t getI2Low(); - static float32_t getIHigh(); - static float32_t getTemperature(); - static float32_t getExtra(); - static float32_t getAnalogComm(); + float32_t getV1Low(); + float32_t getV2Low(); + float32_t getVHigh(); + float32_t getI1Low(); + float32_t getI2Low(); + float32_t getIHigh(); + float32_t getTemperature(); + float32_t getExtra(); + float32_t getAnalogComm(); /** * Use these functions to convert values obtained using - * get***RawValues() functions to relevant unit for the data: - * Volts, Amperes, Degree Celcius. + * dataAcquisition.get*RawValues() functions to relevant + * unit for the data: Volts, Amperes, Degree Celcius. */ - static float32_t convertV1Low(uint16_t raw_value); - static float32_t convertV2Low(uint16_t raw_value); - static float32_t convertVHigh(uint16_t raw_value); - static float32_t convertI1Low(uint16_t raw_value); - static float32_t convertI2Low(uint16_t raw_value); - static float32_t convertIHigh(uint16_t raw_value); - static float32_t convertTemperature(uint16_t raw_value); - static float32_t convertExtra(uint16_t raw_value); - static float32_t convertAnalogComm(uint16_t raw_value); + float32_t convertV1Low(uint16_t raw_value); + float32_t convertV2Low(uint16_t raw_value); + float32_t convertVHigh(uint16_t raw_value); + float32_t convertI1Low(uint16_t raw_value); + float32_t convertI2Low(uint16_t raw_value); + float32_t convertIHigh(uint16_t raw_value); + float32_t convertTemperature(uint16_t raw_value); + float32_t convertExtra(uint16_t raw_value); + float32_t convertAnalogComm(uint16_t raw_value); /** * Use these functions to tweak the conversion values for * a specific sensor if default values are not accurate enough. */ - static void setV1LowParameters(float32_t gain, float32_t offset); - static void setI1LowParameters(float32_t gain, float32_t offset); - static void setV2LowParameters(float32_t gain, float32_t offset); - static void setI2LowParameters(float32_t gain, float32_t offset); - static void setVHighParameters(float32_t gain, float32_t offset); - static void setIHighParameters(float32_t gain, float32_t offset); - static void setTemperatureParameters(float32_t gain, float32_t offset); - static void setExtraParameters(float32_t gain, float32_t offset); - static void setAnalogCommParameters(float32_t gain, float32_t offset); + void setV1LowParameters(float32_t gain, float32_t offset); + void setI1LowParameters(float32_t gain, float32_t offset); + void setV2LowParameters(float32_t gain, float32_t offset); + void setI2LowParameters(float32_t gain, float32_t offset); + void setVHighParameters(float32_t gain, float32_t offset); + void setIHighParameters(float32_t gain, float32_t offset); + void setTemperatureParameters(float32_t gain, float32_t offset); + void setExtraParameters(float32_t gain, float32_t offset); + void setAnalogCommParameters(float32_t gain, float32_t offset); private: @@ -186,17 +202,17 @@ private: } channel_assignment_t; private: - static bool is_started; - - static channel_assignment_t v1_low_assignement; - static channel_assignment_t v2_low_assignement; - static channel_assignment_t v_high_assignement; - static channel_assignment_t i1_low_assignement; - static channel_assignment_t i2_low_assignement; - static channel_assignment_t i_high_assignement; - static channel_assignment_t temp_sensor_assignement; - static channel_assignment_t extra_sensor_assignement; - static channel_assignment_t analog_comm_assignement; + bool is_started = false; + + channel_assignment_t v1_low_assignement = {0}; + channel_assignment_t v2_low_assignement = {0}; + channel_assignment_t v_high_assignement = {0}; + channel_assignment_t i1_low_assignement = {0}; + channel_assignment_t i2_low_assignement = {0}; + channel_assignment_t i_high_assignement = {0}; + channel_assignment_t temp_sensor_assignement = {0}; + channel_assignment_t extra_sensor_assignement = {0}; + channel_assignment_t analog_comm_assignement = {0}; }; diff --git a/zephyr/modules/owntech_gpio_api/zephyr/public_api/GpioApi.h b/zephyr/modules/owntech_gpio_api/zephyr/public_api/GpioApi.h index 78375e3..97c169c 100644 --- a/zephyr/modules/owntech_gpio_api/zephyr/public_api/GpioApi.h +++ b/zephyr/modules/owntech_gpio_api/zephyr/public_api/GpioApi.h @@ -29,6 +29,10 @@ #include <drivers/gpio.h> + +///// +// Public constants + extern const struct device* const GPIO_A; extern const struct device* const GPIO_B; extern const struct device* const GPIO_C; @@ -60,6 +64,10 @@ static const uint8_t P14 = 0xD; static const uint8_t P15 = 0xE; static const uint8_t P16 = 0xF; + +///// +// Public types + typedef enum { PA1 = PA | P1, @@ -115,6 +123,10 @@ typedef enum PD3 = PD | P3 } pin_t; + +///// +// Class definition + class GpioApi { public: diff --git a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h index ad10b66..fe0abae 100644 --- a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h +++ b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h @@ -33,9 +33,12 @@ #include <zephyr.h> +///// +// Public types + typedef void (*task_function_t)(); -enum class scheduling_interrupt_source_t { source_hrtim, source_tim6 }; +typedef enum { source_uninitialized, source_hrtim, source_tim6 } scheduling_interrupt_source_t; ///// @@ -66,12 +69,13 @@ public: * parameter can be provided to set TIM6 as the source in * case the HRTIM is not used or if the task can't be * correlated to an HRTIM event. + * Allowed values are source_hrtim and source_tim6. * @return 0 if everything went well, * -1 if there was an error defining the task. * An error can occur notably when an uninterruptible * task has already been defined previously. */ - int8_t defineUninterruptibleSynchronousTask(task_function_t periodic_task, uint32_t task_period_us, scheduling_interrupt_source_t int_source = scheduling_interrupt_source_t::source_hrtim); + int8_t defineUninterruptibleSynchronousTask(task_function_t periodic_task, uint32_t task_period_us, scheduling_interrupt_source_t int_source = source_hrtim); /** * @brief Use this function to start the previously defined diff --git a/zephyr/modules/owntech_scheduling/zephyr/src/uninterruptible_synchronous_task.cpp b/zephyr/modules/owntech_scheduling/zephyr/src/uninterruptible_synchronous_task.cpp index 2eb0b40..58c0f1d 100644 --- a/zephyr/modules/owntech_scheduling/zephyr/src/uninterruptible_synchronous_task.cpp +++ b/zephyr/modules/owntech_scheduling/zephyr/src/uninterruptible_synchronous_task.cpp @@ -42,7 +42,7 @@ static const struct device* timer6 = DEVICE_DT_GET(TIMER6_DEVICE); static task_status_t uninterruptibleTaskStatus = task_status_t::inexistent; // Interrupt source -static scheduling_interrupt_source_t interrupt_source = scheduling_interrupt_source_t::source_hrtim; +static scheduling_interrupt_source_t interrupt_source = source_uninitialized; // For HRTIM interrupts static uint32_t repetition = 0; @@ -66,7 +66,7 @@ int8_t scheduling_define_uninterruptible_synchronous_task(task_function_t period if (periodic_task == NULL) return -1; - if (interrupt_source == scheduling_interrupt_source_t::source_tim6) + if (interrupt_source == source_tim6) { if (device_is_ready(timer6) == false) return -1; @@ -83,7 +83,7 @@ int8_t scheduling_define_uninterruptible_synchronous_task(task_function_t period return 0; } - else if (interrupt_source == scheduling_interrupt_source_t::source_hrtim) + else if (interrupt_source == source_hrtim) { uint32_t hrtim_period_us = leg_get_period_us(); @@ -110,7 +110,7 @@ void scheduling_start_uninterruptible_synchronous_task() if ( (uninterruptibleTaskStatus != task_status_t::defined) && (uninterruptibleTaskStatus != task_status_t::suspended) ) return; - if (interrupt_source == scheduling_interrupt_source_t::source_tim6) + if (interrupt_source == source_tim6) { if (device_is_ready(timer6) == false) return; @@ -119,7 +119,7 @@ void scheduling_start_uninterruptible_synchronous_task() uninterruptibleTaskStatus = task_status_t::running; } - else if (interrupt_source == scheduling_interrupt_source_t::source_hrtim) + else if (interrupt_source == source_hrtim) { if ( (repetition == 0) || (user_periodic_task == NULL) ) return; @@ -135,7 +135,7 @@ void scheduling_stop_uninterruptible_synchronous_task() if (uninterruptibleTaskStatus != task_status_t::running) return; - if (interrupt_source == scheduling_interrupt_source_t::source_tim6) + if (interrupt_source == source_tim6) { if (device_is_ready(timer6) == false) return; @@ -144,7 +144,7 @@ void scheduling_stop_uninterruptible_synchronous_task() uninterruptibleTaskStatus = task_status_t::suspended; } - else if (interrupt_source == scheduling_interrupt_source_t::source_hrtim) + else if (interrupt_source == source_hrtim) { hrtim_PeriodicEvent_dis(MSTR); -- GitLab