diff --git a/.gitignore b/.gitignore index 7925ddb..8287141 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ .vscode/ipch *.cache* *.ccls* -*compile_commands* +*compile_commands.json diff --git a/m4/.gitignore b/m4/.gitignore deleted file mode 100644 index 89cc49c..0000000 --- a/m4/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch diff --git a/m4/gen_compile_commands.py b/m4/gen_compile_commands.py new file mode 100644 index 0000000..0537d0b --- /dev/null +++ b/m4/gen_compile_commands.py @@ -0,0 +1,8 @@ +import os +Import("env") + +# include toolchain paths +env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) + +# override compilation DB path +env.Replace(COMPILATIONDB_PATH="compile_commands.json") diff --git a/m4/src/Peripherals/God.h b/m4/src/Peripherals/God.h index 8f8ae13..185152c 100644 --- a/m4/src/Peripherals/God.h +++ b/m4/src/Peripherals/God.h @@ -19,7 +19,8 @@ class God { registerMemberFunctionVector(dacLedBufferRampWrapper, "DAC_LED_BUFFER_RAMP"); registerMemberFunction(dacChannelCalibration, "DAC_CH_CAL"); - registerMemberFunctionVector(boxcarAverageRamp, "BOXCAR_BUFFER_RAMP"); + registerMemberFunctionVector(boxcarAverageRamp, + "BOXCAR_BUFFER_RAMP"); } // args: @@ -38,16 +39,19 @@ class God { uint32_t dac_interval_us = static_cast(args[3]); uint32_t adc_interval_us = static_cast(args[4]); + // Check if we have enough arguments for all DAC and ADC channels if (args.size() != static_cast(5 + numDacChannels * 3 + numAdcChannels)) { return OperationResult::Failure("Incorrect number of arguments"); } + // Allocate memory for DAC and ADC channel information int* dacChannels = new int[numDacChannels]; float* dacV0s = new float[numDacChannels]; float* dacVfs = new float[numDacChannels]; int* adcChannels = new int[numAdcChannels]; + // Parse DAC channel information for (int i = 0; i < numDacChannels; ++i) { int baseIndex = 5 + i * 3; dacChannels[i] = static_cast(args[baseIndex]); @@ -55,6 +59,7 @@ class God { dacVfs[i] = static_cast(args[baseIndex + 2]); } + // Parse ADC channel information for (int i = 0; i < numAdcChannels; ++i) { adcChannels[i] = static_cast(args[5 + numDacChannels * 3 + i]); } @@ -77,12 +82,32 @@ class God { if (numDacChannels < 1 || numAdcChannels < 1) { return OperationResult::Failure("Invalid number of channels"); } + // uint32_t adc_comms_period_us = (1.0/SPI_SPEED)*1e6*8*4; // 8 bits per + // byte, 4 bytes per ADC conversion if (adc_interval_us < + // adc_comms_period_us*numAdcChannels) { + // return OperationResult::Failure("ADC interval too short"); + // } + // uint32_t dac_comms_period_us = (1.0/SPI_SPEED)*1e6*8*3; // 8 bits per + // byte, 3 bytes per DAC update if (dac_interval_us < + // dac_comms_period_us*numDacChannels) { + // return OperationResult::Failure("DAC interval too short"); + // } int steps = 0; int x = 0; const int saved_data_size = numSteps * dac_interval_us / adc_interval_us; + // float** voltSetpoints = new float*[numDacChannels]; + + // for (int i = 0; i < numDacChannels; i++) { + // voltSetpoints[i] = new float[numSteps]; + // for (int j = 0; j < numSteps; j++) { + // voltSetpoints[i][j] = + // dacV0s[i] + (dacVfs[i] - dacV0s[i]) * j / (numSteps - 1); + // } + // } + float* voltageStepSize = new float[numDacChannels]; for (int i = 0; i < numDacChannels; i++) { @@ -105,25 +130,28 @@ class God { } while (x < saved_data_size && !getStopFlag()) { - for (int i = 0; i < numAdcChannels; i++) { - if (ADCController::getReadyFlag(adcChannels[i])) { - ADCController::clearReadyFlag(adcChannels[i]); - if (steps <= 1) { + if (TimingUtil::adcFlag) { + ADCBoard::commsController.beginTransaction(); + if (steps <= 1) { + for (int i = 0; i < numAdcChannels; i++) { ADCController::getVoltageDataNoTransaction(adcChannels[i]); - } else { - float* packets = new float[numAdcChannels]; - for (int i = 0; i < numAdcChannels; i++) { - float v = - ADCController::getVoltageDataNoTransaction(adcChannels[i]); - packets[i] = v; - } - m4SendVoltage(packets, numAdcChannels); - delete[] packets; - x++; } + } else { + float* packets = new float[numAdcChannels]; + for (int i = 0; i < numAdcChannels; i++) { + float v = + ADCController::getVoltageDataNoTransaction(adcChannels[i]); + packets[i] = v; + } + m4SendVoltage(packets, numAdcChannels); + delete[] packets; + x++; } + ADCBoard::commsController.endTransaction(); + TimingUtil::adcFlag = false; } if (TimingUtil::dacFlag && steps < numSteps + 1) { + DACChannel::commsController.beginTransaction(); if (steps == 0) { for (int i = 0; i < numDacChannels; i++) { DACController::setVoltageNoTransactionNoLdac(dacChannels[i], @@ -137,6 +165,7 @@ class God { } } DACController::toggleLdac(); + DACChannel::commsController.endTransaction(); steps++; TimingUtil::dacFlag = false; } @@ -179,16 +208,19 @@ class God { uint32_t dac_interval_us = static_cast(args[4]); uint32_t dac_settling_time_us = static_cast(args[5]); + // Check if we have enough arguments for all DAC and ADC channels if (args.size() != static_cast(6 + numDacChannels * 3 + numAdcChannels)) { return OperationResult::Failure("Incorrect number of arguments"); } + // Allocate memory for DAC and ADC channel information int* dacChannels = new int[numDacChannels]; float* dacV0s = new float[numDacChannels]; float* dacVfs = new float[numDacChannels]; int* adcChannels = new int[numAdcChannels]; + // Parse DAC channel information for (int i = 0; i < numDacChannels; ++i) { int baseIndex = 6 + i * 3; dacChannels[i] = static_cast(args[baseIndex]); @@ -196,6 +228,7 @@ class God { dacVfs[i] = static_cast(args[baseIndex + 2]); } + // Parse ADC channel information for (int i = 0; i < numAdcChannels; ++i) { adcChannels[i] = static_cast(args[6 + numDacChannels * 3 + i]); } @@ -230,10 +263,27 @@ class God { "DAC settling time too short for ADC conversion time"); } } + // uint32_t adc_comms_period_us = (1.0/SPI_SPEED)*1e6*8*4; // 8 bits per + // byte, 4 bytes per ADC conversion if + // (numAdcChannels*numAdcAverages*adc_comms_period_us > dac_interval_us - + // dac_settling_time_us) { + // return OperationResult::Failure("Buffer Ramp limited by ADC SPI + // comms"); + // } int steps = 0; int x = 0; + // float** voltSetpoints = new float*[numDacChannels]; + + // for (int i = 0; i < numDacChannels; i++) { + // voltSetpoints[i] = new float[numSteps]; + // for (int j = 0; j < numSteps; j++) { + // voltSetpoints[i][j] = + // dacV0s[i] + (dacVfs[i] - dacV0s[i]) * j / (numSteps - 1); + // } + // } + float* voltageStepSize = new float[numDacChannels]; for (int i = 0; i < numDacChannels; i++) { @@ -259,6 +309,7 @@ class God { } while (x < numSteps && !getStopFlag()) { if (TimingUtil::adcFlag) { + ADCBoard::commsController.beginTransaction(); if (steps <= 1) { for (int i = 0; i < numAdcChannels; i++) { for (int j = 0; j < numAdcAverages; j++) { @@ -280,9 +331,11 @@ class God { delete[] packets; x++; } + ADCBoard::commsController.endTransaction(); TimingUtil::adcFlag = false; } if (TimingUtil::dacFlag && steps < numSteps + 1) { + DACChannel::commsController.beginTransaction(); if (steps == 0) { for (int i = 0; i < numDacChannels; i++) { DACController::setVoltageNoTransactionNoLdac(dacChannels[i], @@ -291,11 +344,12 @@ class God { } else { for (int i = 0; i < numDacChannels; i++) { DACController::setVoltageNoTransactionNoLdac(dacChannels[i], - previousVoltageSet[i]); + previousVoltageSet[i]); previousVoltageSet[i] += voltageStepSize[i]; } } DACController::toggleLdac(); + DACChannel::commsController.endTransaction(); steps++; TimingUtil::dacFlag = false; } @@ -342,9 +396,11 @@ class God { // numAdcMeasuresPerDacStep, numAdcAverages, numAdcConversionSkips, // adcConversionTime_us, {for each dac channel: dac channel, v0_1, vf_1, v0_2, // vf_2}, {for each adc channel: adc channel} - static OperationResult boxcarAverageRamp(const std::vector& args) { + static OperationResult boxcarAverageRamp( + const std::vector& args) { size_t currentIndex = 0; + // Parse initial parameters int numDacChannels = static_cast(args[currentIndex++]); int numAdcChannels = static_cast(args[currentIndex++]); int numDacSteps = static_cast(args[currentIndex++]); @@ -380,8 +436,8 @@ class God { numAdcChannels > 1); } - uint32_t dacPeriod_us = (numAdcMeasuresPerDacStep + numAdcConversionSkips) * - (actualConversionTime_us + 5) * numAdcChannels; + uint32_t dacPeriod_us = + (numAdcMeasuresPerDacStep + numAdcConversionSkips) * (actualConversionTime_us + 5) * numAdcChannels; setStopFlag(false); PeripheralCommsController::dataLedOn(); @@ -407,9 +463,18 @@ class God { int steps = 0; int totalSteps = 2 * numDacSteps * numAdcAverages + 1; int x = 0; - int total_data_size = (totalSteps - 1) * numAdcMeasuresPerDacStep; + int total_data_size = (totalSteps-1) * numAdcMeasuresPerDacStep; int adcGetsSinceLastDacSet = 0; + // float thing = static_cast(total_data_size * numAdcChannels * 4); + // m4SendFloat(&thing, 1); + + // for debugging: + // float dacPeriodFloat = static_cast(dacPeriod_us); + // m4SendFloat(&dacPeriodFloat, 1); + // float adcPeriodFloat = static_cast(actualConversionTime_us); + // m4SendFloat(&adcPeriodFloat, 1); + for (int i = 0; i < numAdcChannels; ++i) { ADCController::startContinuousConversion(adcChannels[i]); } @@ -417,7 +482,8 @@ class God { TimingUtil::setupTimersTimeSeries(dacPeriod_us, actualConversionTime_us); while (x < total_data_size && !getStopFlag()) { - if (TimingUtil::adcFlag && x < (steps - 1) * numAdcMeasuresPerDacStep) { + if (TimingUtil::adcFlag && x < (steps-1) * numAdcMeasuresPerDacStep) { + ADCBoard::commsController.beginTransaction(); if (steps <= 1) { for (int i = 0; i < numAdcChannels; i++) { ADCController::getVoltageDataNoTransaction(adcChannels[i]); @@ -436,9 +502,11 @@ class God { } } adcGetsSinceLastDacSet++; + ADCBoard::commsController.endTransaction(); TimingUtil::adcFlag = false; } if (TimingUtil::dacFlag && steps < totalSteps) { + DACChannel::commsController.beginTransaction(); if (steps == 0) { for (int i = 0; i < numDacChannels; i++) { DACController::setVoltageNoTransactionNoLdac(dacChannels[i], @@ -467,6 +535,7 @@ class God { } } DACController::toggleLdac(); + DACChannel::commsController.endTransaction(); steps++; adcGetsSinceLastDacSet = 0; TimingUtil::dacFlag = false; diff --git a/m7/.gitignore b/m7/.gitignore deleted file mode 100644 index 89cc49c..0000000 --- a/m7/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch diff --git a/m7/gen_compile_commands.py b/m7/gen_compile_commands.py new file mode 100644 index 0000000..0537d0b --- /dev/null +++ b/m7/gen_compile_commands.py @@ -0,0 +1,8 @@ +import os +Import("env") + +# include toolchain paths +env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) + +# override compilation DB path +env.Replace(COMPILATIONDB_PATH="compile_commands.json")