Cart Contact NSDSP Home

nsdsp_session_receive_spi

This function receives data through SPI.

Syntax

int nsdsp_session_receive_spi(
        nsdsp_session_t   session,
        unsigned int      size
);

Parameters

session - a reference to the Session Object

size - the size of the data in bytes

Return

The function returns non-zero if the receive commands have been successfully queued, or zero otherwise

Notes

This instruction only queues a command. The command will be sent to NSDSP when you queue enough commands to fill the buffer or when you call nsdsp_session_flush.

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: SPI

Minimum library version - 163

Northern Software Home NSDSP Contact Us Purchase/View Cart

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