diff --git a/policies/AccessPolicy.h b/policies/AccessPolicy.h index a5b011a..3fcb3b5 100644 --- a/policies/AccessPolicy.h +++ b/policies/AccessPolicy.h @@ -59,10 +59,10 @@ namespace cppreg { */ template inline static T read( - const MMIO_t* const mmio_device, + const MMIO_t& mmio_device, typename std::enable_if::type = nullptr ) noexcept { - return static_cast((*mmio_device & mask) >> offset); + return static_cast((mmio_device & mask) >> offset); }; //! Trivial read implementation. @@ -72,10 +72,10 @@ namespace cppreg { */ template inline static T read( - const MMIO_t* const mmio_device, + const MMIO_t& mmio_device, typename std::enable_if::type = nullptr ) noexcept { - return static_cast(*mmio_device); + return static_cast(mmio_device); }; }; @@ -112,12 +112,12 @@ namespace cppreg { */ template inline static void write( - MMIO_t* const mmio_device, + MMIO_t& mmio_device, T value, typename std::enable_if::type = nullptr ) noexcept { - *mmio_device = static_cast( - (*mmio_device & ~mask) | ((value << offset) & mask) + mmio_device = static_cast( + (mmio_device & ~mask) | ((value << offset) & mask) ); }; @@ -128,11 +128,11 @@ namespace cppreg { */ template inline static void write( - MMIO_t* const mmio_device, + MMIO_t& mmio_device, T value, typename std::enable_if::type = nullptr ) noexcept { - *mmio_device = value; + mmio_device = value; }; }; @@ -169,11 +169,11 @@ namespace cppreg { */ template inline static void write( - MMIO_t* const mmio_device, + MMIO_t& mmio_device, typename std::enable_if::type = nullptr ) noexcept { - *mmio_device = static_cast( - (*mmio_device & ~mask) | ((value << offset) & mask) + mmio_device = static_cast( + (mmio_device & ~mask) | ((value << offset) & mask) ); }; @@ -183,10 +183,10 @@ namespace cppreg { */ template inline static void write( - MMIO_t* const mmio_device, + MMIO_t& mmio_device, typename std::enable_if::type = nullptr ) noexcept { - *mmio_device = value; + mmio_device = value; }; }; @@ -205,7 +205,7 @@ namespace cppreg { * @return The value at the field location. */ template - inline static T read(const MMIO_t* const mmio_device) noexcept { + inline static T read(const MMIO_t& mmio_device) noexcept { return RegisterRead::read(mmio_device); }; @@ -225,7 +225,7 @@ namespace cppreg { * @param value Value to be written at the field location. */ template - inline static void write(MMIO_t* const mmio_device, + inline static void write(MMIO_t& mmio_device, const T value) noexcept { RegisterWrite::write(mmio_device, value); }; @@ -240,7 +240,7 @@ namespace cppreg { * @param mmio_device Pointer to register mapped memory. */ template - inline static void write(MMIO_t* const mmio_device) noexcept { + inline static void write(MMIO_t& mmio_device) noexcept { RegisterWriteConstant ::write(mmio_device); }; @@ -252,7 +252,7 @@ namespace cppreg { * @param mmio_device Pointer to register mapped memory. */ template - inline static void set(MMIO_t* const mmio_device) + inline static void set(MMIO_t& mmio_device) noexcept { RegisterWriteConstant ::write(mmio_device); @@ -266,7 +266,7 @@ namespace cppreg { * @param mmio_device Pointer to register mapped memory. */ template - inline static void clear(MMIO_t* const mmio_device) + inline static void clear(MMIO_t& mmio_device) noexcept { RegisterWriteConstant ::write(mmio_device); @@ -280,9 +280,9 @@ namespace cppreg { * @param mmio_device Pointer to register mapped memory. */ template - inline static void toggle(MMIO_t* const mmio_device) + inline static void toggle(MMIO_t& mmio_device) noexcept { - *mmio_device = static_cast((*mmio_device) ^ mask); + mmio_device = static_cast((mmio_device) ^ mask); }; }; @@ -301,7 +301,7 @@ namespace cppreg { * @param value Value to be written at the field location. */ template - inline static void write(MMIO_t* const mmio_device, + inline static void write(MMIO_t& mmio_device, const T value) noexcept { // For write-only fields we can only write to the whole register. @@ -320,7 +320,7 @@ namespace cppreg { * @param mmio_device Pointer to register mapped memory. */ template - inline static void write(MMIO_t* const mmio_device) noexcept { + inline static void write(MMIO_t& mmio_device) noexcept { // For write-only fields we can only write to the whole register. RegisterWriteConstant< diff --git a/register/Field.h b/register/Field.h index 06fd33f..a5be8b1 100644 --- a/register/Field.h +++ b/register/Field.h @@ -94,7 +94,7 @@ namespace cppreg { */ inline static type read() noexcept { return policy::template read( - parent_register::ro_mem_pointer() + parent_register::ro_mem_device() ); }; @@ -107,7 +107,7 @@ namespace cppreg { write(const typename std::enable_if::type value) noexcept { policy::template write( - parent_register::rw_mem_pointer(), + parent_register::rw_mem_device(), value ); }; @@ -124,12 +124,12 @@ namespace cppreg { // Update shadow value. // This assumes that reading a write-only fields return some value. RegisterWrite - ::write(&parent_register::shadow::shadow_value, value); + ::write(parent_register::shadow::shadow_value, value); // Write as a block to the register, that is, we do not use the // mask and offset. policy::template write::value, 0u>( - parent_register::rw_mem_pointer(), + parent_register::rw_mem_device(), parent_register::shadow::shadow_value ); @@ -152,7 +152,7 @@ namespace cppreg { >::type write() noexcept { policy::template write( - parent_register::rw_mem_pointer() + parent_register::rw_mem_device() ); }; @@ -185,7 +185,7 @@ namespace cppreg { */ inline static void set() noexcept { policy::template - set(parent_register::rw_mem_pointer()); + set(parent_register::rw_mem_device()); }; //! Field clear method. @@ -194,7 +194,7 @@ namespace cppreg { */ inline static void clear() noexcept { policy::template - clear(parent_register::rw_mem_pointer()); + clear(parent_register::rw_mem_device()); }; //! Field toggle method. @@ -203,7 +203,7 @@ namespace cppreg { */ inline static void toggle() noexcept { policy::template - toggle(parent_register::rw_mem_pointer()); + toggle(parent_register::rw_mem_device()); }; //! Is field set bool method. diff --git a/register/MergeWrite.h b/register/MergeWrite.h index 0e4ed35..49b0fc2 100644 --- a/register/MergeWrite.h +++ b/register/MergeWrite.h @@ -94,8 +94,8 @@ namespace cppreg { inline void done() const && noexcept { // Get memory pointer. - typename Register::MMIO_t* const mmio_device = - Register::rw_mem_pointer(); + typename Register::MMIO_t& mmio_device = + Register::rw_mem_device(); // Write to the whole register using the current accumulated value // and combined mask. @@ -193,8 +193,8 @@ namespace cppreg { inline void done() const && noexcept { // Get memory pointer. - typename Register::MMIO_t* const mmio_device = - Register::rw_mem_pointer(); + typename Register::MMIO_t& mmio_device = + Register::rw_mem_device(); // Write to the whole register using the current accumulated value // and combined mask. @@ -231,7 +231,7 @@ namespace cppreg { base_type, F::mask, F::offset - >(&_accumulated_value, value); + >(_accumulated_value, value); return std::move( diff --git a/register/Register.h b/register/Register.h index 216b7ca..8e16174 100644 --- a/register/Register.h +++ b/register/Register.h @@ -62,18 +62,18 @@ namespace cppreg { //! Memory modifier. /** - * @return A pointer to the writable register memory. + * @return A reference to the writable register memory. */ - static MMIO_t* rw_mem_pointer() { - return reinterpret_cast(base_address); + static MMIO_t& rw_mem_device() { + return *(reinterpret_cast(base_address)); }; //! Memory accessor. /** - * @return A pointer to the read-only register memory. + * @return A reference to the read-only register memory. */ - static const MMIO_t* ro_mem_pointer() { - return reinterpret_cast(base_address); + static const MMIO_t& ro_mem_device() { + return *(reinterpret_cast(base_address)); }; //! Merge write start function.