HiResTimer cause stopwatch fail
Posted: Fri Dec 23, 2022 9:53 am
using NANO and 3.3.9, I got legacy code in 2.x from my colleague. I ported the project into 3.x. when I try use the stopwatch, the elapsed time always return as 0. When I comment out the HiResTimer Init function, the stopwatch work properly.
Here's the simple project I build to test
Here's the simple project I build to test
Code: Select all
#include <predef.h>
#include <stdio.h>
#include <nbrtos.h>
#include <http.h>
#include <init.h>
#include <netinterface.h>
#include <HiResTimer.h>
#include <stopwatch.h>
#include <serial.h>
const char * AppName="hrt";
void UserMain(void * pd)
{
init();
GetInterfaceBlock()->discovery_server = "discover.netburner.com";
WaitForActiveNetwork(TICKS_PER_SECOND * 5); // Wait up to 5 seconds for active network activity
StartHttp();
SerialClose( 0 );
int uart0 = SimpleOpenSerial( 0, 115200 );
ReplaceStdio( 0, uart0 );
ReplaceStdio( 1, uart0 );
ReplaceStdio( 2, uart0 );
iprintf("Application %s started\n",AppName );
HiResTimer *hrt = HiResTimer::getHiResTimer(0);
// hrt->init(); // thise cause stopwatch return 0 elapsed time
StopWatch myStopwatch1;
volatile uint32_t count = 0;
const int numLoop = 10000;
while (1)
{
myStopwatch1.Start();
for (int i = 0; i < numLoop; i++)
{
count++;
}
myStopwatch1.Stop();
unsigned long long elapsedTime1 = myStopwatch1.GetTime();
printf("StopWatch1 Elapsed time: %llu, %7.3f microseconds\r\n", elapsedTime1, myStopwatch1.Convert(elapsedTime1)*1000000);
OSTimeDly(TICKS_PER_SECOND);
}
}