Convert Timer for new IO

This commit is contained in:
Jaby 2024-09-28 15:30:40 +02:00
parent 2b03925201
commit bcd2f0c951
3 changed files with 50 additions and 39 deletions

View File

@ -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);
};
}
}

View File

@ -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(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 __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<type*>(adr) #define __new_declare_io_port(type, adr) *reinterpret_cast<type*>(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<type(&)[size]>(*reinterpret_cast<type*>(adr)) #define __new_declare_io_port_array(type, size, adr) reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>(adr))
} }

View File

@ -1,43 +1,21 @@
#pragma once #pragma once
#include "ioport.hpp" #include "IOValues/timer_io_values.hpp"
namespace JabyEngine { namespace JabyEngine {
namespace Timer_IO { namespace Timer_IO {
__declare_io_value(CounterMode, uint32_t) { using namespace Timer_IO_Values;
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) { using CounterModeIO = IOPort<Timer_IO_Values::CounterMode>;
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15); using CounterTargetIO = IOPort<Timer_IO_Values::CounterTarget>;
}; using CounterValueIO = IOPort<Timer_IO_Values::CounterValue>;
__declare_io_value(CounterValue, uint32_t) {
static constexpr auto Value = BitRange::from_to(0, 15);
};
#pragma pack(push, 1) #pragma pack(push, 1)
struct Counter { struct Counter {
IOPort<CounterValue> value; CounterValueIO value;
IOPort<CounterMode> mode; CounterModeIO mode;
IOPort<CounterTarget> target; CounterTargetIO target;
uint32_t unused;
private:
uint32_t _unused;
public:
inline uint16_t get_current_value() const { inline uint16_t get_current_value() const {
return this->value.read().get(CounterValue::Value); return this->value.read().get(CounterValue::Value);
} }
@ -52,10 +30,6 @@ namespace JabyEngine {
}; };
#pragma pack(pop) #pragma pack(pop)
static constexpr uintptr_t counter_base_adr(size_t ID) {
return (0x1F801100 + (ID*0x10));
}
#pragma pack(push, 1) #pragma pack(push, 1)
struct Counter0 : public Counter { struct Counter0 : public Counter {
struct SyncMode { struct SyncMode {
@ -106,8 +80,13 @@ namespace JabyEngine {
}; };
#pragma pack(pop) #pragma pack(pop)
__declare_value_at(, struct Counter0, Counter0, counter_base_adr(0)); static constexpr uintptr_t counter_base_adr(size_t ID) {
__declare_value_at(, struct Counter1, Counter1, counter_base_adr(1)); return (0x1F801100 + (ID*0x10));
__declare_value_at(, struct Counter2, Counter2, counter_base_adr(2)); }
// 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));
} }
} }