EEPROM simplification. Needs tests. (#3713)
This commit is contained in:
@@ -145,7 +145,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
||||
#if defined(EEPROM)
|
||||
if (lun == STORAGE_EEPROM_LUN) {
|
||||
*block_size = BLOCK_SIZE;
|
||||
*block_num = 3 + EESIZE/BLOCK_SIZE + FLASHSIZE/BLOCK_SIZE;
|
||||
*block_num = 3 + EEPROM_SIZE/BLOCK_SIZE + FLASHSIZE/BLOCK_SIZE;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -282,7 +282,7 @@ const char g_FATboot[BLOCK_SIZE] =
|
||||
|
||||
0x01, // Number of FATs
|
||||
0x10, 0x00, // Number of root directory entries
|
||||
3+(EESIZE/BLOCK_SIZE), (FLASHSIZE/BLOCK_SIZE)>>8, // Total sectors
|
||||
3+(EEPROM_SIZE/BLOCK_SIZE), (FLASHSIZE/BLOCK_SIZE)>>8, // Total sectors
|
||||
0xf8, // Media descriptor
|
||||
0x01, 0x00, // Sectors per FAT table
|
||||
0x20, 0x00, // Sectors per track
|
||||
@@ -462,7 +462,7 @@ const FATDirEntry_t g_DIRroot[16] =
|
||||
0xA302,
|
||||
0x3D55,
|
||||
0x0002,
|
||||
EESIZE
|
||||
EEPROM_SIZE
|
||||
},
|
||||
{
|
||||
{ 'F', 'I', 'R', 'M', 'W', 'A', 'R', 'E'},
|
||||
@@ -476,7 +476,7 @@ const FATDirEntry_t g_DIRroot[16] =
|
||||
0x0000,
|
||||
0xA302,
|
||||
0x3D55,
|
||||
0x0002 + (EESIZE/BLOCK_SIZE)/8,
|
||||
0x0002 + (EEPROM_SIZE/BLOCK_SIZE)/8,
|
||||
FLASHSIZE
|
||||
},
|
||||
{
|
||||
@@ -690,12 +690,12 @@ int32_t fat12Read(uint8_t * buffer, uint16_t sector, uint16_t count)
|
||||
else if (sector == 2) {
|
||||
memcpy(buffer, g_DIRroot, BLOCK_SIZE ) ;
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
|
||||
else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE)) {
|
||||
eepromReadBlock(buffer, (sector-3)*BLOCK_SIZE, BLOCK_SIZE);
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||
else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||
uint32_t address;
|
||||
address = sector - 3 - (EESIZE/BLOCK_SIZE);
|
||||
address = sector - 3 - (EEPROM_SIZE/BLOCK_SIZE);
|
||||
address *= BLOCK_SIZE;
|
||||
address += FIRMWARE_ADDRESS;
|
||||
memcpy(buffer, (uint8_t *)address, BLOCK_SIZE);
|
||||
@@ -722,7 +722,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
||||
if (sector < 3) {
|
||||
// reserved, read-only
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCK_SIZE)) {
|
||||
else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE)) {
|
||||
// eeprom
|
||||
while (count) {
|
||||
if (operation == FATWRITE_NONE && isEepromStart(buffer)) {
|
||||
@@ -735,16 +735,16 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
||||
buffer += BLOCK_SIZE;
|
||||
sector++;
|
||||
count--;
|
||||
if (sector-3 >= (EESIZE/BLOCK_SIZE)) {
|
||||
if (sector-3 >= (EEPROM_SIZE/BLOCK_SIZE)) {
|
||||
TRACE("EEPROM end written at sector %d", sector-1);
|
||||
operation = FATWRITE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||
else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
|
||||
// firmware
|
||||
uint32_t address;
|
||||
address = sector - 3 - (EESIZE/BLOCK_SIZE);
|
||||
address = sector - 3 - (EEPROM_SIZE/BLOCK_SIZE);
|
||||
address *= BLOCK_SIZE;
|
||||
address += FIRMWARE_ADDRESS;
|
||||
while (count) {
|
||||
@@ -763,7 +763,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
||||
}
|
||||
sector++;
|
||||
count--;
|
||||
if (sector-3-(EESIZE/BLOCK_SIZE) >= (FLASHSIZE/BLOCK_SIZE)) {
|
||||
if (sector-3-(EEPROM_SIZE/BLOCK_SIZE) >= (FLASHSIZE/BLOCK_SIZE)) {
|
||||
TRACE("FIRMWARE end written at sector %d", sector-1);
|
||||
operation = FATWRITE_NONE;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,11 @@ set(DSM2 "NO" CACHE STRING "LCD type (NO/PPM/SERIAL)")
|
||||
set(LUA NO)
|
||||
set(PULSES_SRC pulses_avr.cpp)
|
||||
set(SRC ${SRC} main_avr.cpp)
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} targets/common/avr/adc_driver.cpp)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
targets/common/avr/adc_driver.cpp
|
||||
targets/common/avr/eeprom_driver.cpp
|
||||
)
|
||||
add_definitions(-DLCD_${LCD})
|
||||
if(DSM2)
|
||||
add_definitions(-DDSM2 -DDSM2_${DSM2})
|
||||
@@ -86,7 +90,10 @@ if(TELEMETRY STREQUAL FRSKY OR TELEMETRY STREQUAL FRSKY_SPORT OR TELEMETRY STREQ
|
||||
option(VARIO "Vario support" ON)
|
||||
add_definitions(-DTELEMETRY_FRSKY)
|
||||
set(SRC ${SRC} telemetry/telemetry.cpp telemetry/telemetry_holders.cpp telemetry/frsky.cpp telemetry/frsky_d.cpp)
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} targets/common/avr/telemetry_driver.cpp)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
targets/common/avr/telemetry_driver.cpp
|
||||
)
|
||||
set(GUI_SRC ${GUI_SRC} view_telemetry.cpp)
|
||||
if(FRSKY_HUB)
|
||||
add_definitions(-DFRSKY_HUB)
|
||||
|
||||
@@ -117,6 +117,19 @@ void lcdRefreshSide();
|
||||
uint8_t lcdRefresh_ST7920(uint8_t full);
|
||||
#endif
|
||||
|
||||
// EEPROM driver
|
||||
#if defined(CPUM2560) || defined(CPUM2561) || defined(CPUM128)
|
||||
#define EEPROM_SIZE 4096
|
||||
#else
|
||||
#define EEPROM_SIZE 2048
|
||||
#endif
|
||||
#if defined(SIMU)
|
||||
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size);
|
||||
#else
|
||||
#define eepromReadBlock(buffer, address, size) eeprom_read_block(buffer, (const void *)address, size)
|
||||
#endif
|
||||
uint8_t eepromIsTransferComplete();
|
||||
|
||||
// USART driver (static register dispatcher)
|
||||
#define RXD_DDR1 DDRD
|
||||
#define RXD_DDR_PIN1 DDD2
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint16_t eeprom_pointer;
|
||||
uint8_t * eeprom_buffer_data;
|
||||
volatile int8_t eeprom_buffer_size = 0;
|
||||
|
||||
inline void eeprom_write_byte()
|
||||
{
|
||||
EEAR = eeprom_pointer;
|
||||
EEDR = *eeprom_buffer_data;
|
||||
// TODO add some define here
|
||||
#if defined (CPUM2560) || defined(CPUM2561)
|
||||
EECR |= 1<<EEMPE;
|
||||
EECR |= 1<<EEPE;
|
||||
#else
|
||||
EECR |= 1<<EEMWE;
|
||||
EECR |= 1<<EEWE;
|
||||
#endif
|
||||
eeprom_pointer++;
|
||||
eeprom_buffer_data++;
|
||||
}
|
||||
|
||||
ISR(EE_READY_vect)
|
||||
{
|
||||
if (--eeprom_buffer_size > 0) {
|
||||
eeprom_write_byte();
|
||||
}
|
||||
else {
|
||||
#if defined(CPUM2560) || defined(CPUM2561)
|
||||
EECR &= ~(1<<EERIE);
|
||||
#else
|
||||
EECR &= ~(1<<EERIE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(eeprom_buffer_size == 0);
|
||||
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = buffer;
|
||||
eeprom_buffer_size = size+1;
|
||||
|
||||
#if defined (CPUM2560) || defined(CPUM2561)
|
||||
EECR |= (1<<EERIE);
|
||||
#else
|
||||
EECR |= (1<<EERIE);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return eeprom_buffer_size == 0;
|
||||
}
|
||||
|
||||
extern uint8_t s_sync_write;
|
||||
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromStartWrite(buffer, address, size);
|
||||
|
||||
if (s_sync_write) {
|
||||
while (!eepromIsTransferComplete()) {
|
||||
wdt_reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user