No description
Find a file
Sergey Vlasov 580ef6d88f
ChibiOS timer fixes (#16017)
* chibios/timer: Move the 16-bit timer handling into a separate function

Extract the code which effectively makes a 32-bit tick counter from a
possibly 16-bit ChibiOS system timer into a separate function.  Does
not really change the behavior of the timer API, but makes the actions
done in `timer_clear()` and `timer_read32()` more obvious.

* chibios/timer: Rename some variable to better reflect their role

* chibios/timer: Fix 32-bit tick counter overflow handling

The QMK timer API implementation for ChibiOS used a 32-bit tick counter
(obtained from the ChibiOS system timer) and then converted the value to
milliseconds to produce the timer value for QMK.  However, the frequency
of the ChibiOS timer is above 1000 Hz in most cases (values of 10000 Hz
or even 100000 Hz are typically used), and therefore the 32-bit tick
counter was overflowing and wrapping around much earlier than expected
(after about 5 days for 10000 Hz, or about 12 hours for 100000 Hz).
When this wraparound happened, the QMK timer value was jumping back to
zero, which broke various code dealing with timers (e.g., deferred
executors).

Just making the tick counter 64-bit to avoid the overflow is not a good
solution, because the ChibiOS code which performs the conversion from
ticks to milliseconds may encounter overflows when handling a 64-bit
value.  Adjusting just the value converted to milliseconds to account
for lost 2**32 ticks is also not possible, because 2**32 ticks may not
correspond to an integer number of milliseconds.  Therefore the tick
counter overflow is handled as follows:

  - A reasonably large number of ticks (the highest multiple of the
    ChibiOS timer frequency that fits into uint32_t) is subtracted from
    the tick counter, so that its value is again brought below 2**32.
    The subtracted value is chosen so that it would correspond to an
    integer number of seconds, therefore it could be converted to
    milliseconds without any loss of precision.

  - The equivalent number of milliseconds is then added to the converted
    QMK timer value, so that the QMK timer continues to count
    milliseconds as it was before the tick counter overflow.

* chibios/timer: Add a virtual timer to make 16-bit timer updates more reliable

The code which extends the 16-bit ChibiOS system timer to a 32-bit tick
counter requires that it is called at least once for every overflow of
the system timer (otherwise the tick counter can skip one or more
overflow periods).  Normally this requirement is satisfied just from
various parts of QMK code reading the current timer value; however, in
some rare circumstances the QMK code may be blocked waiting for some
event, and when this situation is combined with having a rather high
timer frequency, this may result in improper timekeeping.

Enhance the timer reliability by adding a ChibiOS virtual timer which
invokes a callback every half of the timer overflow period.  The virtual
timer callback can be invoked even when the normal QMK code is blocked;
the only requirement is that the timer interrupts are enabled, and the
ChibiOS kernel is not locked for an excessive time (but the timer update
will eventually work correctly if the virtual timer handling is not
delayed by more than a half of the timer overflow period).

Keeping a virtual timer always active also works around a ChibiOS bug
that can manifest with a 16-bit system timer and a relatively high timer
frequency: when all active virtual timers have delays longer than the
timer overflow period, the handling of virtual timers stops completely.
In QMK this bug can result in a `wait_ms()` call with a delay larger
than the timer overflow period just hanging indefinitely.  However, when
the timer update code adds a virtual timer with a shorter delay, all
other virtual timers are also handled properly.
2022-02-05 05:08:50 +11:00
.github Merge remote-tracking branch 'origin/master' into develop 2021-11-23 01:41:28 +00:00
.vscode remove Bracket Pair Colorizer recommendation (#14816) 2021-10-15 11:54:19 +11:00
api_data Generate api data on each push (#10609) 2020-10-25 14:48:44 -07:00
builddefs Create a build error if no bootloader is specified. (#16181) 2022-02-03 19:22:49 +11:00
data [Keyboard] move @kkatano 's keyboards to kkatano user folder (#15684) 2022-01-30 11:22:12 -08:00
docs Merge remote-tracking branch 'origin/master' into develop 2022-02-04 03:45:30 +00:00
drivers Update outputselect to use platform connected state API (#16185) 2022-02-04 09:55:58 -08:00
keyboards Merge remote-tracking branch 'origin/master' into develop 2022-02-04 17:46:59 +00:00
layouts [Keymap] Remove Ergodox community layout “coderkun_neo2” (#16011) 2022-01-23 12:38:02 -08:00
lib Ensure version.h is recreated each build. (#16188) 2022-02-04 07:36:02 +11:00
platforms ChibiOS timer fixes (#16017) 2022-02-05 05:08:50 +11:00
quantum Don't make EEPROM size assumptions with dynamic keymaps. (#16054) 2022-02-02 15:04:37 +11:00
tests Rip out old macro and action_function system (#16025) 2022-01-24 21:22:20 +00:00
tmk_core Rename AdafruitBLE to BluefruitLE (#16127) 2022-01-30 17:29:42 +00:00
users [Keyboard] Overhaul Tractyl Manuform (#16134) 2022-01-30 13:29:43 -08:00
util Add a script that simplifies running commands under docker. (#16028) 2022-01-24 23:58:53 +00:00
.clang-format fix indent size 2019-06-11 01:51:40 -07:00
.editorconfig QMK CLI and JSON keymap support (#6176) 2019-07-15 12:14:27 -07:00
.gitattributes eol=lf, where appropriate (#15752) 2022-01-05 21:56:31 +00:00
.gitignore Remove old .gitignore entry. Add more macOS junk exclusions. (#16167) 2022-02-02 15:36:37 +11:00
.gitmodules Purge uGFX. (#14720) 2021-10-07 10:57:48 +11:00
build_full_test.mk [Tests] Increase QMK test coverage take 2 (#15269) 2021-11-23 13:31:01 +11:00
build_json.mk Add config.h and rules.mk support for data driven keymaps (#12859) 2021-08-18 21:52:41 +01:00
build_keyboard.mk Ensure version.h is recreated each build. (#16188) 2022-02-04 07:36:02 +11:00
build_layout.mk Add config.h and rules.mk support for data driven keymaps (#12859) 2021-08-18 21:52:41 +01:00
build_test.mk Refactor bootloader_jump() implementations (#15450) 2021-12-27 21:10:07 +11:00
common_features.mk Don't make EEPROM size assumptions with dynamic keymaps. (#16054) 2022-02-02 15:04:37 +11:00
Dockerfile move everything from qmkfm/base_container to qmkfm/qmk_cli (#14230) 2021-08-29 16:41:56 -07:00
Doxyfile Generate API docs from source code comments (#2491) 2018-03-22 02:50:38 -04:00
doxygen-todo Remove SERIAL_LINK feature (#14727) 2021-10-07 12:32:05 +11:00
LICENSE add an explicit lisence file for github to pickup 2017-11-13 20:50:54 -05:00
license_GPLv2.md Clarify the quantum license (#1042) 2017-03-28 15:20:36 -07:00
license_GPLv3.md Clarify the quantum license (#1042) 2017-03-28 15:20:36 -07:00
license_Modified_BSD.md Clarify the quantum license (#1042) 2017-03-28 15:20:36 -07:00
Makefile Workaround in Makefile for recursive rule matching (#15988) 2022-01-25 11:50:35 +11:00
nose2.cfg Setup a python test framework 2019-09-07 07:58:41 -07:00
paths.mk Move tmk_core/common/<plat> (#13918) 2021-11-19 10:41:02 -08:00
readme.md Start develop for 2022q1. 2021-11-28 11:16:20 +11:00
requirements-dev.txt Macros in JSON keymaps (#14374) 2021-11-22 11:11:35 -08:00
requirements.txt switch to qmk-dotty-dict (#13460) 2021-07-14 09:08:48 -07:00
setup.cfg Use the schema to eliminate custom code (#11108) 2021-01-09 13:34:14 -08:00
shell.nix Remove bin/qmk (#14231) 2021-08-29 16:50:22 -07:00
testlist.mk [Bug] Revert Assymmetrical Split Encoder support (#12090) (#15311) 2021-11-27 14:40:09 +11:00
Vagrantfile move everything from qmkfm/base_container to qmkfm/qmk_cli (#14230) 2021-08-29 16:41:56 -07:00

This is the develop branch!

See the Breaking Changes document for more information.

Quantum Mechanical Keyboard Firmware

Current Version Discord Docs Status GitHub contributors GitHub forks

This is a keyboard firmware based on the tmk_keyboard firmware with some useful features for Atmel AVR and ARM controllers, and more specifically, the OLKB product line, the ErgoDox EZ keyboard, and the Clueboard product line.

Documentation

The docs are powered by Docsify and hosted on GitHub. They are also viewable offline; see Previewing the Documentation for more details.

You can request changes by making a fork and opening a pull request, or by clicking the "Edit this page" link at the bottom of any page.

Supported Keyboards

The project also includes community support for lots of other keyboards.

Maintainers

QMK is developed and maintained by Jack Humbert of OLKB with contributions from the community, and of course, Hasu. The OLKB product firmwares are maintained by Jack Humbert, the Ergodox EZ by ZSA Technology Labs, the Clueboard by Zach White, and the Atreus by Phil Hagelberg.

Official Website

qmk.fm is the official website of QMK, where you can find links to this page, the documentation, and the keyboards supported by QMK.