<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76758/k_uptime_get-return-a-signed-value</link><description>Hello, 
 I would like to use k_uptime_get, however this is returning an int64_t where I would expect an uint64_t. 
 While looking in the function, I see that k_uptime_get calls k _ticks_to_ms_floor64 ( k_uptime_ticks ()); which should be returning an</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Jun 2021 08:59:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76758/k_uptime_get-return-a-signed-value" /><item><title>RE: k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/thread/317637?ContentTypeID=1</link><pubDate>Tue, 29 Jun 2021 08:59:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95fda7cc-4808-4a41-bc11-210ccc52b397</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>[quote user="Depraz"]Thanks&amp;nbsp;&lt;span&gt;Håkon!&lt;/span&gt;[/quote]
&lt;p&gt;Always happy to help! Please let us know if there&amp;#39;s anything else that should pop up.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope you have a wonderful day, Florian!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/thread/317626?ContentTypeID=1</link><pubDate>Tue, 29 Jun 2021 08:32:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5b7399d-b26f-4db7-881a-f40d028c40a5</guid><dc:creator>Depraz</dc:creator><description>&lt;p&gt;Thanks&amp;nbsp;&lt;span&gt;H&amp;aring;kon!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/thread/317260?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 13:50:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b17053a2-ef5d-4b93-8abf-7e251af06af2</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Florian,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="Depraz"]&lt;p&gt;&lt;span&gt;Once started (without the tickless option), can I safely assume that this counter won&amp;#39;t restart to 0 unless the program runs for years and years (i.e. until 2^64 milliseconds) ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I see that the driver is returning 32bit values. Once we reach 2^32 milliseconds, will we restart to 0 even if we are using k_uptime_get which should return an 64bit?&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If we look deeper into how the ticks are handled, its a diff based on the last time the counter was updated:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/timer/system_timer.h#L124-L132"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/timer/system_timer.h#L124-L132&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is the call from&amp;nbsp;k_uptime_ticks -&amp;gt;&amp;nbsp;sys_clock_tick_get:&lt;/p&gt;
&lt;p&gt;curr_tick + delta&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &amp;quot;curr_tick&amp;quot; is updated when function &amp;quot;sys_clock_announce()&amp;quot; is called.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As long as the sys_clock_announce() updates the curr_tick every 2^24 -1 ticks, (RTC max CC value), it should be able to run as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/thread/317235?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 12:35:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fce5e73-90c7-4804-9005-e12ba479247a</guid><dc:creator>Depraz</dc:creator><description>&lt;p&gt;Thanks for the answer&amp;nbsp;&lt;span&gt;H&amp;aring;kon.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Once started (without the tickless option), can I safely assume that this counter won&amp;#39;t restart to 0 unless the program runs for years and years (i.e. until 2^64 milliseconds) ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I see that the driver is returning 32bit values. Once we reach 2^32 milliseconds, will we restart to 0 even if we are using k_uptime_get which should return an 64bit?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;&lt;/span&gt;&lt;span&gt;Florian&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: k_uptime_get return a signed value</title><link>https://devzone.nordicsemi.com/thread/317229?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 12:11:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30da812c-3186-4e96-8009-16719ba46f42</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;I would like to use k_uptime_get, however this is returning an int64_t where I would expect an uint64_t.&lt;/p&gt;
&lt;p&gt;While looking in the function, I see that k_uptime_get calls k&lt;span&gt;_ticks_to_ms_floor64&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;k_uptime_ticks&lt;/span&gt;&lt;span&gt;()); which should be returning an uint64_t.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What is the reason for this cast?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How is this counter computed? Is it reading a hardware register? Can this counter return to 0 in some cases (apart&amp;nbsp;from a reboot)?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I cannot specifically point directly to the source of the cast, unfortunately.&lt;/p&gt;
&lt;p&gt;This change was introduced with the rework in upstream zephyr:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/pull/23382"&gt;https://github.com/zephyrproject-rtos/zephyr/pull/23382&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This timer is based on the NRF_RTC counter, and this is the nrf specific implementation that (eventually) is fetched by the kernel API:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/timer/nrf_rtc_timer.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/timer/nrf_rtc_timer.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It can be read out as 0, but that is due to being called when its not configured as tickless:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/timer/nrf_rtc_timer.c#L386"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/timer/nrf_rtc_timer.c#L386&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>