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>
|
| 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
} |
| |
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
◆ 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.
|
◆ Client()
◆ 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 |
◆ data_level_changed()
| void Client::data_level_changed |
( |
bool |
level | ) |
|
|
overrideprotectedvirtual |
◆ enabled()
| bool TWI::Client::enabled |
( |
| ) |
const |
|
inline |
Returns true if the client is enabled, false if disabled.
◆ init()
Initialisation of the interface, must be called before any operation.
◆ next()
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
-
| when | current '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()
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
-
| ack | true 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
-
| data | byte to be transmitted |
- Returns
- true if the call was 'legal', false otherwise
◆ state()
Getter for the state of the client.
The documentation for this class was generated from the following files: