MCPcopy Create free account
hub / github.com/SmingHub/Sming / testTimer1

Function testTimer1

tests/HostTests/modules/Clocks.cpp:402–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400};
401
402template <hw_timer_clkdiv_t clkdiv, typename TimeType> void testTimer1()
403{
404 using Clock = Timer1TestSource<clkdiv, NanoTime::Microseconds, uint32_t>;
405 using TimeSource = NanoTime::TimeSource<Clock, NanoTime::Microseconds, TimeType>;
406 Clock timer1;
407
408 CpuCycleTimes m1("ticks"), m2("ticks1"), m3("ticks2");
409
410 for(unsigned i = 0; i < 5000; ++i) {
411 TimeType time = os_random(); //0x7fffffff;
412 if(sizeof(time) == sizeof(uint64_t)) {
413 // time = (time << 32) | os_random();
414 }
415
416 time %= TimeSource::maxCalcTime();
417
418 m1.start();
419 volatile TimeType ticks = TimeSource::timeToTicks(time);
420 m1.update();
421
422 m2.start();
423 volatile TimeType ticks1 = timer1.timeToTicks_test1(time);
424 m2.update();
425
426 m3.start();
427 volatile TimeType ticks2 = timer1.timeToTicks_test2(time);
428 m3.update();
429
430 TimeType refticks = round(double(time) * TimeSource::TicksPerUnit::num / TimeSource::TicksPerUnit::den);
431
432 auto check = [time, refticks](const char* tag, TimeType ticks) {
433 int64_t diff = int64_t(ticks) - int64_t(refticks);
434 if(abs(diff) > 2) {
435 Serial << _F("time = ") << time << _F(", refticks = ") << refticks << ", " << tag << " = " << ticks
436 << _F(", diff = ") << diff << endl;
437 }
438 };
439
440 check("ticks", ticks);
441 check("ticks1", ticks1);
442 check("ticks2", ticks2);
443
444 // if(refticks != ticks || refticks != ticks1 || refticks != ticks2) {
445 // m_printf("time = %u (0x%08x), ticks = %u, ticks1 = %u, ticks2 = %u\r\n", time, time, ticks, ticks1, ticks2);
446 // }
447 }
448
449 Serial.println(m1);
450 Serial.println(m2);
451 Serial.println(m3);
452}
453
454class TimerCalcTest : public TestGroup
455{

Callers

nothing calls this directly

Calls 6

timeToTicks_test1Method · 0.80
timeToTicks_test2Method · 0.80
printlnMethod · 0.80
os_randomFunction · 0.50
startMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected