diff --git a/register/RegisterPack.h b/register/RegisterPack.h index e99bb5d..a802745 100644 --- a/register/RegisterPack.h +++ b/register/RegisterPack.h @@ -21,22 +21,28 @@ namespace cppreg { //! 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 < Address_t PackBase, - std::uint32_t PackByteSize + Width_t RegWidth, + std::uint32_t N > struct RegisterPack { + //! Pack register type. + using register_type = typename RegisterType::type; + //! Type alias for byte array. - using mem_array_t = std::array; + using mem_array_t =std::array; //! Base address. constexpr static const Address_t pack_base = PackBase; //! 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. /** @@ -49,47 +55,44 @@ namespace cppreg { //! RegisterPack byte array reference definition. template < Address_t PackBase, - std::uint32_t PackByteSize + Width_t RegWidth, + std::uint32_t N > - typename RegisterPack::mem_array_t& - RegisterPack::_mem_array = + typename RegisterPack::mem_array_t& + RegisterPack::_mem_array = *( reinterpret_cast< - RegisterPack::mem_array_t* const - >(RegisterPack::pack_base) + RegisterPack::mem_array_t* const + >( + RegisterPack::pack_base + ) ); //! 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 * that belongs to a type. */ template < typename RegisterPack, - Width_t RegWidth, std::uint32_t OffsetInPack, - typename RegisterType::type ResetValue = 0x0, + typename RegisterType::type ResetValue = 0x0, bool UseShadow = false > struct PackedRegister : Register< - RegisterPack::pack_base + OffsetInPack * 8, - RegWidth, + RegisterPack::pack_base + OffsetInPack, + RegisterPack::register_width, ResetValue, UseShadow > { //! Register type. using base_reg = Register< - RegisterPack::pack_base + OffsetInPack * 8, - RegWidth, + RegisterPack::pack_base + OffsetInPack, + RegisterPack::register_width, ResetValue, UseShadow >; @@ -111,7 +114,7 @@ namespace cppreg { }; // 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, "packed register is overflowing the pack");