Improved names again

This commit is contained in:
Jaby
2023-01-15 20:16:20 +01:00
parent 35d5662d3b
commit 09328f8347
5 changed files with 63 additions and 57 deletions

View File

@@ -3,50 +3,56 @@
#include "../../Auxiliary/complex_bitmap.hpp"
namespace JabyEngine {
template<typename T, typename S = T>
class __no_align IOPort {
private:
volatile T value;
template<typename T>
struct VolatilePOD {
volatile T raw;
public:
constexpr T read_raw() const {
return this->value;
constexpr T read() const {
return this->raw;
}
constexpr S read() const {
return S{this->value};
}
constexpr void write_raw(T value) {
this->value = value;
}
constexpr void write(const S& value) {
this->value = static_cast<T>(value);
constexpr void write(T value) {
this->raw = value;
}
};
// For use with ComplexBitMaps or what else satisfies this API
template<typename T>
class __no_align IOPortEx : public IOPort<typename T::UnderlyingType, T> {
private:
struct VolatileBitMapPOD {
typedef typename T::UnderlyingType Raw;
public:
VolatilePOD<Raw> pod;
constexpr Raw read_raw() const {
return this->pod.read();
}
constexpr T read() const {
return T{this->pod.read()};
}
constexpr Raw read_range_value(const BitRange<Raw>& range) const {
return IOPort<Raw, T>::read().get_value(range);
return VolatileBitMapPOD<T>::read().get_value(range);
}
constexpr void write_raw(Raw value) {
this->pod.write(value);
}
constexpr void write(const T& value) {
this->pod.write(static_cast<Raw>(value));
}
constexpr void write_range_value(const BitRangeValue<Raw>& value) {
IOPort<Raw, T>::write(T{T::with(value)});
VolatileBitMapPOD<T>::write(T{T::with(value)});
}
};
struct __no_align ubus32_t {
typedef ComplexBitMap<uint16_t> Base16;
IOPort<Base16::UnderlyingType, Base16> low;
IOPort<Base16::UnderlyingType, Base16> high;
VolatileBitMapPOD<Base16> low;
VolatileBitMapPOD<Base16> high;
constexpr ubus32_t(uint32_t value) {
*this = value;
@@ -74,15 +80,15 @@ namespace JabyEngine {
#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(, IOPortEx<type>, name, adr)
#define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, IOPortEx<type>, name, adr)
#define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, IOPort<type>, name, adr)
#define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, IOPort<type>, name, 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, IOPortEx<type>, name, adr)
#define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, IOPortEx<type>, name, adr)
#define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, IOPort<type>, name, adr)
#define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, IOPort<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))