Is this a legit reason to use a global variable?
I understand the general concept of why global variables are not a great idea but I have a specific use that may make sense and I'd like to see if anyone has a better approach.
I time stamp a lot of events in my applications and also calculate time intervals to make sure activities complete in a defined amount of time. So, I need a quick way to get a timestamp that is accurate to something less than 0.1 seconds. Here's what I'm doing now in my main.cpp:
//sysTickCounter is supposed to be a quick way to get time differences for timeout purposes
//TODO need to check to see if it's accurate
uint64_t sysTickCounter = 0;
extern "C" void SysTick_Handler(void)
{
HAL_IncTick();
sysTickCounter++;
}and I can declare sysTickCounter as an extern wherever I need it like this:
extern uint64_t sysTickCounter;This seems to work so far but I'd be very interested if someone has a better way.
Thanks
