[Core] Use polled waiting on ChibiOS platforms that support it (#17607)
* 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
This commit is contained in:
@@ -30,3 +30,6 @@
|
||||
#define RGB_CI_PIN B1
|
||||
|
||||
#define ADC_PIN F6
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN F6
|
||||
#define QMK_WAITING_TEST_YIELD_PIN F7
|
||||
|
@@ -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
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -30,3 +30,6 @@
|
||||
#define RGB_CI_PIN B1
|
||||
|
||||
#define ADC_PIN F6
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN F6
|
||||
#define QMK_WAITING_TEST_YIELD_PIN F7
|
||||
|
@@ -6,10 +6,15 @@
|
||||
#include "config_common.h"
|
||||
|
||||
#define PRODUCT Onekey Raspberry Pi RP2040
|
||||
#define MATRIX_COL_PINS { GP4 }
|
||||
#define MATRIX_ROW_PINS { GP5 }
|
||||
#define MATRIX_COL_PINS \
|
||||
{ GP4 }
|
||||
#define MATRIX_ROW_PINS \
|
||||
{ GP5 }
|
||||
#define DEBUG_MATRIX_SCAN_RATE
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN GP8
|
||||
#define QMK_WAITING_TEST_YIELD_PIN GP9
|
||||
|
||||
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
|
||||
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_LED GP25
|
||||
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U
|
||||
|
@@ -29,3 +29,6 @@
|
||||
#define RGB_DI_PIN F6
|
||||
|
||||
#define ADC_PIN F6
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN F6
|
||||
#define QMK_WAITING_TEST_YIELD_PIN F7
|
||||
|
@@ -29,3 +29,6 @@
|
||||
#define RGB_DI_PIN F6
|
||||
|
||||
#define ADC_PIN F6
|
||||
|
||||
#define QMK_WAITING_TEST_BUSY_PIN F6
|
||||
#define QMK_WAITING_TEST_YIELD_PIN F7
|
||||
|
@@ -15,14 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "hal.h"
|
||||
#include "timer.h"
|
||||
#include "wait.h"
|
||||
#include "debug.h"
|
||||
#include "matrix.h"
|
||||
#include "quantum.h"
|
||||
|
||||
/*
|
||||
* col: { B11, B10, B2, B1, A7, B0 }
|
||||
@@ -38,9 +31,13 @@ __attribute__((weak)) void matrix_init_user(void) {}
|
||||
|
||||
__attribute__((weak)) void matrix_scan_user(void) {}
|
||||
|
||||
__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
|
||||
__attribute__((weak)) void matrix_init_kb(void) {
|
||||
matrix_init_user();
|
||||
}
|
||||
|
||||
__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
|
||||
__attribute__((weak)) void matrix_scan_kb(void) {
|
||||
matrix_scan_user();
|
||||
}
|
||||
|
||||
void matrix_init(void) {
|
||||
dprintf("matrix init\n");
|
||||
@@ -146,9 +143,13 @@ uint8_t matrix_scan(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & (1 << col)); }
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) {
|
||||
return (matrix[row] & (1 << col));
|
||||
}
|
||||
|
||||
matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
|
||||
matrix_row_t matrix_get_row(uint8_t row) {
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void) {
|
||||
dprintf("\nr/c 01234567\n");
|
||||
|
@@ -15,14 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "hal.h"
|
||||
#include "timer.h"
|
||||
#include "wait.h"
|
||||
#include "debug.h"
|
||||
#include "matrix.h"
|
||||
#include "quantum.h"
|
||||
|
||||
typedef uint16_t matrix_col_t;
|
||||
|
||||
@@ -40,9 +33,13 @@ __attribute__((weak)) void matrix_init_user(void) {}
|
||||
|
||||
__attribute__((weak)) void matrix_scan_user(void) {}
|
||||
|
||||
__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
|
||||
__attribute__((weak)) void matrix_init_kb(void) {
|
||||
matrix_init_user();
|
||||
}
|
||||
|
||||
__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
|
||||
__attribute__((weak)) void matrix_scan_kb(void) {
|
||||
matrix_scan_user();
|
||||
}
|
||||
|
||||
void matrix_init(void) {
|
||||
dprintf("matrix init\n");
|
||||
@@ -150,9 +147,13 @@ uint8_t matrix_scan(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & (1 << col)); }
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) {
|
||||
return (matrix[row] & (1 << col));
|
||||
}
|
||||
|
||||
matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
|
||||
matrix_row_t matrix_get_row(uint8_t row) {
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void) {
|
||||
dprintf("\nr/c 01234567\n");
|
||||
|
Reference in New Issue
Block a user