- A Logic Circuit Simulation Library in C++





lcs::Bus< bits > Class Template Reference

#include <bus.h>

Inheritance diagram for lcs::Bus< bits >:

lcs::InputBus< bits > List of all members.

Detailed Description

template<int bits = 1>
class lcs::Bus< bits >

This is a class encapsulating a set of data lines to be used as a generic bus in logic circuit systems. The data lines are conceptially organised in the little endian format. A user can set the bus line data through access control mechanism. Reading the individual data lines of a 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.

Parameters:
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 > partBus (unsigned int s)
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


Constructor & Destructor Documentation

template<int bits>
lcs::Bus< bits >::Bus ( void   ) 

The default constructor. The data lines are all initialised to the lcs::UNKNOWN state.

template<int bits>
lcs::Bus< bits >::Bus ( int  val  ) 

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.

Parameters:
val The decimal integer with which the bus lines have to be initialised.

template<int bits>
lcs::Bus< bits >::Bus ( const Bus< bits > &  bus  ) 

Copy constructor. Performs only a shallow copy. The new Bus object and bus share the same set of lines.

Parameters:
bus The Bus object whose lines are used to create a new Bus object.

template<int bits>
lcs::Bus< bits >::~Bus (  )  [virtual]

Destructor.


Member Function Documentation

template<int 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 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.

Parameters:
mod Pointer to the lcs::Module object which has locked the Bus object using the Bus::lock function.

template<int bits>
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.

template<int bits>
void lcs::Bus< bits >::lock ( Module mod,
unsigned int  delay = 0 
)

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.

Parameters:
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.

template<int bits = 1>
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 >.

template<int bits>
const Bus< bits+1 > lcs::Bus< bits >::operator, ( const Line line  )  const

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.

Parameters:
line The right operand lcs::Line object.

Reimplemented from lcs::InputBus< bits >.

template<int bits>
template<int w>
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.

Parameters:
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 >.

template<int bits>
template<int w>
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.

Parameters:
bits The width of the left-operand bus
w The width of the right operand bus
bus The right operand lcs::Bus object.

template<int bits>
template<int w>
const Bus< w > lcs::Bus< bits >::partBus ( unsigned int  s  ) 

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.

Parameters:
w The width of the part-bus.
s The start bit from where the part-bus should be accumulated.

template<int bits = 1>
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 >.

template<int bits>
void lcs::Bus< bits >::unLock ( Module mod  ) 

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.

Parameters:
mod Pointer to the module object which wants to unlock/free the bus.


Friends And Related Function Documentation

template<int bits = 1>
friend class Bus [friend]

Bus classes of different sizes are friends of each other.

Reimplemented from lcs::InputBus< bits >.


Copyright © 2006, 2007 Siva Chandra