Incorrect 64-bit Counter Behavior on nRF52840DK and nRF52833DK Devices Using counter_get_value_64() #80272
-
Hi Zephyr Community, Describe the bug To Reproduce
west build -p -b nrf52840dk/nrf52840 <path/file>
west flash
Expected behavior Impact Logs and console output Environment: Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hi @CienetmarkChen! We appreciate you submitting your first issue for our open-source project. 🌟 Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙 |
Beta Was this translation helpful? Give feedback.
-
Where did you start the counter? |
Beta Was this translation helpful? Give feedback.
-
Hi nordicjm, Before calling the function counter_get_value_64, we ensured to start the counter by calling Further testing on the nrf52840dk board showed that calling counter_get_value_64 returns Here is our experimental code: #include <zephyr/kernel.h>
#include <zephyr/sys_clock.h>
#include <zephyr/drivers/counter.h>
#include <stdio.h>
static const struct device *external_sensor_clock = DEVICE_DT_GET(DT_CHOSEN(zephyr_sensor_clock));
int main(void)
{
uint64_t cycles = 0;
uint64_t delta_ns = 0;
int err;
counter_start(external_sensor_clock);
while (true) {
k_sleep(K_MSEC(1000));
err = sensor_clock_get_cycles(&cycles);
if (err) {
printf("Failed to get sensor clock cycles, error: %d\n", err);
}
printf("Cycles: %llu\n", cycles);
delta_ns = sensor_clock_cycles_to_ns(cycles);
printf("Nanoseconds: %llu\n", delta_ns);
}
return 0;
}
int sensor_clock_get_cycles(uint64_t *cycles)
{
__ASSERT_NO_MSG(counter_is_counting_up(external_sensor_clock));
int rc;
rc = counter_get_value_64(external_sensor_clock, cycles);
return rc;
}
uint64_t sensor_clock_cycles_to_ns(uint64_t cycles)
{
uint32_t freq = counter_get_frequency(external_sensor_clock);
if (freq == 0) {
printf("Sensor clock %s has no fixed frequency\n", external_sensor_clock->name);
return 0;
}
return (cycles * NSEC_PER_SEC) / freq;
}
|
Beta Was this translation helpful? Give feedback.
-
Then the function is not supported, this is not a bug |
Beta Was this translation helpful? Give feedback.
Then the function is not supported, this is not a bug