DataFlash: speed up SPI transfers in DataFlash_APM1

This commit is contained in:
Andrew Tridgell 2013-01-13 19:26:33 +11:00
parent 164246c7d8
commit f683cff9e2
1 changed files with 32 additions and 46 deletions

View File

@ -187,19 +187,17 @@ void DataFlash_APM1::PageToBuffer(uint8_t BufferNum, uint16_t PageAdr)
// activate dataflash command decoder // activate dataflash command decoder
_spi->cs_assert(); _spi->cs_assert();
if (BufferNum==0) uint8_t cmd[4];
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_1); cmd[0] = BufferNum?DF_TRANSFER_PAGE_TO_BUFFER_2:DF_TRANSFER_PAGE_TO_BUFFER_1;
else
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_2);
if(df_PageSize==512) { if(df_PageSize==512) {
_spi->transfer((uint8_t)(PageAdr >> 7)); cmd[1] = (uint8_t)(PageAdr >> 7);
_spi->transfer((uint8_t)(PageAdr << 1)); cmd[2] = (uint8_t)(PageAdr << 1);
}else{ }else{
_spi->transfer((uint8_t)(PageAdr >> 6)); cmd[1] = (uint8_t)(PageAdr >> 6);
_spi->transfer((uint8_t)(PageAdr << 2)); cmd[2] = (uint8_t)(PageAdr << 2);
} }
_spi->transfer(0x00); // don´t care bytes cmd[3] = 0;
_spi->transfer(cmd, sizeof(cmd));
//initiate the transfer //initiate the transfer
_spi->cs_release(); _spi->cs_release();
@ -216,19 +214,17 @@ void DataFlash_APM1::BufferToPage (uint8_t BufferNum, uint16_t PageAdr, uint8_t
// activate dataflash command decoder // activate dataflash command decoder
_spi->cs_assert(); _spi->cs_assert();
if (BufferNum==0) uint8_t cmd[4];
_spi->transfer(DF_BUFFER_1_TO_PAGE_WITH_ERASE); cmd[0] = BufferNum?DF_BUFFER_2_TO_PAGE_WITH_ERASE:DF_BUFFER_1_TO_PAGE_WITH_ERASE;
else
_spi->transfer(DF_BUFFER_2_TO_PAGE_WITH_ERASE);
if(df_PageSize==512) { if(df_PageSize==512) {
_spi->transfer((uint8_t)(PageAdr >> 7)); cmd[1] = (uint8_t)(PageAdr >> 7);
_spi->transfer((uint8_t)(PageAdr << 1)); cmd[2] = (uint8_t)(PageAdr << 1);
}else{ }else{
_spi->transfer((uint8_t)(PageAdr >> 6)); cmd[1] = (uint8_t)(PageAdr >> 6);
_spi->transfer((uint8_t)(PageAdr << 2)); cmd[2] = (uint8_t)(PageAdr << 2);
} }
_spi->transfer(0x00); // don´t care bytes cmd[3] = 0;
_spi->transfer(cmd, sizeof(cmd));
//initiate the transfer //initiate the transfer
_spi->cs_release(); _spi->cs_release();
@ -250,28 +246,20 @@ void DataFlash_APM1::BlockWrite (uint8_t BufferNum, uint16_t IntPageAdr,
// activate dataflash command decoder // activate dataflash command decoder
_spi->cs_assert(); _spi->cs_assert();
if (BufferNum==0) uint8_t cmd[4];
_spi->transfer(DF_BUFFER_1_WRITE); cmd[0] = BufferNum?DF_BUFFER_2_WRITE:DF_BUFFER_1_WRITE;
else cmd[1] = 0;
_spi->transfer(DF_BUFFER_2_WRITE); cmd[2] = (uint8_t)(IntPageAdr>>8);
cmd[3] = (uint8_t)(IntPageAdr);
_spi->transfer(0x00); // don't care _spi->transfer(cmd, sizeof(cmd));
_spi->transfer((uint8_t)(IntPageAdr>>8)); // upper part of internal buffer address
_spi->transfer((uint8_t)(IntPageAdr)); // lower part of internal buffer address
const uint8_t *pData;
// transfer header, if any // transfer header, if any
pData = (const uint8_t *)pHeader; if (hdr_size != 0) {
while (hdr_size--) { _spi->transfer((const uint8_t *)pHeader, hdr_size);
_spi->transfer(*pData++);
} }
// transfer data // transfer data
pData = (const uint8_t *)pBuffer; _spi->transfer((const uint8_t *)pBuffer, size);
while (size--) {
_spi->transfer(*pData++);
}
// release SPI bus for use by other sensors // release SPI bus for use by other sensors
_spi->cs_release(); _spi->cs_release();
@ -286,15 +274,13 @@ bool DataFlash_APM1::BlockRead(uint8_t BufferNum, uint16_t IntPageAdr, void *pBu
// activate dataflash command decoder // activate dataflash command decoder
_spi->cs_assert(); _spi->cs_assert();
if (BufferNum==0) uint8_t cmd[5];
_spi->transfer(DF_BUFFER_1_READ); cmd[0] = BufferNum?DF_BUFFER_2_READ:DF_BUFFER_1_READ;
else cmd[1] = 0;
_spi->transfer(DF_BUFFER_2_READ); cmd[2] = (uint8_t)(IntPageAdr>>8);
cmd[3] = (uint8_t)(IntPageAdr);
_spi->transfer(0x00); cmd[4] = 0;
_spi->transfer((uint8_t)(IntPageAdr>>8)); // upper part of internal buffer address _spi->transfer(cmd, sizeof(cmd));
_spi->transfer((uint8_t)(IntPageAdr)); // lower part of internal buffer address
_spi->transfer(0x00); // don't cares
uint8_t *pData = (uint8_t *)pBuffer; uint8_t *pData = (uint8_t *)pBuffer;
while (size--) { while (size--) {