Skip to content

Commit

Permalink
kernel: add k_uptime_seconds
Browse files Browse the repository at this point in the history
Add a helper function for retrieving the system uptime in seconds
without having to do a second division.

Signed-off-by: Jordan Yates <jordan@embeint.com>
  • Loading branch information
JordanYates authored and henrikbrixandersen committed May 14, 2024
1 parent aee130f commit 98deebd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/releases/release-notes-3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ Architectures

* Xtensa

Kernel
******

* Added :c:func:`k_uptime_seconds` function to simplify `k_uptime_get() / 1000` usage.

Bluetooth
*********

Expand Down
13 changes: 13 additions & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,19 @@ static inline uint32_t k_uptime_get_32(void)
return (uint32_t)k_uptime_get();
}

/**
* @brief Get system uptime in seconds.
*
* This routine returns the elapsed time since the system booted,
* in seconds.
*
* @return Current uptime in seconds.
*/
static inline uint32_t k_uptime_seconds(void)
{
return k_ticks_to_sec_floor32(k_uptime_ticks());
}

/**
* @brief Get elapsed time.
*
Expand Down

0 comments on commit 98deebd

Please sign in to comment.