#include <bus.h>
Inheritance diagram for lcs::Bus< bits >:
Bus
object is achieved through the lcs::InputBus::operator[]
function. There are overloaded operators provided which can be used to join two busses to result in a wider bus, or join a line to a bus.
Writing to bus lines should only be allowed for a module which is driving the bus. This sort of access control is provided through the inner class LineAccessor
, and the two member functions Bus::lock
and Bus::getLineAccessor
.
bits | The number of data lines in the bus. |
Public Member Functions | |
Bus (void) | |
Bus (int val) | |
Bus (const Bus< bits > &bus) | |
virtual | ~Bus () |
void | lock (Module *mod) |
void | unLock (Module *mod) |
bool | isLocked (void) |
Bus< bits >::LineAccessor | getLineAccessor (Module *mod) |
template<int w> | |
const Bus< w > | partBus (unsigned int s) |
template<int w> | |
const Bus< w+bits > | operator * (const Bus< w > &bus) const |
const Bus< bits+1 > | operator * (const Line &line) const |
Private Member Functions | |
void | drive (Module *mod) |
void | unDrive (Module *mod) |
Friends | |
class | Bus |
Classes | |
class | LineAccessor |
The default constructor. The data lines are all initialised to the lcs::UNKNOWN
state.
Line initialising constructor. The bus lines are initialised in the little-endian notation with the binary equivalent of a decimal integer. If the integer has excess bits, then they are ignored.
val | The decimal integer with which the bus lines have to be initialised. |
Does nothing. This function is inherited from InputBus
. However, it has been declared private so that the user is prevented from using a Bus
object to register to drive a module.
Reimplemented from lcs::InputBus< bits >.
Bus< bits >::LineAccessor lcs::Bus< bits >::getLineAccessor | ( | Module * | mod | ) |
Returns a LineAccessor
object which can be used for writing on to the bus lines. See the LineAccessor
documentation for more information on using a LineAccessor
object.
To map reality into software, there should be mechanism which provides write-access on to a Bus
object to only one module which is driving the bus. This sort of control is achieved by using this function in conjuction with the Bus::lock
function. The Bus::lock
function locks a Bus
object from being written on to by modules other than the one which has locked it. If a module which has locked the bus requests for a LineAccessor
through this function (Bus::getLineAccessor
), a valid LineAccessor
object is returned. Otherwise, an invalid LineAccessor
object is returned, which will lead to an occurrance of an exception when the bus lines are accessed through it.
Typically, this function should only be used by module implementors while over-riding the lcs::Module::propogate
function. Other users should use this function only if they are sure of what they are doing.
NOTE: A LineAccessor
object should only be used if one needs to write on to the bus lines. Reading the bus lines is available through the function lcs::InputBus::operator[]
. A user who is not implementing his/her own module should never need to use a LineAccessor
object.
mod | Pointer to the lcs::Module object which has locked the Bus object using the Bus::lock function. |
bool lcs::Bus< bits >::isLocked | ( | void | ) |
Returns true if the bus is locked by some module. False if not.
See the functions Bus::lock
, Bus::unLock
, Bus::getLineAccessor
for more information on locking and un-locking busses.
Locks a Bus
object with the module mod
. Locking a bus with a module will provide write access to the bus object only for that module. Other modules trying to write on to the bus will cause a short circuit (which in software is equivalent to an occurrance of an exception). If a bus has been locked previously by an lcs::Module
object, then a warning is issued about a possible short circuit when another module tries to lock the same bus. See Bus::getLineAccessor
and LineAccessor
for more information.
This function should typically be used by module implementors in the constructors of their lcs::Module
derivatives. Other users will never need to use this function.
mod | Pointer to the lcs::Module object to which the bus should be locked. |
The overloaded operator to join a data line to a bus to form a new bus. The line to be joined will have to be the right operand. The joined line takes the MSB location in the resulting Bus
object.
line | The right operand lcs::Line object. |
Reimplemented from lcs::InputBus< bits >.
const Bus< w+bits > lcs::Bus< bits >::operator * | ( | const Bus< w > & | bus | ) | const |
The overloaded operator to join data lines from two busses and form a new bus from these. The right operand bus takes the MSB locations.
bits | The width of the left-operand bus | |
w | The width of the right operand bus | |
bus | The right operand Bus object. |
Returns a part-bus formed from a set of consecutive lines of the original Bus
object. If s+w
goes beyond the range of the original bus width, then only the lines within the range in the new bus are assigned lines from the original bus.
w | The width of the part-bus. | |
s | The start bit from where the part-bus should be accumulated. |
Does nothing. This function is inherited from InputBus
. However, it has been declared private so that the user is prevented from using a Bus
object to de-register to drive (or un-drive) a module.
Reimplemented from lcs::InputBus< bits >.
Un-locks a the bus from a module. If a module does not intend to drive a bus anymore, it can unlock, or free, the bus for use by some other module. A call to this function does nothing if the bus is not locked by a module. Nothing is done even when a module which has not locked the bus tries to unlock.
See Bus::lock
for more information.
This function should typically be used by module implementors in the destrcutors of their lcs::Module
derivatives. Other users will never need to use this function.
mod | Pointer to the module object which wants to unlock/free the bus. |
friend class Bus [friend] |
Bus classes of different sizes are friends of each other.