EEPROM simplification. Needs tests. (#3713)
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
set(ARCH ARM)
|
||||
set(LUA NO)
|
||||
set(MCU cortex-m3)
|
||||
set(SDCARD YES)
|
||||
set(HAPTIC YES)
|
||||
set(EEPROM EEPROM_RAW)
|
||||
set(GUI_DIR 128x64)
|
||||
set(TARGET_DIR sky9x)
|
||||
set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} 9x_bitmaps)
|
||||
|
||||
if(PCB STREQUAL 9XRPRO)
|
||||
add_definitions(-Dat91sam3s8 -DREVX)
|
||||
set(FLAVOUR 9xrpro)
|
||||
@@ -32,14 +40,6 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(MCU cortex-m3)
|
||||
set(SDCARD YES)
|
||||
set(HAPTIC YES)
|
||||
set(EEPROM EEPROM_RAW)
|
||||
set(GUI_DIR 128x64)
|
||||
set(TARGET_DIR sky9x)
|
||||
set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} 9x_bitmaps)
|
||||
|
||||
add_definitions(-DPCBSKY9X -DPPM_PIN_SERIAL)
|
||||
add_definitions(-DAUDIO -DVOICE -DRTCLOCK -DVARIO)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
@@ -57,15 +57,32 @@ set(GUI_SRC
|
||||
view_about.cpp
|
||||
)
|
||||
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} core_cm3.c board_lowlevel.c crt.c vectors_sam3s.c)
|
||||
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} lcd_driver.cpp pwr_driver.cpp
|
||||
usb/device/core/USBD_UDP.c usb/device/core/USBDDriver.c
|
||||
usb/device/massstorage/MSDDriver.c usb/device/massstorage/MSDDStateMachine.c usb/device/massstorage/MSDLun.c
|
||||
usb/device/massstorage/MSDDriverDescriptors.c usb/device/massstorage/SBCMethods.c usb/common/core/USBEndpointDescriptor.c
|
||||
usb/common/core/USBGenericRequest.c usb/common/core/USBFeatureRequest.c usb/common/core/USBInterfaceRequest.c
|
||||
usb/common/core/USBGetDescriptorRequest.c usb/common/core/USBSetAddressRequest.c usb/common/core/USBSetConfigurationRequest.c
|
||||
usb/common/core/USBConfigurationDescriptor.c usb/common/core/USBGenericDescriptor.c MEDSdcard.c
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
core_cm3.c
|
||||
board_lowlevel.c
|
||||
crt.c
|
||||
vectors_sam3s.c
|
||||
eeprom_driver.cpp
|
||||
lcd_driver.cpp
|
||||
pwr_driver.cpp
|
||||
usb/device/core/USBD_UDP.c
|
||||
usb/device/core/USBDDriver.c
|
||||
usb/device/massstorage/MSDDriver.c
|
||||
usb/device/massstorage/MSDDStateMachine.c
|
||||
usb/device/massstorage/MSDLun.c
|
||||
usb/device/massstorage/MSDDriverDescriptors.c
|
||||
usb/device/massstorage/SBCMethods.c
|
||||
usb/common/core/USBEndpointDescriptor.c
|
||||
usb/common/core/USBGenericRequest.c
|
||||
usb/common/core/USBFeatureRequest.c
|
||||
usb/common/core/USBInterfaceRequest.c
|
||||
usb/common/core/USBGetDescriptorRequest.c
|
||||
usb/common/core/USBSetAddressRequest.c
|
||||
usb/common/core/USBSetConfigurationRequest.c
|
||||
usb/common/core/USBConfigurationDescriptor.c
|
||||
usb/common/core/USBGenericDescriptor.c
|
||||
MEDSdcard.c
|
||||
)
|
||||
|
||||
set(TARGET_SRC
|
||||
@@ -73,7 +90,6 @@ set(TARGET_SRC
|
||||
board.cpp
|
||||
telemetry_driver.cpp
|
||||
adc_driver.cpp
|
||||
eeprom_driver.cpp
|
||||
pulses_driver.cpp
|
||||
keys_driver.cpp
|
||||
audio_driver.cpp
|
||||
@@ -81,8 +97,16 @@ set(TARGET_SRC
|
||||
haptic_driver.cpp
|
||||
sdcard_driver.cpp
|
||||
massstorage.cpp
|
||||
)
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
loadboot.cpp
|
||||
)
|
||||
|
||||
set(SRC
|
||||
${SRC}
|
||||
debug.cpp
|
||||
)
|
||||
|
||||
set(SERIAL2_DRIVER serial2_driver.cpp)
|
||||
set(SRC ${SRC} debug.cpp)
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} loadboot.cpp)
|
||||
|
||||
@@ -353,13 +353,11 @@ uint32_t pwroffPressed();
|
||||
#define EEPROM_SIZE (4*1024*1024/8)
|
||||
#define EEPROM_BLOCK_SIZE (4*1024)
|
||||
void eepromInit();
|
||||
uint32_t eepromReadStatus();
|
||||
uint8_t eepromIsSpiComplete(void);
|
||||
void eepromWaitSpiComplete(void);
|
||||
void eepromWriteEnable();
|
||||
uint8_t eepromReadStatus();
|
||||
uint8_t eepromIsTransferComplete(void);
|
||||
void eepromBlockErase(uint32_t address);
|
||||
void eepromReadArray(uint32_t address, uint8_t * buffer, uint32_t size);
|
||||
void eepromByteProgram(uint32_t address, uint8_t * buffer, uint32_t size);
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
|
||||
@@ -20,39 +20,26 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t Spi_complete;
|
||||
volatile uint8_t Spi_complete = 1;
|
||||
uint8_t Spi_tx_buf[24];
|
||||
|
||||
uint8_t eepromIsSpiComplete()
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return Spi_complete;
|
||||
}
|
||||
|
||||
void eepromWaitSpiComplete()
|
||||
{
|
||||
while (!Spi_complete) {
|
||||
SIMU_SLEEP(5/*ms*/);
|
||||
}
|
||||
Spi_complete = false;
|
||||
}
|
||||
|
||||
uint32_t eepromTransmitData(register uint8_t *command, register uint8_t *tx, register uint8_t *rx, register uint32_t comlen, register uint32_t count)
|
||||
{
|
||||
#ifndef SIMU
|
||||
|
||||
register Spi *spiptr;
|
||||
register Spi * spiptr = SPI;
|
||||
register uint32_t condition;
|
||||
static uint8_t discard_rx_command[4];
|
||||
|
||||
// PMC->PMC_PCER0 |= 0x00200000L; // Enable peripheral clock to SPI
|
||||
|
||||
Spi_complete = 0;
|
||||
if (comlen > 4) {
|
||||
Spi_complete = 1;
|
||||
return 0x4FFFF;
|
||||
}
|
||||
|
||||
Spi_complete = 0;
|
||||
condition = SPI_SR_TXEMPTY;
|
||||
spiptr = SPI;
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
@@ -84,21 +71,14 @@ uint32_t eepromTransmitData(register uint8_t *command, register uint8_t *tx, reg
|
||||
}
|
||||
spiptr->SPI_IER = condition;
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t eepromTransmitByte(uint8_t out, bool skipFirst)
|
||||
{
|
||||
register Spi *spiptr;
|
||||
register Spi * spiptr = SPI;
|
||||
register uint32_t delay;
|
||||
|
||||
#if defined(SIMU)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
spiptr = SPI;
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
|
||||
@@ -146,9 +126,10 @@ void eepromPrepareCommand(EepromCommand command, uint32_t address)
|
||||
*(p+3) = address;
|
||||
}
|
||||
|
||||
uint32_t eepromReadStatus()
|
||||
uint8_t eepromReadStatus()
|
||||
{
|
||||
return eepromTransmitByte(COMMAND_READ_STATUS, true);
|
||||
uint8_t read_status = eepromTransmitByte(COMMAND_READ_STATUS, true);
|
||||
return !(read_status & 1);
|
||||
}
|
||||
|
||||
void eepromWriteStatusRegister()
|
||||
@@ -156,25 +137,27 @@ void eepromWriteStatusRegister()
|
||||
eepromTransmitByte(COMMAND_WRITE_STATUS_REGISTER, true);
|
||||
}
|
||||
|
||||
void eepromByteProgram(uint32_t address, uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_BYTE_PROGRAM, address);
|
||||
eepromTransmitData(Spi_tx_buf, buffer, 0, 4, size);
|
||||
}
|
||||
|
||||
void eepromReadArray(uint32_t address, uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_READ_ARRAY, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, buffer, 4, size);
|
||||
}
|
||||
|
||||
void eepromWriteEnable()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_ENABLE, false);
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BYTE_PROGRAM, address);
|
||||
eepromTransmitData(Spi_tx_buf, buffer, 0, 4, size);
|
||||
}
|
||||
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_READ_ARRAY, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, buffer, 4, size);
|
||||
}
|
||||
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BLOCK_ERASE, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, 0, 4, 0);
|
||||
}
|
||||
@@ -189,14 +172,13 @@ void eepromBlockErase(uint32_t address)
|
||||
// Set clock to 3 MHz, AT25 device is rated to 70MHz, 18MHz would be better
|
||||
void eepromInit()
|
||||
{
|
||||
register Spi *spiptr;
|
||||
register Spi * spiptr = SPI;
|
||||
register uint32_t timer;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00200000L; // Enable peripheral clock to SPI
|
||||
/* Configure PIO */
|
||||
configure_pins(0x00007800, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP);
|
||||
|
||||
spiptr = SPI;
|
||||
timer = (Master_frequency / 3000000) << 8; // Baud rate 3Mb/s
|
||||
spiptr->SPI_MR = 0x14000011; // 0001 0100 0000 0000 0000 0000 0001 0001 Master
|
||||
spiptr->SPI_CSR[0] = 0x01180009 | timer; // 0000 0001 0001 1000 xxxx xxxx 0000 1001
|
||||
@@ -206,20 +188,13 @@ void eepromInit()
|
||||
eepromWriteStatusRegister();
|
||||
}
|
||||
|
||||
#ifndef SIMU
|
||||
extern "C" void SPI_IRQHandler()
|
||||
{
|
||||
register Spi *spiptr;
|
||||
|
||||
spiptr = SPI;
|
||||
register Spi * spiptr = SPI;
|
||||
SPI->SPI_IDR = 0x07FF; // All interrupts off
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTDIS | SPI_PTCR_TXTDIS; // Stop tramsfers
|
||||
Spi_complete = 1; // Indicate completion
|
||||
|
||||
// Power save
|
||||
// PMC->PMC_PCER0 &= ~0x00200000L; // Disable peripheral clock to SPI
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user