<div dir="ltr"><div>Okay, then I will just implement using rtems_clock_get_uptime_nanoseconds() , similarly to how it was done in the lwIP sys_now implementation by Pavel.</div><div><br></div><div>Kind Regards</div><div>Robin<br></div><div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 19 Apr 2021 at 19:53, Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 19/04/2021 18:42, Gedare Bloom wrote:<br>
<br>
> On Mon, Apr 19, 2021 at 10:41 AM Gedare Bloom<<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br>
>> On Mon, Apr 19, 2021 at 2:51 AM Robin Müller<<a href="mailto:robin.mueller.m@gmail.com" target="_blank">robin.mueller.m@gmail.com</a>> wrote:<br>
>>> From 88ac5780f5597a8bb3bf68c6b37fe6694956faaf Mon Sep 17 00:00:00 2001<br>
>>> From: Robin Mueller<<a href="mailto:robin.mueller.m@gmail.com" target="_blank">robin.mueller.m@gmail.com</a>><br>
>>> Date: Mon, 19 Apr 2021 10:39:55 +0200<br>
>>> Subject: [PATCH] updated HAL_GetTick function<br>
>>><br>
>>> Patch text went missing, here is the full version of the patch.<br>
>>> Provides implementation for HAL_GetTick but uses RTEMS.<br>
>>> Accounts for the tick base not being 1ms now<br>
>>> ---<br>
>>> bsps/arm/stm32h7/start/bspstart.c | 3 ++-<br>
>>> 1 file changed, 2 insertions(+), 1 deletion(-)<br>
>>><br>
>>> diff --git a/bsps/arm/stm32h7/start/bspstart.c b/bsps/arm/stm32h7/start/bspstart.c<br>
>>> index 2fc8133cca..e6e995a50c 100644<br>
>>> --- a/bsps/arm/stm32h7/start/bspstart.c<br>
>>> +++ b/bsps/arm/stm32h7/start/bspstart.c<br>
>>> @@ -32,9 +32,10 @@<br>
>>><br>
>>> #include <stm32h7xx_hal.h><br>
>>><br>
>>> +/* Get number of milliseconds elapsed since startup */<br>
>>> uint32_t HAL_GetTick(void)<br>
>>> {<br>
>>> - return 0;<br>
>>> + return (rtems_clock_get_ticks_since_boot() * 1000) / rtems_clock_get_ticks_per_second();<br>
>> This is reasonable, but note that:<br>
>> 1. usually it is better to divide before multiplying, to reduce the<br>
>> chance of arithmetic overflows.<br>
>> 2. the ticks_since_boot is 32-bits, with 1000 Hz ticking it overflows<br>
>> in ~2 months<br>
>><br>
>> I suggest you consider<br>
>> return rtems_clock_get_uptime_seconds()*1000;<br>
>><br>
>> Or you can use rtems_clock_get_uptime_nanoseconds() / (10000000) if ms<br>
>> precision is needed.<br>
>><br>
> I just saw that the HAL function also returns a u32, so it will<br>
> overflow anyway and it doesn't really matter what you do.<br>
><br>
The HAL_GetTick() should still be correct, otherwise you have an <br>
infrequent bug which may or may not trouble you seriously. Maybe just do <br>
the computation with 64-bit floating point numbers or just <br>
rtems_clock_get_uptime_nanoseconds() / 1000.<br>
<br>
-- <br>
embedded brains GmbH<br>
Herr Sebastian HUBER<br>
Dornierstr. 4<br>
82178 Puchheim<br>
Germany<br>
email: <a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a><br>
phone: +49-89-18 94 741 - 16<br>
fax: +49-89-18 94 741 - 08<br>
<br>
Registergericht: Amtsgericht München<br>
Registernummer: HRB 157899<br>
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler<br>
Unsere Datenschutzerklärung finden Sie hier:<br>
<a href="https://embedded-brains.de/datenschutzerklaerung/" rel="noreferrer" target="_blank">https://embedded-brains.de/datenschutzerklaerung/</a><br>
<br>
</blockquote></div>