mirror of https://github.com/ArduPilot/ardupilot
DataFlash: speed up SPI transfers in DataFlash_APM1
This commit is contained in:
parent
164246c7d8
commit
f683cff9e2
|
@ -187,19 +187,17 @@ void DataFlash_APM1::PageToBuffer(uint8_t BufferNum, uint16_t PageAdr)
|
|||
// activate dataflash command decoder
|
||||
_spi->cs_assert();
|
||||
|
||||
if (BufferNum==0)
|
||||
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_1);
|
||||
else
|
||||
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_2);
|
||||
|
||||
uint8_t cmd[4];
|
||||
cmd[0] = BufferNum?DF_TRANSFER_PAGE_TO_BUFFER_2:DF_TRANSFER_PAGE_TO_BUFFER_1;
|
||||
if(df_PageSize==512) {
|
||||
_spi->transfer((uint8_t)(PageAdr >> 7));
|
||||
_spi->transfer((uint8_t)(PageAdr << 1));
|
||||
cmd[1] = (uint8_t)(PageAdr >> 7);
|
||||
cmd[2] = (uint8_t)(PageAdr << 1);
|
||||
}else{
|
||||
_spi->transfer((uint8_t)(PageAdr >> 6));
|
||||
_spi->transfer((uint8_t)(PageAdr << 2));
|
||||
cmd[1] = (uint8_t)(PageAdr >> 6);
|
||||
cmd[2] = (uint8_t)(PageAdr << 2);
|
||||
}
|
||||
_spi->transfer(0x00); // don´t care bytes
|
||||
cmd[3] = 0;
|
||||
_spi->transfer(cmd, sizeof(cmd));
|
||||
|
||||
//initiate the transfer
|
||||
_spi->cs_release();
|
||||
|
@ -216,19 +214,17 @@ void DataFlash_APM1::BufferToPage (uint8_t BufferNum, uint16_t PageAdr, uint8_t
|
|||
// activate dataflash command decoder
|
||||
_spi->cs_assert();
|
||||
|
||||
if (BufferNum==0)
|
||||
_spi->transfer(DF_BUFFER_1_TO_PAGE_WITH_ERASE);
|
||||
else
|
||||
_spi->transfer(DF_BUFFER_2_TO_PAGE_WITH_ERASE);
|
||||
|
||||
uint8_t cmd[4];
|
||||
cmd[0] = BufferNum?DF_BUFFER_2_TO_PAGE_WITH_ERASE:DF_BUFFER_1_TO_PAGE_WITH_ERASE;
|
||||
if(df_PageSize==512) {
|
||||
_spi->transfer((uint8_t)(PageAdr >> 7));
|
||||
_spi->transfer((uint8_t)(PageAdr << 1));
|
||||
cmd[1] = (uint8_t)(PageAdr >> 7);
|
||||
cmd[2] = (uint8_t)(PageAdr << 1);
|
||||
}else{
|
||||
_spi->transfer((uint8_t)(PageAdr >> 6));
|
||||
_spi->transfer((uint8_t)(PageAdr << 2));
|
||||
cmd[1] = (uint8_t)(PageAdr >> 6);
|
||||
cmd[2] = (uint8_t)(PageAdr << 2);
|
||||
}
|
||||
_spi->transfer(0x00); // don´t care bytes
|
||||
cmd[3] = 0;
|
||||
_spi->transfer(cmd, sizeof(cmd));
|
||||
|
||||
//initiate the transfer
|
||||
_spi->cs_release();
|
||||
|
@ -250,28 +246,20 @@ void DataFlash_APM1::BlockWrite (uint8_t BufferNum, uint16_t IntPageAdr,
|
|||
// activate dataflash command decoder
|
||||
_spi->cs_assert();
|
||||
|
||||
if (BufferNum==0)
|
||||
_spi->transfer(DF_BUFFER_1_WRITE);
|
||||
else
|
||||
_spi->transfer(DF_BUFFER_2_WRITE);
|
||||
|
||||
_spi->transfer(0x00); // don't care
|
||||
_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;
|
||||
uint8_t cmd[4];
|
||||
cmd[0] = BufferNum?DF_BUFFER_2_WRITE:DF_BUFFER_1_WRITE;
|
||||
cmd[1] = 0;
|
||||
cmd[2] = (uint8_t)(IntPageAdr>>8);
|
||||
cmd[3] = (uint8_t)(IntPageAdr);
|
||||
_spi->transfer(cmd, sizeof(cmd));
|
||||
|
||||
// transfer header, if any
|
||||
pData = (const uint8_t *)pHeader;
|
||||
while (hdr_size--) {
|
||||
_spi->transfer(*pData++);
|
||||
if (hdr_size != 0) {
|
||||
_spi->transfer((const uint8_t *)pHeader, hdr_size);
|
||||
}
|
||||
|
||||
// transfer data
|
||||
pData = (const uint8_t *)pBuffer;
|
||||
while (size--) {
|
||||
_spi->transfer(*pData++);
|
||||
}
|
||||
_spi->transfer((const uint8_t *)pBuffer, size);
|
||||
|
||||
// release SPI bus for use by other sensors
|
||||
_spi->cs_release();
|
||||
|
@ -286,15 +274,13 @@ bool DataFlash_APM1::BlockRead(uint8_t BufferNum, uint16_t IntPageAdr, void *pBu
|
|||
// activate dataflash command decoder
|
||||
_spi->cs_assert();
|
||||
|
||||
if (BufferNum==0)
|
||||
_spi->transfer(DF_BUFFER_1_READ);
|
||||
else
|
||||
_spi->transfer(DF_BUFFER_2_READ);
|
||||
|
||||
_spi->transfer(0x00);
|
||||
_spi->transfer((uint8_t)(IntPageAdr>>8)); // upper part of internal buffer address
|
||||
_spi->transfer((uint8_t)(IntPageAdr)); // lower part of internal buffer address
|
||||
_spi->transfer(0x00); // don't cares
|
||||
uint8_t cmd[5];
|
||||
cmd[0] = BufferNum?DF_BUFFER_2_READ:DF_BUFFER_1_READ;
|
||||
cmd[1] = 0;
|
||||
cmd[2] = (uint8_t)(IntPageAdr>>8);
|
||||
cmd[3] = (uint8_t)(IntPageAdr);
|
||||
cmd[4] = 0;
|
||||
_spi->transfer(cmd, sizeof(cmd));
|
||||
|
||||
uint8_t *pData = (uint8_t *)pBuffer;
|
||||
while (size--) {
|
||||
|
|
Loading…
Reference in New Issue