mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 18:08:30 -04:00
DataFlash: APM2 ported to AP_HAL SPIDeviceDriver
This commit is contained in:
parent
4f07a90b2e
commit
aaffd9d96e
@ -32,21 +32,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C" {
|
#include <AP_HAL.h> // for removing conflict with optical flow sensor on SPI3 bus
|
||||||
// AVR LibC Includes
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
}
|
|
||||||
#include <FastSerial.h>
|
|
||||||
|
|
||||||
#if defined(ARDUINO) && ARDUINO >= 100
|
|
||||||
#include "Arduino.h"
|
|
||||||
#else
|
|
||||||
#include "WConstants.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <AP_Semaphore.h> // for removing conflict with optical flow sensor on SPI3 bus
|
|
||||||
#include "DataFlash_APM2.h"
|
#include "DataFlash_APM2.h"
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
/*
|
/*
|
||||||
* #define ENABLE_FASTSERIAL_DEBUG
|
* #define ENABLE_FASTSERIAL_DEBUG
|
||||||
*
|
*
|
||||||
@ -57,17 +46,8 @@ extern "C" {
|
|||||||
##endif
|
##endif
|
||||||
# //*/
|
# //*/
|
||||||
|
|
||||||
// DataFlash is connected to Serial Port 3 (we will use SPI mode)
|
#define DF_RESET 41 // RESET (PG0)
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(DESKTOP_BUILD)
|
#define DF_CARDDETECT 33 // PC4
|
||||||
#define DF_DATAOUT 14 // MOSI
|
|
||||||
#define DF_DATAIN 15 // MISO
|
|
||||||
#define DF_SPICLOCK PJ2 // SCK
|
|
||||||
#define DF_SLAVESELECT 28 // SS (PA6)
|
|
||||||
#define DF_RESET 41 // RESET (PG0)
|
|
||||||
#define DF_CARDDETECT 33 // PC4
|
|
||||||
#else
|
|
||||||
# error Please check the Tools/Board menu to ensure you have selected Arduino Mega as your target.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// AT45DB321D Commands (from Datasheet)
|
// AT45DB321D Commands (from Datasheet)
|
||||||
#define DF_TRANSFER_PAGE_TO_BUFFER_1 0x53
|
#define DF_TRANSFER_PAGE_TO_BUFFER_1 0x53
|
||||||
@ -90,47 +70,6 @@ extern "C" {
|
|||||||
#define DF_CHIP_ERASE_3 0x9A
|
#define DF_CHIP_ERASE_3 0x9A
|
||||||
|
|
||||||
|
|
||||||
// *** INTERNAL FUNCTIONS ***
|
|
||||||
uint8_t DataFlash_APM2::SPI_transfer(uint8_t data)
|
|
||||||
{
|
|
||||||
uint8_t retval;
|
|
||||||
|
|
||||||
// get spi3 semaphore if required. if failed to get semaphore then
|
|
||||||
// just quietly fail
|
|
||||||
if ( _spi3_semaphore != NULL) {
|
|
||||||
if( !_spi3_semaphore->get(this) ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for empty transmit buffer */
|
|
||||||
while ( !( UCSR3A & (1<<UDRE3)) ) ;
|
|
||||||
/* Put data into buffer, sends the data */
|
|
||||||
UDR3 = data;
|
|
||||||
/* Wait for data to be received */
|
|
||||||
while ( !(UCSR3A & (1<<RXC3)) ) ;
|
|
||||||
/* Get and return received data from buffer */
|
|
||||||
retval = UDR3;
|
|
||||||
|
|
||||||
// release spi3 semaphore
|
|
||||||
if ( _spi3_semaphore != NULL) {
|
|
||||||
_spi3_semaphore->release(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable device
|
|
||||||
void DataFlash_APM2::CS_inactive()
|
|
||||||
{
|
|
||||||
digitalWrite(DF_SLAVESELECT,HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable device
|
|
||||||
void DataFlash_APM2::CS_active()
|
|
||||||
{
|
|
||||||
digitalWrite(DF_SLAVESELECT,LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
void DataFlash_APM2::Init(void)
|
void DataFlash_APM2::Init(void)
|
||||||
@ -138,35 +77,34 @@ void DataFlash_APM2::Init(void)
|
|||||||
// init to zero
|
// init to zero
|
||||||
df_NumPages = 0;
|
df_NumPages = 0;
|
||||||
|
|
||||||
pinMode(DF_DATAOUT, OUTPUT);
|
hal.gpio->pinMode(DF_RESET, GPIO_OUTPUT);
|
||||||
pinMode(DF_DATAIN, INPUT);
|
hal.gpio->pinMode(DF_CARDDETECT, GPIO_INPUT);
|
||||||
pinMode(DF_SLAVESELECT,OUTPUT);
|
|
||||||
pinMode(DF_RESET,OUTPUT);
|
|
||||||
pinMode(DF_CARDDETECT, INPUT);
|
|
||||||
|
|
||||||
// Reset the chip
|
// Reset the chip
|
||||||
digitalWrite(DF_RESET,LOW);
|
hal.gpio->write(DF_RESET,0);
|
||||||
delay(1);
|
hal.scheduler->delay(1);
|
||||||
digitalWrite(DF_RESET,HIGH);
|
hal.gpio->write(DF_RESET,1);
|
||||||
|
|
||||||
// disable device
|
_spi = hal.spi->device(AP_HAL::SPIDevice_Dataflash);
|
||||||
CS_inactive();
|
if (_spi == NULL) {
|
||||||
|
hal.console->println_P(
|
||||||
// Setup Serial Port3 in SPI mode (MSPI), Mode 0, Clock: 8Mhz
|
PSTR("PANIC: DataFlash SPIDeviceDriver not found"));
|
||||||
UBRR3 = 0;
|
return;
|
||||||
DDRJ |= (1<<PJ2); // SPI clock XCK3 (PJ2) as output. This enable SPI Master mode
|
}
|
||||||
// Set MSPI mode of operation and SPI data mode 0.
|
_spi_sem = _spi->get_semaphore();
|
||||||
UCSR3C = (1<<UMSEL31)|(1<<UMSEL30); //|(1<<1)|(1<<UCPOL3);
|
if (_spi_sem) {
|
||||||
// Enable receiver and transmitter.
|
bool got = _spi_sem->get(this);
|
||||||
UCSR3B = (1<<RXEN3)|(1<<TXEN3);
|
if (!got) return;
|
||||||
// Set Baud rate
|
}
|
||||||
UBRR3 = 0; // SPI running at 8Mhz
|
|
||||||
|
|
||||||
// get page size: 512 or 528 (by default: 528)
|
// get page size: 512 or 528 (by default: 528)
|
||||||
df_PageSize=PageSize();
|
df_PageSize=PageSize();
|
||||||
|
|
||||||
ReadManufacturerID();
|
ReadManufacturerID();
|
||||||
|
|
||||||
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
// see page 22 of the spec for the density code
|
// see page 22 of the spec for the density code
|
||||||
uint8_t density_code = (df_device >> 8) & 0x1F;
|
uint8_t density_code = (df_device >> 8) & 0x1F;
|
||||||
|
|
||||||
@ -187,18 +125,18 @@ void DataFlash_APM2::Init(void)
|
|||||||
void DataFlash_APM2::ReadManufacturerID()
|
void DataFlash_APM2::ReadManufacturerID()
|
||||||
{
|
{
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
// Read manufacturer and ID command...
|
// Read manufacturer and ID command...
|
||||||
SPI_transfer(DF_READ_MANUFACTURER_AND_DEVICE_ID);
|
_spi->transfer(DF_READ_MANUFACTURER_AND_DEVICE_ID);
|
||||||
|
|
||||||
df_manufacturer = SPI_transfer(0xff);
|
df_manufacturer = _spi->transfer(0xff);
|
||||||
df_device = SPI_transfer(0xff);
|
df_device = _spi->transfer(0xff);
|
||||||
df_device = (df_device<<8) | SPI_transfer(0xff);
|
df_device = (df_device<<8) | _spi->transfer(0xff);
|
||||||
SPI_transfer(0xff);
|
_spi->transfer(0xff);
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function return 1 if Card is inserted on SD slot
|
// This function return 1 if Card is inserted on SD slot
|
||||||
@ -215,14 +153,14 @@ uint8_t DataFlash_APM2::ReadStatusReg()
|
|||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
|
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
// Read status command
|
// Read status command
|
||||||
SPI_transfer(DF_STATUS_REGISTER_READ);
|
_spi->transfer(DF_STATUS_REGISTER_READ);
|
||||||
tmp = SPI_transfer(0x00); // We only want to extract the READY/BUSY bit
|
tmp = _spi->transfer(0x00); // We only want to extract the READY/BUSY bit
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -248,185 +186,226 @@ void DataFlash_APM2::WaitReady()
|
|||||||
|
|
||||||
void DataFlash_APM2::PageToBuffer(uint8_t BufferNum, uint16_t PageAdr)
|
void DataFlash_APM2::PageToBuffer(uint8_t BufferNum, uint16_t PageAdr)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
if (BufferNum==1)
|
if (BufferNum==1)
|
||||||
SPI_transfer(DF_TRANSFER_PAGE_TO_BUFFER_1);
|
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_1);
|
||||||
else
|
else
|
||||||
SPI_transfer(DF_TRANSFER_PAGE_TO_BUFFER_2);
|
_spi->transfer(DF_TRANSFER_PAGE_TO_BUFFER_2);
|
||||||
|
|
||||||
if(df_PageSize==512) {
|
if(df_PageSize==512) {
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 7));
|
_spi->transfer((uint8_t)(PageAdr >> 7));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 1));
|
_spi->transfer((uint8_t)(PageAdr << 1));
|
||||||
}else{
|
}else{
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 6));
|
_spi->transfer((uint8_t)(PageAdr >> 6));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 2));
|
_spi->transfer((uint8_t)(PageAdr << 2));
|
||||||
}
|
}
|
||||||
SPI_transfer(0x00); // don´t care bytes
|
_spi->transfer(0x00); // don´t care bytes
|
||||||
|
|
||||||
//initiate the transfer
|
//initiate the transfer
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
while(!ReadStatus()) ; //monitor the status register, wait until busy-flag is high
|
while(!ReadStatus()) ; //monitor the status register, wait until busy-flag is high
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFlash_APM2::BufferToPage (uint8_t BufferNum, uint16_t PageAdr, uint8_t wait)
|
void DataFlash_APM2::BufferToPage (uint8_t BufferNum, uint16_t PageAdr, uint8_t wait)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
if (BufferNum==1)
|
if (BufferNum==1)
|
||||||
SPI_transfer(DF_BUFFER_1_TO_PAGE_WITH_ERASE);
|
_spi->transfer(DF_BUFFER_1_TO_PAGE_WITH_ERASE);
|
||||||
else
|
else
|
||||||
SPI_transfer(DF_BUFFER_2_TO_PAGE_WITH_ERASE);
|
_spi->transfer(DF_BUFFER_2_TO_PAGE_WITH_ERASE);
|
||||||
|
|
||||||
if(df_PageSize==512) {
|
if(df_PageSize==512) {
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 7));
|
_spi->transfer((uint8_t)(PageAdr >> 7));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 1));
|
_spi->transfer((uint8_t)(PageAdr << 1));
|
||||||
}else{
|
}else{
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 6));
|
_spi->transfer((uint8_t)(PageAdr >> 6));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 2));
|
_spi->transfer((uint8_t)(PageAdr << 2));
|
||||||
}
|
}
|
||||||
SPI_transfer(0x00); // don´t care bytes
|
_spi->transfer(0x00); // don´t care bytes
|
||||||
|
|
||||||
//initiate the transfer
|
//initiate the transfer
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
CS_active();
|
|
||||||
|
|
||||||
// Check if we need to wait to write the buffer to memory or we can continue...
|
// Check if we need to wait to write the buffer to memory or we can continue...
|
||||||
if (wait)
|
if (wait)
|
||||||
while(!ReadStatus()) ; //monitor the status register, wait until busy-flag is high
|
while(!ReadStatus()) ; //monitor the status register, wait until busy-flag is high
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFlash_APM2::BufferWrite (uint8_t BufferNum, uint16_t IntPageAdr, uint8_t Data)
|
void DataFlash_APM2::BufferWrite (uint8_t BufferNum, uint16_t IntPageAdr, uint8_t Data)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
if (BufferNum==1)
|
if (BufferNum==1)
|
||||||
SPI_transfer(DF_BUFFER_1_WRITE);
|
_spi->transfer(DF_BUFFER_1_WRITE);
|
||||||
else
|
else
|
||||||
SPI_transfer(DF_BUFFER_2_WRITE);
|
_spi->transfer(DF_BUFFER_2_WRITE);
|
||||||
|
|
||||||
SPI_transfer(0x00); // don't care
|
_spi->transfer(0x00); // don't care
|
||||||
SPI_transfer((uint8_t)(IntPageAdr>>8)); // upper part of internal buffer address
|
_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((uint8_t)(IntPageAdr)); // lower part of internal buffer address
|
||||||
SPI_transfer(Data); // write data byte
|
_spi->transfer(Data); // write data byte
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DataFlash_APM2::BufferRead (uint8_t BufferNum, uint16_t IntPageAdr)
|
uint8_t DataFlash_APM2::BufferRead (uint8_t BufferNum, uint16_t IntPageAdr)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return 0;
|
||||||
|
}
|
||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
|
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
if (BufferNum==1)
|
if (BufferNum==1)
|
||||||
SPI_transfer(DF_BUFFER_1_READ);
|
_spi->transfer(DF_BUFFER_1_READ);
|
||||||
else
|
else
|
||||||
SPI_transfer(DF_BUFFER_2_READ);
|
_spi->transfer(DF_BUFFER_2_READ);
|
||||||
|
|
||||||
SPI_transfer(0x00);
|
_spi->transfer(0x00);
|
||||||
SPI_transfer((uint8_t)(IntPageAdr>>8)); //upper part of internal buffer address
|
_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((uint8_t)(IntPageAdr)); //lower part of internal buffer address
|
||||||
SPI_transfer(0x00); //don't cares
|
_spi->transfer(0x00); //don't cares
|
||||||
tmp = SPI_transfer(0x00); //read data byte
|
tmp = _spi->transfer(0x00); //read data byte
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
|
|
||||||
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
return (tmp);
|
return (tmp);
|
||||||
}
|
}
|
||||||
// *** END OF INTERNAL FUNCTIONS ***
|
// *** END OF INTERNAL FUNCTIONS ***
|
||||||
|
|
||||||
void DataFlash_APM2::PageErase (uint16_t PageAdr)
|
void DataFlash_APM2::PageErase (uint16_t PageAdr)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
// Send page erase command
|
// Send page erase command
|
||||||
SPI_transfer(DF_PAGE_ERASE);
|
_spi->transfer(DF_PAGE_ERASE);
|
||||||
|
|
||||||
if(df_PageSize==512) {
|
if(df_PageSize==512) {
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 7));
|
_spi->transfer((uint8_t)(PageAdr >> 7));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 1));
|
_spi->transfer((uint8_t)(PageAdr << 1));
|
||||||
}else{
|
}else{
|
||||||
SPI_transfer((uint8_t)(PageAdr >> 6));
|
_spi->transfer((uint8_t)(PageAdr >> 6));
|
||||||
SPI_transfer((uint8_t)(PageAdr << 2));
|
_spi->transfer((uint8_t)(PageAdr << 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_transfer(0x00);
|
_spi->transfer(0x00);
|
||||||
|
|
||||||
//initiate flash page erase
|
//initiate flash page erase
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
CS_active();
|
|
||||||
while(!ReadStatus()) ;
|
while(!ReadStatus()) ;
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// erase a block of 8 pages.
|
// erase a block of 8 pages.
|
||||||
void DataFlash_APM2::BlockErase(uint16_t BlockAdr)
|
void DataFlash_APM2::BlockErase(uint16_t BlockAdr)
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
// Send block erase command
|
// Send block erase command
|
||||||
SPI_transfer(DF_BLOCK_ERASE);
|
_spi->transfer(DF_BLOCK_ERASE);
|
||||||
|
|
||||||
if (df_PageSize==512) {
|
if (df_PageSize==512) {
|
||||||
SPI_transfer((uint8_t)(BlockAdr >> 4));
|
_spi->transfer((uint8_t)(BlockAdr >> 4));
|
||||||
SPI_transfer((uint8_t)(BlockAdr << 4));
|
_spi->transfer((uint8_t)(BlockAdr << 4));
|
||||||
} else {
|
} else {
|
||||||
SPI_transfer((uint8_t)(BlockAdr >> 3));
|
_spi->transfer((uint8_t)(BlockAdr >> 3));
|
||||||
SPI_transfer((uint8_t)(BlockAdr << 5));
|
_spi->transfer((uint8_t)(BlockAdr << 5));
|
||||||
}
|
}
|
||||||
SPI_transfer(0x00);
|
_spi->transfer(0x00);
|
||||||
//serialDebug("BL Erase, %d\n", BlockAdr);
|
//serialDebug("BL Erase, %d\n", BlockAdr);
|
||||||
|
|
||||||
//initiate flash page erase
|
//initiate flash page erase
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
CS_active();
|
|
||||||
while(!ReadStatus()) ;
|
while(!ReadStatus()) ;
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DataFlash_APM2::ChipErase(void (*delay_cb)(unsigned long))
|
void DataFlash_APM2::ChipErase()
|
||||||
{
|
{
|
||||||
|
if (_spi_sem) {
|
||||||
|
bool got = _spi_sem->get(this);
|
||||||
|
if (!got) return;
|
||||||
|
}
|
||||||
//serialDebug("Chip Erase\n");
|
//serialDebug("Chip Erase\n");
|
||||||
|
|
||||||
// activate dataflash command decoder
|
// activate dataflash command decoder
|
||||||
CS_active();
|
_spi->cs_assert();
|
||||||
|
|
||||||
// opcodes for chip erase
|
// opcodes for chip erase
|
||||||
SPI_transfer(DF_CHIP_ERASE_0);
|
_spi->transfer(DF_CHIP_ERASE_0);
|
||||||
SPI_transfer(DF_CHIP_ERASE_1);
|
_spi->transfer(DF_CHIP_ERASE_1);
|
||||||
SPI_transfer(DF_CHIP_ERASE_2);
|
_spi->transfer(DF_CHIP_ERASE_2);
|
||||||
SPI_transfer(DF_CHIP_ERASE_3);
|
_spi->transfer(DF_CHIP_ERASE_3);
|
||||||
|
|
||||||
//initiate flash page erase
|
//initiate flash page erase
|
||||||
CS_inactive();
|
_spi->cs_release();
|
||||||
CS_active();
|
|
||||||
|
|
||||||
while(!ReadStatus()) {
|
while(!ReadStatus()) {
|
||||||
delay_cb(1);
|
hal.scheduler->delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// release SPI bus for use by other sensors
|
// release SPI bus for use by other sensors
|
||||||
CS_inactive();
|
if (_spi_sem) {
|
||||||
|
_spi_sem->release(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user