nrf: fix off-by-one in modulo of runtime.ticks

This code:
    foo & 0xffffff
Is equivalent to this code:
    foo % 0x1000000
However, to drop the high 8 bits, this calculation was used:
    foo % 0xffffff
This is far more expensive (and incorrect), as it needs an actual modulo
operation which increases code size and probably reduces speed on a
Cortex-M4 and needs library functions for a Cortex-M0 increasing code
size by a much bigger amount.
Этот коммит содержится в:
Ayke van Laethem 2018-09-29 16:16:38 +02:00
родитель c1a833c7cc
коммит 5bf058a0a6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED

Просмотреть файл

@ -75,7 +75,7 @@ var (
// handling the overflow event.
func ticks() timeUnit {
rtcCounter := uint32(nrf.RTC0.COUNTER)
offset := (rtcCounter - rtcLastCounter) % 0xffffff // change since last measurement
offset := (rtcCounter - rtcLastCounter) & 0xffffff // change since last measurement
rtcLastCounter = rtcCounter
timestamp += timeUnit(offset) // TODO: not precise
return timestamp