Public Types | |
enum | StreamType { StreamType_Serial , StreamType_Bulk , StreamType_Interrupt , StreamType_Isochronous , StreamType_Control } |
Stream implementations. | |
Public Member Functions | |
USBDevStream (unsigned id, uint32_t num_bytes, bool retrieve, bool check, bool send, bool verbose) | |
void | SetClosing (bool closing) |
Record whether or not the stream is in the process of closing (shutting down or suspending). More... | |
bool | CanSchedule () const |
Indicate whether an additional I/O transfer may safely be scheduled on this stream, eg. More... | |
virtual void | Stop ()=0 |
Finalize the stream, prior to shutting down. | |
virtual void | Pause ()=0 |
Pause the stream, prior to suspending the device. | |
virtual bool | Resume ()=0 |
Resume streaming. | |
unsigned | ID () const |
Return the Stream IDentifier of this stream. | |
std::string | PrefixID () |
Return a Stream IDentifier prefix suitable for logging/reporting. | |
virtual std::string | Report (bool status=false, bool verbose=false) const =0 |
Return a summary report of the stream settings or status. More... | |
void | SetProperties (unsigned id, bool retrieve, bool check, bool send) |
Set Stream IDentifier and flags. | |
virtual bool | Service () |
Service this stream. More... | |
virtual bool | Completed () const |
Indicates whether this stream has completed its transfer. More... | |
uint32_t | TransferBytes () const |
Returns the total number of bytes to be transferred by this stream. More... | |
uint32_t | BytesRecvd () const |
Returns a count of the number of bytes received from the device. More... | |
uint32_t | BytesSent () const |
Returns a count of the number of bytes sent to the device. More... | |
Static Public Member Functions | |
static const char * | StreamTypeName (StreamType type) |
Return the textual name of the given stream type. More... | |
Protected Types | |
enum | sig_state_t { kSigStateStart = 0 , kSigStateCheckHead , kSigStateSkipBody , kSigStateCheckTail , kSigStateReceived } |
States in reception of signature. | |
Protected Member Functions | |
bool | ProvisionSpace (uint8_t **space, uint32_t len) |
Provision the given number of bytes of contiguous space, and optionally a pointer to the start of the free space. More... | |
uint32_t | SpaceAvailable (uint8_t **space) |
Returns the amount of contiguous free space available in the buffer, and optionally a pointer to the start of the free space. More... | |
bool | AddData (const uint8_t *data, uint32_t len) |
Add the specified number of bytes to the circular buffer; if data is NULL then the bytes shall already be present in the buffer and copying is not performed. More... | |
bool | CommitData (uint32_t len) |
Record that the specified number of bytes have been added to the circular buffer. More... | |
void | ClearBuffer () |
CLear the circular buffer by removing all of its contained data bytes. More... | |
void | SigReset () |
Reset the signature detection; Isochronous streams including a new signature at the start of each packet transferred. | |
bool | SigReceived () const |
Has valid signature been received on this stream? Note that there may be some additional validity checks required for specific= transfer types. More... | |
void | SigProcess (const usbdev_stream_sig_t &sig) |
Collect stream flags from the supplied signature. More... | |
uint32_t | SigDetect (usbdev_stream_sig_t *sig, const uint8_t *sp, uint32_t nrecv) |
Detect and parse stream/packet signature, returning a count of the number of bytes to be discarded from the start of this data. More... | |
void | SigReport (const usbdev_stream_sig_t &sig) |
Diagnostic utility function to report the contents of a stream/packet signature. More... | |
void | GenerateData (uint8_t *dp, uint32_t len) |
Generate a sequence of bytes as if we'd received them correctly from the device. | |
bool | ProcessData (uint8_t *dp, uint32_t len) |
Process the given sequence of bytes according to the current stream state. | |
uint32_t | DataAvailable (uint8_t **data) |
Return the number of contiguous bytes of data available in the stream buffer, and a pointer to the first byte of data. More... | |
bool | DiscardData (uint32_t len) |
Update the stream buffer to indicate that data has been discarded (removed from the buffer but not sent to the USB device). More... | |
bool | ConsumeData (uint32_t len) |
Update the stream buffer to indicate that data has been consumed. More... | |
uint8_t | sig_read8 (size_t offset) |
uint16_t | sig_read16 (size_t offset) |
uint32_t | sig_read32 (size_t offset) |
Protected Attributes | |
unsigned | id_ |
Stream IDentifier. | |
bool | closing_ |
Is the stream being closed? | |
sig_state_t | sig_recvd_ |
Have we received the stream signature yet? | |
unsigned | sig_cnt_ |
bool | retrieve_ |
Retrieve IN data for this stream? | |
bool | check_ |
Check the received data against expectations? | |
bool | send_ |
Send OUT data for this stream? | |
bool | verbose_ |
Verbose reporting? | |
uint32_t | bytes_recvd_ |
Total number of bytes received. | |
uint32_t | bytes_sent_ |
Total number of bytes sent. | |
uint8_t | tst_lfsr_ |
Device-side LFSR; byte stream expected from usbdev_stream_test. | |
uint8_t | dpi_lfsr_ |
Host/DPI-side LFSR. | |
uint32_t | transfer_bytes_ |
Number of bytes to be transferred. | |
struct { | |
uint32_t | wr_idx |
Offset at which to write the next received data (IN from device). | |
uint32_t | rd_idx |
Offset of next byte to be read from the buffer (OUT to device). | |
uint32_t | end_idx |
Offset beyond used portion of the buffer; for packet-based transmission we wrap before the end of the circular buffer if a maximum-length packet does not fit. | |
uint8_t | data [kBufferSize] |
Circular buffer of data being transferred from input to output port. | |
} | buf_ |
Circular buffer of streamed data. | |
Static Protected Attributes | |
static constexpr uint32_t | kBufferSize = 0x10000U |
Size of circular buffer used for streaming. | |
Definition at line 51 of file usbdev_stream.h.
|
protected |
Add the specified number of bytes to the circular buffer; if data
is NULL then the bytes shall already be present in the buffer and copying is not performed.
data | The data to be added to the buffer, or NULL |
len | The number of bytes to be added. |
Definition at line 239 of file usbdev_stream.cc.
|
inline |
Returns a count of the number of bytes received from the device.
Definition at line 149 of file usbdev_stream.h.
|
inline |
Returns a count of the number of bytes sent to the device.
Definition at line 155 of file usbdev_stream.h.
|
inline |
Indicate whether an additional I/O transfer may safely be scheduled on this stream, eg.
it is not suspending/shutting down.
Definition at line 82 of file usbdev_stream.h.
|
protected |
CLear the circular buffer by removing all of its contained data bytes.
Note: this is achieved by advancing the read index to match the current write index, so all committed/added data is discarded, by any write data that has only been provisioned at this point does remain valid and may still be committed subsequently.
Definition at line 376 of file usbdev_stream.cc.
|
inlineprotected |
Record that the specified number of bytes have been added to the circular buffer.
The space must already have provisioned and the data bytes shall already be in the buffer.
Definition at line 214 of file usbdev_stream.h.
|
virtual |
Indicates whether this stream has completed its transfer.
Reimplemented in USBDevIso.
Definition at line 194 of file usbdev_stream.cc.
|
protected |
Update the stream buffer to indicate that data has been consumed.
len | Number of bytes of data consumed. |
Definition at line 367 of file usbdev_stream.cc.
|
protected |
Return the number of contiguous bytes of data available in the stream buffer, and a pointer to the first byte of data.
This may be fewer than the total number of bytes in the buffer, if the data wraps at the end of the circular buffer.
data | Receives the pointer to the first data byte. |
Definition at line 329 of file usbdev_stream.cc.
|
protected |
Update the stream buffer to indicate that data has been discarded (removed from the buffer but not sent to the USB device).
len | Number of bytes of data consumed. |
Definition at line 348 of file usbdev_stream.cc.
|
protected |
Provision the given number of bytes of contiguous space, and optionally a pointer to the start of the free space.
space | Receives the pointer to the start of the free space, or NULL iff pointer not required. |
len | Amount of space (in bytes) to provision. |
Definition at line 198 of file usbdev_stream.cc.
|
pure virtual |
Return a summary report of the stream settings or status.
status | Indicates whether settings or status requested. |
verbose | true iff a more verbose report is required. |
Implemented in USBDevSerial, USBDevIso, and USBDevInt.
|
virtual |
Service this stream.
Reimplemented in USBDevSerial, USBDevIso, and USBDevInt.
Definition at line 386 of file usbdev_stream.cc.
|
inline |
Record whether or not the stream is in the process of closing (shutting down or suspending).
closing | Whether or not the stream is now closing. |
Definition at line 75 of file usbdev_stream.h.
|
protected |
Detect and parse stream/packet signature, returning a count of the number of bytes to be discarded from the start of this data.
Usually this is zero, but if a valid stream signature is required, bytes must be discarded until the signature is received.
Definition at line 65 of file usbdev_stream.cc.
|
protected |
Collect stream flags from the supplied signature.
sig | The latest stream signature received. |
Definition at line 159 of file usbdev_stream.cc.
|
inlineprotected |
Has valid signature been received on this stream? Note that there may be some additional validity checks required for specific= transfer types.
Definition at line 251 of file usbdev_stream.h.
|
protected |
Diagnostic utility function to report the contents of a stream/packet signature.
sig | Stream signature to be reported. |
Definition at line 174 of file usbdev_stream.cc.
|
protected |
Returns the amount of contiguous free space available in the buffer, and optionally a pointer to the start of the free space.
space | Receives the pointer to the start of the free space, or NULL iff pointer not required. |
Definition at line 220 of file usbdev_stream.cc.
|
inlinestatic |
Return the textual name of the given stream type.
type | Stream type. |
Definition at line 162 of file usbdev_stream.h.
|
inline |
Returns the total number of bytes to be transferred by this stream.
Number | of bytes to be transferred. |
Definition at line 143 of file usbdev_stream.h.