| Example |
/* SPI Device Driver Control Block */
SPI_DRV spi0_drv = {
Init,
UnInit,
Send,
SendBuf,
RecBuf,
BusSpeed,
SetSS,
CheckMedia /* Can be NULL if not existing */
};
static BOOL SendBuf (U8 *buf, U32 sz) {
/* Send buffer to SPI interface. */
U32 i;
for (i = 0; i < sz; i++) {
SSPDR = buf[i];
/* Wait if Tx FIFO is full. */
while (!(SSPSR & TNF));
SSPDR;
}
/* Wait until Tx finished, drain Rx FIFO. */
while (SSPSR & (BSY | RNE)) {
SSPDR;
}
return (__TRUE);
}
|