NRF_GRTC_TIMER_SOURCE had two unconditional defaults so second
one was never used. When synth clock source is used then GRTC source
clock should default to system lfclk.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The generic companion is armed only by sys_clock_set_timeout(0, true).
The default idle-entry hook passes the actual tick deadline instead, so a
nonzero deadline programs only the OS Timer. A state that stops that timer
then has no companion alarm for the deadline.
Implement sys_clock_idle_enter() to program the deadline first and hand it
to the generic companion for a configured handoff state. Keep the legacy
companion on the SoC zero-tick path, and avoid rearming a generic companion
if that poke follows the new hook.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
enable the or1k time that is part of the cpu
by default, just like it is already done at
ARCV2_TIMER and XTENSA_TIMER.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Replace direct NVIC_*PendingIRQ()/NVIC_EnableIRQ()/NVIC_DisableIRQ()
calls with k_irq_clear_pending()/k_irq_set_pending()/k_irq_is_pending() and
irq_enable()/irq_disable(), dropping the driver's dependency on
cmsis_core.h where nothing else needed it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This RISCV_MACHINE_TIMER_SYSTEM_CLOCK_DIVIDER was introduced for
the gd32vf103 where the CPU clock and mtime clock are different,
but it is now handled properly by timebase-frequency.
We will remove this as no one is referring to it anymore.
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
The counter and the alarm are two different timers here, which the core
keeps apart. The cycle domain is the free-running 64-bit ITIM64; the wakeup
comes from a separate 32-bit ITIM32 counting down at the low-frequency
clock. That makes it a RELOAD backend whose range is bounded by the second
timer rather than by the counter, so TIMER_CORE_ALARM_MAX_CYCLES is
NPCX_ITIM32_MAX_CNT of the event timer's cycles expressed in the counter's,
and the floor is one of them.
The core takes over the tick accounting: cyc_sys_announced, last_ticks and
last_elapsed go, and with them the deadline computation that turned a tick
count into an event-timer countdown. timer_driver_set_reload() is left with
the domain conversion and the register sequence. sys_clock_set_timeout(),
sys_clock_elapsed() and both cycle getters come from the core.
Reading ITIM64 is a two-register sequence that the power-management path
also adds a compensation to, so TIMER_CORE_COUNTER_NONATOMIC has the core
take the clock lock around the public getters, as the driver's own getters
did.
The event timer is one-shot, so the ISR re-arms it for a ticked kernel: the
core leaves a reload backend alone there, expecting hardware that reloads
itself.
Build-tested on npcx9m6f_evb, tickless and tickful, with
CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE and with CONFIG_PM.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
EVT_CYCLES_FROM_TICKS() has no user. Remove it.
NPCX_ITIM_EN_TIMEOUT_CYCLES hand-rolls a microsecond to cycle conversion
through SYS_CYCLES_PER_USEC, which truncates on a rate that is not a
multiple of a megahertz. Use k_us_to_cyc_ceil32() instead and drop
SYS_CYCLES_PER_USEC, its only user.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Update the driver for using the generic timer core.
Enable the TICKLESS_CAPABLE support for mchp_pit_g1_timer.
Signed-off-by: Tony Han <tony.han@microchip.com>
Announce PICNT directly in tickful ISR by removing the unnecessary
multiplication and division.
Add a guard for early calls for "mchp_pit_get_cycles()" before MMIO is
mapped.
Signed-off-by: Tony Han <tony.han@microchip.com>
The 16-bit CMT1 counter is extended to 32 bits in software: a read
counts a wrap when it sees the IR flag, or the count going backwards
during the read, then clears IR. A wrap landing between the count
sample and that clear loses its flag, and the next read sees neither
the flag nor a backwards step. The count then steps back by a period,
which the core announces as a jump of about 2^32 cycles (716 s at
6 MHz). Since commit dc295cc414 ("drivers: timer: renesas_rx_cmt:
use the generic timer core") the alarm can be armed for COUNTER_MAX,
one count short of a CMT1 period, so the read point creeps through the
period and regularly hits that window. Nothing but the alarm paced the
reads either, so two wraps could also pass between them.
Remember the last count read, so a count below it is a wrap whatever
became of the flag, and enable CMT1's compare-match interrupt to do a
read every period, so wraps can't pile up between reads however the
alarm is armed. Accepting the interrupt clears IR; a read that already
folded the wrap leaves nothing for the interrupt to add.
The wrap interrupt also wakes the CPU from idle, so raise the number
of early wakes the k_cpu_idle() test allows for this driver.
Fixes#123189
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
QEMU's icount mode without sleep advances the virtual clock straight to
the next armed deadline whenever the guest idles, and its timer models
have no unarmed state: any comparator value is a deadline. With nothing
pending the kernel asks for SYS_CLOCK_MAX_WAIT ticks, 248 days at
100 Hz, and the comparator is armed that far out. A few hundred idle
periods then saturate QEMU's signed 64-bit nanosecond clock:
k_uptime_get() reports 9223372036850 ms and no timer fires again, so any
later timeout hangs the guest. A device model with a periodic timer,
such as the OHCI frame timer, spins inside QEMU trying to catch up and
the emulator stops responding altogether.
Before commit 742f7c3d22 ("drivers: timer: riscv_machine: use the
generic timer core") the 32-bit build clamped the reach to 2^32 cycles,
429 s at 10 MHz, which hid this on qemu_riscv32. The 64-bit build never
did, and qemu_riscv64 saturates its clock within seconds of idling with
either driver.
The condition is not specific to that driver. Every 64-bit compare
backend on the generic core is exposed the same way, and the others only
avoid it by board configuration: qemu_cortex_a53 enables
QEMU_ICOUNT_SLEEP, qemu_x86_64 disables icount, and qemu_x86 disables it
only when the shell is built in.
Fold a cap into the core's TIMER_CORE_MAX_ARM_CYCLES instead: one second
of the counter's own rate, applied when CONFIG_QEMU_ICOUNT is set
without CONFIG_QEMU_ICOUNT_SLEEP, which is the pair that actually
triggers the jump. An idle guest then costs one wakeup per virtual
second, which is nothing under emulation, and the clock needs days of
wall time to saturate. With icount off or sleeping, virtual time
advances on its own and the extra wakeup buys nothing, so the hardware
reach stands. TIMER_CORE_ALARM_MAX_CYCLES stays a pure hardware
statement, a driver's smaller arming range still wins through the
existing MIN, and every driver on the core gets the bound.
Reproduced with samples/subsys/shell/shell_module on qemu_riscv32 and
qemu_riscv64: `kernel uptime` reads 9223372036850 ms after a few seconds
of idle. With this change it keeps counting, and the USB host shell
sample on qemu_riscv32 enumerates its devices again instead of hanging
after `usbh enable`.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Do not reprogram the LPTIM auto-reload value when entering the idle state.
The exit latency is 0 and the timer has already been programmed.
This avoids a case where the board enters STOP mode and immediately exits
because the ARROK interrupt is raised as expected. Preserve the behavior
that existed before commit 7fab907cf1.
Tested on NUCLEO-WBA25CE1, NUCLEO-WBA55CG, and NUCLEO-WBA65RI
with the affected PM workload.
Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
Spinlock time-limit checks may read the cycle counter before the HPET
registers have been mapped. The unmapped-MMIO guard currently only
covers 32-bit builds, so early reads on x86_64 dereference address 0xf0.
Move the existing guard before the word-size split so both counter
read paths return zero until the mapping is available.
Signed-off-by: Jinming Zhao <jinmzhao@qti.qualcomm.com>
Export the SMP IRQ lock helpers used by irq_lock()/irq_unlock() and
the 32-bit counter used by k_cycle_get_32() and spinlock time limits.
These existing inline APIs leave imports in loadable extensions that
cannot resolve them without entries in the built-in symbol table.
Signed-off-by: Jinming Zhao <jinmzhao@qti.qualcomm.com>
Add an explicit (void *) cast when assigning the const device pointer
to the FSP context field to avoid the build warning.
Signed-off-by: Duc Bui <duc.bui.vt@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
Some tests are restricted to running on 1 CPU only.
These tests would hold other CPUs spinning with interrupts
disabled. As sys_clock_driver_init() is only called on
core #0, if core #0 is not the one running the tests and
simply spinning with interrupts locked, we would not be
getting any timer interrupts, resulting in hung tests.
So just for testing, we enable timer interrupt for all
cores.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Both drivers depended on the SoC family symbol, which now also covers
the Arm cpuclusters on the same dies, so they were offered where the
hardware they drive does not exist.
Both are already devicetree driven: the interrupt controller iterates
mediatek,adsp_intc instances, and the timer reads its registers and its
interrupt out of the ostimer nodes. Depend on the nodes instead, which
is what the Kconfig style guide asks for and what leaves the drivers
independent of how the SoC tree is arranged.
The timer names the 64-bit node because that is the one with a binding;
both ostimer nodes are present on every audio DSP board.
Signed-off-by: Aary Patil <aary.patil@mediatek.com>
soc.yml names this family mt8xxx, so the hardware model v2 symbol for it is
SOC_FAMILY_MT8XXX. The tree used SOC_FAMILY_MTK, which names no family
present in soc.yml, and never set the SOC_FAMILY string at all.
Rename the symbol and add the missing default. No functional change: the
only references are inside soc/mediatek and the two audio DSP driver
Kconfig files.
Signed-off-by: Aary Patil <aary.patil@mediatek.com>
Implement the initialization hook of the Low-Power Counter Companion
Interface in the Counter API-based implementation. From this hook, we
assert that the device was configured as a potential wake-up source in
DTS and enable it as wake-up source at runtime. While we cannot prevent
an external caller from disabling the counter as wake-up source, we can
detect this and panic the kernel via an __ASSERT() to help developers
figure out their application has an error.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Update relevant drivers to invoke the newly defined hook of the
Low-Power Companion Interface during initialization.
Only two drivers currently support the Low-Power Companion:
- cortex_m_systick
- mcux_os
In the Cortex-M SysTick case, the initialization hook is called from the
"system_timer_generic" code used by that driver so that all driver based
on this shared code will also invoke the init hook appropriately if they
are ever updated to implement Low-Power Companion support.
In the MCUX OS timer case, the "system_timer_generic" code is not used
so the initialization hook is called directly from the driver.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Add a new hook to the System Timer Low-Power Companion Interface that
must be called by the System Timer driver during its initialization.
This can be used to perform one-shot configuration that may be required
by the platform implementation.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Remove dependency of CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE (and the
associated choice) on SYSTEM_TIMER_HAS_LPM_COMPANION_SUPPORT. This makes
the option visible in every build, regardless of whether the companion
timer is supported or not, which allows using the option as an indicator
of whether or not a companion timer is used:
- CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=y: companion timer not used
(either unsupported by systimer driver, or not available/enabled)
- CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=n: companion timer used
This change will allow simplifications in common code since it is no
longer necessary to check for HAS_COMPANION_SUPPORT before looking at
CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE.
While at it, update the relevant header to make this explicit: the API
is not available when there is no low-power companion configured, which
is now when CONFIG_SYSTEM_TIMER_LPM_COMPANION_NONE=y.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
An auto-reload 32-bit down-counter: a RELOAD backend. The driver keeps
its synthesized cycle count and the reprogram that recovers the cycles
passing between reading the counter and rewriting it, the val1/val2
drift compensation, now named timer_driver_cycle_get() and
timer_driver_set_reload(). The core takes over the tick accounting:
announced_cycles and last_elapsed leave the device data, and with them
the deadline-to-cycles math, the range clamp and the announce.
The counter is not free-running, it counts one programmed interval at a
time, so the synthesized read is not atomic against the ISR and the
reprogram path. TIMER_CORE_COUNTER_NONATOMIC has the core serialise
sys_clock_cycle_get_32() under the clock lock.
The arm range narrows to the core default, half the synthesized count's
span, from the full 32-bit interval the hardware can hold: a full-span
interval wraps that count.
The driver states no cycles-per-tick of its own: MIN_DELAY_CYCLES and
the one-tick interval at init both read the core's
TIMER_CORE_CYC_PER_TICK.
The special case for CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE goes away. It armed
the longest interval the hardware could hold on SYS_CLOCK_MAX_WAIT,
which is also an ordinary capped timeout, so a far deadline was treated
as no deadline. The core arms the longest interval it allows once
nothing is pending, through the weak sys_clock_no_timeout().
Tested on mps2/an385, which needs a devicetree overlay pointing
/chosen/zephyr,system-timer at the arm,cmsdk-timer node plus
CONFIG_CORTEX_M_SYSTICK=n: timer_api passes. The sloppy-idle variant
hangs in test_timeout_abs, which reproduces without this commit, so the
platform is not added to that variant.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The generic timer core already extends this driver's 32-bit count from its
announce baseline, so sys_clock_cycle_get_64() works. Without the select,
k_cycle_get_64() returns 0.
Assisted-by: Claude:opus-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
sys_clock_driver_init() seeded the timer core's announce baseline from
the counter and only then enabled the timer. QEMU's Cortex-A9 global
timer model reports the time since machine start while the timer is
disabled and restarts the count from zero once it is enabled, so the
baseline ended up ahead of the counter for the first few milliseconds
of the run. Every sys_clock_elapsed() in that window computed a wrapped
delta that clamps to UINT32_MAX ticks, so a timeout queued then was
placed about 2^32 ticks out and never expired. Which timeouts land in
the window depends on the boot timing, so an unrelated change in code
layout made tests/net/lib/mqtt_sn_client hang in its first test case
on qemu_cortex_a9.
Enable the timer before timer_core_init() so the baseline is taken from
the running counter, and keep the compare interrupt masked until the
core has armed the first deadline.
Assisted-by: Claude Fable 5.1
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Introduce a Kconfig option to let users configure the SysTick interrupt
priority like any other hardware interrupt in the system.
This allows adjusting the SysTick priority to reduce latency impact on
higher-priority interrupts when needed.
Note that the timekeeping code in the Systick driver tolerates at most
one counter wrap between updates, so the tick must not be held off longer
than the wrap period. The minimum timeout is now a fixed 10 us budget
(SYSTICK_MIN_DELAY_US) converted to cycles at the actual clock rate and
floored at two cycles, with zephyr,min-timeout-cycles on the systick node
still overriding it. Lowering SysTick below other interrupts makes its
worst-case hold-off the nested run time of every higher-priority
interrupt, and any missed wrap silently drops a full last_load of uptime
with no diagnostic.
This 10 us budget is far tighter than the older tick-based floor, so
non-default priorities are safe ONLY while the worst-case hold-off stays
below the wrap period, and in practice **must** be paired with a larger
zephyr,min-timeout-cycles on the systick node.
The default priority preserves the current behavior of using the highest
maskable/kernel IRQ priority (_IRQ_PRIO_OFFSET).
Signed-off-by: Marouen Ghodhbane <marouen.ghodhbane@nxp.com>
Fixes various issues with Kconfigs, including:
- Using the wrong indentation
- Not having [EXPERIMENTAL] in the prompt, or not having it at
the end
- Wrongly stating the CONFIG_EXPERIMENTAL is needed to enable
an experimental Kconfig
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Fixes various issues with Kconfigs, including:
- Redundent `default n` on bools
- Not select deprecated on supposed deprecated symbols
- Using the wrong indentation
- Not having [DEPRECATED] in the prompt, or not having it at the
end
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Replaced SOC dependent kconfigs CONFIG_SOC_SERIES_NRF54H,
CONFIG_SOC_SERIES_NRF92 with feature oriented
CONFIG_HAS_MULTI_OPTION_CLOCKS, in clock related drivers.
Signed-off-by: Michal Frankiewicz <michal.frankiewicz@nordicsemi.no>
Add system timer drivers using the STM (System Timer Module)
on TC3x and TC4x. The STM provides the kernel tick source for
scheduling and timeouts.
Signed-off-by: Christoph Seitz <christoph.seitz@infineon.com>
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
ULPT instance 1 free-runs and provides the cycle counter (its
down-counter read back inverted counts up); ULPT instance 0 is armed with
a relative delay and its underflow announces ticks. That is a RELOAD
backend whose cycle source is a genuine free-running counter, so the
driver keeps only timer_driver_cycle_get() (~INST1 counter) and
timer_driver_set_reload() (arm INST0), and the core takes over the tick
accounting and the tick-aligned deadline.
This removes the driver's open-coded "ticks - 1" adjustment and round-up
dance, the code carrying the "preserve the original behavior even though
it looks wrong; to be revisited" comment: the core computes the reload
from an absolute tick-aligned deadline. The private spinlock and the
announce baseline (cycle_announced) go with it.
The sloppy-idle sentinel branch goes as well. The core arms the longest
reload the hardware can hold instead of leaving whatever the previous arm
programmed in place.
Build-tested on ek_ra8m1 with CONFIG_PM=y, which is what selects this
driver as the system timer.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The free-running 64-bit wall clock (external to the CPUs, shared across
SMP) with its absolute comparator. Arming disarms the comparator, writes
both halves and rearms it, so a counter that reaches the target during
that sequence leaves the match unarmed, and on a 64-bit counter it never
comes round again. That makes this a COMPARE_EXACT backend: the core
rewrites through its verify loop until the target is genuinely ahead of
the counter, which is what the driver's MIN_DELAY floor used to
approximate.
The driver keeps timer_driver_cycle_get() (the counter) and
timer_driver_set_compare() (arm the comparator), and the core takes over
the tick accounting: the last_count baseline, the deadline math, the
range clamp and the announce. The ISR reduces to acknowledging the
trigger and announcing.
The wall clock is a genuine 64-bit counter on this 32-bit CPU, so
TIMER_CORE_COUNTER_WIDTH is set to 64 to use its full range.
The driver keeps both cycle getters: count32() reads the counter's low
half in a single access where the core's extend path takes three, and a
driver that supplies one getter supplies the other.
Build-tested on intel_adsp/cavs25 and intel_adsp/ace15_mtpm.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
GPTIMER has no absolute compare register, only a relative reload, so it is
a RELOAD backend: subtimer 1 free-runs as the cycle source and subtimer 0
is loaded with the relative delay the core derives from a tick-aligned
deadline. The driver keeps timer_driver_cycle_get() (the free-running
counter) and timer_driver_set_reload() (program subtimer 0); the core takes
over the announce baseline, the deadline math, the range clamp and the
announce. The ISR reduces to acknowledging, one-shot stop when tickless and
keep periodic otherwise, and announcing.
The subtimers run at the system rate divided by the shared prescaler, so
the core works in that divided cycle domain and derives its cycles-per-tick
from it. sys_clock_cycle_get_32() stays the driver's own and scales the
subtimer count back up to the system cycle rate.
timer_api, context, sleep and tickless pass on qemu_leon3, and timer_api
passes there with CONFIG_TICKLESS_KERNEL=n (the periodic path).
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
TIMER_CORE_COUNTER_WIDTH used __LONG_WIDTH__, a predefined macro that
doesn't exist with older toolchains such as the Xtensa xt-clang
(Clang 10.0.1).
Use (__SIZEOF_LONG__ * 8) instead, which every GCC/Clang defines and
yields the same width.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Add the tickless Hexagon system timer driver on top of the generic
tickless core (system_timer_generic.h). The H2 hypervisor exposes a
free-running 64-bit nanosecond counter via vmtimerop(hvmt_gettime) and
an absolute-deadline timeout via vmtimerop(hvmt_settimeout); the driver
supplies only these cycle-domain primitives and lets the generic core
own all tick accounting.
hvmt_settimeout matches on equality only: a deadline at or before the
current time is mapped by the hypervisor to BIGBANG, which disables
the timer rather than firing it immediately. This classifies Hexagon
as a TIMER_CORE_BACKEND_COMPARE_EXACT backend, whose core-side verify
loop re-arms a deadline the counter has already passed, removing the
need for a driver-side minimum-delay fallback.
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
Convert the RISC-V machine timer to system_timer_generic.h. The mtime
counter with its absolute mtimecmp compare is a COMPARE_ORDERED backend:
the driver keeps only timer_driver_cycle_get() (mtime) and
timer_driver_set_compare() (set_mtimecmp), and the core takes over the
cycle-to-tick accounting, the deadline math, the range clamp and the
announce. smp_timer_init() primes the per-hart comparator through
timer_core_smp_prime() rather than reaching into the core's baseline.
The public cycle counter applies the DT clock divider to raw mtime, so
the driver keeps its own sys_clock_cycle_get_32/64() and says so with
TIMER_CORE_HAVE_CYCLE_GET_32/64.
Tested with timer_api and context on qemu_riscv64.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
MTIP is level sensitive: it stays asserted for as long as mtime is past
mtimecmp, and writing mtimecmp is the only way to clear it. The ISR never
did, relying instead on sys_clock_set_timeout() being called after the
announce to move the compare forward.
That holds only as long as something does call it. On SMP with a per-hart
mtimecmp, every hart takes the interrupt when a shared deadline expires,
but sys_clock_announce_locked() returns early on all but one of them, so
only the announcing hart gets its compare rewritten. The others return
from the ISR with the compare still in the past and take the interrupt
again immediately, once per hart until each has had a turn as announcer.
It is not specific to SMP either. Nothing guarantees the kernel arms
another deadline: with no timeout pending it may legitimately choose not
to, and a driver has no business depending on that to stop its own
interrupt.
Push the compare out of reach on entry instead, so the interrupt fires
once for the deadline it was armed with. The arming path overwrites it
with the real deadline in the normal case.
Fixes: #115442
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Clock source selection for the 32 kHz clock is now handled by the clock
control driver. Remove the redundant clock source configuration from the
WUT timer driver and rely on the clock control subsystem to provide the
selected source.
Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
Tickless GRTC skipped the first compare and waited for
sys_clock_set_timeout(). The kernel only calls that when insert
reports a new soon-list head. Wheel timeouts past the later window
never do, so announce never starts and k_sleep latches.
The !TICKLESS guard was the old split, a tickful driver must fire
from boot because set_timeout is a no-op, while tickless assumed the
kernel would program the first real deadline. That first call never
comes if soon stays empty, so drop the guard and always arm one tick
at init, matching SysTick and timer_core_init(). The ISR still only
re-arms itself when TICKLESS=n.
Signed-off-by: Dhruv Menon <dhruvmenon1104@gmail.com>
Replace direct NVIC pending-state calls with k_irq_set_pending()/
k_irq_is_pending()/k_irq_clear_pending(), dropping the dependency on
cmsis_core.h where nothing else needed it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
commit 98500853d9 ("drivers: timer: nrf_rtc_timer: fix RTC init issue")
added an unconditional 46 us busy wait between the CLEAR and START tasks,
so that a counter value left behind by a bootloader is gone by the time
timer_core_init() reads the counter. On a cold boot the counter is
already zero, and on the simulated nRF targets tasks take effect
immediately, so there the wait only starts the system clock 46 us later.
That shifts the kernel tick phase relative to the radio timeline, and on
nrf52_bsim it made tests.bsim.bluetooth.mesh.bridge (the
brg_net_key_refresh.sh scenario) fail with the seed CI uses; every pull
request's bsim-test run has failed on it since the commit merged.
Only clear the counter, and wait for the clear to take effect, when it
holds a non-zero value, which is the case the wait exists for. Verified on
an nRF52 DK with a PRE_KERNEL_1 hook that starts LFCLK and RTC1 and lets
the counter run before the driver initializes: the counter register keeps
returning the old value for up to 46 us after CLEAR, so with START issued
immediately timer_core_init() can read it, while after the wait it reads
zero; k_msleep() and the uptime clock behave the same as on a cold boot.
The bsim mesh scenario passes again with the default seed. That scenario
is timing sensitive on its own (it also fails for other seeds without this
change), which is tracked in #118188.
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The driver initialization routine has been changed to use the generic
`timer_core_init`. As per nRF52840 RTC specification / section section
TASK and EVENT jitter/delay, a delay of 46usec should be observed after
a TASK CLEAR event before the counter is reset to 0.
Failing to do so will cause a spurious RTC wrap under certain
conditions, such as on the Arduino Nano 33. The timer core logic will
incorrectly assume that the RTC has wrapped, setting the main thread's
initial timeslice far in the future. As a result, k_msleep() blocks for
a very, very long time.
This bug was present before the driver rework, but changes to the driver
initialization code likely exposed it.
Fixes: #117522
Signed-off-by: Loic Domaigne <tech@domaigne.com>
Replace direct NVIC pending-state calls with k_irq_set_pending()/
k_irq_is_pending()/k_irq_clear_pending(), dropping the dependency on
cmsis_core.h where nothing else needed it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
The REUSE tool then folds the literal "<text>" into the holder name
and drops the second line from the SBOM.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
Counter 2 of the MCWDT free-runs at the low-frequency clock and is the
cycle domain, while counters 0 and 1, cascaded into a 32-bit match, are
armed as a one-shot relative delay: a RELOAD backend whose alarm is a
separate timer from the counter. Arming resets that pair before setting
the match, so the delay always runs from zero and cannot be programmed
into the past, which is why no reload floor is stated.
The core takes over the tick accounting. announced_cycles, the spinlock
and the cycle-to-tick math go with it, and so do sys_clock_set_timeout(),
sys_clock_elapsed() and sys_clock_cycle_get_32(), which the core emits.
What is left of the interrupt handler is the acknowledge and the announce.
A ticked kernel now works. The core leaves the period of a reload backend
to the driver, and this alarm does not reload itself, so init and the
handler arm one tick. The driver used to arm the full 32-bit range at
init and never again in that configuration, which put the first tick some
36 hours out.
The counter is reported to the kernel as it reads, so the devicetree
clock-frequency and CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC have to agree.
That was already assumed; a BUILD_ASSERT now says so.
Also drop the unused gpio.h and pull in kernel.h, which the removed
headers happened to provide for WAIT_FOR().
Build-tested on kit_psc3m5_evk, ticked and tickless.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>