34 lines
1.3 KiB
C++
34 lines
1.3 KiB
C++
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
|
#include <PSX/System/syscalls.h>
|
|
#define private public
|
|
#include <PSX/Timer/high_res_timer.hpp>
|
|
#undef private
|
|
|
|
namespace JabyEngine {
|
|
namespace Timer {
|
|
extern InterrupCallback IRQCallback;
|
|
}
|
|
|
|
namespace boot {
|
|
namespace Timer {
|
|
using namespace JabyEngine::Timer;
|
|
|
|
void setup() {
|
|
using namespace Timer_IO;
|
|
|
|
static constexpr auto Mode = CounterMode_t::from(CounterMode_t::FreeRun, Counter2_v::SyncMode::FreeRun, CounterMode_t::ResetAfterTarget, CounterMode_t::IRQAtTarget, CounterMode_t::IRQEveryTime, CounterMode_t::IRQPulse, Counter2_v::Source::System_Clock_Div_8);
|
|
|
|
// We disable the IRQ here so it can be enabled by user demand later
|
|
// Having the interrupt fire every 10ms will slow us down slightly so we only do it on demand
|
|
Interrupt::disable_irq(Interrupt::Timer2);
|
|
|
|
__syscall_EnterCriticalSection();
|
|
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
|
|
__syscall_ExitCriticalSection();
|
|
|
|
Counter2.set_target_value(HighResTime::TicksFor10ms);
|
|
Counter2.set_mode(Mode);
|
|
}
|
|
}
|
|
}
|
|
} |