Convert Timer for new IO
This commit is contained in:
parent
2b03925201
commit
bcd2f0c951
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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<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))
|
||||
}
|
|
@ -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<Timer_IO_Values::CounterMode>;
|
||||
using CounterTargetIO = IOPort<Timer_IO_Values::CounterTarget>;
|
||||
using CounterValueIO = IOPort<Timer_IO_Values::CounterValue>;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Counter {
|
||||
IOPort<CounterValue> value;
|
||||
IOPort<CounterMode> mode;
|
||||
IOPort<CounterTarget> 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue