Add timer.[ch]
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "init_peripherals.h"
|
||||
#include "eeprom.h"
|
||||
#include "microseconds/microseconds_pit.c"
|
||||
#include "timer.h"
|
||||
|
||||
void InitInterruptPriorities(void)
|
||||
{
|
||||
@@ -109,6 +110,7 @@ void InitI2c(void)
|
||||
void InitPeripherals(void)
|
||||
{
|
||||
InitInterruptPriorities();
|
||||
Timer_Init();
|
||||
InitLedDriver();
|
||||
InitResetButton();
|
||||
InitMergeSensor();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __KEY_SCANNER_H__
|
||||
#define __KEY_SCANNER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
#define PIT_I2C_WATCHDOG_IRQ_ID PIT0_IRQn
|
||||
#define PIT_I2C_WATCHDOG_CHANNEL kPIT_Chnl_0
|
||||
|
||||
#define PIT_KEY_SCANNER_HANDLER PIT1_IRQHandler
|
||||
#define PIT_KEY_SCANNER_IRQ_ID PIT1_IRQn
|
||||
#define PIT_KEY_SCANNER_CHANNEL kPIT_Chnl_1
|
||||
#define PIT_TIMER_HANDLER PIT1_IRQHandler
|
||||
#define PIT_TIMER_IRQ_ID PIT1_IRQn
|
||||
#define PIT_TIMER_CHANNEL kPIT_Chnl_1
|
||||
|
||||
#define PIT_KEY_SCANNER_HANDLER PIT2_IRQHandler
|
||||
#define PIT_KEY_SCANNER_IRQ_ID PIT2_IRQn
|
||||
#define PIT_KEY_SCANNER_CHANNEL kPIT_Chnl_2
|
||||
|
||||
#endif
|
||||
|
||||
18
right/src/timer.c
Normal file
18
right/src/timer.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "fsl_pit.h"
|
||||
#include "timer.h"
|
||||
|
||||
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_EnableInterrupts(PIT, PIT_TIMER_CHANNEL, kPIT_TimerInterruptEnable);
|
||||
// EnableIRQ(PIT_TIMER_IRQ_ID);
|
||||
PIT_StartTimer(PIT, PIT_TIMER_CHANNEL);
|
||||
}
|
||||
|
||||
uint32_t Timer_GetTime(void)
|
||||
{
|
||||
return PIT_GetCurrentTimerCount(PIT, PIT_TIMER_CHANNEL);
|
||||
}
|
||||
17
right/src/timer.h
Normal file
17
right/src/timer.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "peripherals/pit.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define TIMER_INTERVAL_USEC 1000
|
||||
|
||||
// Functions:
|
||||
|
||||
void Timer_Init(void);
|
||||
uint32_t Timer_GetTime(void);
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "slave_scheduler.h"
|
||||
#include "i2c_watchdog.h"
|
||||
#include "buffer.h"
|
||||
#include "timer.h"
|
||||
|
||||
uint8_t DebugBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||
|
||||
@@ -13,6 +14,7 @@ void UsbCommand_GetDebugBuffer(void)
|
||||
SetDebugBufferUint32(5, I2cSlaveScheduler_Counter);
|
||||
SetDebugBufferUint32(9, I2cWatchdog_WatchCounter);
|
||||
SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter);
|
||||
SetDebugBufferUint32(40, Timer_GetTime());
|
||||
|
||||
memcpy(GenericHidOutBuffer, DebugBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user