Wire Class Reference

yasimavr: Wire Class Reference
yasimavr
Loading...
Searching...
No Matches

General Purpose wire model. More...

#include <sim_wire.h>

Inheritance diagram for Wire:
Pin

Classes

class  state_t
 

Public Types

enum  StateEnum {
  State_Floating = 0x00 , State_PullUp = 0x03 , State_PullDown = 0x01 , State_Analog = 0x04 ,
  State_High = 0x07 , State_Low = 0x05 , State_Shorted = 0x80 , State_Error = 0x90
}
 
enum  SignalId { Signal_StateChange = 0 , Signal_DigitalChange , Signal_VoltageChange }
 

Public Member Functions

 Wire ()
 
 Wire (Wire &other)
 
 Wire (const Wire &other)
 
virtual ~Wire ()
 
DataSignalsignal ()
 
const state_tstate () const
 
bool digital_state () const
 
double voltage () const
 
void set_state (const state_t &state)
 
void set_state (StateEnum state, double v=0.0)
 
void set_state (char state, double v=0.0)
 
void attach (Wire &other)
 
void detach ()
 
bool attached (const Wire &other) const
 
bool attached () const
 
std::vector< Wire * > siblings () const
 
Wireoperator= (Wire &other)
 
Wireoperator= (const Wire &other)
 

Static Public Member Functions

static StateEnum char2state (char c)
 
static state_t resolve_two_states (const state_t &a, const state_t &b)
 

Protected Member Functions

void auto_resolve_state ()
 
virtual void notify_digital_state (bool state)
 
virtual state_t state_for_resolution () const
 

Detailed Description

General Purpose wire model.

This class models a logical line used to represents digital/analog electrical signals. Its main purpose is to serve as base class for the MCU pin models and can be used by external component models to simulate digital or analog signals connected to a MCU model.

Wires need to be attached to each other. An attachment represents an electrical connection between two input and/or output circuits. Wires have a individual state (one of the State enum values) representing how the local circuit is driving them (or not driving) and a resolved state, shared by all attached Wires representing the common state.

For example, if Wires A and B are attached, A's state is Floating, B's state is High, the common resolved state is High.

As for the rest of the library, analog voltage levels are relative to VCC, hence limited to the range [0.0, 1.0].

See also
Pin

Member Enumeration Documentation

◆ SignalId

Signal IDs raised by the pin. For all signals, the index is set to the pin ID.

Enumerator
Signal_StateChange 

Signal raised for any change of the resolved state. data is set to the new state (one of State enum values)

Signal_DigitalChange 

Signal raised for any change of the resolved digital state. data is set to the new digital state (0 or 1).

Signal_VoltageChange 

Signal raised for any change to the analog value, including when induced by a digital state change. data is set to the analog value (double, in range [0;1])

◆ StateEnum

Pin state enum. All the possible logical/analog electrical states that the wire can take.

Enumerator
State_Floating 
State_PullUp 
State_PullDown 
State_Analog 
State_High 
State_Low 
State_Shorted 
State_Error 

Constructor & Destructor Documentation

◆ Wire() [1/3]

Wire::Wire ( )

Build a Wire.

◆ Wire() [2/3]

Wire::Wire ( Wire other)

Build a Wire by copy and attach to another Wire.

◆ Wire() [3/3]

Wire::Wire ( const Wire other)

Build a Wire by copy. The new instance is not attached to the other Wire.

◆ ~Wire()

Wire::~Wire ( )
virtual

Member Function Documentation

◆ attach()

void Wire::attach ( Wire other)

Attach another Wire.

Note
if a and b are standalone Wire objects (i.e. not already attached), "a.attach(b)" and "b.attach(a)" have the same functional result. If a or b are already attached to other Wire objects, the effect is essentially to merge both groups of Wire objects.

◆ attached() [1/2]

bool Wire::attached ( ) const
Returns
whether 'this' is attached to any other Wire object.

◆ attached() [2/2]

bool Wire::attached ( const Wire other) const
Returns
whether 'this' is attached to the other Wire object.

◆ auto_resolve_state()

void Wire::auto_resolve_state ( )
protected

◆ char2state()

Wire::StateEnum Wire::char2state ( char  c)
static

Converts an ASCII charcode into a wire state enum value :

  • 'Z'/'z' : Floating
  • 'H'/'h' : High
  • 'L'/'l' : Low
  • 'U'/'u' : PullUp
  • 'D'/'d' : PullDown
  • 'A'/'a' : Analog
  • 'S'/'s' : Shorted
  • any other value : Error

◆ detach()

void Wire::detach ( )

Detach from all Wire 'this' is attached to.

◆ digital_state()

bool Wire::digital_state ( ) const

Returns the resolved state reduced to a boolean.

◆ notify_digital_state()

void Wire::notify_digital_state ( bool  state)
protectedvirtual

◆ operator=() [1/2]

Wire & Wire::operator= ( const Wire other)

Copy assignment without attachment

◆ operator=() [2/2]

Wire & Wire::operator= ( Wire other)

Copy assignment with attachment

◆ resolve_two_states()

Wire::state_t Wire::resolve_two_states ( const state_t a,
const state_t b 
)
static

Resolution algorithm for combining two state_t structures representing the logical state of two Wires attached together and returning the common resolved state.

◆ set_state() [1/3]

void Wire::set_state ( char  state,
double  level = 0.0 
)
inline

Set the state of the wire using a charcode

See also
char2state
Parameters
statenew Wire state
levelvoltage level (only for the Analog state)

◆ set_state() [2/3]

void Wire::set_state ( const state_t state)

Set the state of the Wire.

◆ set_state() [3/3]

void Wire::set_state ( StateEnum  state,
double  level = 0.0 
)
inline

Set the state of the wire using one of the StateEnum values

Parameters
statenew Wire state
levelvoltage level (only for the Analog state)

◆ siblings()

std::vector< Wire * > Wire::siblings ( ) const

Return all Wire objects 'this' is attached to. The returned vector also contains 'this'.

If a and b are Wire objects attached to each other, "a.siblings()" and "b.siblings()" will return the same result, albeit possibly in a different order.

◆ signal()

DataSignal & Wire::signal ( )
inline
Returns
the signal raising the state/value changes

◆ state()

const Wire::state_t & Wire::state ( ) const
inline
Returns
the resolved state

◆ state_for_resolution()

Wire::state_t Wire::state_for_resolution ( ) const
protectedvirtual

◆ voltage()

double Wire::voltage ( ) const
inline
Returns
the pin voltage value

The documentation for this class was generated from the following files: