1.1.8.4.8 DRV_SPI_WriteTransferAdd Function

C

void DRV_SPI_WriteTransferAdd
(
    const DRV_HANDLE handle,
    void* pTransmitData,
    size_t txSize,
    DRV_SPI_TRANSFER_HANDLE * const transferHandle
);

Summary

Queues a write operation.

Description

This function schedules a non-blocking write operation. The function returns with a valid transfer handle in the transferHandle argument if the request was scheduled successfully. The function adds the request to the instance specific software queue and returns immediately. While the request is in the queue, the application buffer is owned by the driver and should not be modified. This API will write txSize bytes of data and the dummy data received will be ignored.

The function returns DRV_SPI_TRANSFER_HANDLE_INVALID in the transferHandle argument:

  • if pTransmitData is NULL.

  • if txSize is zero.

  • if the transfer handle is NULL.

  • if the queue size is full or queue depth is insufficient.

  • if the driver handle is invalid.

If the requesting client registered an event callback with the driver, the driver will issue a DRV_SPI_TRANSFER_EVENT_COMPLETE event if the transfer was processed successfully or DRV_SPI_TRANSFER_EVENT_ERROR event if the transfer was not processed successfully.

Precondition

  • DRV_SPI_Open must have been called to obtain a valid opened device handle.

  • DRV_SPI_TransferSetup must have been called if GPIO pin has to be used for

chip select or any of the setup parameters has to be changed dynamically.

Parameters

ParamDescription
handleHandle of the communication channel as returned by the DRV_SPI_Open function. *pTransmitData- Pointer to the data which has to be transmitted.
txSizeNumber of bytes to be transmitted. The size must be specified in terms of the SPI data width. For example, if the data width is 8-bits, and if 10 bytes are being transmitted, then the txSize must be set to 10. If the data width is 16-bits then transmitting 10 bytes requires specifying the txSize as 10 (meaning 10 16-bit words).
transferHandleHandle which is returned by transfer add function.

Returns

None.

Example

MY_APP_OBJ myAppObj;
uint8_t myTxBuffer[MY_TX_BUFFER_SIZE];
DRV_SPI_TRANSFER_HANDLE transferHandle;

// mySPIHandle is the handle returned by the DRV_SPI_Open function.

DRV_SPI_WriteTransferAdd(mySPIhandle, myTxBuffer, MY_TX_BUFFER_SIZE, &transferHandle);

if(transferHandle == DRV_SPI_TRANSFER_HANDLE_INVALID)
{
    // Error handling here
}

// Event is received when the transfer is processed.

Remarks

  • This function can be called from within the SPI Driver Transfer Event Handler that is registered by the client.

  • It should NOT be called in the event handler associated with another SPI driver instance or event handler of any other peripheral.

  • It should not be called directly in any ISR.