Hi,
I am trying to port some STM32 code that uses the millis() oder HAL_GetTick() functions to measure time intervals since startup.
Now I wonder how this is properly done with Netburner. I browsed the docs but did not find a suitable function so far.
So what is the proper way to do it?
Thanks in advance,
Anguel
How to get milliseconds since boot?
Re: How to get milliseconds since boot?
Hello Anguel,
What version of tools are you using, and what platform?
The value you describe rolls over every 9.9 hours as a 32-bit integer. How do you handle that?
What version of tools are you using, and what platform?
The value you describe rolls over every 9.9 hours as a 32-bit integer. How do you handle that?
Re: How to get milliseconds since boot?
Hi Tom,
I am using your ARM module and plan to use the latest NB tools. The time periods they measure in the original code are not very long, they use it to detect timeouts when communicating with another device, but you are right, I must prevent this rollover problem somehow...
They actually seem to poll the serial port for data and watch for timeouts in the meantime. Can you maybe recommend a more elegant way to solve this when using the Netburner API?
Anguel
I am using your ARM module and plan to use the latest NB tools. The time periods they measure in the original code are not very long, they use it to detect timeouts when communicating with another device, but you are right, I must prevent this rollover problem somehow...
They actually seem to poll the serial port for data and watch for timeouts in the meantime. Can you maybe recommend a more elegant way to solve this when using the Netburner API?
Anguel
Re: How to get milliseconds since boot?
Hello,
I would start with the timer examples in \nburn\examples\timers. There is an interval timer, and a stopwatch timer. Sounds like the stopwatch would work for you.
I would start with the timer examples in \nburn\examples\timers. There is an interval timer, and a stopwatch timer. Sounds like the stopwatch would work for you.
Re: How to get milliseconds since boot?
With zero additional work there are two variables
#include <nbrtos.h>
TimeTick and Secs...
TimeTick happens each tick (defaults to 20 per second)
So that gets you to 50 msec with ZERO work.
If you need better:
#include <stopwatch.h>
StopWatch my_stopwatch;
my_stopwatch.Start();
Then you can get the time count (unsigned 64 bit value)
unsigned long long now=my_stopwatch.GetTime();
You can get this time interval in a platform independant way:
double time_of_one_tick=my_stopwatch. CountResolution();
On the M7 it is basically 1 cpu cycle so if you wnat to work with integers:
On the M7 the stopwatch tick is :
1/extern volatile uint32_t CPU_CLOCK; //300Mhz
So its waaaaaaay more accurate then 1msec.
Or you can use the function StopWatch uses...without the start offset...
inside
nburn\arch\cortex-m7\cpu\SAME70\source\stopwatch.cpp
Look for GetNow...
So three ways to solve your problem...
#include <nbrtos.h>
TimeTick and Secs...
TimeTick happens each tick (defaults to 20 per second)
So that gets you to 50 msec with ZERO work.
If you need better:
#include <stopwatch.h>
StopWatch my_stopwatch;
my_stopwatch.Start();
Then you can get the time count (unsigned 64 bit value)
unsigned long long now=my_stopwatch.GetTime();
You can get this time interval in a platform independant way:
double time_of_one_tick=my_stopwatch. CountResolution();
On the M7 it is basically 1 cpu cycle so if you wnat to work with integers:
On the M7 the stopwatch tick is :
1/extern volatile uint32_t CPU_CLOCK; //300Mhz
So its waaaaaaay more accurate then 1msec.
Or you can use the function StopWatch uses...without the start offset...
inside
nburn\arch\cortex-m7\cpu\SAME70\source\stopwatch.cpp
Look for GetNow...
So three ways to solve your problem...
Re: How to get milliseconds since boot?
Or go to the stopwatch file listed above and add this at the end...
unsigned long long GetMsec()
{
unsigned long long tv = GetNow();
tv/=(CPU_CLOCK/1000);
return tv;
}
unsigned long long GetMsec()
{
unsigned long long tv = GetNow();
tv/=(CPU_CLOCK/1000);
return tv;
}
Re: How to get milliseconds since boot?
Just added that to the repository so it should be in future versions of the tools.
Re: How to get milliseconds since boot?
Actually Get_msec is in future versions of the tools.
Re: How to get milliseconds since boot?
Thank you very much for all the information!