Prepare for new IOPort code
This commit is contained in:
parent
30759b85c7
commit
5f87cfee09
|
@ -4,6 +4,114 @@
|
||||||
#include "../../Auxiliary/bits.hpp"
|
#include "../../Auxiliary/bits.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
|
namespace New {
|
||||||
|
namespace internal {
|
||||||
|
template<typename T, typename S>
|
||||||
|
struct IOValue {
|
||||||
|
typedef S UnderlyingType;
|
||||||
|
|
||||||
|
UnderlyingType raw;
|
||||||
|
|
||||||
|
template<typename...ARGS>
|
||||||
|
static constexpr T from(const ARGS&...args) {
|
||||||
|
return T{0}.set_va(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T& set(Bit bit) {
|
||||||
|
this->raw = bit::set(this->raw, bit);
|
||||||
|
return static_cast<T&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T& set(ClearBit bit) {
|
||||||
|
this->raw = bit::set(this->raw, bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T& set(BitRange bits, T value) {
|
||||||
|
this->raw = bit::value::set_normalized(this->raw, bits, value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
constexpr T& set(const BitRange::RangeValuePair<U>& value) {
|
||||||
|
this->raw = bit::value::set_normalized(this->raw, value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
constexpr T& set_va(const U& head) {
|
||||||
|
return this->set(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U, typename...ARGS>
|
||||||
|
constexpr T& set_va(const U& head, const ARGS&...tail) {
|
||||||
|
return this->set(head).set_va(tail...);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr IOValue<T, S>::UnderlyingType get(BitRange bits) const {
|
||||||
|
return bit::value::get_normalized(this->raw, bits.pos, bits.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr T& clear(Bit bit) {
|
||||||
|
this->raw = bit::clear(this->raw, bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool is_set(Bit bit) const {
|
||||||
|
return bit::is_set(this->raw, bit);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ubus32_t {
|
||||||
|
uint16_t low;
|
||||||
|
uint16_t high;
|
||||||
|
|
||||||
|
static ubus32_t from(uint32_t value) {
|
||||||
|
return {.low = static_cast<uint16_t>(value & 0xFFFF), .high = static_cast<uint16_t>(value >> 16)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct IOPort {
|
||||||
|
T value;
|
||||||
|
|
||||||
|
T read() const {
|
||||||
|
return {const_cast<const volatile IOPort<T>*>(this)->value.raw};
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(T value) {
|
||||||
|
const_cast<volatile IOPort<T>*>(this)->value.raw = value.raw;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IOPort<ubus32_t> {
|
||||||
|
ubus32_t value;
|
||||||
|
|
||||||
|
ubus32_t read() const {
|
||||||
|
auto*const cv_this = const_cast<const volatile IOPort<ubus32_t>*>(this);
|
||||||
|
|
||||||
|
return {.low = cv_this->value.low, .high = cv_this->value.high};
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(ubus32_t value) {
|
||||||
|
auto*const cv_this = const_cast<volatile IOPort<ubus32_t>*>(this);
|
||||||
|
|
||||||
|
cv_this->value.low = value.low;
|
||||||
|
cv_this->value.high = value.high;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(uint32_t value) {
|
||||||
|
IOPort<ubus32_t>::write(ubus32_t::from(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define __new_declare_io_value(name, type) struct name : public New::internal::IOValue<name, type>
|
||||||
|
#define __new_declare_io_port_w_type(type, name, adr) static auto& name = *reinterpret_cast<New::IOPort<struct type>*>(IOAdress::patch_adr(adr))
|
||||||
|
#define __new_declare_io_port(name, adr) __new_declare_io_port_w_type(name, name, adr)
|
||||||
|
}
|
||||||
|
|
||||||
namespace IOPort {
|
namespace IOPort {
|
||||||
struct IOValueType {
|
struct IOValueType {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
"cmake.configureOnOpen": false,
|
||||||
"C_Cpp.default.includePath": [
|
"C_Cpp.default.includePath": [
|
||||||
"include",
|
"include",
|
||||||
"../../include"
|
"../../include"
|
||||||
|
|
|
@ -11,9 +11,26 @@ extern "C" uint32_t __planschi_start;
|
||||||
extern "C" uint32_t __planschi_end;
|
extern "C" uint32_t __planschi_end;
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
|
// For now
|
||||||
|
namespace Blubb {
|
||||||
|
__new_declare_io_value(Test, uint32_t) {
|
||||||
|
};
|
||||||
|
__new_declare_io_port(Test, 0);
|
||||||
|
static void bla(New::IOPort<struct Test>& wuff) {
|
||||||
|
asm("#planschi");
|
||||||
|
const auto a = Test::from(Bit(1), Bit(2));
|
||||||
|
|
||||||
|
wuff.write(a);
|
||||||
|
wuff.write(a);
|
||||||
|
wuff.write(a);
|
||||||
|
asm("#planschi");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace boot {
|
namespace boot {
|
||||||
namespace Start {
|
namespace Start {
|
||||||
static void enable_DMA() {
|
static void enable_DMA() {
|
||||||
|
::JabyEngine::Blubb::bla(::JabyEngine::Blubb::Test);
|
||||||
DMA_IO::DPCR = DMA_IO::DPCR_t(DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable).set(DMA_IO::DPCR_t::CDROMEnable);
|
DMA_IO::DPCR = DMA_IO::DPCR_t(DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable).set(DMA_IO::DPCR_t::CDROMEnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue