Skip to content

[RFC] abstract clock subsystem: counter syntonization #60400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
07cc2bd
kernel: sys_clock: concentrate state in struct
fg-cfh Oct 8, 2023
1121119
tests: kernel: pipe: increase stack size
fg-cfh Oct 20, 2023
11fd8d2
kernel: timeout: generalize timeout api
fg-cfh Oct 19, 2023
11d988f
kernel: timeout: separate sys_clock Kconfig from timeout api
fg-cfh Oct 20, 2023
54ea77b
kernel: timeout: publish multi-instance to api
fg-cfh Oct 20, 2023
e24f584
doc: kernel: clocks: fix macro references
fg-cfh Oct 20, 2023
61191f5
doc: kernel: clock: prefix system clock apis
fg-cfh Oct 20, 2023
856e8d8
net: time: minor doc improvement
fg-cfh Oct 20, 2023
dc7f3df
kernel: time: header to represent generic time concepts
fg-cfh Oct 20, 2023
7d6afcf
doc: sys: time_units: let doxygen recognize doc target
fg-cfh Oct 20, 2023
d6d3130
sys: time_units: move time to timeout conversion
fg-cfh Oct 20, 2023
1a16aa0
sys: time_units: move time converter generator macros
fg-cfh Oct 20, 2023
4b2d418
doc: sys_time: slightly improve time converter macro docs
fg-cfh Oct 20, 2023
89fcf9c
sys: time_units: remove obsolete TIME_CONSTEXPR
fg-cfh Oct 20, 2023
d9e7e89
doc: sys: time_units: improve readability
fg-cfh Oct 20, 2023
3f70ac2
sys_clock: move public generic time constants
fg-cfh Oct 20, 2023
4890122
sys_clock: move private generic time constants
fg-cfh Oct 20, 2023
430d88f
sys_clock: move timepoint related utilities
fg-cfh Oct 20, 2023
e4e144f
sys_clock: clean up condition macros
fg-cfh Oct 20, 2023
e9017b5
kernel: timeout: special timepoint values
fg-cfh Sep 13, 2023
a1689a2
kernel: timer/timeout: make timer instance aware
fg-cfh Aug 7, 2023
dc1b46f
net: introduce network uptime reference API
fg-cfh Aug 12, 2023
1ced4ae
drivers: ieee802154: introduce network uptime API
fg-cfh Sep 28, 2023
541428e
[DNM] arm: linker: workaround for #58080
fg-cfh Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/linker_script/common/common-ram.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ if(CONFIG_NETWORKING)
zephyr_iterable_section(NAME eth_bridge GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)
endif()

if(CONFIG_NET_TIME_REFERENCE_CLOCK)
zephyr_iterable_section(NAME net_time_timer GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)
endif()

