1
0
mirror of https://github.com/sendyne/cppreg.git synced 2025-05-09 15:14:05 +00:00

CPPREG MEMORY ACCESS REVISION

All access to memory are now done through reference (const reference for
read-only access). This is done to facilitate the implementation of register
packs.
This commit is contained in:
Nicolas Clauvelin 2018-03-12 16:35:26 -04:00
parent f1d98d6bd5
commit e4ae5641ec
4 changed files with 42 additions and 42 deletions

View File

@ -59,10 +59,10 @@ namespace cppreg {
*/
template <typename U = void>
inline static T read(
const MMIO_t* const mmio_device,
const MMIO_t& mmio_device,
typename std::enable_if<!is_trivial, U*>::type = nullptr
) noexcept {
return static_cast<T>((*mmio_device & mask) >> offset);
return static_cast<T>((mmio_device & mask) >> offset);
};
//! Trivial read implementation.
@ -72,10 +72,10 @@ namespace cppreg {
*/
template <typename U = void>
inline static T read(
const MMIO_t* const mmio_device,
const MMIO_t& mmio_device,
typename std::enable_if<is_trivial, U*>::type = nullptr
) noexcept {
return static_cast<T>(*mmio_device);
return static_cast<T>(mmio_device);
};
};
@ -112,12 +112,12 @@ namespace cppreg {
*/
template <typename U = void>
inline static void write(
MMIO_t* const mmio_device,
MMIO_t& mmio_device,
T value,
typename std::enable_if<!is_trivial, U*>::type = nullptr
) noexcept {
*mmio_device = static_cast<T>(
(*mmio_device & ~mask) | ((value << offset) & mask)
mmio_device = static_cast<T>(
(mmio_device & ~mask) | ((value << offset) & mask)
);
};
@ -128,11 +128,11 @@ namespace cppreg {
*/
template <typename U = void>
inline static void write(
MMIO_t* const mmio_device,
MMIO_t& mmio_device,
T value,
typename std::enable_if<is_trivial, U*>::type = nullptr
) noexcept {
*mmio_device = value;
mmio_device = value;
};
};
@ -169,11 +169,11 @@ namespace cppreg {
*/
template <typename U = void>
inline static void write(
MMIO_t* const mmio_device,
MMIO_t& mmio_device,
typename std::enable_if<!is_trivial, U*>::type = nullptr
) noexcept {
*mmio_device = static_cast<T>(
(*mmio_device & ~mask) | ((value << offset) & mask)
mmio_device = static_cast<T>(
(mmio_device & ~mask) | ((value << offset) & mask)
);
};
@ -183,10 +183,10 @@ namespace cppreg {
*/
template <typename U = void>
inline static void write(
MMIO_t* const mmio_device,
MMIO_t& mmio_device,
typename std::enable_if<is_trivial, U*>::type = nullptr
) noexcept {
*mmio_device = value;
mmio_device = value;
};
};
@ -205,7 +205,7 @@ namespace cppreg {
* @return The value at the field location.
*/
template <typename MMIO_t, typename T, T mask, Offset_t offset>
inline static T read(const MMIO_t* const mmio_device) noexcept {
inline static T read(const MMIO_t& mmio_device) noexcept {
return RegisterRead<MMIO_t, T, mask, offset>::read(mmio_device);
};
@ -225,7 +225,7 @@ namespace cppreg {
* @param value Value to be written at the field location.
*/
template <typename MMIO_t, typename T, T mask, Offset_t offset>
inline static void write(MMIO_t* const mmio_device,
inline static void write(MMIO_t& mmio_device,
const T value) noexcept {
RegisterWrite<MMIO_t, T, mask, offset>::write(mmio_device, value);
};
@ -240,7 +240,7 @@ namespace cppreg {
* @param mmio_device Pointer to register mapped memory.
*/
template <typename MMIO_t, typename T, T mask, Offset_t offset, T value>
inline static void write(MMIO_t* const mmio_device) noexcept {
inline static void write(MMIO_t& mmio_device) noexcept {
RegisterWriteConstant<MMIO_t, T, mask, offset, value>
::write(mmio_device);
};
@ -252,7 +252,7 @@ namespace cppreg {
* @param mmio_device Pointer to register mapped memory.
*/
template <typename MMIO_t, typename T, T mask>
inline static void set(MMIO_t* const mmio_device)
inline static void set(MMIO_t& mmio_device)
noexcept {
RegisterWriteConstant<MMIO_t, T, mask, 0u, mask>
::write(mmio_device);
@ -266,7 +266,7 @@ namespace cppreg {
* @param mmio_device Pointer to register mapped memory.
*/
template <typename MMIO_t, typename T, T mask>
inline static void clear(MMIO_t* const mmio_device)
inline static void clear(MMIO_t& mmio_device)
noexcept {
RegisterWriteConstant<MMIO_t, T, mask, 0u, ~mask>
::write(mmio_device);
@ -280,9 +280,9 @@ namespace cppreg {
* @param mmio_device Pointer to register mapped memory.
*/
template <typename MMIO_t, typename T, T mask>
inline static void toggle(MMIO_t* const mmio_device)
inline static void toggle(MMIO_t& mmio_device)
noexcept {
*mmio_device = static_cast<T>((*mmio_device) ^ mask);
mmio_device = static_cast<T>((mmio_device) ^ mask);
};
};
@ -301,7 +301,7 @@ namespace cppreg {
* @param value Value to be written at the field location.
*/
template <typename MMIO_t, typename T, T mask, Offset_t offset>
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 <typename MMIO_t, typename T, T mask, Offset_t offset, T value>
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<

View File

@ -94,7 +94,7 @@ namespace cppreg {
*/
inline static type read() noexcept {
return policy::template read<MMIO_t, type, mask, offset>(
parent_register::ro_mem_pointer()
parent_register::ro_mem_device()
);
};
@ -107,7 +107,7 @@ namespace cppreg {
write(const typename std::enable_if<!has_shadow, T>::type value)
noexcept {
policy::template write<MMIO_t, type, mask, offset>(
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<type, type, mask, offset>
::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<MMIO_t, type, type_mask<type>::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<MMIO_t, type, mask, offset, value>(
parent_register::rw_mem_pointer()
parent_register::rw_mem_device()
);
};
@ -185,7 +185,7 @@ namespace cppreg {
*/
inline static void set() noexcept {
policy::template
set<MMIO_t, type, mask>(parent_register::rw_mem_pointer());
set<MMIO_t, type, mask>(parent_register::rw_mem_device());
};
//! Field clear method.
@ -194,7 +194,7 @@ namespace cppreg {
*/
inline static void clear() noexcept {
policy::template
clear<MMIO_t, type, mask>(parent_register::rw_mem_pointer());
clear<MMIO_t, type, mask>(parent_register::rw_mem_device());
};
//! Field toggle method.
@ -203,7 +203,7 @@ namespace cppreg {
*/
inline static void toggle() noexcept {
policy::template
toggle<MMIO_t, type, mask>(parent_register::rw_mem_pointer());
toggle<MMIO_t, type, mask>(parent_register::rw_mem_device());
};
//! Is field set bool method.

View File

@ -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(

View File

@ -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<MMIO_t* const>(base_address);
static MMIO_t& rw_mem_device() {
return *(reinterpret_cast<MMIO_t* const>(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<const MMIO_t* const>(base_address);
static const MMIO_t& ro_mem_device() {
return *(reinterpret_cast<const MMIO_t* const>(base_address));
};
//! Merge write start function.