/* Receive a piece of data for SPI master. 
This function computes the number of data to receive from D register or Rx FIFO, and write the data to destination address. At the same time, this function updates the values in master handle structure. */
static void SPI_ReceiveTransfer(SPI_Type *base, spi_master_handle_t *handle)
/* Receive a piece of data for SPI master. 
This function computes the number of data to receive from D register or Rx FIFO, and write the data to destination address. At the same time, this function updates the values in master handle structure. */
static void SPI_ReceiveTransfer(SPI_Type *base, spi_master_handle_t *handle)
{
    uint8_t bytes = MIN((handle->watermark * 2U), handle->rxRemainingBytes);
    uint8_t val = 1U;
    if (handle->watermark == 1U)
    {
        val = base->S & SPI_S_SPRF_MASK;
        if (bytes != 0U)
        {
            bytes = handle->bytePerFrame;
        }
    }
    if (val)
    {
        SPI_ReadNonBlocking(base, handle->rxData, bytes);
        if (handle->rxData)
        {
            handle->rxData += bytes;
        }
        handle->rxRemainingBytes -= bytes;
    }
}