在线时间36 小时
UID423505
注册时间2013-3-27
NXP金币0
该用户从未签到
高级会员

- 积分
- 651
- 最后登录
- 2020-9-4
|
我使用的芯片是K64系列,利用mqx系统下的函数对dataflash读写数据。
当我写入528字节数据时,程序会处于 红字处。任务处于等待EVENT_IO_FINISHED。
我将DSPI_FIFO_DEPTH = 4;改为DSPI_FIFO_DEPTH = 2;程序可以正常运行。
哪位大侠帮解答一下。
static _mqx_int _dspi_tx_rx
(
/* [IN] Device specific context structure */
void *io_info_ptr,
/* [IN] Data to transmit */
uint8_t *txbuf,
/* [OUT] Received data */
uint8_t *rxbuf,
/* [IN] Length of transfer in bytes */
uint32_t len
)
{
DSPI_INFO_STRUCT_PTR dspi_info_ptr = (DSPI_INFO_STRUCT_PTR)io_info_ptr;
VDSPI_REG_STRUCT_PTR dspi_ptr = dspi_info_ptr->DSPI_PTR;
uint32_t tx_len;
uint32_t rx_len;
uint32_t data;
bool use_isr;
uint32_t i;
use_isr = dspi_info_ptr->NUM_VECTORS && dspi_info_ptr->ATTR & DSPI_ATTR_USE_ISR;
data = dspi_info_ptr->DUMMY_PATTERN;
/* Is frame larger than a single byte? */
if (DSPI_CTAR_FMSZ_GET(dspi_ptr->CTAR[0]) > 7)
{
len = len & (~1UL);
rx_len = tx_len = len/2;
while (rx_len)
{
if (tx_len) {
if ((dspi_ptr->SR & DSPI_SR_TFFF_MASK) && ((rx_len-tx_len)<DSPI_FIFO_DEPTH))
{
if (txbuf)
{
data = *txbuf++;
data = (data << 8) | *txbuf++;
}
dspi_ptr->PUSHR = DSPI_PUSHR_TXDATA(data);
dspi_ptr->SR = DSPI_SR_TFFF_MASK;
tx_len--;
}
else if (use_isr)
{
/* do not wait for RX data in a loop, break it and use ISR */
break;
}
}
if (dspi_ptr->SR & DSPI_SR_RFDF_MASK)
{
data = DSPI_POPR_RXDATA_GET(dspi_ptr->POPR);
dspi_ptr->SR = DSPI_SR_RFDF_MASK;
if (rxbuf)
{
*rxbuf++ = data >> 8;
*rxbuf++ = data & 0xff;
}
rx_len--;
}
else if (tx_len == 0 && use_isr)
{
/* do not wait for RX data in a loop, break it and use ISR */
break;
}
}
}
else
{
rx_len = tx_len = len;
/* Optimized loop for single byte frames */
while (rx_len)
{
if (tx_len) {
if ((dspi_ptr->SR & DSPI_SR_TFFF_MASK) && ((rx_len-tx_len)<DSPI_FIFO_DEPTH))
{
if (txbuf)
data = *txbuf++;
dspi_ptr->PUSHR = DSPI_PUSHR_TXDATA(data);
dspi_ptr->SR = DSPI_SR_TFFF_MASK;
tx_len--;
}
else if (use_isr)
{
/* do not wait for RX data in a loop, break it and use ISR */
break;
}
}
if (dspi_ptr->SR & DSPI_SR_RFDF_MASK)
{
if (rxbuf)
*rxbuf++ = DSPI_POPR_RXDATA_GET(dspi_ptr->POPR);
else
dspi_ptr->POPR; /* dummy read to drain FIFO */
dspi_ptr->SR = DSPI_SR_RFDF_MASK;
rx_len--;
}
else if (tx_len == 0 && use_isr)
{
/* do not wait for RX data in a loop, break it and use ISR */
break;
}
}
}
if (rx_len)
{
/* finish the transfer using ISR */
dspi_info_ptr->TX_BUF = txbuf;
dspi_info_ptr->TX_LEN = tx_len;
dspi_info_ptr->RX_BUF = rxbuf;
dspi_info_ptr->RX_LEN = rx_len;
/* enable interrupt and wait for ISR state machine to finish the job */
dspi_ptr->RSER = DSPI_RSER_RFDF_RE_MASK;
_lwsem_wait(&dspi_info_ptr->EVENT_IO_FINISHED);
}
return len;
}
|
|