Skip to content

Commit

Permalink
grainuum: add functions to drop currently-queued data
Browse files Browse the repository at this point in the history
These can be used to ignore data that's already in the buffer.

Signed-off-by: Sean Cross <[email protected]>
  • Loading branch information
xobs committed Jun 2, 2017
1 parent fd71e6f commit 3ee596e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions grainuum-state.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ static int grainuum_state_send_data(struct GrainuumState *state,
return 0;
}

void grainuumDropData(struct GrainuumUSB *usb)
{
usb->state.packet_queued = 0;
usb->state.data_out = 0;
grainuumWriteQueue(usb, 0, NULL, 0);
}

int grainuumDataQueued(struct GrainuumUSB *usb)
{
return (usb->state.data_out || usb->state.packet_queued);
}

int grainuumSendData(struct GrainuumUSB *usb, int epnum,
const void *data, int size)
{
Expand Down
22 changes: 22 additions & 0 deletions grainuum.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,28 @@ int grainuumInitialized(struct GrainuumUSB *usb);
*/
int grainuumSendData(struct GrainuumUSB *usb, int epnum, const void *data, int size);

/**
* @brief Clears the send buffer, if not empty.
* @note If data has already been queued for the PHY, then
* this will not prevent it from being sent.
* This function is intended to be used to prevent
* grainuumSendData() from returning -EAGAIN.
* @param[in] usb pointer to the @p GrainuumUSB object.
* @api
*/
void grainuumDropData(struct GrainuumUSB *usb);

/**
* @brief Determines if data is already queued.
* @note If data has been queued, then this will return
* nonzero. If this returns zero, then you can
* trust grainuumSendData() will succeed.
* @param[in] usb pointer to the @p GrainuumUSB object.
* @return Nonzero if data is already queued.
* @api
*/
int grainuumDataQueued(struct GrainuumUSB *usb);

/**
* @brief Process one received packet through the Grainuum state machine.
* @note This feeds USB packets into the state machine. It should not
Expand Down

0 comments on commit 3ee596e

Please sign in to comment.