This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于C6747 的SPI读写问题



下载了 spiflash_writer_dsp 这个程序,运行正确,仔细分析了代码,有个疑惑的地方:

spi_xfer这个函数:

int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
const void *dout, void *din, unsigned long flags)
{
struct davinci_spi_slave *ds = to_davinci_spi(slave);
unsigned int len;
int i;
const Uint8 *txp = dout;
Uint8 *rxp = din;

if (bitlen == 0)
/* Finish any previously submitted transfers */
goto out;


/*
* It's not clear how non-8-bit-aligned transfers are supposed to be
* represented as a stream of bytes...this is a limitation of
* the current SPI interface - here we terminate on receiving such a
* transfer request.
*/
if (bitlen % 8) {
/* Errors always terminate an ongoing transfer */
flags |= SPI_XFER_END;
goto out;
}

len = bitlen / 8;

/* do an empty read to clear the current contents */
SPI_SPIBUF;

/* keep writing and reading 1 byte until done */
for (i = 0; i < len; i++)
{
/* wait till TXFULL is asserted */
while( SPI_SPIBUF & 0x20000000 );

/* write the data */
data1_reg_val &= ~0xFFFF;
if(txp) {
data1_reg_val |= *txp & 0xFF;
txp++;
}

/* write to DAT1 is required to keep the serial transfer going */
/* we just terminate when we reach the end */
if((i == (len -1)) && (flags & SPI_XFER_END)) {
SPI_SPIDAT1 = data1_reg_val & ~(1 << 28);
} else {
SPI_SPIDAT1 = data1_reg_val;
}

/* read the data - wait for data availability */
while ( SPI_SPIBUF & ( 0x80000000 ) );

if(rxp) {
*rxp = SPI_SPIBUF & 0xFF;
rxp++;
} else {
SPI_SPIBUF;
}

}

return 0;

out:
if (flags & SPI_XFER_END) {
SPI_SPIDAT1 = data1_reg_val & ~(1 << 28);
}

return 0;
}

有一个语句:

/* read the data - wait for data availability */
while ( SPI_SPIBUF & ( 0x80000000 ) );

为什么需要这个?winbond SPI有些命令,比如 0x06,写允许命令,并不返回数据,岂不是一直等待!

请 TI 专家解释解释。