From 14b760dd54bd48aac1ff110634d880ea0d8364ca Mon Sep 17 00:00:00 2001 From: jaby Date: Sat, 28 Sep 2024 15:30:40 +0200 Subject: [PATCH] Convert Timer for new IO --- .../IOPorts/IOValues/timer_io_values.hpp | 31 +++++++++++ include/PSX/System/IOPorts/ioport.hpp | 3 +- include/PSX/System/IOPorts/timer_io.hpp | 55 ++++++------------- 3 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 include/PSX/System/IOPorts/IOValues/timer_io_values.hpp diff --git a/include/PSX/System/IOPorts/IOValues/timer_io_values.hpp b/include/PSX/System/IOPorts/IOValues/timer_io_values.hpp new file mode 100644 index 00000000..12f467b1 --- /dev/null +++ b/include/PSX/System/IOPorts/IOValues/timer_io_values.hpp @@ -0,0 +1,31 @@ +#pragma once +#include "../ioport.hpp" + +namespace JabyEngine { + namespace Timer_IO_Values { + __declare_io_value(CounterMode, uint32_t) { + static constexpr auto SyncEnable = Bit(0); + static constexpr auto FreeRun = !SyncEnable; + static constexpr auto SyncMode = BitRange::from_to(1, 2); + static constexpr auto ResetAfterTarget = Bit(3); + static constexpr auto IRQAtTarget = Bit(4); + static constexpr auto IRQAtMax = Bit(5); + static constexpr auto IRQEveryTime = Bit(6); + static constexpr auto IRQOneShot = !IRQEveryTime; + static constexpr auto IRQToggle = Bit(7); + static constexpr auto IRQPulse = !IRQToggle; + static constexpr auto ClockSource = BitRange::from_to(8, 9); + static constexpr auto HasIRQRequest = Bit(10); + static constexpr auto IsTargetReached = Bit(11); + static constexpr auto IsMaxReached = Bit(12); + }; + + __declare_io_value(CounterTarget, uint32_t) { + static constexpr auto CounterTargetValue = BitRange::from_to(0, 15); + }; + + __declare_io_value(CounterValue, uint32_t) { + static constexpr auto Value = BitRange::from_to(0, 15); + }; + } +} \ No newline at end of file diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 264af11b..f4ff88ad 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -118,6 +118,7 @@ namespace JabyEngine { #define __declare_io_port(cv, name, adr) __declare_io_port_w_type(cv, struct name, name, adr) #define __declare_io_port_array(cv, name, size, adr) __declare_array_at(cv, struct name, name, size, adr) - #define __new_declare_io_port(type, adr) *reinterpret_cast(adr) + #define __new_declare_io_port(type, adr) *reinterpret_cast(adr) + #define __new_declare_io_value(type, adr) __new_declare_io_port(type, adr) #define __new_declare_io_port_array(type, size, adr) reinterpret_cast(*reinterpret_cast(adr)) } \ No newline at end of file diff --git a/include/PSX/System/IOPorts/timer_io.hpp b/include/PSX/System/IOPorts/timer_io.hpp index d1a395b3..7d3f5a37 100644 --- a/include/PSX/System/IOPorts/timer_io.hpp +++ b/include/PSX/System/IOPorts/timer_io.hpp @@ -1,43 +1,21 @@ #pragma once -#include "ioport.hpp" +#include "IOValues/timer_io_values.hpp" namespace JabyEngine { namespace Timer_IO { - __declare_io_value(CounterMode, uint32_t) { - static constexpr auto SyncEnable = Bit(0); - static constexpr auto FreeRun = !SyncEnable; - static constexpr auto SyncMode = BitRange::from_to(1, 2); - static constexpr auto ResetAfterTarget = Bit(3); - static constexpr auto IRQAtTarget = Bit(4); - static constexpr auto IRQAtMax = Bit(5); - static constexpr auto IRQEveryTime = Bit(6); - static constexpr auto IRQOneShot = !IRQEveryTime; - static constexpr auto IRQToggle = Bit(7); - static constexpr auto IRQPulse = !IRQToggle; - static constexpr auto ClockSource = BitRange::from_to(8, 9); - static constexpr auto HasIRQRequest = Bit(10); - static constexpr auto IsTargetReached = Bit(11); - static constexpr auto IsMaxReached = Bit(12); - }; + using namespace Timer_IO_Values; - __declare_io_value(CounterTarget, uint32_t) { - static constexpr auto CounterTargetValue = BitRange::from_to(0, 15); - }; - - __declare_io_value(CounterValue, uint32_t) { - static constexpr auto Value = BitRange::from_to(0, 15); - }; + using CounterModeIO = IOPort; + using CounterTargetIO = IOPort; + using CounterValueIO = IOPort; #pragma pack(push, 1) struct Counter { - IOPort value; - IOPort mode; - IOPort target; + CounterValueIO value; + CounterModeIO mode; + CounterTargetIO target; + uint32_t unused; - private: - uint32_t _unused; - - public: inline uint16_t get_current_value() const { return this->value.read().get(CounterValue::Value); } @@ -52,10 +30,6 @@ namespace JabyEngine { }; #pragma pack(pop) - static constexpr uintptr_t counter_base_adr(size_t ID) { - return (0x1F801100 + (ID*0x10)); - } - #pragma pack(push, 1) struct Counter0 : public Counter { struct SyncMode { @@ -106,8 +80,13 @@ namespace JabyEngine { }; #pragma pack(pop) - __declare_value_at(, struct Counter0, Counter0, counter_base_adr(0)); - __declare_value_at(, struct Counter1, Counter1, counter_base_adr(1)); - __declare_value_at(, struct Counter2, Counter2, counter_base_adr(2)); + static constexpr uintptr_t counter_base_adr(size_t ID) { + return (0x1F801100 + (ID*0x10)); + } + + // TODO: Improve this to actually use it for measurement - if possible + static auto& Counter0 = __new_declare_io_value(struct Counter0, counter_base_adr(0)); + static auto& Counter1 = __new_declare_io_value(struct Counter1, counter_base_adr(1)); + static auto& Counter2 = __new_declare_io_value(struct Counter2, counter_base_adr(2)); } } \ No newline at end of file