Set up the timer properly and introduce CurrentTime.
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
#include "fsl_pit.h"
|
||||
#include "timer.h"
|
||||
|
||||
uint32_t CurrentTime = 1;
|
||||
|
||||
void PIT_TIMER_HANDLER(void)
|
||||
{
|
||||
CurrentTime++;
|
||||
PIT_ClearStatusFlags(PIT, PIT_TIMER_CHANNEL, PIT_TFLG_TIF_MASK);
|
||||
}
|
||||
|
||||
void Timer_Init(void)
|
||||
{
|
||||
pit_config_t pitConfig;
|
||||
PIT_GetDefaultConfig(&pitConfig);
|
||||
PIT_Init(PIT, &pitConfig);
|
||||
PIT_SetTimerPeriod(PIT, PIT_TIMER_CHANNEL, USEC_TO_COUNT(TIMER_INTERVAL_USEC, PIT_SOURCE_CLOCK));
|
||||
PIT_SetTimerPeriod(PIT, PIT_TIMER_CHANNEL, MSEC_TO_COUNT(TIMER_INTERVAL_MSEC, PIT_SOURCE_CLOCK));
|
||||
PIT_EnableInterrupts(PIT, PIT_TIMER_CHANNEL, kPIT_TimerInterruptEnable);
|
||||
// EnableIRQ(PIT_TIMER_IRQ_ID);
|
||||
EnableIRQ(PIT_TIMER_IRQ_ID);
|
||||
PIT_StartTimer(PIT, PIT_TIMER_CHANNEL);
|
||||
}
|
||||
|
||||
uint32_t Timer_GetTime(void)
|
||||
uint32_t Timer_GetElapsedTime(uint32_t *time)
|
||||
{
|
||||
return PIT_GetCurrentTimerCount(PIT, PIT_TIMER_CHANNEL);
|
||||
uint32_t elapsedTime = CurrentTime - *time;
|
||||
*time = CurrentTime;
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user