mmio: provide bits method for bitsets

ref #1006
This commit is contained in:
Martin Stein 2013-12-19 17:31:56 +01:00 committed by Norman Feske
parent e142d0d2e8
commit ff70ca6427
2 changed files with 35 additions and 0 deletions

View File

@ -235,6 +235,18 @@ namespace Genode
};
typedef typename Trait::Uint_width<ACCESS_WIDTH>::Type access_t;
typedef Bitset_2<Bits_0, Bits_1> Bitset_2_base;
/**
* Get register with the bitset set to a given value and rest left 0
*
* \param T access type of register
* \param v bitset value
*/
template <typename T>
static inline T bits(T const v)
{
return Bits_0::bits(v) | Bits_1::bits(v >> Bits_0::WIDTH);
}
};
/**
@ -260,6 +272,19 @@ namespace Genode
};
typedef typename Trait::Uint_width<ACCESS_WIDTH>::Type access_t;
typedef Bitset_3<Bits_0, Bits_1, Bits_2> Bitset_3_base;
/**
* Get register with the bitset set to a given value and rest left 0
*
* \param T access type of register
* \param v bitset value
*/
template <typename T>
static inline T bits(T const v)
{
typedef Bitset_2<Bits_0, Bits_1> Bits_0_1;
return Bits_0_1::bits(v) | Bits_2::bits(v >> Bits_0_1::WIDTH);
}
};
}

View File

@ -126,15 +126,18 @@ struct Test_mmio : public Mmio
{
struct Bits_0 : Bitfield<1, 3> { };
struct Bits_1 : Bitfield<12, 4> { };
struct Bits_2 : Bitfield<6, 2> { };
};
struct Reg_2 : Register<0x4, 32>
{
struct Bits_0 : Bitfield<4, 5> { };
struct Bits_1 : Bitfield<17, 12> { };
struct Bits_2 : Bitfield<1, 3> { };
};
struct My_bitset_2 : Bitset_2<Reg_1::Bits_0, Reg_0> { };
struct My_bitset_3 : Bitset_3<Reg_0, Reg_2::Bits_1, Reg_2::Bits_0> { };
struct My_bitset_4 : Bitset_2<My_bitset_2, Reg_2::Bits_0> { };
struct My_bitset_5 : Bitset_3<Reg_1::Bits_2, Reg_2::Bits_2, Reg_1::Bits_1> { };
};
@ -467,6 +470,13 @@ int main()
if (mmio.read<Test_mmio::My_bitset_4>() != 0x5679)
return test_failed(19);
/**
* Test 20, bitfield methods of bitsets
*/
if (Test_mmio::My_bitset_5::bits(0b110010110) != 0b1100000010001010) {
return test_failed(20);
}
printf("Test done\n");
return 0;
}