From 30cf6ea38bdd58b663f0b6fc56141293ec0a204e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 22 May 2022 09:54:31 -0400 Subject: [PATCH] dynamic code time measurement --- source/communication.cpp | 14 ++++++-------- source/conversion.cpp | 8 ++++---- source/conversion.hpp | 4 ++-- source/error.hpp | 3 ++- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/source/communication.cpp b/source/communication.cpp index b5ee28e..e85828b 100644 --- a/source/communication.cpp +++ b/source/communication.cpp @@ -32,7 +32,7 @@ static void setBufferSize(unsigned char *); static void updateGenerator(unsigned char *); static void loadAlgorithm(unsigned char *); static void readStatus(unsigned char *); -static void startConversionMeasure(unsigned char *); +static void measureConversion(unsigned char *); static void startConversion(unsigned char *); static void stopConversion(unsigned char *); static void startGenerator(unsigned char *); @@ -53,7 +53,7 @@ static const std::array, 19> commandT {'D', updateGenerator}, {'E', loadAlgorithm}, {'I', readStatus}, - {'M', startConversionMeasure}, + {'M', measureConversion}, {'R', startConversion}, {'S', stopConversion}, {'W', startGenerator}, @@ -159,12 +159,10 @@ void readStatus(unsigned char *) USBSerial::write(buf, sizeof(buf)); } -void startConversionMeasure(unsigned char *) +void measureConversion(unsigned char *) { - if (EM.assert(run_status == RunStatus::Idle, Error::NotIdle)) { - run_status = RunStatus::Running; - ConversionManager::startMeasured(); - } + if (EM.assert(run_status == RunStatus::Running, Error::NotRunning)) + ConversionManager::startMeasurement(); } void startConversion(unsigned char *) @@ -177,7 +175,7 @@ void startConversion(unsigned char *) void stopConversion(unsigned char *) { - if (run_status == RunStatus::Running) { + if (EM.assert(run_status == RunStatus::Running, Error::NotRunning)) { ConversionManager::stop(); run_status = RunStatus::Idle; } diff --git a/source/conversion.cpp b/source/conversion.cpp index 6fdea07..56a689e 100644 --- a/source/conversion.cpp +++ b/source/conversion.cpp @@ -65,11 +65,9 @@ void ConversionManager::start() DAC::start(0, Samples::Out.data(), Samples::Out.size()); } -void ConversionManager::startMeasured() +void ConversionManager::startMeasurement() { - Samples::Out.clear(); - ADC::start(Samples::In.data(), Samples::In.size(), adcReadHandlerMeasure); - DAC::start(0, Samples::Out.data(), Samples::Out.size()); + ADC::setOperation(adcReadHandlerMeasure); } void ConversionManager::stop() @@ -157,12 +155,14 @@ void ConversionManager::threadRunner(void *) asm("mov %0, sp" : "=r" (sp)); samples = entry(samples, size); asm("mov sp, %0" :: "r" (sp)); + volatile auto testRead = *samples; } else { // Start execution timer: asm("mov %0, sp; eor r0, r0; svc 2" : "=r" (sp)); samples = entry(samples, size); // Stop execution timer: asm("mov r0, #1; svc 2; mov sp, %0" :: "r" (sp)); + volatile auto testRead = *samples; } } diff --git a/source/conversion.hpp b/source/conversion.hpp index a26dd19..ca0054a 100644 --- a/source/conversion.hpp +++ b/source/conversion.hpp @@ -31,8 +31,8 @@ public: // Begins sample conversion. static void start(); - // Begins conversion with execution time measured. - static void startMeasured(); + // Prepare to measure execution time of next conversion. + static void startMeasurement(); // Stops conversion. static void stop(); diff --git a/source/error.hpp b/source/error.hpp index 9bbbe2c..c6a7f5c 100644 --- a/source/error.hpp +++ b/source/error.hpp @@ -22,7 +22,8 @@ enum class Error : char BadUserCodeLoad, BadUserCodeSize, NotIdle, - ConversionAborted + ConversionAborted, + NotRunning }; class ErrorManager