82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
#ifndef __JABYENGINE_IOPORT_HPP__
|
|
#define __JABYENGINE_IOPORT_HPP__
|
|
#include "../../Auxiliary/complex_bitmap.hpp"
|
|
|
|
template<typename T>
|
|
class __no_align IOPort {
|
|
private:
|
|
T value;
|
|
|
|
public:
|
|
//For easy access
|
|
constexpr T read() const {
|
|
return const_cast<volatile IOPort<T>*>(this)->value;
|
|
}
|
|
|
|
constexpr void write(T value) {
|
|
const_cast<volatile IOPort<T>*>(this)->value = value;
|
|
}
|
|
|
|
constexpr volatile T& ref() {
|
|
return const_cast<volatile IOPort<T>*>(this)->value;
|
|
}
|
|
};
|
|
|
|
struct __no_align ubus32_t {
|
|
ComplexBitMap<uint16_t> low;
|
|
ComplexBitMap<uint16_t> high;
|
|
|
|
constexpr ubus32_t(uint32_t value) {
|
|
*this = value;
|
|
}
|
|
|
|
constexpr operator uint32_t() const {
|
|
return ((this->high.raw << 16) | this->low.raw);
|
|
}
|
|
|
|
operator uint32_t() const volatile {
|
|
return ((this->high.raw << 16) | this->low.raw);
|
|
}
|
|
|
|
constexpr ubus32_t& operator=(uint32_t value) {
|
|
this->low.raw = (value & 0xFFFF);
|
|
this->high.raw = (value >> 16);
|
|
|
|
return *this;
|
|
}
|
|
|
|
constexpr void operator=(uint32_t value) volatile {
|
|
this->low.raw = (value & 0xFFFF);
|
|
this->high.raw = (value >> 16);
|
|
}
|
|
};
|
|
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
|
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
|
#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast<IOPort<type>*>((IO_Base_Adr + (adr & ~IO_Base_Mask)))
|
|
|
|
#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr)
|
|
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, 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_Base_Adr + (adr & ~IO_Base_Mask))));
|
|
#define __io_port_inherit_complex_bit_map(name) \
|
|
constexpr name() = default; \
|
|
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
|
} \
|
|
template<typename...ARGS> \
|
|
static constexpr name with(ARGS...args) { \
|
|
return {ComplexBitMap::with(args...)}; \
|
|
}\
|
|
template<typename T> \
|
|
constexpr void operator=(ComplexBitMap<T> value) volatile { \
|
|
this->raw = value.raw; \
|
|
}
|
|
|
|
/*\
|
|
using ComplexBitMap::operator=; \
|
|
constexpr name() = default; \
|
|
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
|
}\
|
|
template<typename...ARGS> \
|
|
constexpr name(ARGS...args) : ComplexBitMap(args...) {\
|
|
}*/
|
|
|
|
#endif //!__JABYENGINE_IOPORT_HPP__
|