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

MINOR FIXES FOR CONSISTENCY PURPOSES

This commit is contained in:
Nicolas Clauvelin 2018-03-15 17:24:03 -04:00
parent 95288090d4
commit 23a5580d2b
7 changed files with 42 additions and 47 deletions

View File

@ -35,25 +35,15 @@ namespace cppreg {
enum class RegBitSize { enum class RegBitSize {
b8, //!< 8-bit register. b8, //!< 8-bit register.
b16, //!< 16-bit register. b16, //!< 16-bit register.
b32 //!< 32-bit register. b32, //!< 32-bit register.
b64 //!< 64-bit register.
}; };
// //! Type alias for register and field widths. //! Type alias field width.
// /**
// * This limit the implementation to a maximum size of 256 bits for any
// * register or field.
// * This corresponds to the number of bits in the a register or field.
// */
using FieldWidth_t = std::uint8_t; using FieldWidth_t = std::uint8_t;
//! Type alias for register and field offsets. //! Type alias for field offset.
/**
* This limit the implementation to a maximum offset of 256 bits for any
* register or field.
* Given that we consider 32 bits address space and 32 bits register this
* should be enough.
*/
using FieldOffset_t = std::uint8_t; using FieldOffset_t = std::uint8_t;

View File

@ -170,8 +170,8 @@ namespace cppreg {
>::type >::type
write() noexcept { write() noexcept {
// For this particular we can simply forward to the non-constant // For this particular we simply forward to the non-constant
// implementation. // implementation because the shadow value needs to be updated.
write(value); write(value);
}; };

View File

@ -51,14 +51,11 @@ namespace cppreg {
> class MergeWrite_tmpl { > class MergeWrite_tmpl {
public:
//! Type alias to register base type.
using base_type = typename Register::type;
private: private:
// Type alias to register base type.
using base_type = typename Register::type;
// Disabled for shadow value register. // Disabled for shadow value register.
static_assert(!Register::shadow::value, static_assert(!Register::shadow::value,
"merge write is not available for shadow value register"); "merge write is not available for shadow value register");
@ -135,7 +132,16 @@ namespace cppreg {
T T
>::type&& >::type&&
with() const && noexcept { with() const && noexcept {
// Check that the field belongs to the register.
static_assert(std::is_same<
typename F::parent_register,
Register
>::value,
"field is not from the same register in merge_write");
return std::move(T::make()); return std::move(T::make());
}; };

View File

@ -25,8 +25,8 @@ namespace cppreg {
/** /**
* @tparam reg_address Register address. * @tparam reg_address Register address.
* @tparam reg_size Register size enum value. * @tparam reg_size Register size enum value.
* @tparam ResetValue Register reset value (0x0 if unknown). * @tparam reset_value Register reset value (0x0 if unknown).
* @tparam UseShadow shadow Boolean flag to enable shadow value. * @tparam use_shadow shadow Boolean flag to enable shadow value.
* *
* This data structure will act as a container for fields and is * This data structure will act as a container for fields and is
* therefore limited to a strict minimum. It only carries information * therefore limited to a strict minimum. It only carries information

View File

@ -97,18 +97,18 @@ namespace internals {
//! Packed register implementation. //! Packed register implementation.
/** /**
* @tparam RegisterPack Pack to which the register belongs. * @tparam RegisterPack Pack to which the register belongs.
* @tparam BitOffset Offset in bits for the register with respect to base. * @tparam reg_size Register size enum value.
* @tparam RegWidth Register width. * @tparam bit_offset Offset in bits for the register with respect to base.
* @tparam ResetValue Register reset value (0x0 if unknown). * @tparam reset_value Register reset value (0x0 if unknown).
* @tparam UseShadow shadow Boolean flag to enable shadow value. * @tparam use_shadow Boolean flag to enable shadow value.
* *
* 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 peripheral group. * that belongs to a peripheral group.
*/ */
template < template <
typename RegisterPack, typename RegisterPack,
std::uint32_t bit_offset,
RegBitSize reg_size, RegBitSize reg_size,
std::uint32_t bit_offset,
typename TypeTraits<reg_size>::type reset_value = 0x0, typename TypeTraits<reg_size>::type reset_value = 0x0,
bool use_shadow = false bool use_shadow = false
> >

View File

@ -20,11 +20,12 @@ namespace cppreg {
//! Shadow value generic implementation. //! Shadow value generic implementation.
/** /**
* @tparam Register Register type. * @tparam Register Register type.
* @tparam UseShadow Boolean flag indicating if shadow value is required. * @tparam use_shadow Boolean flag indicating if shadow value is required.
* *
* This implementation is for register which do not require shadow value. * This implementation is for register which do not require shadow value.
*/ */
template <typename Register, bool UseShadow> struct Shadow : std::false_type {}; template <typename Register, bool use_shadow>
struct Shadow : std::false_type {};
//! Shadow value implementation. //! Shadow value implementation.

View File

@ -19,22 +19,6 @@
namespace cppreg { namespace cppreg {
// //! Register data type default implementation.
// /**
// * @tparam Size Register size.
// *
// * This will fail to compile if the register size is not implemented.
// */
// template <Width_t Size>
// struct RegisterType;
//
// //!@{ Specializations based on register size.
// template <> struct RegisterType<8u> { using type = std::uint8_t; };
// template <> struct RegisterType<16u> { using type = std::uint16_t; };
// template <> struct RegisterType<32u> { using type = std::uint32_t; };
// //!@}
//! Register type traits based on size. //! Register type traits based on size.
/** /**
* @tparam S Register size in bits. * @tparam S Register size in bits.
@ -42,6 +26,9 @@ namespace cppreg {
template <RegBitSize S> template <RegBitSize S>
struct TypeTraits; struct TypeTraits;
//!@{ TypeTraits specializations.
//! 8-bit specialization.
template <> struct TypeTraits<RegBitSize::b8> { template <> struct TypeTraits<RegBitSize::b8> {
using type = std::uint8_t; using type = std::uint8_t;
constexpr static const std::uint8_t bit_size = 8u; constexpr static const std::uint8_t bit_size = 8u;
@ -49,6 +36,7 @@ namespace cppreg {
constexpr static const std::uint8_t max_field_width = 8u; constexpr static const std::uint8_t max_field_width = 8u;
constexpr static const std::uint8_t max_field_offset = 8u; constexpr static const std::uint8_t max_field_offset = 8u;
}; };
//! 16-bit specialization.
template <> struct TypeTraits<RegBitSize::b16> { template <> struct TypeTraits<RegBitSize::b16> {
using type = std::uint16_t; using type = std::uint16_t;
constexpr static const std::uint8_t bit_size = 16u; constexpr static const std::uint8_t bit_size = 16u;
@ -56,6 +44,7 @@ namespace cppreg {
constexpr static const std::uint8_t max_field_width = 16u; constexpr static const std::uint8_t max_field_width = 16u;
constexpr static const std::uint8_t max_field_offset = 16u; constexpr static const std::uint8_t max_field_offset = 16u;
}; };
//! 32-bit specialization.
template <> struct TypeTraits<RegBitSize::b32> { template <> struct TypeTraits<RegBitSize::b32> {
using type = std::uint32_t; using type = std::uint32_t;
constexpr static const std::uint8_t bit_size = 32u; constexpr static const std::uint8_t bit_size = 32u;
@ -63,6 +52,15 @@ namespace cppreg {
constexpr static const std::uint8_t max_field_width = 32u; constexpr static const std::uint8_t max_field_width = 32u;
constexpr static const std::uint8_t max_field_offset = 32u; constexpr static const std::uint8_t max_field_offset = 32u;
}; };
//! 64-bit specialization.
template <> struct TypeTraits<RegBitSize::b64> {
using type = std::uint64_t;
constexpr static const std::uint8_t bit_size = 64u;
constexpr static const std::uint8_t byte_size = 8u;
constexpr static const std::uint8_t max_field_width = 64u;
constexpr static const std::uint8_t max_field_offset = 64u;
};
//!@}
} }