accurate bench test (#2441)

* accurate bench test

* allow shorter pulses
This commit is contained in:
Matthew Kennedy 2021-03-10 14:30:13 -08:00 committed by GitHub
parent 112aa4f57f
commit 208088847b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 7 deletions

View File

@ -65,11 +65,22 @@ bool isRunningBenchTest(void) {
return isRunningBench; return isRunningBench;
} }
static scheduling_s benchSchedStart;
static scheduling_s benchSchedEnd;
void benchOn(OutputPin* output) {
output->setValue(true);
}
void benchOff(OutputPin* output) {
output->setValue(false);
}
static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs, static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs,
int count) { int count) {
int delayUs = MS2US(maxF(1, delayMs)); int delayUs = MS2US(maxF(0.1, delayMs));
int onTimeUs = MS2US(maxF(1, onTimeMs)); int onTimeUs = MS2US(maxF(0.1, onTimeMs));
int offTimeUs = MS2US(maxF(1, offTimeMs)); int offTimeUs = MS2US(maxF(0.1, offTimeMs));
scheduleMsg(logger, "Running bench: ON_TIME=%.2f us OFF_TIME=%.2f us Counter=%d", onTimeUs, offTimeUs, count); scheduleMsg(logger, "Running bench: ON_TIME=%.2f us OFF_TIME=%.2f us Counter=%d", onTimeUs, offTimeUs, count);
scheduleMsg(logger, "output on %s", hwPortname(brainPin)); scheduleMsg(logger, "output on %s", hwPortname(brainPin));
@ -77,12 +88,21 @@ static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, flo
chThdSleepMicroseconds(delayUs); chThdSleepMicroseconds(delayUs);
isRunningBench = true; isRunningBench = true;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
output->setValue(true); efitick_t nowNt = getTimeNowNt();
chThdSleepMicroseconds(onTimeUs); // start in a short time so the scheduler can precisely schedule the start event
output->setValue(false); efitick_t startTime = nowNt + US2NT(50);
chThdSleepMicroseconds(offTimeUs); efitick_t endTime = startTime + US2NT(onTimeUs);
// Schedule both events
engine->executor.scheduleByTimestampNt(&benchSchedStart, startTime, {benchOn, output});
engine->executor.scheduleByTimestampNt(&benchSchedEnd, endTime, {benchOff, output});
// Wait one full cycle time for the event + delay to happen
chThdSleepMicroseconds(onTimeUs + offTimeUs);
} }
scheduleMsg(logger, "Done!"); scheduleMsg(logger, "Done!");
isRunningBench = false; isRunningBench = false;
} }