Add busy loop code and make HighResTimer work on demand rather automatically or ifdefed

This commit is contained in:
Jaby
2023-04-26 19:09:07 +02:00
committed by Jaby
parent 646897f83e
commit 31d6062d05
10 changed files with 131 additions and 133 deletions

View File

@@ -1,46 +1,34 @@
#include <PSX/jabyengine_config.hpp>
#ifdef JABYENGINE_USE_HIGH_PERCISION_TIMER
#include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/syscalls.h>
#define private public
#include <PSX/Timer/high_res_timer.hpp>
#undef private
#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 JabyEngine {
namespace Timer {
extern InterrupCallback IRQCallback;
}
namespace boot {
namespace Timer {
extern InterrupCallback IRQCallback;
}
using namespace JabyEngine::Timer;
void setup() {
using namespace Timer_IO;
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);
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);
Interrupt::disable_irq(Interrupt::Timer2);
__syscall_EnterCriticalSection();
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_ExitCriticalSection();
__syscall_EnterCriticalSection();
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_ExitCriticalSection();
Counter2.set_target_value(HighResTime::TicksFor10ms);
Counter2.set_mode(Mode);
Interrupt::enable_irq(Interrupt::Timer2);
}
Counter2.set_target_value(HighResTime::TicksFor10ms);
Counter2.set_mode(Mode);
}
}
}
#else
namespace JabyEngine {
namespace boot {
namespace Timer {
void setup() {
}
}
}
}
#endif //JABYENGINE_USE_HIGH_PERCISION_TIMER
}