Port TimerIO
This commit is contained in:
parent
66d3eb3337
commit
9e0f9acdd1
|
@ -94,11 +94,11 @@ namespace JabyEngine {
|
||||||
New::IOPort<BCR> block_ctrl;
|
New::IOPort<BCR> block_ctrl;
|
||||||
New::IOPort<CHCHR> channel_ctrl;
|
New::IOPort<CHCHR> channel_ctrl;
|
||||||
|
|
||||||
void set_adr(uintptr_t adr) {
|
inline void set_adr(uintptr_t adr) {
|
||||||
this->adr.write({bit::value::set_normalized(0u, MADR::MemoryAdr.with(adr))});
|
this->adr.write({bit::value::set_normalized(0u, MADR::MemoryAdr.with(adr))});
|
||||||
}
|
}
|
||||||
|
|
||||||
void wait() {
|
inline void wait() {
|
||||||
while(this->channel_ctrl.read().is_set2(CHCHR::Busy));
|
while(this->channel_ctrl.read().is_set2(CHCHR::Busy));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace JabyEngine {
|
||||||
|
|
||||||
template<typename...ARGS>
|
template<typename...ARGS>
|
||||||
static constexpr T from(const ARGS&...args) {
|
static constexpr T from(const ARGS&...args) {
|
||||||
return T{0}.set_va(args...);
|
return T{0}.set2(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& set2(Bit bit) {
|
constexpr T& set2(Bit bit) {
|
||||||
|
@ -27,7 +27,7 @@ namespace JabyEngine {
|
||||||
return static_cast<T&>(*this);
|
return static_cast<T&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T& set2(BitRange bits, T value) {
|
constexpr T& set_range(const BitRange& bits, UnderlyingType value) {
|
||||||
this->raw = bit::value::set_normalized(this->raw, bits, value);
|
this->raw = bit::value::set_normalized(this->raw, bits, value);
|
||||||
return static_cast<T&>(*this);
|
return static_cast<T&>(*this);
|
||||||
}
|
}
|
||||||
|
@ -37,26 +37,10 @@ namespace JabyEngine {
|
||||||
this->raw = bit::value::set_normalized(this->raw, value);
|
this->raw = bit::value::set_normalized(this->raw, value);
|
||||||
return static_cast<T&>(*this);
|
return static_cast<T&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
constexpr T& set2(const U& first) {
|
|
||||||
return IOValue<T, S>::set2(first);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U, typename...ARGS>
|
template<typename U, typename...ARGS>
|
||||||
constexpr T& set2(const U& first, const ARGS& ...args) {
|
constexpr T& set2(const U& head, const ARGS&...tail) {
|
||||||
IOValue<T, S>::set2(first);
|
return this->set2(head).set2(tail...);
|
||||||
return IOValue<T, S>::set2(args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
constexpr T& set_va(const U& head) {
|
|
||||||
return this->set2(head);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U, typename...ARGS>
|
|
||||||
constexpr T& set_va(const U& head, const ARGS&...tail) {
|
|
||||||
return this->set2(head).set_va(tail...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr IOValue<T, S>::UnderlyingType get2(BitRange bits) const {
|
constexpr IOValue<T, S>::UnderlyingType get2(BitRange bits) const {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace Timer_IO {
|
namespace Timer_IO {
|
||||||
__declare_io_type(CounterMode, uint32_t,
|
__new_declare_io_value(CounterMode, uint32_t) {
|
||||||
static constexpr auto SyncEnable = Bit(0);
|
static constexpr auto SyncEnable = Bit(0);
|
||||||
static constexpr auto FreeRun = !SyncEnable;
|
static constexpr auto FreeRun = !SyncEnable;
|
||||||
static constexpr auto SyncMode = BitRange::from_to(1, 2);
|
static constexpr auto SyncMode = BitRange::from_to(1, 2);
|
||||||
|
@ -19,36 +19,36 @@ namespace JabyEngine {
|
||||||
static constexpr auto HasIRQRequest = Bit(10);
|
static constexpr auto HasIRQRequest = Bit(10);
|
||||||
static constexpr auto IsTargetReached = Bit(11);
|
static constexpr auto IsTargetReached = Bit(11);
|
||||||
static constexpr auto IsMaxReached = Bit(12);
|
static constexpr auto IsMaxReached = Bit(12);
|
||||||
);
|
};
|
||||||
|
|
||||||
__declare_io_type(CounterTarget, uint32_t,
|
__new_declare_io_value(CounterTarget, uint32_t) {
|
||||||
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
|
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
|
||||||
);
|
};
|
||||||
|
|
||||||
__declare_io_type(CounterValue, uint32_t,
|
__new_declare_io_value(CounterValue, uint32_t) {
|
||||||
static constexpr auto Value = BitRange::from_to(0, 15);
|
static constexpr auto Value = BitRange::from_to(0, 15);
|
||||||
);
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct Counter {
|
struct Counter {
|
||||||
CounterValue_v value;
|
New::IOPort<CounterValue> value;
|
||||||
CounterMode_v mode;
|
New::IOPort<CounterMode> mode;
|
||||||
CounterTarget_v target;
|
New::IOPort<CounterTarget> target;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t _unused;
|
uint32_t _unused;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr uint16_t get_current_value() const {
|
inline uint16_t get_current_value() const {
|
||||||
return this->value.get(CounterValue_v::Value);
|
return this->value.read().get2(CounterValue::Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void set_target_value(uint16_t value) {
|
inline void set_target_value(uint16_t value) {
|
||||||
this->target.set(CounterTarget_v::CounterTargetValue, value);
|
this->target.write(CounterTarget{0}.set_range(CounterTarget::CounterTargetValue, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void set_mode(CounterMode_t mode) {
|
inline void set_mode(CounterMode mode) {
|
||||||
this->mode = mode;
|
this->mode.write(mode);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
@ -58,58 +58,58 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct Counter0_v : public Counter {
|
struct Counter0 : public Counter {
|
||||||
struct SyncMode {
|
struct SyncMode {
|
||||||
static constexpr auto Pause_During_Hblank = CounterMode_v::SyncMode.with(0u);
|
static constexpr auto Zero_At_Hblank = CounterMode::SyncMode.with(1u);
|
||||||
static constexpr auto Zero_At_Hblank = CounterMode_v::SyncMode.with(1u);
|
static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0u);
|
||||||
static constexpr auto Zero_At_Hblank_Pause_Outside_Hblank = CounterMode_v::SyncMode.with(2u);
|
static constexpr auto Zero_At_Hblank_Pause_Outside_Hblank = CounterMode::SyncMode.with(2u);
|
||||||
static constexpr auto Pause_Until_Hblank_Then_Freerun = CounterMode_v::SyncMode.with(3u);
|
static constexpr auto Pause_Until_Hblank_Then_Freerun = CounterMode::SyncMode.with(3u);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Source {
|
struct Source {
|
||||||
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
|
||||||
static constexpr auto Dot_Clock = CounterMode_v::ClockSource.with(1u);
|
static constexpr auto Dot_Clock = CounterMode::ClockSource.with(1u);
|
||||||
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(2u);
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2u);
|
||||||
static constexpr auto Dot_Clock_Too = CounterMode_v::ClockSource.with(3u);
|
static constexpr auto Dot_Clock_Too = CounterMode::ClockSource.with(3u);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Counter1_v : public Counter {
|
struct Counter1 : public Counter {
|
||||||
struct SyncMode {
|
struct SyncMode {
|
||||||
static constexpr auto Pause_During_Vblank = CounterMode_v::SyncMode.with(0u);
|
static constexpr auto Pause_During_Vblank = CounterMode::SyncMode.with(0u);
|
||||||
static constexpr auto Zero_At_Vblank = CounterMode_v::SyncMode.with(1u);
|
static constexpr auto Zero_At_Vblank = CounterMode::SyncMode.with(1u);
|
||||||
static constexpr auto Zero_At_Vblank_Pause_Outside_Vblank = CounterMode_v::SyncMode.with(2u);
|
static constexpr auto Zero_At_Vblank_Pause_Outside_Vblank = CounterMode::SyncMode.with(2u);
|
||||||
static constexpr auto Pause_Until_Vblank_Then_FreeRun = CounterMode_v::SyncMode.with(3u);
|
static constexpr auto Pause_Until_Vblank_Then_FreeRun = CounterMode::SyncMode.with(3u);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Source {
|
struct Source {
|
||||||
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
|
||||||
static constexpr auto Hblank = CounterMode_v::ClockSource.with(1u);
|
static constexpr auto Hblank = CounterMode::ClockSource.with(1u);
|
||||||
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(2u);
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2u);
|
||||||
static constexpr auto Hblank_Too = CounterMode_v::ClockSource.with(3u);
|
static constexpr auto Hblank_Too = CounterMode::ClockSource.with(3u);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Counter2_v : public Counter {
|
struct Counter2 : public Counter {
|
||||||
struct SyncMode {
|
struct SyncMode {
|
||||||
static constexpr auto Stop_Counter = CounterMode_v::SyncMode.with(0u);
|
static constexpr auto Stop_Counter = CounterMode::SyncMode.with(0u);
|
||||||
static constexpr auto FreeRun = CounterMode_v::SyncMode.with(1u);
|
static constexpr auto FreeRun = CounterMode::SyncMode.with(1u);
|
||||||
static constexpr auto FreeRun_Too = CounterMode_v::SyncMode.with(2u);
|
static constexpr auto FreeRun_Too = CounterMode::SyncMode.with(2u);
|
||||||
static constexpr auto Stop_Counter_Too = CounterMode_v::SyncMode.with(3u);
|
static constexpr auto Stop_Counter_Too = CounterMode::SyncMode.with(3u);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Source {
|
struct Source {
|
||||||
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
|
||||||
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(1u);
|
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(1u);
|
||||||
static constexpr auto System_Clock_Div_8 = CounterMode_v::ClockSource.with(2u);
|
static constexpr auto System_Clock_Div_8 = CounterMode::ClockSource.with(2u);
|
||||||
static constexpr auto System_Clock_Div_8_Too = CounterMode_v::ClockSource.with(3u);
|
static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3u);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
__declare_new_io_port(Counter0, counter_base_adr(0));
|
__new_declare_value_at(, struct Counter0, Counter0, counter_base_adr(0));
|
||||||
__declare_new_io_port(Counter1, counter_base_adr(1));
|
__new_declare_value_at(, struct Counter1, Counter1, counter_base_adr(1));
|
||||||
__declare_new_io_port(Counter2, counter_base_adr(2));
|
__new_declare_value_at(, struct Counter2, Counter2, counter_base_adr(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace JabyEngine {
|
||||||
void setup() {
|
void setup() {
|
||||||
using namespace Timer_IO;
|
using namespace Timer_IO;
|
||||||
|
|
||||||
static constexpr auto Mode = CounterMode_t::from(CounterMode_t::FreeRun, Counter2_v::SyncMode::FreeRun, CounterMode_t::ResetAfterTarget, CounterMode_t::IRQAtTarget, CounterMode_t::IRQEveryTime, CounterMode_t::IRQPulse, Counter2_v::Source::System_Clock_Div_8);
|
static constexpr auto Mode = CounterMode::from(CounterMode::FreeRun, Counter2::SyncMode::FreeRun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8);
|
||||||
|
|
||||||
// We disable the IRQ here so it can be enabled by user demand later
|
// We disable the IRQ here so it can be enabled by user demand later
|
||||||
// Having the interrupt fire every 10ms will slow us down slightly so we only do it on demand
|
// Having the interrupt fire every 10ms will slow us down slightly so we only do it on demand
|
||||||
|
|
Loading…
Reference in New Issue