CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
rx_reorder_payloads.c File Reference

When payloads are received from the transmitter, they can arrive in any order. The routines here will put the payloads in order. More...

#include <stdbool.h>
#include "rx_reorder_payloads.h"
#include "cdi_core_api.h"
#include "cdi_logger_api.h"
#include "cdi_pool_api.h"
#include "cdi_raw_api.h"
#include "internal_rx.h"
#include "private.h"
#include "utilities_api.h"

Functions

 CDI_STATIC_ASSERT ((0==(CDI_MAX_RX_PAYLOAD_OUT_OF_ORDER_BUFFER % 2)), "The define must be a power of 2.")
 Ensure define is a power of 2.
 
 CDI_STATIC_ASSERT ((CDI_MAX_RX_PACKET_OUT_OF_ORDER_WINDOW<=CDI_MAX_RX_PAYLOAD_OUT_OF_ORDER_BUFFER), "...WINDOW must be <= ...BUFFER.")
 Ensure the packet out of order window is less than or equal to the payload out of order buffer.
 
static int AdvanceStateArrayIndex (int payload_num_max, int index)
 Advance the specified state array index value by 1. If a maximum limit is reached, the value wraps to zero.
 
static void SetIgnoreState (RxPayloadState *payload_state_ptr)
 Set the specified payload to the ignore state.
 
static void DecreasePacketWindowCount (RxEndpointState *endpoint_state_ptr, int packet_count)
 Decrease packet window count by the specified value.
 
static void FreePayloadState (CdiEndpointState *endpoint_ptr, int index)
 Free payload state by removing it from the payload Rx reorder list and returning it to the pool.
 
static bool SendPayloadIfCompleteOrError (CdiEndpointState *endpoint_ptr, int index)
 Send the payload if it is ready.
 
static void FlushPartialPayload (CdiEndpointState *endpoint_ptr)
 
void RxReorderPayloadResetState (RxPayloadState *payload_state_ptr, int payload_num)
 
void RxReorderPayloadError (CdiEndpointState *endpoint_ptr, RxPayloadState *payload_state_ptr)
 Set payload in an error state and free associated payload resources (but not payload state).
 
bool RxReorderPayloadIsStale (CdiEndpointState *endpoint_ptr, RxPayloadState *payload_state_ptr)
 Determine if a payload has not received any packets within the packet out of order window. See CDI_MAX_RX_PACKET_OUT_OF_ORDER_WINDOW.
 
RxPayloadStateRxReorderPayloadStateGet (CdiEndpointState *endpoint_ptr, CdiPoolHandle rx_payload_state_pool_handle, int payload_num)
 
void RxReorderPayloadSendReadyPayloads (CdiEndpointState *endpoint_ptr)
 
void RxReorderPayloadSeekFirstPayload (CdiEndpointState *endpoint_ptr)
 

Detailed Description

When payloads are received from the transmitter, they can arrive in any order. The routines here will put the payloads in order.

Function Documentation

◆ AdvanceStateArrayIndex()

static int AdvanceStateArrayIndex ( int payload_num_max,
int index )
inlinestatic

Advance the specified state array index value by 1. If a maximum limit is reached, the value wraps to zero.

Parameters
payload_num_maxMaximum value for payload number (protocol dependent).
indexCurrent index value.
Returns
New index value.

◆ DecreasePacketWindowCount()

static void DecreasePacketWindowCount ( RxEndpointState * endpoint_state_ptr,
int packet_count )
static

Decrease packet window count by the specified value.

Parameters
endpoint_state_ptrPointer to endpoint state data.
packet_countNumber of packets to decrease window by.

◆ FlushPartialPayload()

static void FlushPartialPayload ( CdiEndpointState * endpoint_ptr)
static

Starting at the window start index, flush partial payloads or erred payloads freeing up enough Rx packet reorder resources to get below the packet limit of MAX_RX_PACKET_OUT_OF_ORDER_WINDOW packets.

Parameters
endpoint_ptrPointer to endpoint state structure.

◆ FreePayloadState()

static void FreePayloadState ( CdiEndpointState * endpoint_ptr,
int index )
static

Free payload state by removing it from the payload Rx reorder list and returning it to the pool.

Parameters
endpoint_ptrPointer to endpoint data.
indexIndex of payload state pointer in payload_state_array_ptr.

◆ RxReorderPayloadError()

void RxReorderPayloadError ( CdiEndpointState * endpoint_ptr,
RxPayloadState * payload_state_ptr )

Set payload in an error state and free associated payload resources (but not payload state).

Parameters
endpoint_ptrPointer to endpoint state structure.
payload_state_ptrPointer to the payload state.

◆ RxReorderPayloadIsStale()

bool RxReorderPayloadIsStale ( CdiEndpointState * endpoint_ptr,
RxPayloadState * payload_state_ptr )

Determine if a payload has not received any packets within the packet out of order window. See CDI_MAX_RX_PACKET_OUT_OF_ORDER_WINDOW.

Parameters
endpoint_ptrPointer to endpoint state structure.
payload_state_ptrPointer to the payload state.
Returns
true if payload is stale, otherwise false.

◆ RxReorderPayloadResetState()

void RxReorderPayloadResetState ( RxPayloadState * payload_state_ptr,
int payload_num )

Reset payload state data.

Parameters
payload_state_ptrPointer to payload state data to reset.
payload_numPayload number to set.

◆ RxReorderPayloadSeekFirstPayload()

void RxReorderPayloadSeekFirstPayload ( CdiEndpointState * endpoint_ptr)

Advance the current Rx reorder window index to the first entry that contains a payload.

Parameters
endpoint_ptrPointer to endpoint state structure.

◆ RxReorderPayloadSendReadyPayloads()

void RxReorderPayloadSendReadyPayloads ( CdiEndpointState * endpoint_ptr)

Starting at the beginning of the payload state list, sends any payloads that are complete or in an error state.

Parameters
endpoint_ptrPointer to endpoint state structure.

◆ RxReorderPayloadStateGet()

RxPayloadState * RxReorderPayloadStateGet ( CdiEndpointState * endpoint_ptr,
CdiPoolHandle rx_payload_state_pool_handle,
int sequence_num )

Get pointer to Rx payload state structure for the specified payload sequence number. If one does not already exist then a new one is created.

Parameters
endpoint_ptrPointer to endpoint state structure.
rx_payload_state_pool_handleHandle of Rx payload state pool to use when allocating new payload state structures.
sequence_numPayload sequence number.
Returns
Pointer to returned Rx payload state structure. If an error occurred, NULL is returned.

◆ SendPayloadIfCompleteOrError()

static bool SendPayloadIfCompleteOrError ( CdiEndpointState * endpoint_ptr,
int index )
static

Send the payload if it is ready.

Parameters
endpoint_ptrPointer to endpoint state data.
indexIndex of payload state pointer in payload_state_array_ptr.
Returns
true if payload was sent, otherwise false.

◆ SetIgnoreState()

static void SetIgnoreState ( RxPayloadState * payload_state_ptr)
static

Set the specified payload to the ignore state.

Parameters
payload_state_ptrPointer to payload state data.