As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>. This patch proposes to then include <zephyr/kernel.h> instead of <zephyr/zephyr.h> since it is more clear that you are including the Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a catch-all header that may be confusing. Most applications need to include a bunch of other things to compile, e.g. driver headers or subsystem headers like BT, logging, etc. The idea of a catch-all header in Zephyr is probably not feasible anyway. Reason is that Zephyr is not a library, like it could be for example `libpython`. Zephyr provides many utilities nowadays: a kernel, drivers, subsystems, etc and things will likely grow. A catch-all header would be massive, difficult to keep up-to-date. It is also likely that an application will only build a small subset. Note that subsystem-level headers may use a catch-all approach to make things easier, though. NOTE: This patch is **NOT** removing the header, just removing its usage in-tree. I'd advocate for its deprecation (add a #warning on it), but I understand many people will have concerns. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
79 lines
1.4 KiB
C
79 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2021 Friedt Professional Engineering Services, Inc
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr/ztest.h>
|
|
#include <zephyr/kernel.h>
|
|
|
|
static void swap64(uint64_t *a, uint64_t *b)
|
|
{
|
|
uint64_t t = *a;
|
|
*a = *b;
|
|
*b = t;
|
|
}
|
|
|
|
static void msg(uint64_t c64)
|
|
{
|
|
int64_t ms = k_uptime_get();
|
|
int s = ms / 1000;
|
|
int m = s / 60;
|
|
int h = m / 60;
|
|
int d = h / 24;
|
|
|
|
h %= 24;
|
|
m %= 60;
|
|
s %= 60;
|
|
ms %= 1000;
|
|
|
|
printk("[%03d:%02d:%02d:%02d.%03d]: cycle: %016" PRIx64 "\n", d, h, m, s, (int)ms, c64);
|
|
}
|
|
|
|
uint32_t timeout(uint64_t prev, uint64_t now)
|
|
{
|
|
uint64_t next = prev + BIT64(32) - now;
|
|
|
|
next &= UINT32_MAX;
|
|
if (next == 0) {
|
|
next = UINT32_MAX;
|
|
}
|
|
|
|
return (uint32_t)next;
|
|
}
|
|
|
|
ZTEST(cycle64_tests, test_32bit_wrap_around)
|
|
{
|
|
enum {
|
|
CURR,
|
|
PREV,
|
|
};
|
|
|
|
int i;
|
|
uint64_t now;
|
|
uint64_t c64[2];
|
|
|
|
printk("32-bit wrap-around should occur every %us\n",
|
|
(uint32_t)(BIT64(32) / (uint32_t)sys_clock_hw_cycles_per_sec()));
|
|
|
|
printk("[ddd:hh:mm:ss.0ms]\n");
|
|
|
|
c64[CURR] = k_cycle_get_64();
|
|
msg(c64[CURR]);
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
k_sleep(Z_TIMEOUT_CYC(timeout(c64[CURR], k_cycle_get_64())));
|
|
|
|
now = k_cycle_get_64();
|
|
swap64(&c64[PREV], &c64[CURR]);
|
|
c64[CURR] = now;
|
|
|
|
msg(c64[CURR]);
|
|
|
|
zassert_equal(((c64[CURR] - c64[PREV]) >> 32), 1,
|
|
"The 64-bit cycle counter did not increment by 2^32");
|
|
}
|
|
}
|
|
|
|
ZTEST_SUITE(cycle64_tests, NULL, NULL, NULL, NULL, NULL);
|