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

REVISED REGISTER PACK IMPLEMENTATION FOR SIZE ISSUES

The revision brings the support for 16-bits and 32-bits registers.
This commit is contained in:
Nicolas Clauvelin 2018-03-12 22:18:54 -04:00
parent 984d4ceb58
commit ae6da9b7f5

View File

@ -21,22 +21,28 @@ namespace cppreg {
//! Register pack base implementation. //! Register pack base implementation.
/** /**
* @tparam PackBase Base address to use for the pack memory.
* @tparam PackByteSize Size in bytes of the memory region for the pack.
*/ */
template < template <
Address_t PackBase, Address_t PackBase,
std::uint32_t PackByteSize Width_t RegWidth,
std::uint32_t N
> struct RegisterPack { > struct RegisterPack {
//! Pack register type.
using register_type = typename RegisterType<RegWidth>::type;
//! Type alias for byte array. //! Type alias for byte array.
using mem_array_t = std::array<volatile std::uint8_t, PackByteSize>; using mem_array_t =std::array<volatile register_type, N>;
//! Base address. //! Base address.
constexpr static const Address_t pack_base = PackBase; constexpr static const Address_t pack_base = PackBase;
//! Pack size in bytes. //! Pack size in bytes.
constexpr static const std::uint32_t size_in_bytes = PackByteSize; constexpr static const std::uint32_t size_in_bytes =
N * sizeof(register_type);
//! Register width in the pack.
constexpr static const Width_t register_width = RegWidth;
//! Reference to the byte array. //! Reference to the byte array.
/** /**
@ -49,47 +55,44 @@ namespace cppreg {
//! RegisterPack byte array reference definition. //! RegisterPack byte array reference definition.
template < template <
Address_t PackBase, Address_t PackBase,
std::uint32_t PackByteSize Width_t RegWidth,
std::uint32_t N
> >
typename RegisterPack<PackBase, PackByteSize>::mem_array_t& typename RegisterPack<PackBase, RegWidth, N>::mem_array_t&
RegisterPack<PackBase, PackByteSize>::_mem_array = RegisterPack<PackBase, RegWidth, N>::_mem_array =
*( *(
reinterpret_cast< reinterpret_cast<
RegisterPack<PackBase, PackByteSize>::mem_array_t* const RegisterPack<PackBase, RegWidth, N>::mem_array_t* const
>(RegisterPack<PackBase, PackByteSize>::pack_base) >(
RegisterPack<PackBase, RegWidth, N>::pack_base
)
); );
//! Packed register implementation. //! Packed register implementation.
/** /**
* @tparam RegisterPack Pack to which the register belongs.
* @tparam RegWidth Register total width in bits.
* @tparam OffsetInPack Register offset in the pack in bytes.
* @tparam reset Register reset value (0x0 if unknown).
* @tparam shadow Boolean flag to enable shadow value (enabled if `true`).
* *
* This implementation is intended to be used when defining a register * This implementation is intended to be used when defining a register
* that belongs to a type. * that belongs to a type.
*/ */
template < template <
typename RegisterPack, typename RegisterPack,
Width_t RegWidth,
std::uint32_t OffsetInPack, std::uint32_t OffsetInPack,
typename RegisterType<RegWidth>::type ResetValue = 0x0, typename RegisterType<RegisterPack::register_width>::type ResetValue = 0x0,
bool UseShadow = false bool UseShadow = false
> >
struct PackedRegister : struct PackedRegister :
Register< Register<
RegisterPack::pack_base + OffsetInPack * 8, RegisterPack::pack_base + OffsetInPack,
RegWidth, RegisterPack::register_width,
ResetValue, ResetValue,
UseShadow UseShadow
> { > {
//! Register type. //! Register type.
using base_reg = Register< using base_reg = Register<
RegisterPack::pack_base + OffsetInPack * 8, RegisterPack::pack_base + OffsetInPack,
RegWidth, RegisterPack::register_width,
ResetValue, ResetValue,
UseShadow UseShadow
>; >;
@ -111,7 +114,7 @@ namespace cppreg {
}; };
// Safety check to detect if are overflowing the pack. // Safety check to detect if are overflowing the pack.
static_assert((OffsetInPack + (RegWidth / 8u)) <= static_assert((OffsetInPack + (RegisterPack::register_width / 8u)) <=
RegisterPack::size_in_bytes, RegisterPack::size_in_bytes,
"packed register is overflowing the pack"); "packed register is overflowing the pack");