Prepare IO Ports for timer
This commit is contained in:
parent
c503ce663d
commit
4870813d2d
|
@ -1,82 +1,88 @@
|
||||||
#ifndef __JABYENGINE_IOPORT_HPP__
|
#ifndef __JABYENGINE_IOPORT_HPP__
|
||||||
#define __JABYENGINE_IOPORT_HPP__
|
#define __JABYENGINE_IOPORT_HPP__
|
||||||
#include "../../Auxiliary/complex_bitmap.hpp"
|
#include "../../Auxiliary/complex_bitmap.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class __no_align IOPort {
|
class __no_align IOPort {
|
||||||
private:
|
private:
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//For easy access
|
//For easy access
|
||||||
constexpr T read() const {
|
constexpr T read() const {
|
||||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void write(T value) {
|
constexpr void write(T value) {
|
||||||
const_cast<volatile IOPort<T>*>(this)->value = value;
|
const_cast<volatile IOPort<T>*>(this)->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr volatile T& ref() {
|
constexpr volatile T& ref() {
|
||||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const volatile T& ref() const {
|
constexpr const volatile T& ref() const {
|
||||||
return const_cast<volatile IOPort<T>*>(this)->value;
|
return const_cast<volatile IOPort<T>*>(this)->value;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
constexpr IOPort<T>& operator=(T value) {
|
||||||
struct __no_align ubus32_t {
|
IOPort::write(value);
|
||||||
ComplexBitMap<uint16_t> low;
|
return *this;
|
||||||
ComplexBitMap<uint16_t> high;
|
}
|
||||||
|
};
|
||||||
constexpr ubus32_t(uint32_t value) {
|
|
||||||
*this = value;
|
struct __no_align ubus32_t {
|
||||||
}
|
ComplexBitMap<uint16_t> low;
|
||||||
|
ComplexBitMap<uint16_t> high;
|
||||||
constexpr operator uint32_t() const {
|
|
||||||
return ((this->high.raw << 16) | this->low.raw);
|
constexpr ubus32_t(uint32_t value) {
|
||||||
}
|
*this = value;
|
||||||
|
}
|
||||||
operator uint32_t() const volatile {
|
|
||||||
return ((this->high.raw << 16) | this->low.raw);
|
constexpr operator uint32_t() const {
|
||||||
}
|
return ((this->high.raw << 16) | this->low.raw);
|
||||||
|
}
|
||||||
constexpr ubus32_t& operator=(uint32_t value) {
|
|
||||||
this->low.raw = (value & 0xFFFF);
|
operator uint32_t() const volatile {
|
||||||
this->high.raw = (value >> 16);
|
return ((this->high.raw << 16) | this->low.raw);
|
||||||
|
}
|
||||||
return *this;
|
|
||||||
}
|
constexpr ubus32_t& operator=(uint32_t value) {
|
||||||
|
this->low.raw = (value & 0xFFFF);
|
||||||
constexpr void operator=(uint32_t value) volatile {
|
this->high.raw = (value >> 16);
|
||||||
this->low.raw = (value & 0xFFFF);
|
|
||||||
this->high.raw = (value >> 16);
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
constexpr void operator=(uint32_t value) volatile {
|
||||||
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
this->low.raw = (value & 0xFFFF);
|
||||||
|
this->high.raw = (value >> 16);
|
||||||
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask))
|
}
|
||||||
#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<IOPort<type>*>(__io_port_adr(adr))
|
};
|
||||||
|
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
||||||
#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr)
|
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
||||||
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
|
|
||||||
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))))
|
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask))
|
||||||
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
|
#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<IOPort<type>*>(__io_port_adr(adr))
|
||||||
|
|
||||||
#define __io_port_inherit_complex_bit_map(name) \
|
#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr)
|
||||||
constexpr __always_inline name() = default; \
|
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
|
||||||
constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \
|
|
||||||
} \
|
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))))
|
||||||
template<typename...ARGS> \
|
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
|
||||||
static constexpr __always_inline name with(ARGS...args) { \
|
|
||||||
return {ComplexBitMap::with(args...)}; \
|
#define __io_port_inherit_complex_bit_map(name) \
|
||||||
}\
|
constexpr __always_inline name() = default; \
|
||||||
template<typename T> \
|
constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \
|
||||||
constexpr void __always_inline operator=(ComplexBitMap<T> value) volatile { \
|
} \
|
||||||
this->raw = value.raw; \
|
template<typename...ARGS> \
|
||||||
}
|
static constexpr __always_inline name with(ARGS...args) { \
|
||||||
}
|
return {ComplexBitMap::with(args...)}; \
|
||||||
|
}\
|
||||||
|
template<typename T> \
|
||||||
|
constexpr void __always_inline operator=(ComplexBitMap<T> value) volatile { \
|
||||||
|
this->raw = value.raw; \
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif //!__JABYENGINE_IOPORT_HPP__
|
#endif //!__JABYENGINE_IOPORT_HPP__
|
|
@ -0,0 +1,93 @@
|
||||||
|
#ifndef __JABYENGINE_TIMER_IO_HPP__
|
||||||
|
#define __JABYENGINE_TIMER_IO_HPP__
|
||||||
|
#include "ioport.hpp"
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
namespace Timer {
|
||||||
|
enum struct SyncMode {};
|
||||||
|
|
||||||
|
struct __no_align CounterMode : public ComplexBitMap<uint32_t> {
|
||||||
|
__io_port_inherit_complex_bit_map(CounterMode);
|
||||||
|
|
||||||
|
static constexpr auto SyncEnable = Bit<uint32_t>(0);
|
||||||
|
static constexpr auto SyncMode = BitRange<uint32_t>::from_to(1, 2);
|
||||||
|
static constexpr auto ResetAfterTarget = Bit<uint32_t>(3);
|
||||||
|
static constexpr auto IRQAtTarget = Bit<uint32_t>(4);
|
||||||
|
static constexpr auto IRQAtMax = Bit<uint32_t>(5);
|
||||||
|
static constexpr auto IRQOneShot = !Bit<uint32_t>(6);
|
||||||
|
static constexpr auto IRQEveryTime = Bit<uint32_t>(6);
|
||||||
|
static constexpr auto IRQPulse = !Bit<uint32_t>(7);
|
||||||
|
static constexpr auto IRQToggle = Bit<uint32_t>(7);
|
||||||
|
static constexpr auto ClockSource = BitRange<uint32_t>::from_to(8, 9);
|
||||||
|
static constexpr auto HasIRQRequest = Bit<uint32_t>(10);
|
||||||
|
static constexpr auto IsTargetReached = Bit<uint32_t>(11);
|
||||||
|
static constexpr auto IsMaxReached = Bit<uint32_t>(12);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __no_align CounterTarget : public ComplexBitMap<uint32_t> {
|
||||||
|
__io_port_inherit_complex_bit_map(CounterTarget);
|
||||||
|
|
||||||
|
static constexpr auto CounterTargetValue = BitRange<uint32_t>::from_to(0, 15);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __no_align Timer {
|
||||||
|
IOPort<CounterMode> counter_mode;
|
||||||
|
IOPort<CounterTarget> counter_target;
|
||||||
|
private:
|
||||||
|
uint32_t _unused[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
__declare_io_port_global_array(Timer, timer, 0x1F801104, 3);
|
||||||
|
static_assert(sizeof(Timer) == 0x10);
|
||||||
|
|
||||||
|
namespace Counter0 {
|
||||||
|
struct SyncMode {
|
||||||
|
static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0);
|
||||||
|
static constexpr auto Zero_At_Hblank = CounterMode::SyncMode.with(1);
|
||||||
|
static constexpr auto Zero_At_Hblank_Pause_Outside_Hblank = CounterMode::SyncMode.with(2);
|
||||||
|
static constexpr auto Pause_Until_Hblank_Then_Freerun = CounterMode::SyncMode.with(3);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Source {
|
||||||
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0);
|
||||||
|
static constexpr auto Dot_Clock = CounterMode::ClockSource.with(1);
|
||||||
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2);
|
||||||
|
static constexpr auto Dot_Clock_Too = CounterMode::ClockSource.with(3);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Counter1 {
|
||||||
|
struct SyncMode {
|
||||||
|
static constexpr auto Pause_During_Vblank = CounterMode::SyncMode.with(0);
|
||||||
|
static constexpr auto Zero_At_Vblank = CounterMode::SyncMode.with(1);
|
||||||
|
static constexpr auto Zero_At_Vblank_Pause_Outside_Vblank = CounterMode::SyncMode.with(2);
|
||||||
|
static constexpr auto Pause_Until_Vblank_Then_Freerun = CounterMode::SyncMode.with(3);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Source {
|
||||||
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0);
|
||||||
|
static constexpr auto Hblank = CounterMode::ClockSource.with(1);
|
||||||
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2);
|
||||||
|
static constexpr auto Hblank_Too = CounterMode::ClockSource.with(3);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Counter2 {
|
||||||
|
struct SyncMode {
|
||||||
|
static constexpr auto Stop_Counter = CounterMode::SyncMode.with(0);
|
||||||
|
static constexpr auto Freerun = CounterMode::SyncMode.with(1);
|
||||||
|
static constexpr auto Freerun_Too = CounterMode::SyncMode.with(2);
|
||||||
|
static constexpr auto Stop_Counter_Too = CounterMode::SyncMode.with(3);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Source {
|
||||||
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0);
|
||||||
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(1);
|
||||||
|
static constexpr auto System_Clock_Div_8 = CounterMode::ClockSource.with(2);
|
||||||
|
static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //!__JABYENGINE_TIMER_IO_HPP__
|
|
@ -20,5 +20,9 @@ namespace JabyEngine {
|
||||||
namespace BootFile {
|
namespace BootFile {
|
||||||
JabyEngine::NextRoutine setup();
|
JabyEngine::NextRoutine setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Timer {
|
||||||
|
void setup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif //!BOOT_LOADER_HPP
|
#endif //!BOOT_LOADER_HPP
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include <PSX/System/IOPorts/timer_io.hpp>
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
namespace Timer {
|
||||||
|
void setup() {
|
||||||
|
// Just testing around
|
||||||
|
static constexpr auto wuff = CounterMode::with(CounterMode::IRQAtMax, Counter0::SyncMode::Zero_At_Hblank);
|
||||||
|
|
||||||
|
timer[0].counter_mode = wuff;
|
||||||
|
timer[0].counter_mode = wuff;
|
||||||
|
timer[0].counter_mode = wuff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue