- A Logic Circuit Simulation Library in C++ |
#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 form a wider composite 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 three member functions Bus::lock
, Bus::unLock
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, unsigned int delay=0) |
void | unLock (Module *mod) |
bool | isLocked (void) |
Bus< bits >::LineAccessor | getLineAccessor (Module *mod) |
template<int w> | |
const Bus< w > | partSelect (int s) const |
template<unsigned int delay, int exBits, ExprType Type, typename LExprType, typename RExprType> | |
void | cass (const Expression< exBits, Type, LExprType, RExprType > &expr) |
template<unsigned int delay, int width> | |
void | cass (const InputBus< width > &b) |
template<int w> | |
const Bus< w+bits > | operator, (const Bus< w > &bus) const |
template<int w> | |
const InputBus< w+bits > | operator, (const InputBus< w > &bus) const |
const Bus< bits+1 > | operator, (const Line &line) const |
Private Member Functions | |
void | notify (Module *mod, const LineEvent &event, const int &portId, const int &line=-1) throw (OutOfRangeException<int>) |
void | stopNotification (Module *mod, const LineEvent &event, const int &portId, const int &line=-1) throw (OutOfRangeException<int>) |
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 than the bus width, then they are ignored.
val | The decimal integer with which the bus lines have to be initialised. |
void lcs::Bus< bits >::cass | ( | const InputBus< width > & | b | ) |
A template function to assign a continuous assignment to the bus from an lcs::InputBus
object. The template parameter width
is deduced from the width of the lcs::InputBus
object passed as an argument to the function. Hence, a call to this function will have to explicitly specify a single parameter which indicates the assignment delay.
void lcs::Bus< bits >::cass | ( | const Expression< exBits, Type, LExprType, RExprType > & | expr | ) |
A template function to assign a continuous assignment expression to the bus. All template parameters except the parameter delay
are deduced from the expression passed as an argument to the function. Hence, a call to this function will have to explicitly specify a single parameter which indicates the assignment delay.
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 bus write access only to that module which is driving the bus. This sort of control is achieved by using this function in conjuction with the Bus::lock
function. The lcs::Bus::lock
function locks a lcs::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 (lcs::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
virtual member functions. 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 lcs::Bus::lock
, lcs::Bus::unLock
, lcs::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 bus line write access only to 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 a lcs::Module
derivative, then a warning is issued about a possible short circuit when an other module tries to lock the same bus.
Apart from locking the bus, one can also use this function to set the assignment delay associated with the bus. The assignment delays can be used to simulate input to output propogation delays involved with modules.
This function should typically be used by module implementers in the constructors of their lcs::Module
derivatives. Other users will never need to use this function.
See Bus::getLineAccessor
and LineAccessor
for more information.
mod | Pointer to an object which is a lcs::Module derivative. The bus will be locked with write access only to this object. | |
delay | The assignment delay associated with the line in system time units. |
void lcs::Bus< bits >::notify | ( | Module * | mod, | |
const LineEvent & | event, | |||
const int & | portId, | |||
const int & | line = -1 | |||
) | throw (OutOfRangeException<int>) [inline, private] |
Does nothing. This function is inherited from InputBus
. However, it has been declared private so that a lcs::Module derivative is prevented from using a lcs::Bus
object to register to drive a module.
Reimplemented from lcs::InputBus< bits >.
The overloaded operator to join a data line to a bus to form a new composite bus. The line to be joined will have to be the right operand. The joined line takes the MSB location in the resulting lcs::Bus
object.
line | The right operand lcs::Line object. |
Reimplemented from lcs::InputBus< bits >.
const InputBus< w+bits > lcs::Bus< bits >::operator, | ( | const InputBus< 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 of the new InputBus
object.
bits | The width of the left-operand bus | |
w | The width of the right operand bus | |
bus | The right operand Bus 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 composite bus. 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 lcs::Bus object. |
Returns a part-bus formed from a set of consecutive lines of the original lcs::Bus
object. If s+w
goes beyond the range of the original bus width, then, only the lines within range are assigned lines of the new bus object.
w | The width of the part-bus. | |
s | The start bit from where the part-bus should be accumulated. |
Reimplemented from lcs::InputBus< bits >.
void lcs::Bus< bits >::stopNotification | ( | Module * | mod, | |
const LineEvent & | event, | |||
const int & | portId, | |||
const int & | line = -1 | |||
) | throw (OutOfRangeException<int>) [inline, private] |
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 the bus from a module. If a module does not intend to drive a bus anymore, it can (ideally should) 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 tries to unlock a bus which has been locked by another module.
This function should typically be used by module implementers in the destructors of their lcs::Module
derivatives. Other users will never need to use this function.
See lcs::Bus::lock
for more information.
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.
Reimplemented from lcs::InputBus< bits >.