Skip to content

Commit 98deebd

Browse files
JordanYateshenrikbrixandersen
authored andcommitted
kernel: add k_uptime_seconds
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>
1 parent aee130f commit 98deebd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

doc/releases/release-notes-3.7.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Architectures
7171

7272
* Xtensa
7373

74+
Kernel
75+
******
76+
77+
* Added :c:func:`k_uptime_seconds` function to simplify `k_uptime_get() / 1000` usage.
78+
7479
Bluetooth
7580
*********
7681

include/zephyr/kernel.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,19 @@ static inline uint32_t k_uptime_get_32(void)
17741774
return (uint32_t)k_uptime_get();
17751775
}
17761776

1777+
/**
1778+
* @brief Get system uptime in seconds.
1779+
*
1780+
* This routine returns the elapsed time since the system booted,
1781+
* in seconds.
1782+
*
1783+
* @return Current uptime in seconds.
1784+
*/
1785+
static inline uint32_t k_uptime_seconds(void)
1786+
{
1787+
return k_ticks_to_sec_floor32(k_uptime_ticks());
1788+
}
1789+
17771790
/**
17781791
* @brief Get elapsed time.
17791792
*

0 commit comments

Comments
 (0)