112 lines
5.3 KiB
C++
112 lines
5.3 KiB
C++
#ifndef __JABYENGINE_TIMER_IO_HPP__
|
|
#define __JABYENGINE_TIMER_IO_HPP__
|
|
#include "ioport.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace Timer_IO {
|
|
__declare_io_type(CounterMode, uint32_t,
|
|
static constexpr auto SyncEnable = IOBitSet(0);
|
|
static constexpr auto FreeRun = !SyncEnable;
|
|
static constexpr auto SyncMode = IOValueSet::from_to(1, 2);
|
|
static constexpr auto ResetAfterTarget = IOBitSet(3);
|
|
static constexpr auto IRQAtTarget = IOBitSet(4);
|
|
static constexpr auto IRQAtMax = IOBitSet(5);
|
|
static constexpr auto IRQEveryTime = IOBitSet(6);
|
|
static constexpr auto IRQOneShot = !IRQEveryTime;
|
|
static constexpr auto IRQToggle = IOBitSet(7);
|
|
static constexpr auto IRQPulse = !IRQToggle;
|
|
static constexpr auto ClockSource = IOValueSet::from_to(8, 9);
|
|
static constexpr auto HasIRQRequest = IOBitSet(10);
|
|
static constexpr auto IsTargetReached = IOBitSet(11);
|
|
static constexpr auto IsMaxReached = IOBitSet(12);
|
|
);
|
|
|
|
__declare_io_type(CounterTarget, uint32_t,
|
|
static constexpr auto CounterTargetValue = IOValueSet::from_to(0, 15);
|
|
);
|
|
|
|
__declare_io_type(CounterValue, uint32_t,
|
|
static constexpr auto Value = IOValueSet::from_to(0, 15);
|
|
);
|
|
|
|
struct __no_align Counter {
|
|
CounterValue_v value;
|
|
CounterMode_v mode;
|
|
CounterTarget_v target;
|
|
|
|
private:
|
|
uint32_t _unused;
|
|
|
|
public:
|
|
constexpr uint16_t get_current_value() const {
|
|
return this->value.get(CounterValue_v::Value);
|
|
}
|
|
|
|
constexpr void set_target_value(uint16_t value) {
|
|
this->target.set(CounterTarget_v::CounterTargetValue, value);
|
|
}
|
|
|
|
constexpr void set_mode(CounterMode_t mode) {
|
|
this->mode = mode;
|
|
}
|
|
};
|
|
|
|
static constexpr uintptr_t counter_base_adr(size_t ID) {
|
|
return (0x1F801100 + (ID*0x10));
|
|
}
|
|
|
|
struct __no_align Counter0_v : public Counter {
|
|
struct SyncMode {
|
|
static constexpr auto Pause_During_Hblank = CounterMode_v::SyncMode.with(0u);
|
|
static constexpr auto Zero_At_Hblank = CounterMode_v::SyncMode.with(1u);
|
|
static constexpr auto Zero_At_Hblank_Pause_Outside_Hblank = CounterMode_v::SyncMode.with(2u);
|
|
static constexpr auto Pause_Until_Hblank_Then_Freerun = CounterMode_v::SyncMode.with(3u);
|
|
};
|
|
|
|
struct Source {
|
|
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
|
static constexpr auto Dot_Clock = CounterMode_v::ClockSource.with(1u);
|
|
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(2u);
|
|
static constexpr auto Dot_Clock_Too = CounterMode_v::ClockSource.with(3u);
|
|
};
|
|
};
|
|
|
|
struct __no_align Counter1_v : public Counter {
|
|
struct SyncMode {
|
|
static constexpr auto Pause_During_Vblank = CounterMode_v::SyncMode.with(0u);
|
|
static constexpr auto Zero_At_Vblank = CounterMode_v::SyncMode.with(1u);
|
|
static constexpr auto Zero_At_Vblank_Pause_Outside_Vblank = CounterMode_v::SyncMode.with(2u);
|
|
static constexpr auto Pause_Until_Vblank_Then_FreeRun = CounterMode_v::SyncMode.with(3u);
|
|
};
|
|
|
|
struct Source {
|
|
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
|
static constexpr auto Hblank = CounterMode_v::ClockSource.with(1u);
|
|
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(2u);
|
|
static constexpr auto Hblank_Too = CounterMode_v::ClockSource.with(3u);
|
|
};
|
|
};
|
|
|
|
struct __no_align Counter2_v : public Counter {
|
|
struct SyncMode {
|
|
static constexpr auto Stop_Counter = CounterMode_v::SyncMode.with(0u);
|
|
static constexpr auto FreeRun = CounterMode_v::SyncMode.with(1u);
|
|
static constexpr auto FreeRun_Too = CounterMode_v::SyncMode.with(2u);
|
|
static constexpr auto Stop_Counter_Too = CounterMode_v::SyncMode.with(3u);
|
|
};
|
|
|
|
struct Source {
|
|
static constexpr auto System_Clock = CounterMode_v::ClockSource.with(0u);
|
|
static constexpr auto System_Clock_Too = CounterMode_v::ClockSource.with(1u);
|
|
static constexpr auto System_Clock_Div_8 = CounterMode_v::ClockSource.with(2u);
|
|
static constexpr auto System_Clock_Div_8_Too = CounterMode_v::ClockSource.with(3u);
|
|
};
|
|
};
|
|
|
|
__declare_new_io_port(Counter0, counter_base_adr(0));
|
|
__declare_new_io_port(Counter1, counter_base_adr(1));
|
|
__declare_new_io_port(Counter2, counter_base_adr(2));
|
|
}
|
|
}
|
|
|
|
#endif //!__JABYENGINE_TIMER_IO_HPP__
|