Use GlobalTime

This commit is contained in:
Jaby
2023-01-08 16:20:30 +01:00
committed by Jaby
parent 749a872bf2
commit 69c29e4dcd
8 changed files with 55 additions and 12 deletions

View File

@@ -2,19 +2,46 @@
#include <PSX/System/IOPorts/timer_io.hpp>
#include <PSX/System/syscalls.h>
#include <GPU/gpu.hpp>
#include <stdio.h>
namespace JabyEngine {
namespace Timer {
extern InterrupCallback IRQCallback;
void setup() {
static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, Counter2::Source::System_Clock_Div_8);
static constexpr uint16_t Target = 0x1234;
static constexpr double CPU_Frequency_Hz = 33868800.0;
static constexpr double CPU_Frequncey_Hz_Div8 = (CPU_Frequency_Hz/8.0);
//Counter[2].target.ref().set(CounterTarget::CounterTargetValue.with(Target));
template<typename T>
static constexpr T NS_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>((1.0/CPU_Frequency_Hz)*1000.0*1000.0*1000.0);
}
template<typename T>
static constexpr T US_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>((1000.0/NS_Per_Tick<double>(CPU_Frequency_Hz)));
}
template<typename T>
static constexpr T MS_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>(((1000.0*1000.0)/NS_Per_Tick<double>(CPU_Frequency_Hz)));
}
void setup() {
static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8);
static constexpr uint16_t Target = MS_Per_Tick<uint16_t>(CPU_Frequncey_Hz_Div8)*10;
printf("Timer2 Target: %i\n", Target);
Interrupt::disable_irq(Interrupt::Timer2);
__syscall_EnterCriticalSection();
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_ExitCriticalSection();
Counter[2].target.write(CounterTarget::CounterTargetValue.with(Target));
Counter[2].mode.write(Mode);
Interrupt::enable_irq(Interrupt::Timer2);
}
}