Buy Contact NSDSP Home

nsdsp_session_fetch_data_nb

This function retrieves the data from NSDSP. Unlike nsdsp_session_fetch_data, if the data is not immediately available, it fetches whatever data is available and returns.

Syntax

unsigned int nsdsp_session_fetch_data_nb(
        nsdsp_session_t   session,
        void*             data,
        unsigned int      size
);

Parameters

session - a reference to the Session Object

data - the buffer to be filled in with data

size - the size of the data requested in bytes

Return

The function returns the amount of data put into the buffer. This may be less than size. If there is no data immediately available, the function returns zero.

Example

This example shows how to organize a pipeline to receive SPI data.

#define MAX_CHUNK 0x8000

int ReceiveSPIData(nsdsp_session_t Session, char* Buffer, int Length) {
  int Chunk;
  int Outstanding;
  int Received;

  Outstanding = 0;
  while (Length) {
    Chunk = MAX_CHUNK;
    if (Chunk > Length) Chunk = Length;
    // Transmit read commands to the NSDSP programmer
    if (!nsdsp_session_receive_spi(Session,Chunk)) return 0;
    Outstanding += Chunk;
    Length -= Chunk;

    // Receive only the data that has already arrived
    Received = nsdsp_session_fetch_data_nb(Session,Buffer,Outstanding);
    Outstanding -= Received;
    Buffer += Received;
  }

  // Make sure all the commands are transferred to the NSDSP programmer
  if (!nsdsp_session_flush(Session)) return 0;

  if (Outstanding == 0) return 1;

  // Wait until the rest of the data arrives and fetch it
  return nsdsp_session_fetch_data(Session,Buffer,Outstanding);
}

 

Supported session types: UART,SPI

Minimum library version - 163

Northern Software Home NSDSP Contact Us Purchase/View Cart

© 2007-2025 Northern Software Inc. All Rights Reserved.