class Fusb302Protocol

Defined at line 117 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

FUSB302-specific implementation of the USB PD Protocol Layer.

The FUSB302 hardware can take on some aspects of the PD Protocol Layer. This

class is responsible for a complete implementation, while delegating some

parts to hardware.

Receiving messages works as follows:

* The hardware control logic is responsible for calling DrainReceiveFifo()

when the hardware signals that its receive FIFO is not empty.

* The USB PD implementation uses HasUnreadMessage() and FirstUnreadMessage()

to process received messages. MarkMessageAsRead() must be called after a

message is processed, before transmitting any reply to the message.

* The hardware control logic is responsible for calling

DidTransmitHardwareGeneratedGoodCrc() when the hardware signals that it

generated and transmitted a GoodCRC reply for a received PD packet.

Transmitting messages works as follows:

* next_transmitted_message_id() produces the MessageID to be used in the

usb_pd::Header constructor for a usb_pd::Message.

* Transmit() drives the hardware to transmit a usb_pd::Message over the PD

connection.

* DrainReceiveFifo(), documented in the reception section above, tracks

the USB PD connection partner's acknowledgement of Transmit() messages.

* The hardware control logic is responsible for calling

DidTimeoutWaitingForGoodCrc() when a message transmitted via Transmit()

is not acknowledged (via GoodCRC) by the other side of the USB PD

connection within the time mandated by the USB PD specification.

The implementation supports 3 integration models with a hardware-accelerated

GoodCRC generation module, which map to the 3 member variables of the

`GoodCrcGenerationMode` enum.

* kSoftware - MarkMessageAsRead() generates a GoodCRC packet for the returned

packet, and drives the hardware to transmit it

* kTracked - DidTransmitHardwareGeneratedGoodCrc() is called when the

hardware generates and transmits a GoodCRC packet; Transmit() queues its

argument for transmission if any previously received packet lacks a GoodCRC

reply; DidTransmitHardwareGeneratedGoodCrc() transmits any queued packet

* kAssumed - GoodCRC generation is completely ignored by the software

implementation

Public Methods

void Fusb302Protocol (GoodCrcGenerationMode good_crc_generation_mode, Fusb302Fifos & fifos)

`fifos` must remain alive throughout the new instance's lifetime.

Defined at line 24 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

zx::result<> MarkMessageAsRead ()

Removes a message from the unread queue. Transmits a GoodCRC if neceesary.

`HasUnreadMessage()` must be true.

Returns an error if an I/O error occurred while transmitting a GoodCRC

acknowledging the read message.

Defined at line 34 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

zx::result<> DrainReceiveFifo ()

Reads any PD messages that may be pending in the Rx (receive) FIFO.

Returns an error if retrieving the PD message from the PHY layer encounters

an I/O error. Otherwise, performs PD Protocol Layer processing (mostly

MessageID validation), and updates (TBD: queue name).

Defined at line 67 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

void Fusb302Protocol (const Fusb302Protocol & )

Defined at line 122 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

Fusb302Protocol & operator= (const Fusb302Protocol & )

Defined at line 123 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

void ~Fusb302Protocol ()

Trivially destructible.

Defined at line 126 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

TransmissionState transmission_state ()

See `TransmissionState` member comments.

Defined at line 129 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

bool HasUnreadMessage ()

True if the unread queue is not empty.

All the messages in the unread queue must be processed and acknowledged via

`MarkMessageAsRead()` before `DrainReceiveFifo()` is called.

Defined at line 135 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

const usb_pd::Message & FirstUnreadMessage ()

Returns the first message in the unread messages queue.

`HasUnreadMessage()` must be true.

Defined at line 140 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

usb_pd::MessageId next_transmitted_message_id ()

Not meaningful while `transmission_state()` is `kPending`.

Defined at line 154 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

void SetGoodCrcTemplate (usb_pd::Header good_crc_template)

The template will be used as-is (modulo MessageID) for GoodCRC messages.

Defined at line 180 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

zx::result<> Transmit (const usb_pd::Message & message)

Transmits a PD message.

`message` must not be a GoodCRC. MarkMessageAsRead() dispatches any

necessary GoodCRC message internally.

`message`'s MessageID header field must equal

`next_transmitted_message_id()`.

Must not be called while `transmission_status()` is `kPending`. This is

because PD messages (with the excepton of GoodCRC) form a synchronous

stream that is blocked on the other side's GoodCRC acknowledgements.

Defined at line 188 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

void FullReset ()

PD protocol layer reset.

This method can be used when a new Type C connection is established, or

right before sending a Soft Reset message.

`DidReceiveSoftReset()` must be called instead of this method when a Soft

Reset message is received, because that situation requires different

initial values for MessageID counters.

Defined at line 211 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

bool UsesHardwareAcceleratedGoodCrcNotifications ()

If false, `DidTransmitHardwareGeneratedGoodCrc()` must never be called.

Defined at line 212 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.h

void DidReceiveSoftReset ()

PD protocol layer reset, used after receiving a Soft Reset packet.

This must only be used for a soft reset initiated by a port partner

message. Incorrect use will result in incorrect initial MessageID values,

which will break future communication.

Defined at line 223 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

void DidTimeoutWaitingForGoodCrc ()

Hardware-side PD protocol layer says it gave up waiting for a GoodCRC.

This signal comes from the interrupt unit.

Defined at line 249 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc

void DidTransmitHardwareGeneratedGoodCrc ()

Hardware-side PD protocol layer says it replied with a GoodCRC message.

This signal comes from the interrupt unit.

Defined at line 258 of file ../../src/devices/power/drivers/fusb302/fusb302-protocol.cc