forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Use polled waiting on ChibiOS platforms that support it (qmk#1…
…7607) * Use polled waiting on platforms that support it Due to context switching overhead waiting a very short amount of time on a sleeping thread is often not accurate and in fact not usable for timing critical usage i.e. in a driver. Thus we use polled waiting for ranges in the us range on platforms that support it instead. The fallback is the thread sleeping mechanism. This includes: * ARM platforms with CYCCNT register (ARMv7, ARMv8) this is incremented at CPU clock frequency * GD32VF103 RISC-V port with CSR_MCYCLE register this is incremented at CPU clock frequency * RP2040 ARMv6 port which uses the integrated timer peripheral which is incremented with a fixed 1MHz frequency * Use wait_us() instead of chSysPolledDelayX ...as it is powered by busy waiting now. * Add chibios waiting methods test bench
- Loading branch information
1 parent
ab21d06
commit 55a4889
Showing
14 changed files
with
126 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
keyboards/handwired/onekey/keymaps/chibios_waiting_test/config.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2022 Stefan Kerkmann | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#if !defined(QMK_WAITING_TEST_BUSY_PIN) | ||
# define QMK_WAITING_TEST_BUSY_PIN A8 | ||
#endif | ||
|
||
#if !defined(QMK_WAITING_TEST_YIELD_PIN) | ||
# define QMK_WAITING_TEST_YIELD_PIN A9 | ||
#endif |
47 changes: 47 additions & 0 deletions
47
keyboards/handwired/onekey/keymaps/chibios_waiting_test/keymap.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 Stefan Kerkmann | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include QMK_KEYBOARD_H | ||
|
||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {LAYOUT_ortho_1x1(KC_A)}; | ||
|
||
#if defined(__AVR__) | ||
# pragma message "AVR uses polled waiting by default, running theses tests will not show any difference" | ||
static inline void chThdSleepMicroseconds(uint32_t us) { | ||
wait_us(us); | ||
} | ||
#endif | ||
|
||
void keyboard_post_init_user(void) { | ||
setPinOutput(QMK_WAITING_TEST_BUSY_PIN); | ||
setPinOutput(QMK_WAITING_TEST_YIELD_PIN); | ||
} | ||
|
||
static inline void wait_us_polling_with_strobe(uint32_t us) { | ||
writePinHigh(QMK_WAITING_TEST_BUSY_PIN); | ||
wait_us(us); | ||
writePinLow(QMK_WAITING_TEST_BUSY_PIN); | ||
} | ||
|
||
static inline void wait_us_yield_with_strobe(uint32_t us) { | ||
writePinHigh(QMK_WAITING_TEST_YIELD_PIN); | ||
chThdSleepMicroseconds(us); | ||
writePinLow(QMK_WAITING_TEST_YIELD_PIN); | ||
} | ||
|
||
static const uint32_t waiting_values[] = {0, 1, 5, 10, 25, 50, 100, 150, 200, 500, 1000}; | ||
|
||
void housekeeping_task_user(void) { | ||
static uint32_t last_bench = 0; | ||
if (timer_elapsed32(last_bench) > 500) { | ||
for (int i = 0; i < (sizeof(waiting_values) / sizeof(waiting_values[0])); i++) { | ||
wait_us_polling_with_strobe(waiting_values[i]); | ||
wait_us(10); | ||
} | ||
for (int i = 0; i < (sizeof(waiting_values) / sizeof(waiting_values[0])); i++) { | ||
wait_us_yield_with_strobe(waiting_values[i]); | ||
wait_us(10); | ||
} | ||
last_bench = timer_read32(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters