v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | Public Attributes | List of all members
Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity > Struct Template Reference

A memory buffer for bidirectional USB communications. More...

#include <sifteo/usb.h>

Public Member Functions

void attach ()
 Attach this pipe to the system. More...
 
void detach ()
 Detach all pipes from the system. More...
 
bool read (UsbPacket &buffer)
 If a packet is available in the queue, read it. More...
 
bool readAvailable () const
 Does this queue have at least one packet to read?
 
bool write (const UsbPacket &buffer)
 Write one packet to the send queue, if space is available. More...
 
bool writeAvailable () const
 Does this queue have room to write at least one packet?
 

Public Attributes

UsbQueue< tReceiveCapacity > receiveQueue
 Queue for packets that have been received but not yet processed.
 
UsbQueue< tSendCapacity > sendQueue
 Queue for packets we're waiting to send.
 

Detailed Description

template<unsigned tSendCapacity = 4, unsigned tReceiveCapacity = 4>
struct Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity >

A memory buffer for bidirectional USB communications.

This is a pair of FIFO buffers which can be used for bidirectional communication over USB. When the pipe is "attached", this Base becomes available to send and receive application-specific packets over USB.

When the pipe is not attached or no pipe has been allocated, the Sifteo USB API will throw an error if application-specific packets are sent. However the USB API provides generic functionality which can be used even without a UsbPipe.

If the UsbPipe's receiveQueue is full, the Sifteo USB API will not be allowed to transmit more packets until our receiveQueue has room. Packets will not be dropped if the buffer fills up.

Some applications may desire lower-level access to the data queues we use. Those applications may access 'sendQueue' and 'receiveQueue' directly, and use the methods on those UsbQueue objects.

Applications that do not need this level of control can use the read() and write() methods on this object directly.

Template Parameters
tSendCapacityCapacity of the send queue in this pipe.
tReceiveCapacityCapacity of the receive queue in this pipe.

Member Function Documentation

template<unsigned tSendCapacity = 4, unsigned tReceiveCapacity = 4>
void Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity >::attach ( )
inline

Attach this pipe to the system.

When a pipe is "attached", the system will write incoming packets to our receiveQueue and it will be looking for transmittable packets in our sendQueue.

This buffer must stay allocated as long as it's attached to the system. If you plan on recycling or freeing this memory, make sure to detach() it first.

If there was already a different pipe attached, this one replaces it. The previous pipe is automatically detached.

This method clears the send and receive queues. Both queues will be empty when they're first attached to the system.

template<unsigned tSendCapacity = 4, unsigned tReceiveCapacity = 4>
void Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity >::detach ( )
inline

Detach all pipes from the system.

After this call, the Sifteo USB API will throw an error if application-specific packets are sent to us. The UsbPipe may be recycled or freed.

template<unsigned tSendCapacity = 4, unsigned tReceiveCapacity = 4>
bool Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity >::read ( UsbPacket buffer)
inline

If a packet is available in the queue, read it.

If a packet is available, copies it to 'buffer' and returns 'true'. If no packets are waiting, returns 'false'.

template<unsigned tSendCapacity = 4, unsigned tReceiveCapacity = 4>
bool Sifteo::UsbPipe< tSendCapacity, tReceiveCapacity >::write ( const UsbPacket buffer)
inline

Write one packet to the send queue, if space is available.

This copies the provided packet into our send queue and returns 'true' if space is available. If the queue is full, returns 'false'.

For more detailed control over the queue, see the methods on our 'sendQueue' member.


The documentation for this struct was generated from the following file: