|
|
|
|
@@ -20,8 +20,17 @@ namespace JabyEngine {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace IOAdress {
|
|
|
|
|
constexpr uintptr_t patch_adr(uintptr_t adr) {
|
|
|
|
|
constexpr uintptr_t Mask = 0xF0000000;
|
|
|
|
|
constexpr uintptr_t Base = 0x10000000; // We might want to change this later to 0xB0000000 for caching and stuff (More research needed)
|
|
|
|
|
|
|
|
|
|
return (Base + (adr & ~Mask));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define __declare_new_named_io_port(type, name, adr) \
|
|
|
|
|
static inline auto& name = *reinterpret_cast<type##_v*>(adr)
|
|
|
|
|
static inline auto& name = *reinterpret_cast<type##_v*>(IOAdress::patch_adr(adr))
|
|
|
|
|
|
|
|
|
|
#define __declare_new_io_port(name, adr) \
|
|
|
|
|
__declare_new_named_io_port(name, name, adr)
|
|
|
|
|
@@ -32,8 +41,8 @@ namespace JabyEngine {
|
|
|
|
|
#define __declare_new_io_port_array(name, adr, size) \
|
|
|
|
|
static inline auto& name = reinterpret_cast<name##_v(&)[size]>(*reinterpret_cast<name##_v*>(adr))
|
|
|
|
|
|
|
|
|
|
// We need this construct to ensure the types end up being a POD - Inheritance doesn't qualify for a POD
|
|
|
|
|
#define __declare_io_type(name, type, ...) \
|
|
|
|
|
/*We need this type to be a POD sadly*/ \
|
|
|
|
|
template<template<typename> typename T> \
|
|
|
|
|
struct name##_io_base { \
|
|
|
|
|
typedef T<type>::UnderlyingValue UnderlyingValue; \
|
|
|
|
|
@@ -104,19 +113,6 @@ namespace JabyEngine {
|
|
|
|
|
typedef name##_io_base<IOPort::IOValueType::Volatile> name##_v; \
|
|
|
|
|
typedef name##_io_base<IOPort::IOValueType::Normal> name##_t
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct VolatilePOD {
|
|
|
|
|
volatile T raw;
|
|
|
|
|
|
|
|
|
|
constexpr T read() const {
|
|
|
|
|
return this->raw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr void write(T value) {
|
|
|
|
|
this->raw = value;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct __no_align ubus32_t {
|
|
|
|
|
__declare_io_type(uint16_t, uint16_t,);
|
|
|
|
|
uint16_t_v low;
|
|
|
|
|
@@ -144,24 +140,5 @@ namespace JabyEngine {
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
|
|
|
|
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
|
|
|
|
|
|
|
|
|
#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask))
|
|
|
|
|
#define __cast_io_adr_with_type(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define __declare_io_port_global(type, name, adr) __cast_io_adr_with_type(, VolatileBitMapPOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, VolatileBitMapPOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, VolatilePOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, VolatilePOD<type>, name, adr)
|
|
|
|
|
|
|
|
|
|
#define __declare_io_port_member(type, name, adr) __cast_io_adr_with_type(inline, VolatileBitMapPOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, VolatileBitMapPOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, VolatilePOD<type>, name, adr)
|
|
|
|
|
#define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, VolatilePOD<type>, name, adr)
|
|
|
|
|
|
|
|
|
|
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>(__io_port_adr(adr)))
|
|
|
|
|
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
|
|
|
|
|
}
|
|
|
|
|
#endif //!__JABYENGINE_IOPORT_HPP__
|