/* Get the status of an SPI transfer. 
Returns status of an ongoing transfer. If no transfer is in progress, the status of the last transfer is reported. */
Ecode_t SPIDRV_GetTransferStatus(SPIDRV_Handle_t handle, int *itemsTransferred, int *itemsRemaining)
/* Get the status of an SPI transfer. 
Returns status of an ongoing transfer. If no transfer is in progress, the status of the last transfer is reported. */
Ecode_t SPIDRV_GetTransferStatus(SPIDRV_Handle_t handle, int *itemsTransferred, int *itemsRemaining)
{
  int remaining;
  if ( handle == NULL ) {
    return ECODE_EMDRV_SPIDRV_ILLEGAL_HANDLE;
  }
  if ( (itemsTransferred == NULL) || (itemsRemaining == NULL) ) {
    return ECODE_EMDRV_SPIDRV_PARAM_ERROR;
  }
  CORE_ATOMIC_SECTION(
    if ( handle->state == spidrvStateIdle ) {
    remaining = handle->remaining;
  } else {
    DMADRV_TransferRemainingCount(handle->rxDMACh, &remaining);
  }
    )
  * itemsTransferred = handle->transferCount - remaining;
  *itemsRemaining   = remaining;
  return ECODE_EMDRV_SPIDRV_OK;
}