Skip to content

Commit

Permalink
Merge pull request #2251 from particle-iot/bug/ch68808/low-level-inpu…
Browse files Browse the repository at this point in the history
…t-output-slow-on-os-2-0-0-rc4

Always inline fastPinGetPinmap to speed pin sets
  • Loading branch information
avtolstoy authored Dec 9, 2020
2 parents 657937f + 09c59f1 commit fca6e98
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 fca6e98

Please sign in to comment.