1 /* 2 * (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com> 3 * 4 * This file is part of TUD:OS and distributed under the terms of the 5 * GNU General Public License 2. 6 * Please see the COPYING-GPL-2 file for details. 7 */ 8 #pragma once 9 10 #include "hw_register_block.h" 11 12 namespace Hw { 13 14 class Mmio_register_block_base 15 { 16 private: 17 l4_addr_t _base; 18 l4_addr_t _shift; 19 20 public: 21 explicit Mmio_register_block_base(l4_addr_t base = 0, l4_addr_t shift = 0) 22 : _base(base), _shift(shift) {} 23 24 template< typename T > 25 T read(l4_addr_t reg) const 26 { return *reinterpret_cast<volatile const T *>(_base + (reg << _shift)); } 27 28 template< typename T > 29 void write(T value, l4_addr_t reg) const 30 { *reinterpret_cast<volatile T *>(_base + (reg << _shift)) = value; } 31 32 void set_base(l4_addr_t base) { _base = base; } 33 void set_shift(l4_addr_t shift) { _shift = shift; } 34 }; 35 36 template< unsigned MAX_BITS = 32 > 37 struct Mmio_register_block : 38 Register_block_impl<Mmio_register_block<MAX_BITS>, MAX_BITS>, 39 Mmio_register_block_base 40 { 41 explicit Mmio_register_block(l4_addr_t base = 0, l4_addr_t shift = 0) 42 : Mmio_register_block_base(base, shift) {} 43 }; 44 45 } 46 47