Code:
#ifndef BITFIELD_HPP_20120215_1257
#define BITFIELD_HPP_20120215_1257
namespace bitfield
{
template<int adr, int bit, typename adr_t> class get_op { public: static bool get() { return *(volatile adr_t*)adr & (1 << (bit - 1)); } };
template<int adr, int bit, typename adr_t> class set_op { public: static void set() { *(volatile adr_t*)adr |= (1 << (bit - 1)); } };
template<int adr, int bit, typename adr_t> class clear_op { public: static void clear() { *(volatile adr_t*)adr &= ~(1 << (bit - 1)); } };
template<int adr, int bit, typename adr_t>
class trio: public get_op<adr, bit, adr_t>, public set_op<adr, bit, adr_t>, public clear_op<adr, bit, adr_t> {};
template<int adr, int bit, typename adr_t>
class clear_get: public get_op<adr, bit, adr_t>, public clear_op<adr, bit, adr_t> {};
template<int adr, int bit, typename adr_t>
class clear_set: public set_op<adr, bit, adr_t>, public clear_op<adr, bit, adr_t> {};
}
#endif /*BITFIELD_HPP_*/
#define FUSION_MAX_VECTOR_SIZE 18
#include <boost/fusion/algorithm.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/container/vector.hpp>
#undef FUSION_MAX_VECTOR_SIZE
namespace io_toggles
{
namespace detail
{
const int data = 0x850;
const int interrupt = 0x858;
const int interrupt_restore = 0x85C;
}
template<int bit>
class toggle
{
public:
class : public bitfield::get_op<detail::data, bit, int> {} status;
class
{
public:
class : public bitfield::trio<detail::interrupt, bit, int> {} status;
class : public bitfield::get_op<detail::interrupt_restore, bit, int> {} restore;
} interrupt;
};
#define TGL(n) toggle<n>
typedef boost::fusion::vector<TGL(1), TGL(2), TGL(3), TGL(4), TGL(5), TGL(6), TGL(7), TGL(8), TGL(9),
TGL(10), TGL(11), TGL(12), TGL(13), TGL(14), TGL(15), TGL(16), TGL(17), TGL(18)> key_t;
#undef TGL
key_t key;
}
struct tmp
{
template<int N>
void operator ()(io_toggles::toggle<N>& elem) const
{
elem.interrupt.status.set();
}
};
extern "C"
{
void init_toggles()
{
boost::fusion::for_each(io_toggles::key, tmp());
}
}