Skip to content

Commit

Permalink
soc: arm: nordic_nrf: change default SYS_CLOCKS_PER_SEC
Browse files Browse the repository at this point in the history
The default system clock on all Nordic devices is based on a 32 KiHz
(2^15 Hz) timer.  Scheduling ticks requires that deadlines be specified
with a timer counter that aligns to a system clock.  With the Zephyr
default 100 clocks-per-sec configuration this results in 100 ticks every
32700 ticks of the cycle timer.  This reveals two problems:

* The uptime clock misrepresents elapsed time because it runs 0.208%
  (68/32768) faster than the best available clock;

* Calculation of timer counter compare values often requires an integer
  division and multiply operation to produce a value that's a multiple
  of clock-ticks-per-second.

Integer division on the Cortex-M1 nRF51 is done in software with a
(value-dependent) algorithm with a non-constant runtime that can be
significant.  This can produce missed Bluetooth deadlines as discussed
in upstream #14577 and others.

By changing the default divisor to one that evenly divides the 2^15
clock rate the time interrupts are disabled to manage timers is
significantly reduced, as is the error between uptime and real time.  Do
this at the top level, moving SYS_CLOCK_HW_CYCLES_PER_SEC there as well
since the two parameters are related.

Note that the central_hr configuration described in upstream #13610 does
not distinguish latency due to timer management from other
irq_block/spinlock regions, and the maximum observed latency will still
exceed the nominal 10 us allowed maximum.  However this does occur
much less frequently than changing the timer deadline which can happen
multiple times per tick.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information
pabigot authored and carlescufi committed May 7, 2019
1 parent f1f1a9f commit c76dd1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
8 changes: 8 additions & 0 deletions soc/arm/nordic_nrf/Kconfig.defconfig
Expand Up @@ -9,6 +9,14 @@ if SOC_FAMILY_NRF


source "soc/arm/nordic_nrf/*/Kconfig.defconfig.series" source "soc/arm/nordic_nrf/*/Kconfig.defconfig.series"


config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768

config SYS_CLOCK_TICKS_PER_SEC
int
default 128

config BUILD_OUTPUT_HEX config BUILD_OUTPUT_HEX
default y default y


Expand Down
4 changes: 0 additions & 4 deletions soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series
Expand Up @@ -13,10 +13,6 @@ source "soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.nrf51*"
config SOC_SERIES config SOC_SERIES
default "nrf51" default "nrf51"


config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768

config SYS_POWER_MANAGEMENT config SYS_POWER_MANAGEMENT
default y default y


Expand Down
4 changes: 0 additions & 4 deletions soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series
Expand Up @@ -12,10 +12,6 @@ source "soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.nrf52*"
config SOC_SERIES config SOC_SERIES
default "nrf52" default "nrf52"


config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768

config SYS_POWER_MANAGEMENT config SYS_POWER_MANAGEMENT
default y default y


Expand Down
4 changes: 0 additions & 4 deletions soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series
Expand Up @@ -12,10 +12,6 @@ source "soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf91*"
config SOC_SERIES config SOC_SERIES
default "nrf91" default "nrf91"


config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768

config ARCH_HAS_CUSTOM_BUSY_WAIT config ARCH_HAS_CUSTOM_BUSY_WAIT
default y default y


Expand Down

0 comments on commit c76dd1e

Please sign in to comment.