if(CONFIG_SENSING)
zephyr_iterable_section(NAME sensing_sensor GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)
endif()
Expand Down
8 changes: 4 additions & 4 deletions doc/kernel/services/timing/clocks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ read operation is very fast. The expectation is that very sensitive
application code might use this in a polling manner to achieve maximal
precision. The frequency of this counter is required to be steady
over time, and is available from
:c:func:`sys_clock_hw_cycles_per_sec` (which on almost all
:c:macro:`sys_clock_hw_cycles_per_sec` (which on almost all
platforms is a runtime constant that evaluates to
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC).

Expand All @@ -53,10 +53,10 @@ Control of rounding is provided, and each conversion is available in
"near" (round to nearest). Finally the output precision can be
specified as either 32 or 64 bits.

For example: :c:func:`k_ms_to_ticks_ceil32` will convert a
For example: :c:macro:`k_ms_to_ticks_ceil32` will convert a
millisecond input value to the next higher number of ticks, returning
a result truncated to 32 bits of precision; and
:c:func:`k_cyc_to_us_floor64` will convert a measured cycle count
:c:macro:`k_cyc_to_us_floor64` will convert a measured cycle count
to an elapsed number of microseconds in a full 64 bits of precision.
See the reference documentation for the full enumeration of conversion
routines.
Expand Down Expand Up @@ -370,4 +370,4 @@ value, and should never be called iteratively in a loop.
API Reference
*************

.. doxygengroup:: clock_apis
.. doxygengroup:: sys_clock_apis
2 changes: 1 addition & 1 deletion drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ add_subdirectory_ifdef(CONFIG_SENSOR sensor)
add_subdirectory_ifdef(CONFIG_SERIAL serial)
add_subdirectory_ifdef(CONFIG_SPI spi)
add_subdirectory_ifdef(CONFIG_SYSCON syscon)
add_subdirectory_ifdef(CONFIG_SYS_CLOCK_EXISTS timer)
add_subdirectory_ifdef(CONFIG_TIMEOUT_QUEUE timer)
add_subdirectory_ifdef(CONFIG_VIDEO video)
add_subdirectory_ifdef(CONFIG_VIRTUALIZATION virtualization)
add_subdirectory_ifdef(CONFIG_W1 w1)
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/arch/arm/cortex_m/scripts/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ SECTIONS
SECTION_PROLOGUE(padding_section,,)
{
__rodata_region_end = .;
MPU_ALIGN(__rodata_region_end - ADDR(rom_start));
. = ALIGN(8);
} GROUP_LINK_IN(ROMABLE_REGION)
#else
__rodata_region_end = .;
Expand Down
3 changes: 2 additions & 1 deletion include/zephyr/drivers/timer/system_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ extern "C" {

/**
* @brief System Clock APIs
* @defgroup clock_apis System Clock APIs
* @defgroup sys_clock_apis System Clock APIs
* @ingroup kernel_apis
* @{
*/

Expand Down
12 changes: 7 additions & 5 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ const char *k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size);
*/

/**
* @addtogroup clock_apis
* @addtogroup sys_clock_apis
* @{
*/

Expand Down Expand Up @@ -1463,6 +1463,8 @@ struct k_timer {
/* wait queue for the (single) thread waiting on this timer */
_wait_q_t wait_q;

struct k_timeout_api *timeout_api;

/* runs in ISR context */
void (*expiry_fn)(struct k_timer *timer);

Expand Down Expand Up @@ -1492,6 +1494,7 @@ struct k_timer {
.fn = z_timer_expiration_handler, \
.dticks = 0, \
}, \
.timeout_api = &Z_SYS_CLOCK_TIMEOUT_API, \
.wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
.expiry_fn = expiry, \
.stop_fn = stop, \
Expand Down Expand Up @@ -1633,7 +1636,7 @@ __syscall uint32_t k_timer_status_get(struct k_timer *timer);
*/
__syscall uint32_t k_timer_status_sync(struct k_timer *timer);

#ifdef CONFIG_SYS_CLOCK_EXISTS
#ifdef CONFIG_TIMEOUT_QUEUE

/**
* @brief Get next expiration time of a timer, in system ticks
Expand Down Expand Up @@ -1683,7 +1686,7 @@ static inline uint32_t k_timer_remaining_get(struct k_timer *timer)
return k_ticks_to_ms_floor32(k_timer_remaining_ticks(timer));
}

#endif /* CONFIG_SYS_CLOCK_EXISTS */
#endif /* CONFIG_TIMEOUT_QUEUE */

/**
* @brief Associate user-specific data with a timer.
Expand Down Expand Up @@ -1725,8 +1728,7 @@ static inline void *z_impl_k_timer_user_data_get(const struct k_timer *timer)
/** @} */

/**
* @addtogroup clock_apis
* @ingroup kernel_apis
* @addtogroup sys_clock_apis
* @{
*/

Expand Down
4 changes: 4 additions & 0 deletions include/zephyr/linker/common-ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#endif
#endif /* NETWORKING */

#if defined(CONFIG_NET_TIME_REFERENCE_CLOCK)
ITERABLE_SECTION_RAM(net_time_timer, 4)
#endif

#if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_DYNAMIC_INTERRUPTS)
SECTION_DATA_PROLOGUE(sw_isr_table,,)
{
Expand Down
19 changes: 19 additions & 0 deletions include/zephyr/net/ieee802154_radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,10 @@ struct ieee802154_radio_api {
*
* See @ref net_time_t for semantic details.
*
* @note This is an alias for `radio_api->get_time_reference()
* ->get_time()` for drivers that support the network uptime
* reference API.
*
* @note requires IEEE802154_HW_TXTIME and/or IEEE802154_HW_RXTIME
* capabilities. Implementations SHALL be **isr-ok** and MUST NOT
* **sleep**. MAY be called in any interface state once the driver is
Expand All @@ -1763,6 +1767,21 @@ struct ieee802154_radio_api {
*/
net_time_t (*get_time)(const struct device *dev);

/**
* @brief Provides access to the full API of the underlying network
* uptime reference of the driver.
*
* @note Implementations SHALL be **isr-ok** and MUST NOT **sleep**. MAY
* be called in any interface state once the driver is fully initialized
* ("ready").
*
* @param dev pointer to IEEE 802.15.4 driver device
*
* @returns a pointer to the driver's underlying network uptime
* reference or NULL if not supported.
*/
const struct net_time_reference_api *(*get_time_reference)(const struct device *dev);

/**
* @brief Get the current estimated worst case accuracy (maximum ±
* deviation from the nominal frequency) of the network subsystem's
Expand Down
Loading