|
| 1 | + |
| 2 | +#include "application.h" |
| 3 | +#include "unit-test/unit-test.h" |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +test(FASTPIN_01_MaxDuration_PinSet) { |
| 8 | + // Attempt pinSetFast and pinResetFast numerous times and check speed. |
| 9 | + // Duration went from about 62 -> 24 ticks per set on Gen2 with this change list |
| 10 | + |
| 11 | +#if HAL_PLATFORM_GEN == 3 |
| 12 | + // expected max ticks of pinSetFast / pinResetFast on Gen3 |
| 13 | + const uint32_t MAX_DURATION_PINSET_TICKS = 61; |
| 14 | +#elif HAL_PLATFORM_GEN == 2 |
| 15 | + // expected max ticks of pinSetFast / pinResetFast on Gen2 |
| 16 | + const uint32_t MAX_DURATION_PINSET_TICKS = 24; |
| 17 | +#else |
| 18 | +#error "No gpio fastpin timing benchmark yet measured for this platform" |
| 19 | +#endif |
| 20 | + |
| 21 | + const uint32_t NUM_ITERATIONS = 100; |
| 22 | + uint32_t start, finish; |
| 23 | + |
| 24 | + ATOMIC_BLOCK() { |
| 25 | + start = System.ticks(); |
| 26 | + for (uint32_t i = 0; i < NUM_ITERATIONS; i++) { |
| 27 | + pinSetFast(D7); |
| 28 | + //pinResetFast(D7); |
| 29 | + } |
| 30 | + finish = System.ticks(); |
| 31 | + } |
| 32 | + uint32_t duration = finish - start; |
| 33 | +// Serial.print("Set duration:"); |
| 34 | +// Serial.println(duration); |
| 35 | + assertLessOrEqual(duration, NUM_ITERATIONS*MAX_DURATION_PINSET_TICKS); |
| 36 | +} |
| 37 | + |
| 38 | +test(FASTPIN_02_MaxDuration_PinReset) { |
| 39 | + // Attempt pinResetFast numerous times and check speed. |
| 40 | + |
| 41 | +#if HAL_PLATFORM_GEN == 3 |
| 42 | + // expected max ticks of pinResetFast on Gen3 |
| 43 | + const uint32_t MAX_DURATION_PINRESET_TICKS = 60; |
| 44 | +#elif HAL_PLATFORM_GEN == 2 |
| 45 | + // expected max ticks of pinResetFast on Gen2 |
| 46 | + const uint32_t MAX_DURATION_PINRESET_TICKS = 25; |
| 47 | +#else |
| 48 | +#error "No gpio fastpin timing benchmark yet measured for this platform" |
| 49 | +#endif |
| 50 | + |
| 51 | + const uint32_t NUM_ITERATIONS = 100; |
| 52 | + uint32_t start, finish; |
| 53 | + |
| 54 | + ATOMIC_BLOCK() { |
| 55 | + start = System.ticks(); |
| 56 | + for (uint32_t i = 0; i < NUM_ITERATIONS; i++) { |
| 57 | + pinResetFast(D7); |
| 58 | + } |
| 59 | + finish = System.ticks(); |
| 60 | + } |
| 61 | + uint32_t duration = finish - start; |
| 62 | +// Serial.print("Reset duration:"); |
| 63 | +// Serial.println(duration); |
| 64 | + assertLessOrEqual(duration, NUM_ITERATIONS*MAX_DURATION_PINRESET_TICKS); |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | + |
0 commit comments