24#ifndef __YASIMAVR_TWI_H__
25#define __YASIMAVR_TWI_H__
27#include "../core/sim_signal.h"
28#include "../core/sim_cycle_timer.h"
66#define AVR_CTLREQ_TWI_BUS_ERROR (AVR_CTLREQ_BASE + 1)
207 void line_state_changed(
TWI::Line line,
bool dig_state);
209 bool get_clock_drive()
const;
210 bool get_data_drive()
const;
218 void set_clock_drive(
bool level);
219 bool get_clock_level()
const;
220 void set_data_drive(
bool level);
221 bool get_data_level()
const;
235 return m_clock_drive;
240 return m_clock_level;
301 void set_enabled(
bool enabled);
302 bool enabled()
const;
307 bool clock_hold()
const;
308 unsigned char rw()
const;
311 bool set_ack(
bool ack);
312 bool start_data_tx(uint8_t data);
313 bool start_data_rx();
321 virtual void clock_level_changed(
bool level)
override;
322 virtual void data_level_changed(
bool level)
override;
332 int m_deferred_drive;
335 void set_state(State state);
336 void defer_clock_release();
337 void defer_data_drive(
bool level);
427 void set_enabled(
bool enabled);
428 bool enabled()
const;
434 bool bus_busy()
const;
436 bool clock_hold()
const;
437 bool clock_stretched()
const;
438 unsigned char rw()
const;
441 bool start_transfer();
442 bool set_address(uint8_t addr_rw);
443 bool start_data_tx(uint8_t data);
444 bool start_data_rx();
445 bool set_ack(
bool ack);
446 bool stop_transfer();
454 virtual void clock_level_changed(
bool level)
override;
455 virtual void data_level_changed(
bool level)
override;
472 void set_state(State state);
473 void apply_pattern();
474 void process_state_and_reschedule();
475 bool process_state(
bool inc_step);
476 void transition_state();
512 return m_addr_rw & 0x01;
Definition sim_cycle_timer.h:134
Definition sim_cycle_timer.h:41
Signalling framework class.
Definition sim_signal.h:97
Base abstract definition for a TWI client. This class implements the basic state machine to interface...
Definition sim_twi.h:265
Signal & signal()
Definition sim_twi.h:370
bool enabled() const
Definition sim_twi.h:352
bool ack() const
Definition sim_twi.h:362
State state() const
Definition sim_twi.h:344
State
Definition sim_twi.h:269
@ State_Disabled
Client disabled
Definition sim_twi.h:271
@ State_DataRxAck
Data received, pending/sending ACK bit.
Definition sim_twi.h:289
@ State_DataTx
Read request ACKed, in TX mode, pending/transmitting data.
Definition sim_twi.h:283
@ State_AddressWAck
Pending/transmitting a ACK/NACK for a Write request.
Definition sim_twi.h:281
@ State_DataTxAck
Data sent, receiving ACK bit from the host.
Definition sim_twi.h:285
@ State_DataRx
Write request ACKed, in RX mode, pending/receiving data.
Definition sim_twi.h:287
@ State_AddressRx
Receving a Address/RW byte.
Definition sim_twi.h:277
@ State_Idle
Client idle
Definition sim_twi.h:273
@ State_AddressRAck
Pending/transmitting a ACK/NACK for a read request.
Definition sim_twi.h:279
@ State_Start
Receiving a Start condition.
Definition sim_twi.h:275
@ State_Count
Total number of states.
Definition sim_twi.h:292
An endpoint connected to a TWI bus. Represents a device connected to a TWI bus model and implements t...
Definition sim_twi.h:200
bool get_data_level() const
Definition sim_twi.h:248
virtual ~EndPoint()=default
bool get_data_drive() const
Definition sim_twi.h:243
bool get_clock_drive() const
Definition sim_twi.h:233
virtual void data_level_changed(bool level)=0
bool get_clock_level() const
Definition sim_twi.h:238
virtual void clock_level_changed(bool level)=0
virtual void set_line_state(TWI::Line line, bool dig_state)=0
Base abstract definition for a TWI host. This class implements the basic state machine to interface a...
Definition sim_twi.h:387
State state() const
Definition sim_twi.h:491
bool clock_hold() const
Definition sim_twi.h:518
State
Definition sim_twi.h:391
@ State_Disabled
Host disabled
Definition sim_twi.h:393
@ State_Idle
Host idle
Definition sim_twi.h:395
@ State_DataRxAck
Sending a ACK/NACK bit after receiving a data byte.
Definition sim_twi.h:409
@ State_Start
Sending a START condition.
Definition sim_twi.h:397
@ State_AddressAck
Waiting for a ACK/NACK bit after an address/RW byte.
Definition sim_twi.h:401
@ State_DataRx
Receiving a data byte.
Definition sim_twi.h:407
@ State_Stop
Sending a STOP condition.
Definition sim_twi.h:411
@ State_DataTxAck
Waiting for a ACK/NACK bit after sending a data byte.
Definition sim_twi.h:405
@ State_BusBusy
START condition by another host detected on the bus.
Definition sim_twi.h:413
@ State_DataTx
Sending a data byte.
Definition sim_twi.h:403
@ State_ArbLost
Arbitration lost.
Definition sim_twi.h:415
@ State_AddressTx
Sending an address/RW byte.
Definition sim_twi.h:399
Signal & signal()
Definition sim_twi.h:526
unsigned char rw() const
Definition sim_twi.h:510
bool enabled() const
Definition sim_twi.h:483
bool ack() const
Definition sim_twi.h:501
Common enums and signal definitions for TWI classes.
Definition sim_twi.h:79
BusState
Definition sim_twi.h:94
@ Bus_Idle
The bus is not in use.
Definition sim_twi.h:96
@ Bus_Owned
The current interface (host only) owns the bus.
Definition sim_twi.h:100
@ Bus_Busy
The bus is busy and owned by a host different from the current interface.
Definition sim_twi.h:98
SignalId
Definition sim_twi.h:106
@ Signal_ArbitrationLost
Definition sim_twi.h:176
@ Signal_BusStateChanged
Definition sim_twi.h:118
@ Signal_DataAckReceived
Definition sim_twi.h:159
@ Signal_AddressReceived
Definition sim_twi.h:143
@ Signal_Stop
Definition sim_twi.h:189
@ Signal_DataSent
Definition sim_twi.h:153
@ Signal_Start
Definition sim_twi.h:125
@ Signal_StateChanged
Definition sim_twi.h:111
@ Signal_AddressSent
Definition sim_twi.h:137
@ Signal_AddressStandby
Definition sim_twi.h:131
@ Signal_DataStandby
Definition sim_twi.h:148
@ Signal_DataAckSent
Definition sim_twi.h:170
@ Signal_BusCollision
Definition sim_twi.h:181
@ Signal_DataReceived
Definition sim_twi.h:165
Line
Definition sim_twi.h:84
@ Line_Clock
Index for the SCL line.
Definition sim_twi.h:86
@ Line_Data
Index for the SDA line.
Definition sim_twi.h:88
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define AVR_CORE_PUBLIC_API
Definition sim_globals.h:46
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
YASIMAVR_BEGIN_NAMESPACE typedef long long cycle_count_t
Definition sim_types.h:40