dynamic code time measurement

master
Clyne 3 years ago
parent 1310b7f0f6
commit 30cf6ea38b
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -32,7 +32,7 @@ static void setBufferSize(unsigned char *);
static void updateGenerator(unsigned char *); static void updateGenerator(unsigned char *);
static void loadAlgorithm(unsigned char *); static void loadAlgorithm(unsigned char *);
static void readStatus(unsigned char *); static void readStatus(unsigned char *);
static void startConversionMeasure(unsigned char *); static void measureConversion(unsigned char *);
static void startConversion(unsigned char *); static void startConversion(unsigned char *);
static void stopConversion(unsigned char *); static void stopConversion(unsigned char *);
static void startGenerator(unsigned char *); static void startGenerator(unsigned char *);
@ -53,7 +53,7 @@ static const std::array<std::pair<char, void (*)(unsigned char *)>, 19> commandT
{'D', updateGenerator}, {'D', updateGenerator},
{'E', loadAlgorithm}, {'E', loadAlgorithm},
{'I', readStatus}, {'I', readStatus},
{'M', startConversionMeasure}, {'M', measureConversion},
{'R', startConversion}, {'R', startConversion},
{'S', stopConversion}, {'S', stopConversion},
{'W', startGenerator}, {'W', startGenerator},
@ -159,12 +159,10 @@ void readStatus(unsigned char *)
USBSerial::write(buf, sizeof(buf)); USBSerial::write(buf, sizeof(buf));
} }
void startConversionMeasure(unsigned char *) void measureConversion(unsigned char *)
{ {
if (EM.assert(run_status == RunStatus::Idle, Error::NotIdle)) { if (EM.assert(run_status == RunStatus::Running, Error::NotRunning))
run_status = RunStatus::Running; ConversionManager::startMeasurement();
ConversionManager::startMeasured();
}
} }
void startConversion(unsigned char *) void startConversion(unsigned char *)
@ -177,7 +175,7 @@ void startConversion(unsigned char *)
void stopConversion(unsigned char *) void stopConversion(unsigned char *)
{ {
if (run_status == RunStatus::Running) { if (EM.assert(run_status == RunStatus::Running, Error::NotRunning)) {
ConversionManager::stop(); ConversionManager::stop();
run_status = RunStatus::Idle; run_status = RunStatus::Idle;
} }

@ -65,11 +65,9 @@ void ConversionManager::start()
DAC::start(0, Samples::Out.data(), Samples::Out.size()); DAC::start(0, Samples::Out.data(), Samples::Out.size());
} }
void ConversionManager::startMeasured() void ConversionManager::startMeasurement()
{ {
Samples::Out.clear(); ADC::setOperation(adcReadHandlerMeasure);
ADC::start(Samples::In.data(), Samples::In.size(), adcReadHandlerMeasure);
DAC::start(0, Samples::Out.data(), Samples::Out.size());
} }
void ConversionManager::stop() void ConversionManager::stop()
@ -157,12 +155,14 @@ void ConversionManager::threadRunner(void *)
asm("mov %0, sp" : "=r" (sp)); asm("mov %0, sp" : "=r" (sp));
samples = entry(samples, size); samples = entry(samples, size);
asm("mov sp, %0" :: "r" (sp)); asm("mov sp, %0" :: "r" (sp));
volatile auto testRead = *samples;
} else { } else {
// Start execution timer: // Start execution timer:
asm("mov %0, sp; eor r0, r0; svc 2" : "=r" (sp)); asm("mov %0, sp; eor r0, r0; svc 2" : "=r" (sp));
samples = entry(samples, size); samples = entry(samples, size);
// Stop execution timer: // Stop execution timer:
asm("mov r0, #1; svc 2; mov sp, %0" :: "r" (sp)); asm("mov r0, #1; svc 2; mov sp, %0" :: "r" (sp));
volatile auto testRead = *samples;
} }
} }

@ -31,8 +31,8 @@ public:
// Begins sample conversion. // Begins sample conversion.
static void start(); static void start();
// Begins conversion with execution time measured. // Prepare to measure execution time of next conversion.
static void startMeasured(); static void startMeasurement();
// Stops conversion. // Stops conversion.
static void stop(); static void stop();

@ -22,7 +22,8 @@ enum class Error : char
BadUserCodeLoad, BadUserCodeLoad,
BadUserCodeSize, BadUserCodeSize,
NotIdle, NotIdle,
ConversionAborted ConversionAborted,
NotRunning
}; };
class ErrorManager class ErrorManager

Loading…
Cancel
Save