Skip to content

Commit

Permalink
Always inline fastPinGetPinmap to speed pin sets
Browse files Browse the repository at this point in the history
Use separate pinSetFast benchmark for Gen3

Separate timing benchmarks for pinSet and pinReset
  • Loading branch information
tstellanova committed Dec 9, 2020
1 parent 657937f commit 09c59f1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
68 changes: 68 additions & 0 deletions user/tests/wiring/no_fixture/fastpin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

#include "application.h"
#include "unit-test/unit-test.h"



test(FASTPIN_01_MaxDuration_PinSet) {
// Attempt pinSetFast and pinResetFast numerous times and check speed.
// Duration went from about 62 -> 24 ticks per set on Gen2 with this change list

#if HAL_PLATFORM_GEN == 3
// expected max ticks of pinSetFast / pinResetFast on Gen3
const uint32_t MAX_DURATION_PINSET_TICKS = 61;
#elif HAL_PLATFORM_GEN == 2
// expected max ticks of pinSetFast / pinResetFast on Gen2
const uint32_t MAX_DURATION_PINSET_TICKS = 24;
#else
#error "No gpio fastpin timing benchmark yet measured for this platform"
#endif

const uint32_t NUM_ITERATIONS = 100;
uint32_t start, finish;

ATOMIC_BLOCK() {
start = System.ticks();
for (uint32_t i = 0; i < NUM_ITERATIONS; i++) {
pinSetFast(D7);
//pinResetFast(D7);
}
finish = System.ticks();
}
uint32_t duration = finish - start;
// Serial.print("Set duration:");
// Serial.println(duration);
assertLessOrEqual(duration, NUM_ITERATIONS*MAX_DURATION_PINSET_TICKS);
}

test(FASTPIN_02_MaxDuration_PinReset) {
// Attempt pinResetFast numerous times and check speed.

#if HAL_PLATFORM_GEN == 3
// expected max ticks of pinResetFast on Gen3
const uint32_t MAX_DURATION_PINRESET_TICKS = 60;
#elif HAL_PLATFORM_GEN == 2
// expected max ticks of pinResetFast on Gen2
const uint32_t MAX_DURATION_PINRESET_TICKS = 25;
#else
#error "No gpio fastpin timing benchmark yet measured for this platform"
#endif

const uint32_t NUM_ITERATIONS = 100;
uint32_t start, finish;

ATOMIC_BLOCK() {
start = System.ticks();
for (uint32_t i = 0; i < NUM_ITERATIONS; i++) {
pinResetFast(D7);
}
finish = System.ticks();
}
uint32_t duration = finish - start;
// Serial.print("Reset duration:");
// Serial.println(duration);
assertLessOrEqual(duration, NUM_ITERATIONS*MAX_DURATION_PINRESET_TICKS);
}



4 changes: 2 additions & 2 deletions wiring/inc/fast_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern "C" {
* by @pkourany on PR: https://github.com/spark/firmware/pull/556 */
#define USE_BIT_BAND 0

inline const Hal_Pin_Info* fastPinGetPinmap() {
static Hal_Pin_Info* pinMap = HAL_Pin_Map();
__attribute__((always_inline)) inline const Hal_Pin_Info* fastPinGetPinmap() {
static const Hal_Pin_Info* pinMap = HAL_Pin_Map();
return pinMap;
}

Expand Down

0 comments on commit 09c59f1

Please sign in to comment.