Client Class Reference

yasimavr: TWI::Client Class Reference
yasimavr
Loading...
Searching...
No Matches

Base abstract definition for a TWI client. This class implements the basic state machine to interface a TWI bus as a client. It is design to be controlled by a upper layer object (a controller). The interface notifies the controller of bus events (start, address, etc) via the signals and the controller shall use the API of this class to react accordingly. More...

#include <sim_twi.h>

Inheritance diagram for TWI::Client:
TWI::EndPoint CycleTimer ArchAVR_TWI::_Client ArchXT_TWI::_Client

Public Types

enum  State {
  State_Disabled = 0 , State_Idle , State_Start , State_AddressRx ,
  State_AddressRAck , State_AddressWAck , State_DataTx , State_DataTxAck ,
  State_DataRx , State_DataRxAck , State_Count
}
 

Public Member Functions

 Client ()
 
void init (CycleManager &cycle_manager)
 
State state () const
 
void set_enabled (bool enabled)
 
bool enabled () const
 
void reset ()
 
bool active () const
 
bool clock_hold () const
 
unsigned char rw () const
 
bool ack () const
 
bool set_ack (bool ack)
 
bool start_data_tx (uint8_t data)
 
bool start_data_rx ()
 
Signalsignal ()
 
virtual cycle_count_t next (cycle_count_t when) override
 Callback from the cycle loop.
 
- Public Member Functions inherited from TWI::EndPoint
 EndPoint ()
 
virtual ~EndPoint ()=default
 
void line_state_changed (TWI::Line line, bool dig_state)
 
bool get_clock_drive () const
 
bool get_data_drive () const
 
- Public Member Functions inherited from CycleTimer
 CycleTimer ()
 
 CycleTimer (const CycleTimer &other)
 
virtual ~CycleTimer ()
 
bool scheduled () const
 Returns true if this timer is scheduled with a manager.
 
bool paused () const
 
cycle_count_t remaining_delay () const
 
CycleTimeroperator= (const CycleTimer &other)
 

Protected Member Functions

virtual void clock_level_changed (bool level) override
 
virtual void data_level_changed (bool level) override
 
- Protected Member Functions inherited from TWI::EndPoint
virtual void set_line_state (TWI::Line line, bool dig_state)=0
 
void set_clock_drive (bool level)
 
bool get_clock_level () const
 
void set_data_drive (bool level)
 
bool get_data_level () const
 

Detailed Description

Base abstract definition for a TWI client. This class implements the basic state machine to interface a TWI bus as a client. It is design to be controlled by a upper layer object (a controller). The interface notifies the controller of bus events (start, address, etc) via the signals and the controller shall use the API of this class to react accordingly.

See also
TWI, EndPoint, Host

Member Enumeration Documentation

◆ State

Enumerator
State_Disabled 

Client disabled

State_Idle 

Client idle

State_Start 

Receiving a Start condition.

State_AddressRx 

Receving a Address/RW byte.

State_AddressRAck 

Pending/transmitting a ACK/NACK for a read request.

State_AddressWAck 

Pending/transmitting a ACK/NACK for a Write request.

State_DataTx 

Read request ACKed, in TX mode, pending/transmitting data.

State_DataTxAck 

Data sent, receiving ACK bit from the host.

State_DataRx 

Write request ACKed, in RX mode, pending/receiving data.

State_DataRxAck 

Data received, pending/sending ACK bit.

State_Count 

Total number of states.

Constructor & Destructor Documentation

◆ Client()

Client::Client ( )

Member Function Documentation

◆ ack()

bool TWI::Client::ack ( ) const
inline

Returns the latest state of the ACK bit, either sent by this client, or received by the host, after an address or a data byte.

Returns
true for ACK, false for NACK

◆ active()

bool Client::active ( ) const

Returns whether the interface is currently active, i.e. participating in bus traffic. For a client, it means it has positively acknowledged the address byte.

◆ clock_hold()

bool Client::clock_hold ( ) const

Returns whether the client is currently holding the clock line.

◆ clock_level_changed()

void Client::clock_level_changed ( bool  level)
overrideprotectedvirtual

Implements TWI::EndPoint.

◆ data_level_changed()

void Client::data_level_changed ( bool  level)
overrideprotectedvirtual

Implements TWI::EndPoint.

◆ enabled()

bool TWI::Client::enabled ( ) const
inline

Returns true if the client is enabled, false if disabled.

◆ init()

void Client::init ( CycleManager manager)

Initialisation of the interface, must be called before any operation.

◆ next()

cycle_count_t Client::next ( cycle_count_t  when)
overridevirtual

Callback from the cycle loop.

Note
there's no guarantee the method will be called exactly on the required 'when' cycle. The only guarantee is "called 'when' <= 'current cycle'", the implementations must account for this.
Parameters
whencurrent 'when' cycle, at which the timer was scheduled
Returns
the next 'when' the timer requires to be called at.
Note
The next 'when' can be in the 'past' (i.e. <= 'current cycle'). In this case, the timer will be called again within the same cycle with the given next 'when'. The only constraint is that it must be greater than the previous 'when'. If it's negative or zero, the timer is removed from the queue.

Implements CycleTimer.

◆ reset()

void Client::reset ( )

Reset the interface to the Idle state. No-op if the interface is disabled.

◆ rw()

unsigned char Client::rw ( ) const

Returns the direction of the current request, depending on the latest RW bit received.

Returns
1 for a Read Request, 0 for a Write Request

◆ set_ack()

bool Client::set_ack ( bool  ack)

Set the ack reply, after either an address or a data byte has been received.

Parameters
acktrue for ACK, false for NACK
Returns
true if the call was 'legal' i.e. the host was waiting for a ACK, false otherwise

◆ set_enabled()

void Client::set_enabled ( bool  enabled)

Enable/disable the interface.

◆ signal()

Signal & TWI::Client::signal ( )
inline

Getter for the client signal.

◆ start_data_rx()

bool Client::start_data_rx ( )

Start receiving a data byte, in response to a Write Request.

Returns
true if the call was 'legal', false otherwise

◆ start_data_tx()

bool Client::start_data_tx ( uint8_t  data)

Start transmitting a data byte, in response to a Read Request.

Parameters
databyte to be transmitted
Returns
true if the call was 'legal', false otherwise

◆ state()

Client::State TWI::Client::state ( ) const
inline

Getter for the state of the client.


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