pic32/libraries/DSPI/DSPI.cpp
/* ------------------------------------------------------------ */
/***	DSPI::transfer
**
**	Parameters:
**		cbReq	- number of bytes to transfer
**		pbSnd	- pointer to buffer to bytes to send
**		pbRcv	- pointer to hold received bytes
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		This function will send the requested bytes to the SPI
**		slave device, simultaneously saving the bytes received
**		from the slave device.
*/
:transfer

cbReq   - number of bytes to transfer
pbSnd   - pointer to buffer to bytes to send
pbRcv   - pointer to hold received bytes

Return Value:
none

none

This function will send the requested bytes to the SPI
slave device, simultaneously saving the bytes received
from the slave device.
: transfer cbReq - number of bytes to transfer pbSnd - pointer to buffer to bytes to send pbRcv - pointer to hold received bytes Return Value : none none This function will send the requested bytes to the SPI slave device simultaneously saving the bytes received from the slave device .
void
DSPI::transfer(uint16_t cbReq, uint8_t * pbSnd, uint8_t * pbRcv) {
#if ENH_BUFFER
    pspi->sxCon.set = 1<<ENH_BUFFER;
    uint16_t toWrite = cbReq;
    uint16_t toRead = cbReq;
    uint16_t rPos = 0;
    uint16_t wPos = 0;
    while (toWrite > 0 || toRead > 0) {
        if (toWrite > 0) {
            if ((pspi->sxStat.reg & (1<<_SPISTAT_SPITBF)) == 0) {
                pspi->sxBuf.reg = pbSnd[wPos++];
                toWrite--;
            }
        }
        if (toRead > 0) {
            if ((pspi->sxStat.reg & (1<<_SPISTAT_SPIRBE)) == 0) {
                pbRcv[rPos++] = pspi->sxBuf.reg;
                toRead--;
            }
        }
    }
    pspi->sxCon.clr = 1<<ENH_BUFFER;
#else
    for (cbCur = cbReq; cbCur > 0; cbCur--) {
        *pbRcv++ = transfer(*pbSnd++);
    }
#endif
}
void DSPI :: transfer ( uint16_t cbReq , uint8_t * pbSnd , uint8_t * pbRcv ) { #if ENH_BUFFER pspi -> sxCon . set = 1 << ENH_BUFFER ; uint16_t toWrite = cbReq ; uint16_t toRead = cbReq ; uint16_t rPos = 0 ; uint16_t wPos = 0 ; while ( toWrite > 0 || toRead > 0 ) { if ( toWrite > 0 ) { if ( ( pspi -> sxStat . reg & ( 1 << _SPISTAT_SPITBF ) ) == 0 ) { pspi -> sxBuf . reg = pbSnd [ wPos ++ ] ; toWrite -- ; } } if ( toRead > 0 ) { if ( ( pspi -> sxStat . reg & ( 1 << _SPISTAT_SPIRBE ) ) == 0 ) { pbRcv [ rPos ++ ] = pspi -> sxBuf . reg ; toRead -- ; } } } pspi -> sxCon . clr = 1 << ENH_BUFFER ; #else for ( cbCur = cbReq ; cbCur > 0 ; cbCur -- ) { * pbRcv ++ = transfer ( * pbSnd ++ ) ; } #endif }
DSPI::transfer
DSPI :: transfer
// If we have one ENHBUF we have all ENHBUF, and all the registers // are the same.  We'll just use SPI1A's macros for all the ports // as it makes no difference.