This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

k_uptime_get()

I need to keep track of the time elapsed since boot-up using the function k_uptime_get() but it is always returning zero (0).

I am using an nRF5340PDK and Zephyr OS build v2.3.0-rc1-ncs1. The IDE used is SES for ARM (Nordic Edition) v5.10d (64-bit) running under windows 10.

This is what I am doing in my code.

#include <zephyr.h>

#include <kernel.h>

#include <sys/printk.h>

#include <stdio.h>

s64_t time_ms = k_uptime_get();

printf( "Booting-up @%i: \n", time_ms );

printk( "%i: ", time_ms );

Can someone please help?

Kind regards

Mohamed

Parents
  • Try the following:

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    //#include <zephyr.h>
    #include <sys/printk.h>
    #include <stdio.h>
    #include <zephyr.h>
    //#include <kernel.h>
    
    void main(void)
    {
    	s64_t time_ms = k_uptime_get();
    	//printf( "Booting-up @%i: \n", time_ms );
    	//printk( "%i\n: ", time_ms );
    	printk("Time %" PRId64 "\n", time_ms);
    
    	printk("Hello World! %s\n", CONFIG_BOARD);
    }
    

    If you're using a newer version of NCS (e.g. v1.4.0, which I'm using), you have to set CONFIG_DEPRECATED_ZEPHYR_INT_TYPES=y in the prj.conf

    Best regards,

    Simon

  • Hi Simon,

    Happy new year to you.

    Thank you for your answer and apologies for my late reply. I've only just noticed your post.

    I am using NCS v1.3.0.

    I can now get non-zero times using the following lines of code.

    #include <zephyr.h>
    #include <kernel.h>
    #include <sys/printk.h>
    #include <stdio.h>

    s64_t time_ms = k_uptime_get();


    time_ms = k_uptime_get();
    printk( "%i: ", (int)time_ms );

    Kind regards

    Mohamed

  • Happy new year to you as well.

    I'm happy you found a solution

    Best regards,

    Simon

Reply Children
Related