Landfall

Annotated pkg/devices/lib/common/include/hw_mmio_register_block.h

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