timer: add Timer class

Timer class consists of systack_handler functionality
with an internal timer for global counter in main()
This commit is contained in:
Vasily Davydov
2022-10-14 14:20:00 +03:00
parent 1b4c37b9c5
commit 52c4ebb003
5 changed files with 441 additions and 0 deletions

64
Timer/src/Timer.cpp Normal file
View File

@@ -0,0 +1,64 @@
/*
* Timer.cpp
*
* Created on: Oct 14, 2022
* Author: tylen
*/
#include <Timer.h>
extern "C"
{
void
SysTick_Handler (void)
{
if (timer > 0)
timer--;
}
}
Timer::Timer (uint32_t freq = 1000)
{
Chip_Clock_SetSysTickClockDiv (1);
uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate ();
SysTick_Config (sysTickRate / freq);
counter = 0;
}
Timer::~Timer ()
{
// TODO Auto-generated destructor stub
}
void
Timer::tickCounter (int ms)
{
if (counter >= INT_MAX)
{
counter = 0;
}
counter++;
Sleep (ms);
}
void
Timer::Sleep (int ms)
{
timer = ms;
while (timer > 0)
{
__WFI ();
}
}
int
Timer::getCounter ()
{
return counter;
}
void
Timer::resetCounter ()
{
counter = 0;
}