您好,我在使用2944驱动中遇到了问题,以下是本人理解存在疑问的相关函数:
int32_t QSPI_readCmd(QSPI_Handle handle, QSPI_ReadCmdParams *rdParams)
{
int32_t status = SystemP_SUCCESS;
if((handle != NULL) && (rdParams != NULL))
{
QSPI_Attrs const *attrs = ((QSPI_Config *)handle)->attrs;
QSPI_ConfigAccess cfgAccess = {0};
uint32_t frmLength = 0;
QSPI_setMemAddrSpace(handle, QSPI_MEM_MAP_PORT_SEL_CFG_PORT);
if(rdParams->cmdAddr != QSPI_CMD_INVALID_ADDR)
{
/* Total transaction frame length in words (bytes) */
frmLength = QSPI_CMD_LEN + QSPI_ADDR_LEN +
(rdParams->rxDataLen / (attrs->wrdLen >> 3U));
}
else
{
/* Total transaction frame length in words (bytes) */
frmLength = QSPI_CMD_LEN + (rdParams->rxDataLen / (attrs->wrdLen >> 3U));
}
/* Send the command */
cfgAccess.buf = (unsigned char *)&rdParams->cmd;
cfgAccess.count = QSPI_CMD_LEN;
cfgAccess.wlen = 8;
/* formulate the command */
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_FLEN, (frmLength - 1));
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_CSNUM, attrs->chipSelect);
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_CMD,
CSL_QSPI_SPI_CMD_REG_CMD_FOUR_PIN_WRITE_SINGLE);
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_WLEN, (cfgAccess.wlen - 1));
status = QSPI_spiConfigWrite(handle, &cfgAccess);
/* Send address associated with command, if any */
if(rdParams->cmdAddr != QSPI_CMD_INVALID_ADDR)
{
cfgAccess.buf = (unsigned char *)&rdParams->cmdAddr;
cfgAccess.count = QSPI_ADDR_LEN;
/* Number of address Bytes to bits. */
cfgAccess.wlen = (rdParams->numAddrBytes << 3U);
/* Update the command register value. */
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_WLEN, (cfgAccess.wlen - 1));
status += QSPI_spiConfigWrite(handle, &cfgAccess);
}
/* Send data associated with command, if any */
if( rdParams->rxDataLen != 0)
{
cfgAccess.buf = (unsigned char *)rdParams->rxDataBuf;
cfgAccess.count = rdParams->rxDataLen / (attrs->wrdLen >> 3U);
cfgAccess.wlen = attrs->wrdLen;
/* Update the command register value. */
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_WLEN, (cfgAccess.wlen - 1));
CSL_FINS(cfgAccess.cmdRegVal, QSPI_SPI_CMD_REG_CMD,
CSL_QSPI_SPI_CMD_REG_CMD_FOUR_PIN_READ_SINGLE);
status += QSPI_spiConfigRead(handle, &cfgAccess);
}
QSPI_setMemAddrSpace(handle, QSPI_MEM_MAP_PORT_SEL_MEM_MAP_PORT);
}
else
{
status = SystemP_FAILURE;
}
return status;
}
static int32_t QSPI_spiConfigRead(QSPI_Handle handle, QSPI_ConfigAccess *cfgAccess)
{
/* Source address */
uint8_t *dstAddr8 = NULL;
uint16_t *dstAddr16 = NULL;
uint32_t *dstAddr32 = NULL;
uint32_t wordLenBytes;
/* Data to be written */
uint32_t dataVal[4] = {0};
int32_t status = SystemP_SUCCESS;
QSPI_Attrs const *attrs = ((QSPI_Config *)handle)->attrs;
const CSL_QspiRegs *pReg = (const CSL_QspiRegs *)attrs->baseAddr;
if (cfgAccess->wlen <= 8)
{
dstAddr8 = (uint8_t *)(cfgAccess->buf);
wordLenBytes = 1;
}
else if (cfgAccess->wlen <= 16)
{
dstAddr16 = (uint16_t *)(cfgAccess->buf);
wordLenBytes = 2;
}
else
{
dstAddr32 = (uint32_t *)(cfgAccess->buf);
wordLenBytes = 4;
}
/* Write the data into shift registers */
while(cfgAccess->count)
{
/* Write tx command to command register */
CSL_REG32_WR(&pReg->SPI_CMD_REG, cfgAccess->cmdRegVal);
/* Wait for the QSPI busy status */
status += QSPI_waitIdle(handle);
/* Store the number of data registers needed to read data */
status += QSPI_readData(handle, &dataVal[0], 1U);
if (wordLenBytes == 1)
{
*dstAddr8 = (uint8_t) dataVal[0];
dstAddr8++;
}
else if (wordLenBytes == 2)
{
*dstAddr16 = (uint16_t) dataVal[0];
dstAddr16++;
}
else
{
*dstAddr32 = (uint32_t) dataVal[0];
dstAddr32++;
}
/* update the cmd Val reg by reading it again for next word. */
cfgAccess->cmdRegVal = CSL_REG32_RD(&pReg->SPI_CMD_REG);
/* Update the number of bytes to be transmitted */
cfgAccess->count -= wordLenBytes;
}
return status;
}
问题1:
在QSPI的驱动函数当中,QSPI_readCmd中的
这里的count我理解的是字的长度。为什么在QSPI_spiConfigRead中,每传输完一个字不是将count减一?
问题2:
我在使用提供的例程对flash进行读写时,
在drivers_config.c中,attrs->wrdLen字长,只有设置为8时可以正常使用,设置为16或32时不能正常使用。这是为什么呢?