Line states can be set only for lcs::Bus
objects. lcs::InputBus
objects are readonly busses. Moreover, setting the line states of an lcs::Bus
object is provided through a locking mechanism. Such a mechanism is provided so that two lcs::Module
derivates do not end up setting the line states of the same bus un-noticed. In reality, a short-circuit occurs if two modules drive the same bus. The locking mechanism detects such a short-circuit (which in software occurs if one single bus is assigned to the output of two different modules) and warns the user. Moreover, because of such a locking mechanism, bus lines can only be set by a module which is a derivative of the lcs::Module
class and has locked the bus. Hence, this topic guide is usefull only for module implementers. Other users will never need to set bus lines.
A module desirous of driving a bus should lock the bus. Once locked, only the module which locked the bus can un-lock it. Locking and un-locking are done using the lcs::Bus::lock
and lcs::Bus::unLock
functions. A warning message is displayed if a module tries to lock a bus which has already been locked by another module. Moreover, if a module tries to set the lines of bus which has been locked by another module, then a lcs::ShortCircuitException
is thrown following a warning message.
Unlocking a bus is neccessary as it then allows other modules to lock the bus and set its lines. Typically, the output busses of a module should be locked by the constructor of the module class by passing the this
argument to the lock
function of the output busses. Similarly, the same output busses should be un-locked by the destructor of the module class by passing the this
argument to the unLock
function of the output busses.
A module which has successfully locked a bus can set the lines of the bus through the class lcs::Bus::LineAccessor
. The LineAccessor
object corresponding to a particular bus can be obtained from the lcs::Bus::getLineAccessor
function of the bus. The bus lines can then be set using the overloaded operator[]
of the LineAccessor
object. A LineAccessor
object is typically used when over-riding the function lcs::Module::propogate
. A detailed example of using the functions lcs::Bus::lock
, lcs::Bus::unLock
, lcs::Bus::getLineAccessor
, and the class lcs::Bus::LineAccessor
can be found here. These functions and the LineAccessor
class will typically have to the used in the implemention of functional realisations of circuit modules as in the case of the 1-bit full-adder module in that example.