mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-21 08:29:41 +00:00
Complement test for MMIO framework
The run script 'run/util_mmio.run' runs a test over basic functionalities of 'Mmio::Register' and 'Mmio::Register::Subreg'. The test covers the functions 'read' and 'bits', 'set', 'clear' and 'get'. Inline function in 'Mmio::Register::Subreg' whose definition otherwise looks ugly.
This commit is contained in:
committed by
Norman Feske
parent
9329b91aca
commit
01bb7536dd
@ -4,6 +4,13 @@
|
||||
* \date 2011-10-26
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2011-2012 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _BASE__INCLUDE__UTIL__MMIO_H_
|
||||
#define _BASE__INCLUDE__UTIL__MMIO_H_
|
||||
|
||||
@ -87,8 +94,14 @@ namespace Genode
|
||||
* Calculate the MMIO-relative offset 'offset' and shift 'shift'
|
||||
* within the according 'storage_t' value to acces subreg no. 'index'
|
||||
*/
|
||||
inline static void access_dest(off_t & offset, unsigned long & shift,
|
||||
unsigned long const index);
|
||||
static void access_dest(off_t & offset, unsigned long & shift,
|
||||
unsigned long const index)
|
||||
{
|
||||
unsigned long const bit_off = (index+1) * ITERATION_WIDTH - WIDTH;
|
||||
offset = (off_t) ((bit_off / STORAGE_WIDTH) * sizeof(STORAGE_T));
|
||||
shift = bit_off - ( offset << BYTE_EXP );
|
||||
offset += Compound_reg::OFFSET;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -166,20 +179,6 @@ namespace Genode
|
||||
}
|
||||
|
||||
|
||||
template <Genode::off_t OFFSET, typename STORAGE_T>
|
||||
template <unsigned long BIT_SHIFT, unsigned long BIT_SIZE, unsigned long SUBREGS>
|
||||
void
|
||||
Genode::Mmio::Register<OFFSET, STORAGE_T>::Subreg_array<BIT_SHIFT, BIT_SIZE, SUBREGS>::access_dest(Genode::off_t & offset,
|
||||
unsigned long & shift,
|
||||
unsigned long const index)
|
||||
{
|
||||
unsigned long const bit_off = (index+1) * ITERATION_WIDTH - WIDTH;
|
||||
offset = (off_t) ((bit_off / STORAGE_WIDTH) * sizeof(STORAGE_T));
|
||||
shift = bit_off - ( offset << BYTE_EXP );
|
||||
offset += Compound_reg::OFFSET;
|
||||
}
|
||||
|
||||
|
||||
template <typename STORAGE_T>
|
||||
void Genode::Mmio::_write(off_t const o, STORAGE_T const value)
|
||||
{
|
||||
|
@ -4,6 +4,13 @@
|
||||
* \date 2011-11-10
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2011-2012 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _BASE__INCLUDE__UTIL__REGISTER_H_
|
||||
#define _BASE__INCLUDE__UTIL__REGISTER_H_
|
||||
|
||||
@ -37,32 +44,34 @@ namespace Genode
|
||||
typedef Register<storage_t> Compound_reg;
|
||||
|
||||
/**
|
||||
* Get a register value with this subreg set to 'value'
|
||||
* and the rest left zero
|
||||
* Get a register value with this subreg set to 'value' and the rest left zero
|
||||
*
|
||||
* \detail Useful to combine successive access to multiple subregs
|
||||
* into one operation
|
||||
*/
|
||||
static storage_t bits(storage_t const value) { return (value & MASK) << SHIFT; }
|
||||
|
||||
/**
|
||||
* Get value of this subreg from 'reg'
|
||||
*/
|
||||
static storage_t value(storage_t const reg) { return (reg >> SHIFT) & MASK; }
|
||||
static storage_t get(storage_t const reg) { return (reg >> SHIFT) & MASK; }
|
||||
|
||||
/**
|
||||
* Get registervalue 'reg' with this subreg set to zero
|
||||
*/
|
||||
static void clear_bits(storage_t & reg) { reg &= ~(MASK << SHIFT); }
|
||||
static void clear(storage_t & reg) { reg &= ~(MASK << SHIFT); }
|
||||
|
||||
/**
|
||||
* Get registervalue 'reg' with this subreg set to 'value'
|
||||
*/
|
||||
static void set_bits(storage_t & reg, storage_t const value = ~0)
|
||||
static void set(storage_t & reg, storage_t const value = ~0)
|
||||
{
|
||||
clear_bits(reg);
|
||||
clear(reg);
|
||||
reg |= (value & MASK) << SHIFT;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _BASE__INCLUDE__UTIL__CPU_REGISTER_H_ */
|
||||
#endif /* _BASE__INCLUDE__UTIL__REGISTER_H_ */
|
||||
|
||||
|
Reference in New Issue
Block a user