Use GlobalTime
This commit is contained in:
parent
749a872bf2
commit
69c29e4dcd
|
@ -36,6 +36,10 @@ namespace JabyEngine {
|
||||||
Status.write(Status.read().clear_bit(irq));
|
Status.write(Status.read().clear_bit(irq));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void disable_irq(Bit<uint32_t> irq) {
|
||||||
|
Mask.write(Mask.read().clear_bit(irq));
|
||||||
|
}
|
||||||
|
|
||||||
static void enable_irq(Bit<uint32_t> irq) {
|
static void enable_irq(Bit<uint32_t> irq) {
|
||||||
Mask.write(Mask.read().set_bit(irq));
|
Mask.write(Mask.read().set_bit(irq));
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,11 @@ namespace JabyEngine {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __no_align Timer {
|
struct __no_align Timer {
|
||||||
|
IOPort<uint32_t> value;
|
||||||
IOPort<CounterMode> mode;
|
IOPort<CounterMode> mode;
|
||||||
IOPort<CounterTarget> target;
|
IOPort<CounterTarget> target;
|
||||||
private:
|
private:
|
||||||
uint32_t _unused[2];
|
uint32_t _unused[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Counter0 {
|
namespace Counter0 {
|
||||||
|
@ -86,7 +87,7 @@ namespace JabyEngine {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
__declare_io_port_global_array(Timer, Counter, 0x1F801104, 3);
|
__declare_io_port_global_array(Timer, Counter, 0x1F801100, 3);
|
||||||
static_assert(sizeof(Timer) == 0x10);
|
static_assert(sizeof(Timer) == 0x10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,14 @@ namespace JabyEngine {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr size_t milliseconds_to(const TimeStamp& ts) const {
|
constexpr size_t milliseconds_to(const TimeStamp& ts) const {
|
||||||
return (ts.value - this->value);
|
return (ts.value - this->value)*10;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class GlobalTime;
|
friend class GlobalTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static size_t global_counter;
|
static volatile size_t global_counter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalTime() = delete;
|
GlobalTime() = delete;
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <PSX/System/IOPorts/dma_io.hpp>
|
#include <PSX/System/IOPorts/dma_io.hpp>
|
||||||
#include <PSX/System/IOPorts/gpu_io.hpp>
|
#include <PSX/System/IOPorts/gpu_io.hpp>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace GPU {
|
namespace GPU {
|
||||||
namespace Screen {
|
namespace Screen {
|
||||||
|
@ -94,6 +96,7 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_src(uintptr_t adr) {
|
static void set_src(uintptr_t adr) {
|
||||||
|
printf("Source: 0x%p\n", adr);
|
||||||
::JabyEngine::DMA::GPU.adr.write(::JabyEngine::DMA::MADR::MemoryAdr.with(static_cast<uint32_t>(adr)));
|
::JabyEngine::DMA::GPU.adr.write(::JabyEngine::DMA::MADR::MemoryAdr.with(static_cast<uint32_t>(adr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "BootLoader/boot_loader.hpp"
|
#include "BootLoader/boot_loader.hpp"
|
||||||
#include <PSX/System/IOPorts/dMa_io.hpp>
|
#include <PSX/System/IOPorts/dMa_io.hpp>
|
||||||
|
|
||||||
|
#include <PSX/Timer/timer.hpp>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
|
@ -14,8 +16,13 @@ namespace JabyEngine {
|
||||||
SPU::stop_voices();
|
SPU::stop_voices();
|
||||||
Timer::setup();
|
Timer::setup();
|
||||||
|
|
||||||
|
const auto start = GlobalTime::get_time_stamp();
|
||||||
|
printf("Start...\n");
|
||||||
GPU::setup();
|
GPU::setup();
|
||||||
GPU::display_logo();
|
GPU::display_logo();
|
||||||
|
const auto end = GlobalTime::get_time_stamp();
|
||||||
|
printf("GPU setup took %ims\n", start.milliseconds_to(end));
|
||||||
|
|
||||||
//Pause??
|
//Pause??
|
||||||
|
|
||||||
SPU::setup();
|
SPU::setup();
|
||||||
|
|
|
@ -2,19 +2,46 @@
|
||||||
#include <PSX/System/IOPorts/timer_io.hpp>
|
#include <PSX/System/IOPorts/timer_io.hpp>
|
||||||
#include <PSX/System/syscalls.h>
|
#include <PSX/System/syscalls.h>
|
||||||
|
|
||||||
|
#include <GPU/gpu.hpp>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace Timer {
|
namespace Timer {
|
||||||
extern InterrupCallback IRQCallback;
|
extern InterrupCallback IRQCallback;
|
||||||
|
|
||||||
void setup() {
|
static constexpr double CPU_Frequency_Hz = 33868800.0;
|
||||||
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 double CPU_Frequncey_Hz_Div8 = (CPU_Frequency_Hz/8.0);
|
||||||
static constexpr uint16_t Target = 0x1234;
|
|
||||||
|
|
||||||
//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_EnterCriticalSection();
|
||||||
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
|
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
|
||||||
__syscall_ExitCriticalSection();
|
__syscall_ExitCriticalSection();
|
||||||
|
|
||||||
|
Counter[2].target.write(CounterTarget::CounterTargetValue.with(Target));
|
||||||
|
Counter[2].mode.write(Mode);
|
||||||
|
|
||||||
Interrupt::enable_irq(Interrupt::Timer2);
|
Interrupt::enable_irq(Interrupt::Timer2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#define private public
|
#define private public
|
||||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||||
|
#include <PSX/System/IOPorts/timer_io.hpp>
|
||||||
#include <PSX/System/syscalls.h>
|
#include <PSX/System/syscalls.h>
|
||||||
#include <PSX/Timer/timer.hpp>
|
#include <PSX/Timer/timer.hpp>
|
||||||
#undef private
|
#undef private
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
size_t GlobalTime :: global_counter = 0;
|
volatile size_t GlobalTime :: global_counter = 0;
|
||||||
|
|
||||||
namespace Timer {
|
namespace Timer {
|
||||||
InterruptVerifierResult interrupt_verifier() {
|
InterruptVerifierResult interrupt_verifier() {
|
||||||
const auto irq_status = Interrupt::Status.read();
|
|
||||||
|
|
||||||
if(Interrupt::is_irq(Interrupt::Timer2)) {
|
if(Interrupt::is_irq(Interrupt::Timer2)) {
|
||||||
return InterruptVerifierResult::ExecuteHandler;
|
return InterruptVerifierResult::ExecuteHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "../include/BootLoader/boot_loader.hpp"
|
#include "../include/BootLoader/boot_loader.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <PSX/Timer/timer.hpp>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
static NextRoutine execute(NextRoutine routine) {
|
static NextRoutine execute(NextRoutine routine) {
|
||||||
// Support currently only direct call
|
// Support currently only direct call
|
||||||
|
|
Loading…
Reference in New Issue