Skip to content

Commit fca6e98

Browse files
authored
Merge pull request #2251 from particle-iot/bug/ch68808/low-level-input-output-slow-on-os-2-0-0-rc4
Always inline fastPinGetPinmap to speed pin sets
2 parents 657937f + 09c59f1 commit fca6e98

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+

wiring/inc/fast_pin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ extern "C" {
3232
* by @pkourany on PR: https://github.com/spark/firmware/pull/556 */
3333
#define USE_BIT_BAND 0
3434

35-
inline const Hal_Pin_Info* fastPinGetPinmap() {
36-
static Hal_Pin_Info* pinMap = HAL_Pin_Map();
35+
__attribute__((always_inline)) inline const Hal_Pin_Info* fastPinGetPinmap() {
36+
static const Hal_Pin_Info* pinMap = HAL_Pin_Map();
3737
return pinMap;
3838
}
3939

0 commit comments

Comments
 (0)