1
0
mirror of https://github.com/sendyne/cppreg.git synced 2025-05-09 15:14: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.
/**
* @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<RegWidth>::type;
//! 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.
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<PackBase, PackByteSize>::mem_array_t&
RegisterPack<PackBase, PackByteSize>::_mem_array =
typename RegisterPack<PackBase, RegWidth, N>::mem_array_t&
RegisterPack<PackBase, RegWidth, N>::_mem_array =
*(
reinterpret_cast<
RegisterPack<PackBase, PackByteSize>::mem_array_t* const
>(RegisterPack<PackBase, PackByteSize>::pack_base)
RegisterPack<PackBase, RegWidth, N>::mem_array_t* const
>(
RegisterPack<PackBase, RegWidth, N>::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<RegWidth>::type ResetValue = 0x0,
typename RegisterType<RegisterPack::register_width>::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");