mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-24 08:45:15 +03:00
EEPROM simplification. Needs tests. (#3713)
This commit is contained in:
parent
c16ad94e3a
commit
0ff601a3fa
28 changed files with 485 additions and 480 deletions
|
@ -140,7 +140,7 @@ elseif(${EEPROM} STREQUAL EEPROM_RLC)
|
|||
add_definitions(-DEEPROM -DEEPROM_RLC)
|
||||
else()
|
||||
set(SRC ${SRC} storage/storage_common.cpp storage/eeprom_common.cpp storage/eeprom_raw.cpp)
|
||||
add_definitions(-DEEPROM)
|
||||
add_definitions(-DEEPROM -DEEPROM_RAW)
|
||||
endif()
|
||||
|
||||
if(ARCH STREQUAL ARM AND NOT PCB STREQUAL HORUS AND NOT PCB STREQUAL FLAMENCO)
|
||||
|
|
|
@ -88,7 +88,7 @@ void perMain()
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!eeprom_buffer_size) {
|
||||
if (eepromIsTransferComplete()) {
|
||||
if (theFile.isWriting())
|
||||
theFile.nextWriteStep();
|
||||
else if (TIME_TO_WRITE())
|
||||
|
|
|
@ -111,7 +111,7 @@ void storageReadAll()
|
|||
|
||||
void storageEraseAll(bool warn)
|
||||
{
|
||||
TRACE("storageEraseAll()");
|
||||
TRACE("storageEraseAll");
|
||||
|
||||
generalDefault();
|
||||
modelDefault(0);
|
||||
|
|
|
@ -63,7 +63,14 @@ uint8_t eepromWriteBuffer[EEPROM_BUFFER_SIZE] __DMA;
|
|||
|
||||
void eepromWaitReadStatus()
|
||||
{
|
||||
while ((eepromReadStatus() & 1) != 0) {
|
||||
while (eepromReadStatus() == 0) {
|
||||
SIMU_SLEEP(5/*ms*/);
|
||||
}
|
||||
}
|
||||
|
||||
void eepromWaitTransferComplete()
|
||||
{
|
||||
while (!eepromIsTransferComplete()) {
|
||||
SIMU_SLEEP(5/*ms*/);
|
||||
}
|
||||
}
|
||||
|
@ -71,46 +78,44 @@ void eepromWaitReadStatus()
|
|||
void eepromEraseBlock(uint32_t address, bool blocking=true)
|
||||
{
|
||||
// TRACE("eepromEraseBlock(%d)", address);
|
||||
|
||||
eepromWriteEnable();
|
||||
|
||||
eepromBlockErase(address);
|
||||
|
||||
if (blocking) {
|
||||
eepromWaitSpiComplete();
|
||||
eepromWaitTransferComplete();
|
||||
eepromWaitReadStatus();
|
||||
}
|
||||
}
|
||||
|
||||
void eepromRead(uint32_t address, uint8_t * buffer, uint32_t size, bool blocking=true)
|
||||
void eepromRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
// TRACE("eepromRead(%d, %p, %d)", address, buffer, size);
|
||||
// TRACE("eepromRead(%p, %d, %d)", buffer, address, size);
|
||||
|
||||
eepromReadArray(address, buffer, size);
|
||||
if (blocking) {
|
||||
eepromWaitSpiComplete();
|
||||
}
|
||||
eepromStartRead(buffer, address, size);
|
||||
eepromWaitTransferComplete();
|
||||
}
|
||||
|
||||
void eepromWrite(uint32_t address, uint8_t * buffer, uint32_t size, bool blocking=true)
|
||||
void eepromWrite(uint8_t * buffer, size_t address, size_t size, bool blocking=true)
|
||||
{
|
||||
// TRACE("eepromWrite(%d, %p, %d)", address, buffer, size);
|
||||
// TRACE("eepromWrite(%p, %d, %d)", buffer, address, size);
|
||||
|
||||
eepromWriteEnable();
|
||||
eepromByteProgram(address, buffer, size);
|
||||
eepromStartWrite(buffer, address, size);
|
||||
|
||||
if (blocking) {
|
||||
eepromWaitSpiComplete();
|
||||
eepromWaitTransferComplete();
|
||||
eepromWaitReadStatus();
|
||||
}
|
||||
}
|
||||
|
||||
bool eepromOpen()
|
||||
{
|
||||
TRACE("eepromOpen");
|
||||
|
||||
int32_t bestFatAddr = -1;
|
||||
uint32_t bestFatIndex = 0;
|
||||
eepromFatAddr = 0;
|
||||
while (eepromFatAddr < EEPROM_ZONE_SIZE) {
|
||||
eepromRead(eepromFatAddr, (uint8_t *)&eepromHeader, sizeof(eepromHeader.mark) + sizeof(eepromHeader.index));
|
||||
eepromRead((uint8_t *)&eepromHeader, eepromFatAddr, sizeof(eepromHeader.mark) + sizeof(eepromHeader.index));
|
||||
if (eepromHeader.mark == EEPROM_MARK && eepromHeader.index >= bestFatIndex) {
|
||||
bestFatAddr = eepromFatAddr;
|
||||
bestFatIndex = eepromHeader.index;
|
||||
|
@ -119,7 +124,7 @@ bool eepromOpen()
|
|||
}
|
||||
if (bestFatAddr >= 0) {
|
||||
eepromFatAddr = bestFatAddr;
|
||||
eepromRead(eepromFatAddr, (uint8_t *)&eepromHeader, sizeof(eepromHeader));
|
||||
eepromRead((uint8_t *)&eepromHeader, eepromFatAddr, sizeof(eepromHeader));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -132,12 +137,12 @@ uint32_t readFile(int index, uint8_t * data, uint32_t size)
|
|||
if (eepromHeader.files[index].exists) {
|
||||
EepromFileHeader header;
|
||||
uint32_t address = eepromHeader.files[index].zoneIndex * EEPROM_ZONE_SIZE;
|
||||
eepromRead(address, (uint8_t *)&header, sizeof(header));
|
||||
eepromRead((uint8_t *)&header, address, sizeof(header));
|
||||
if (size < header.size) {
|
||||
header.size = size;
|
||||
}
|
||||
if (header.size > 0) {
|
||||
eepromRead(address + sizeof(header), data, header.size);
|
||||
eepromRead(data, address + sizeof(header), header.size);
|
||||
size -= header.size;
|
||||
}
|
||||
if (size > 0) {
|
||||
|
@ -199,8 +204,8 @@ bool eeCopyModel(uint8_t dst, uint8_t src)
|
|||
|
||||
// write model
|
||||
for (int pos=0; pos<EEPROM_ZONE_SIZE; pos+=EEPROM_BUFFER_SIZE) {
|
||||
eepromRead(eepromWriteSourceAddr+pos, eepromWriteBuffer, EEPROM_BUFFER_SIZE);
|
||||
eepromWrite(eepromWriteDestinationAddr+pos, eepromWriteBuffer, EEPROM_BUFFER_SIZE);
|
||||
eepromRead(eepromWriteBuffer, eepromWriteSourceAddr+pos, EEPROM_BUFFER_SIZE);
|
||||
eepromWrite(eepromWriteBuffer, eepromWriteDestinationAddr+pos, EEPROM_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
// write FAT
|
||||
|
@ -292,7 +297,7 @@ void storageFormat()
|
|||
}
|
||||
eepromEraseBlock(0);
|
||||
eepromEraseBlock(EEPROM_BLOCK_SIZE);
|
||||
eepromWrite(0, (uint8_t *)&eepromHeader, sizeof(eepromHeader));
|
||||
eepromWrite((uint8_t *)&eepromHeader, 0, sizeof(eepromHeader));
|
||||
}
|
||||
|
||||
void eepromWriteWait(EepromWriteState state/* = EEPROM_IDLE*/)
|
||||
|
@ -346,7 +351,7 @@ void eepromWriteProcess()
|
|||
case EEPROM_WRITING_BUFFER:
|
||||
case EEPROM_ERASING_FAT_BLOCK:
|
||||
case EEPROM_WRITING_NEW_FAT:
|
||||
if (eepromIsSpiComplete()) {
|
||||
if (eepromIsTransferComplete()) {
|
||||
eepromWriteState = EepromWriteState(eepromWriteState + 1);
|
||||
}
|
||||
break;
|
||||
|
@ -356,7 +361,7 @@ void eepromWriteProcess()
|
|||
case EEPROM_WRITING_BUFFER_WAIT:
|
||||
case EEPROM_ERASING_FAT_BLOCK_WAIT:
|
||||
case EEPROM_WRITING_NEW_FAT_WAIT:
|
||||
if ((eepromReadStatus() & 1) == 0) {
|
||||
if (eepromReadStatus()) {
|
||||
eepromWriteState = EepromWriteState(eepromWriteState + 1);
|
||||
}
|
||||
break;
|
||||
|
@ -379,7 +384,7 @@ void eepromWriteProcess()
|
|||
uint32_t size = min<uint32_t>(EEPROM_BUFFER_SIZE-sizeof(EepromFileHeader), eepromWriteSize);
|
||||
memcpy(eepromWriteBuffer+sizeof(EepromFileHeader), eepromWriteSourceAddr, size);
|
||||
eepromWriteState = EEPROM_WRITING_BUFFER;
|
||||
eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, sizeof(EepromFileHeader)+size, false);
|
||||
eepromWrite(eepromWriteBuffer, eepromWriteDestinationAddr, sizeof(EepromFileHeader)+size, false);
|
||||
eepromWriteSourceAddr += size;
|
||||
eepromWriteDestinationAddr += sizeof(EepromFileHeader)+size;
|
||||
eepromWriteSize -= size;
|
||||
|
@ -392,7 +397,7 @@ void eepromWriteProcess()
|
|||
if (size > 0) {
|
||||
memcpy(eepromWriteBuffer, eepromWriteSourceAddr, size);
|
||||
eepromWriteState = EEPROM_WRITING_BUFFER;
|
||||
eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, size, false);
|
||||
eepromWrite(eepromWriteBuffer, eepromWriteDestinationAddr, size, false);
|
||||
eepromWriteSourceAddr += size;
|
||||
eepromWriteDestinationAddr += size;
|
||||
eepromWriteSize -= size;
|
||||
|
@ -408,7 +413,7 @@ void eepromWriteProcess()
|
|||
|
||||
case EEPROM_WRITE_NEW_FAT:
|
||||
eepromWriteState = EEPROM_WRITING_NEW_FAT;
|
||||
eepromWrite(eepromFatAddr, (uint8_t *)&eepromHeader, sizeof(eepromHeader), false);
|
||||
eepromWrite((uint8_t *)&eepromHeader, eepromFatAddr, sizeof(eepromHeader), false);
|
||||
break;
|
||||
|
||||
case EEPROM_END_WRITE:
|
||||
|
@ -427,7 +432,7 @@ uint16_t eeModelSize(uint8_t index)
|
|||
if (eepromHeader.files[index+1].exists) {
|
||||
uint32_t address = eepromHeader.files[index+1].zoneIndex * EEPROM_ZONE_SIZE;
|
||||
EepromFileHeader header;
|
||||
eepromRead(address, (uint8_t *)&header, sizeof(header));
|
||||
eepromRead((uint8_t *)&header, address, sizeof(header));
|
||||
result = header.size;
|
||||
}
|
||||
|
||||
|
@ -483,7 +488,7 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
|
|||
uint32_t address = eepromHeader.files[i_fileSrc+1].zoneIndex * EEPROM_ZONE_SIZE + sizeof(EepromFileHeader);
|
||||
while (size > 0) {
|
||||
uint16_t blockSize = min<uint16_t>(size, EEPROM_BUFFER_SIZE);
|
||||
eepromRead(address, eepromWriteBuffer, blockSize);
|
||||
eepromRead(eepromWriteBuffer, address, blockSize);
|
||||
result = f_write(&archiveFile, eepromWriteBuffer, blockSize, &written);
|
||||
if (result != FR_OK || written != blockSize) {
|
||||
f_close(&archiveFile);
|
||||
|
@ -567,7 +572,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
|
|||
f_close(&g_oLogFile);
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
eepromWrite(address, eepromWriteBuffer, blockSize+offset);
|
||||
eepromWrite(eepromWriteBuffer, address, blockSize+offset);
|
||||
size -= blockSize;
|
||||
address += EEPROM_BUFFER_SIZE;
|
||||
offset = 0;
|
||||
|
|
|
@ -29,74 +29,15 @@ EeFs eeFs;
|
|||
|
||||
#if defined(CPUARM)
|
||||
blkid_t freeBlocks = 0;
|
||||
#endif
|
||||
|
||||
uint8_t s_sync_write = false;
|
||||
|
||||
#if !defined(CPUARM)
|
||||
uint16_t eeprom_pointer;
|
||||
uint8_t * eeprom_buffer_data;
|
||||
volatile int8_t eeprom_buffer_size = 0;
|
||||
|
||||
#if !defined(SIMU)
|
||||
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
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void eepromWriteBlock(uint8_t * i_pointer_ram, uint16_t i_pointer_eeprom, size_t size)
|
||||
{
|
||||
assert(!eeprom_buffer_size);
|
||||
|
||||
eeprom_pointer = i_pointer_eeprom;
|
||||
eeprom_buffer_data = i_pointer_ram;
|
||||
eeprom_buffer_size = size+1;
|
||||
|
||||
#if defined(SIMU)
|
||||
sem_post(eeprom_write_sem);
|
||||
#elif defined (CPUM2560) || defined(CPUM2561)
|
||||
EECR |= (1<<EERIE);
|
||||
#else
|
||||
EECR |= (1<<EERIE);
|
||||
#endif
|
||||
|
||||
if (s_sync_write) {
|
||||
while (eeprom_buffer_size > 0) wdt_reset();
|
||||
}
|
||||
}
|
||||
uint8_t s_sync_write = false;
|
||||
#endif
|
||||
|
||||
static uint8_t EeFsRead(blkid_t blk, uint8_t ofs)
|
||||
{
|
||||
uint8_t ret;
|
||||
eepromReadBlock(&ret, (uint16_t)(blk*BS+ofs+BLOCKS_OFFSET), 1);
|
||||
return ret;
|
||||
uint8_t byte;
|
||||
eepromReadBlock(&byte, (size_t)(blk*BS+ofs+BLOCKS_OFFSET), 1);
|
||||
return byte;
|
||||
}
|
||||
|
||||
static blkid_t EeFsGetLink(blkid_t blk)
|
||||
|
@ -246,10 +187,10 @@ void storageFormat()
|
|||
{
|
||||
ENABLE_SYNC_WRITE(true);
|
||||
|
||||
#ifdef SIMU
|
||||
#if defined(SIMU)
|
||||
// write zero to the end of the new EEPROM file to set it's proper size
|
||||
uint8_t dummy = 0;
|
||||
eepromWriteBlock(&dummy, EESIZE-1, 1);
|
||||
static uint8_t dummy = 0;
|
||||
eepromWriteBlock(&dummy, EEPROM_SIZE-1, 1);
|
||||
#endif
|
||||
|
||||
memclear(&eeFs, sizeof(eeFs));
|
||||
|
@ -831,9 +772,8 @@ void RlcFile::nextRlcWriteStep()
|
|||
|
||||
void RlcFile::flush()
|
||||
{
|
||||
#if !defined(CPUARM)
|
||||
while (eeprom_buffer_size > 0) wdt_reset();
|
||||
#endif
|
||||
while (!eepromIsTransferComplete())
|
||||
wdt_reset();
|
||||
|
||||
ENABLE_SYNC_WRITE(true);
|
||||
|
||||
|
@ -1008,11 +948,11 @@ void eepromBackup()
|
|||
// open the file for writing...
|
||||
f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
|
||||
for (int i=0; i<EESIZE; i+=1024) {
|
||||
for (int i=0; i<EEPROM_SIZE; i+=1024) {
|
||||
UINT count;
|
||||
eepromReadBlock(buffer, i, 1024);
|
||||
f_write(&file, buffer, 1024, &count);
|
||||
updateProgressBar(i, EESIZE);
|
||||
updateProgressBar(i, EEPROM_SIZE);
|
||||
SIMU_SLEEP(100/*ms*/);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,27 +25,16 @@
|
|||
|
||||
#if defined(PCBTARANIS)
|
||||
#define blkid_t uint16_t
|
||||
#if !defined(EESIZE)
|
||||
#if defined(REV4a)
|
||||
#define EESIZE (64*1024)
|
||||
#else
|
||||
#define EESIZE (32*1024)
|
||||
#endif
|
||||
#else
|
||||
#define EESIZE_SIMU (64*1024)
|
||||
#endif
|
||||
#define EEFS_VERS 5
|
||||
#define MAXFILES 62
|
||||
#define BS 64
|
||||
#elif defined(CPUM2560) || defined(CPUM2561) || defined(CPUM128)
|
||||
#define blkid_t uint8_t
|
||||
#define EESIZE 4096
|
||||
#define EEFS_VERS 5
|
||||
#define MAXFILES 36
|
||||
#define BS 16
|
||||
#else
|
||||
#define blkid_t uint8_t
|
||||
#define EESIZE 2048
|
||||
#define EEFS_VERS 4
|
||||
#define MAXFILES 20
|
||||
#define BS 16
|
||||
|
@ -87,20 +76,16 @@ extern EeFs eeFs;
|
|||
|
||||
#if defined(CPUM64)
|
||||
#define FIRSTBLK (RESV/BS)
|
||||
#define BLOCKS (EESIZE/BS)
|
||||
#define BLOCKS (EEPROM_SIZE/BS)
|
||||
#define BLOCKS_OFFSET 0
|
||||
#else
|
||||
#define FIRSTBLK 1
|
||||
#define BLOCKS (1+(EESIZE-RESV)/BS)
|
||||
#define BLOCKS (1+(EEPROM_SIZE-RESV)/BS)
|
||||
#define BLOCKS_OFFSET (RESV-BS)
|
||||
#endif
|
||||
|
||||
uint16_t EeFsGetFree();
|
||||
|
||||
#if !defined(CPUARM)
|
||||
extern volatile int8_t eeprom_buffer_size;
|
||||
#endif
|
||||
|
||||
class EFile
|
||||
{
|
||||
public:
|
||||
|
@ -134,9 +119,14 @@ class EFile
|
|||
#define ERR_FULL 1
|
||||
extern uint8_t s_write_err; // error reasons
|
||||
|
||||
extern uint8_t s_sync_write;
|
||||
#define ENABLE_SYNC_WRITE(val) s_sync_write = val;
|
||||
#define IS_SYNC_WRITE_ENABLE() s_sync_write
|
||||
#if defined(CPUARM)
|
||||
#define ENABLE_SYNC_WRITE(val)
|
||||
#define IS_SYNC_WRITE_ENABLE() true
|
||||
#else
|
||||
#define ENABLE_SYNC_WRITE(val) s_sync_write = val;
|
||||
#define IS_SYNC_WRITE_ENABLE() s_sync_write
|
||||
#endif
|
||||
|
||||
|
||||
///deliver current errno, this is reset in open
|
||||
inline uint8_t write_errno() { return s_write_err; }
|
||||
|
@ -200,6 +190,8 @@ inline void eeFlush()
|
|||
theFile.flush();
|
||||
}
|
||||
|
||||
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
inline bool eepromIsWriting()
|
||||
{
|
||||
return theFile.isWriting();
|
||||
|
|
|
@ -22,5 +22,8 @@ endif()
|
|||
if(PWM_BACKLIGHT)
|
||||
add_definitions(-DPWM_BACKLIGHT)
|
||||
endif()
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} lcd_driver.cpp)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
lcd_driver.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -240,9 +240,4 @@ void rotencPoll();
|
|||
#define buzzerOn() PORTE |= (1 << OUT_E_BUZZER)
|
||||
#define buzzerOff() PORTE &= ~(1 << OUT_E_BUZZER)
|
||||
|
||||
// EEPROM driver
|
||||
#if !defined(SIMU)
|
||||
#define eepromReadBlock(a, b, c) eeprom_read_block(a, (const void *)b, c)
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_STOCK_H_
|
||||
|
|
|
@ -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
|
||||
|
|
87
radio/src/targets/common/avr/eeprom_driver.cpp
Normal file
87
radio/src/targets/common/avr/eeprom_driver.cpp
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -175,7 +175,7 @@ uint8_t keyState(uint8_t index)
|
|||
|
||||
uint8_t switchState(uint8_t index)
|
||||
{
|
||||
uint8_t result;
|
||||
uint8_t result = 0;
|
||||
|
||||
switch (index) {
|
||||
case SW_ELE:
|
||||
|
|
|
@ -168,9 +168,4 @@ void pwrOff();
|
|||
#define buzzerOn() PORTE |= (1 << OUT_E_BUZZER)
|
||||
#define buzzerOff() PORTE &= ~(1 << OUT_E_BUZZER)
|
||||
|
||||
// EEPROM driver
|
||||
#if !defined(SIMU)
|
||||
#define eepromReadBlock(a, b, c) eeprom_read_block(a, (const void *)b, c)
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_GRUVIN9X_H_
|
||||
|
|
|
@ -188,9 +188,4 @@ void pwrOff();
|
|||
#define WTV20SD_CLK (PING & 0x20)
|
||||
#endif
|
||||
|
||||
// EEPROM driver
|
||||
#if !defined(SIMU)
|
||||
#define eepromReadBlock(a, b, c) eeprom_read_block(a, (const void *)b, c)
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_MEGA2560_H_
|
||||
|
|
|
@ -2,7 +2,11 @@ foreach(FILE ${SRC})
|
|||
set(SIMU_SRC ${SIMU_SRC} ../../${FILE})
|
||||
endforeach()
|
||||
|
||||
set(SIMU_SRC ${SIMU_SRC} simpgmspace.cpp)
|
||||
set(SIMU_SRC
|
||||
${SIMU_SRC}
|
||||
simpgmspace.cpp
|
||||
simueeprom.cpp
|
||||
)
|
||||
|
||||
add_definitions(-DSIMU)
|
||||
remove_definitions(-DCLI)
|
||||
|
|
|
@ -90,7 +90,9 @@ bool OpenTxSimulator::lcdChanged(bool & lightEnable)
|
|||
|
||||
void OpenTxSimulator::start(QByteArray & ee, bool tests)
|
||||
{
|
||||
memcpy(eeprom, ee.data(), std::min<int>(EESIZE_SIMU, ee.size()));
|
||||
#if defined(EEPROM_SIZE)
|
||||
memcpy(eeprom, ee.data(), std::min<int>(EEPROM_SIZE, ee.size()));
|
||||
#endif
|
||||
start((const char *)0, tests);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,6 @@ uint8_t MCUCSR, MCUSR, MCUCR;
|
|||
volatile uint8_t pina=0xff, pinb=0xff, pinc=0xff, pind, pine=0xff, pinf=0xff, ping=0xff, pinh=0xff, pinj=0, pinl=0;
|
||||
uint8_t portb, portc, porth=0, dummyport;
|
||||
uint16_t dummyport16;
|
||||
const char *eepromFile = NULL;
|
||||
FILE *fp = NULL;
|
||||
int g_snapshot_idx = 0;
|
||||
|
||||
#if !defined(CPUARM)
|
||||
|
@ -73,23 +71,10 @@ Dacc dacc;
|
|||
Adc Adc0;
|
||||
#endif
|
||||
|
||||
#if defined(EEPROM_RLC)
|
||||
extern uint16_t eeprom_pointer;
|
||||
extern uint8_t * eeprom_buffer_data;
|
||||
#else
|
||||
uint32_t eeprom_pointer;
|
||||
uint8_t * eeprom_buffer_data;
|
||||
volatile int32_t eeprom_buffer_size;
|
||||
bool eeprom_read_operation;
|
||||
#endif
|
||||
|
||||
#if defined(SDCARD) && !defined(SKIP_FATFS_DECLARATION)
|
||||
char simuSdDirectory[1024] = "";
|
||||
#endif
|
||||
|
||||
uint8_t eeprom[EESIZE_SIMU];
|
||||
sem_t *eeprom_write_sem;
|
||||
|
||||
void lcdInit()
|
||||
{
|
||||
}
|
||||
|
@ -311,76 +296,6 @@ void simuSetSwitch(uint8_t swtch, int8_t state)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(EEPROM_RAW)
|
||||
uint8_t Spi_complete = 1;
|
||||
void * eeprom_write_function(void *)
|
||||
{
|
||||
while (!sem_wait(eeprom_write_sem)) {
|
||||
if (!eeprom_thread_running)
|
||||
return NULL;
|
||||
if (eeprom_read_operation) {
|
||||
assert(eeprom_buffer_size);
|
||||
eepromReadBlock(eeprom_buffer_data, eeprom_pointer, eeprom_buffer_size);
|
||||
}
|
||||
else {
|
||||
if (fp) {
|
||||
if (fseek(fp, eeprom_pointer, SEEK_SET) == -1)
|
||||
perror("error in fseek");
|
||||
}
|
||||
while (--eeprom_buffer_size) {
|
||||
assert(eeprom_buffer_size > 0);
|
||||
if (fp) {
|
||||
if (fwrite(eeprom_buffer_data, 1, 1, fp) != 1)
|
||||
perror("error in fwrite");
|
||||
}
|
||||
else {
|
||||
memcpy(&eeprom[eeprom_pointer], eeprom_buffer_data, 1);
|
||||
}
|
||||
eeprom_pointer++;
|
||||
eeprom_buffer_data++;
|
||||
|
||||
if (fp && eeprom_buffer_size == 1) {
|
||||
fflush(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
Spi_complete = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#elif !defined(PCBTARANIS) && !defined(PCBHORUS)
|
||||
bool eeprom_thread_running = true;
|
||||
void * eeprom_write_function(void *)
|
||||
{
|
||||
while (!sem_wait(eeprom_write_sem)) {
|
||||
if (!eeprom_thread_running)
|
||||
return NULL;
|
||||
if (fp) {
|
||||
if (fseek(fp, eeprom_pointer, SEEK_SET) == -1)
|
||||
perror("error in fseek");
|
||||
}
|
||||
while (--eeprom_buffer_size) {
|
||||
assert(eeprom_buffer_size > 0);
|
||||
if (fp) {
|
||||
if (fwrite(eeprom_buffer_data, 1, 1, fp) != 1)
|
||||
perror("error in fwrite");
|
||||
sleep(5/*ms*/);
|
||||
}
|
||||
else {
|
||||
memcpy(&eeprom[eeprom_pointer], eeprom_buffer_data, 1);
|
||||
}
|
||||
eeprom_pointer++;
|
||||
eeprom_buffer_data++;
|
||||
|
||||
if (fp && eeprom_buffer_size == 1) {
|
||||
fflush(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void StartSimu(bool tests)
|
||||
{
|
||||
s_current_protocol[0] = 255;
|
||||
|
@ -484,7 +399,6 @@ int32_t getVolume()
|
|||
#endif
|
||||
|
||||
#if defined(SIMU_AUDIO) && defined(CPUARM)
|
||||
|
||||
void copyBuffer(uint8_t * dest, uint16_t * buff, unsigned int samples)
|
||||
{
|
||||
for(unsigned int i=0; i<samples; i++) {
|
||||
|
@ -602,94 +516,11 @@ void StopAudioThread()
|
|||
}
|
||||
#endif // #if defined(SIMU_AUDIO) && defined(CPUARM)
|
||||
|
||||
pthread_t eeprom_thread_pid;
|
||||
|
||||
void StartEepromThread(const char *filename)
|
||||
{
|
||||
eepromFile = filename;
|
||||
if (eepromFile) {
|
||||
fp = fopen(eepromFile, "rb+");
|
||||
if (!fp)
|
||||
fp = fopen(eepromFile, "wb+");
|
||||
if (!fp) perror("error in fopen");
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
eeprom_write_sem = sem_open("eepromsem", O_CREAT, S_IRUSR | S_IWUSR, 0);
|
||||
#else
|
||||
eeprom_write_sem = (sem_t *)malloc(sizeof(sem_t));
|
||||
sem_init(eeprom_write_sem, 0, 0);
|
||||
#endif
|
||||
|
||||
#if !defined(PCBTARANIS) && !defined(PCBHORUS)
|
||||
eeprom_thread_running = true;
|
||||
assert(!pthread_create(&eeprom_thread_pid, NULL, &eeprom_write_function, NULL));
|
||||
#endif
|
||||
}
|
||||
|
||||
void StopEepromThread()
|
||||
{
|
||||
#if !defined(PCBTARANIS) && !defined(PCBFLAMENCO) && !defined(PCBHORUS)
|
||||
eeprom_thread_running = false;
|
||||
sem_post(eeprom_write_sem);
|
||||
pthread_join(eeprom_thread_pid, NULL);
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
//TODO free semaphore eeprom_write_sem
|
||||
#else
|
||||
sem_destroy(eeprom_write_sem);
|
||||
free(eeprom_write_sem);
|
||||
#endif
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
void eepromReadBlock (uint8_t * pointer_ram, uint32_t pointer_eeprom, uint32_t size)
|
||||
{
|
||||
assert(size);
|
||||
|
||||
if (fp) {
|
||||
// TRACE("EEPROM read (pos=%d, size=%d)", pointer_eeprom, size);
|
||||
if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek");
|
||||
if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in fread");
|
||||
}
|
||||
else {
|
||||
memcpy(pointer_ram, &eeprom[(uint64_t)pointer_eeprom], size);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBFLAMENCO)
|
||||
void eepromWriteBlock(uint8_t * pointer_ram, uint32_t pointer_eeprom, uint32_t size)
|
||||
{
|
||||
assert(size);
|
||||
|
||||
if (fp) {
|
||||
// TRACE("EEPROM write (pos=%d, size=%d)", pointer_eeprom, size);
|
||||
if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek");
|
||||
if (fwrite(pointer_ram, size, 1, fp) <= 0) perror("error in fwrite");
|
||||
}
|
||||
else {
|
||||
memcpy(&eeprom[(uint64_t)pointer_eeprom], pointer_ram, size);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint16_t stackAvailable()
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void EeFsDump(){
|
||||
for(int i=0; i<EESIZE; i++)
|
||||
{
|
||||
printf("%02x ",eeprom[i]);
|
||||
if(i%16 == 15) puts("");
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SDCARD) && !defined(SKIP_FATFS_DECLARATION) && !defined(SIMU_DISKIO)
|
||||
namespace simu {
|
||||
#include <dirent.h>
|
||||
|
@ -1438,39 +1269,3 @@ OS_TID CoCreateTask(FUNCPtr task, void *argv, uint32_t parameter, void * stk, ui
|
|||
pthread_create(&tid, NULL, start_routine, (void *)task);
|
||||
return tid;
|
||||
}
|
||||
|
||||
#if defined(EEPROM_RAW)
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
static uint8_t erasedBlock[EEPROM_BLOCK_SIZE]; // can't be on the stack!
|
||||
memset(erasedBlock, 0xff, sizeof(erasedBlock));
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = erasedBlock;
|
||||
eeprom_buffer_size = EEPROM_BLOCK_SIZE;
|
||||
eeprom_read_operation = false;
|
||||
Spi_complete = false;
|
||||
sem_post(eeprom_write_sem);
|
||||
}
|
||||
|
||||
void eepromReadArray(uint32_t address, uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
assert(size);
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = buffer;
|
||||
eeprom_buffer_size = size;
|
||||
eeprom_read_operation = true;
|
||||
Spi_complete = false;
|
||||
sem_post(eeprom_write_sem);
|
||||
}
|
||||
|
||||
void eepromByteProgram(uint32_t address, uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
assert(size);
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = buffer;
|
||||
eeprom_buffer_size = size + 1;
|
||||
eeprom_read_operation = false;
|
||||
Spi_complete = false;
|
||||
sem_post(eeprom_write_sem);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -199,13 +199,10 @@ extern Pwm pwm;
|
|||
#define PWM (&pwm)
|
||||
#endif
|
||||
|
||||
extern sem_t *eeprom_write_sem;
|
||||
|
||||
#if !defined(EEPROM_RLC)
|
||||
extern uint32_t eeprom_pointer;
|
||||
extern uint8_t * eeprom_buffer_data;
|
||||
extern volatile int32_t eeprom_buffer_size;
|
||||
extern bool eeprom_read_operation;
|
||||
#if defined(EEPROM_SIZE)
|
||||
extern uint8_t eeprom[EEPROM_SIZE];
|
||||
#else
|
||||
extern uint8_t * eeprom;
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
@ -387,16 +384,6 @@ void StopEepromThread();
|
|||
#define StopAudioThread()
|
||||
#endif
|
||||
|
||||
#if !defined(EEPROM_RLC)
|
||||
#define EESIZE_SIMU (128*4096)
|
||||
#else
|
||||
#define EESIZE_SIMU EESIZE
|
||||
#endif
|
||||
|
||||
extern uint8_t eeprom[];
|
||||
extern const char * eepromFile;
|
||||
void eepromReadBlock (uint8_t * pointer_ram, uint32_t address, uint32_t size);
|
||||
|
||||
#if !defined(CPUARM)
|
||||
#define wdt_disable(...) sleep(1/*ms*/)
|
||||
#define wdt_enable(...) sleep(1/*ms*/)
|
||||
|
@ -490,8 +477,4 @@ extern char simuSdDirectory[1024];
|
|||
#define sdMounted() (true)
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
#endif // _SIMPGMSPACE_H_
|
||||
|
|
178
radio/src/targets/simu/simueeprom.cpp
Normal file
178
radio/src/targets/simu/simueeprom.cpp
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
const char * eepromFile = NULL;
|
||||
FILE * fp = NULL;
|
||||
|
||||
uint32_t eeprom_pointer;
|
||||
uint8_t * eeprom_buffer_data;
|
||||
volatile int32_t eeprom_buffer_size;
|
||||
bool eeprom_read_operation;
|
||||
|
||||
bool eeprom_thread_running = true;
|
||||
|
||||
#if defined(EEPROM_SIZE)
|
||||
uint8_t eeprom[EEPROM_SIZE];
|
||||
#else
|
||||
uint8_t * eeprom = NULL;
|
||||
#endif
|
||||
|
||||
sem_t * eeprom_write_sem;
|
||||
|
||||
void eepromReadBlock (uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(size);
|
||||
|
||||
if (fp) {
|
||||
// TRACE("EEPROM read (pos=%d, size=%d)", pointer_eeprom, size);
|
||||
if (fseek(fp, address, SEEK_SET) < 0)
|
||||
perror("error in fseek");
|
||||
if (fread(buffer, size, 1, fp) <= 0)
|
||||
perror("error in fread");
|
||||
}
|
||||
else {
|
||||
memcpy(buffer, &eeprom[address], size);
|
||||
}
|
||||
}
|
||||
|
||||
void eepromSimuWriteBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(size);
|
||||
|
||||
if (fp) {
|
||||
// TRACE("EEPROM write (pos=%d, size=%d)", pointer_eeprom, size);
|
||||
if (fseek(fp, address, SEEK_SET) < 0)
|
||||
perror("error in fseek");
|
||||
if (fwrite(buffer, size, 1, fp) <= 0)
|
||||
perror("error in fwrite");
|
||||
}
|
||||
else {
|
||||
memcpy(&eeprom[address], buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
volatile uint8_t eepromTransferComplete = 1;
|
||||
void * eeprom_thread_function(void *)
|
||||
{
|
||||
while (!sem_wait(eeprom_write_sem)) {
|
||||
if (!eeprom_thread_running)
|
||||
return NULL;
|
||||
assert(eeprom_buffer_size);
|
||||
if (eeprom_read_operation) {
|
||||
eepromReadBlock(eeprom_buffer_data, eeprom_pointer, eeprom_buffer_size);
|
||||
}
|
||||
else {
|
||||
eepromSimuWriteBlock(eeprom_buffer_data, eeprom_pointer, eeprom_buffer_size);
|
||||
}
|
||||
eepromTransferComplete = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t eepromReadStatus()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return eepromTransferComplete;
|
||||
}
|
||||
|
||||
void eepromTransmitData(uint32_t address, uint8_t * buffer, uint32_t size, bool read)
|
||||
{
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = buffer;
|
||||
eeprom_buffer_size = size;
|
||||
eeprom_read_operation = read;
|
||||
eepromTransferComplete = 0;
|
||||
sem_post(eeprom_write_sem);
|
||||
}
|
||||
|
||||
#if defined(EEPROM_BLOCK_SIZE)
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
static uint8_t erasedBlock[EEPROM_BLOCK_SIZE]; // can't be on the stack!
|
||||
memset(erasedBlock, 0xff, sizeof(erasedBlock));
|
||||
eepromTransmitData(address, erasedBlock, EEPROM_BLOCK_SIZE, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(size);
|
||||
eepromTransmitData(address, buffer, size, true);
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(size);
|
||||
eepromTransmitData(address, buffer, size, false);
|
||||
}
|
||||
|
||||
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromStartWrite(buffer, address, size);
|
||||
|
||||
while (!eepromIsTransferComplete()) {
|
||||
sleep(1/*ms*/);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_t eeprom_thread_pid;
|
||||
|
||||
void StartEepromThread(const char * filename)
|
||||
{
|
||||
eepromFile = filename;
|
||||
if (eepromFile) {
|
||||
fp = fopen(eepromFile, "rb+");
|
||||
if (!fp)
|
||||
fp = fopen(eepromFile, "wb+");
|
||||
if (!fp)
|
||||
perror("error in fopen");
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
eeprom_write_sem = sem_open("eepromsem", O_CREAT, S_IRUSR | S_IWUSR, 0);
|
||||
#else
|
||||
eeprom_write_sem = (sem_t *)malloc(sizeof(sem_t));
|
||||
sem_init(eeprom_write_sem, 0, 0);
|
||||
#endif
|
||||
|
||||
eeprom_thread_running = true;
|
||||
assert(!pthread_create(&eeprom_thread_pid, NULL, &eeprom_thread_function, NULL));
|
||||
}
|
||||
|
||||
void StopEepromThread()
|
||||
{
|
||||
eeprom_thread_running = false;
|
||||
sem_post(eeprom_write_sem);
|
||||
pthread_join(eeprom_thread_pid, NULL);
|
||||
|
||||
#ifdef __APPLE__
|
||||
sem_close(eeprom_write_sem);
|
||||
#else
|
||||
sem_destroy(eeprom_write_sem);
|
||||
free(eeprom_write_sem);
|
||||
#endif
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -427,9 +427,16 @@ void usbSerialPutc(uint8_t c);
|
|||
#endif
|
||||
|
||||
// I2C driver: EEPROM + Audio Volume
|
||||
#if defined(REV4a)
|
||||
#define EEPROM_SIZE (64*1024)
|
||||
#else
|
||||
#define EEPROM_SIZE (32*1024)
|
||||
#endif
|
||||
|
||||
void i2cInit(void);
|
||||
void eepromReadBlock(uint8_t * buffer, uint32_t address, uint32_t size);
|
||||
void eepromWriteBlock(uint8_t * buffer, uint32_t address, uint32_t size);
|
||||
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
uint8_t eepromIsTransferComplete();
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
|
|
@ -594,7 +594,7 @@ int main()
|
|||
else {
|
||||
writeEepromBlock();
|
||||
eepromWritten += sizeof(Block_buffer);
|
||||
progress = (200*eepromWritten) / EESIZE;
|
||||
progress = (200*eepromWritten) / EEPROM_SIZE;
|
||||
}
|
||||
|
||||
lcdDrawRect( 3, 6*FH+4, 204, 7);
|
||||
|
@ -609,7 +609,7 @@ int main()
|
|||
if (firmwareWritten >= FLASHSIZE - BOOTLOADER_SIZE) {
|
||||
state = ST_FLASH_DONE; // Backstop
|
||||
}
|
||||
if (eepromWritten >= EESIZE) {
|
||||
if (eepromWritten >= EEPROM_SIZE) {
|
||||
state = ST_FLASH_DONE; // Backstop
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,41 +130,46 @@ bool I2C_EE_ReadBlock(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRea
|
|||
return true;
|
||||
}
|
||||
|
||||
void eepromReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead)
|
||||
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
while (!I2C_EE_ReadBlock(pBuffer, ReadAddr, NumByteToRead)) {
|
||||
while (!I2C_EE_ReadBlock(buffer, address, size)) {
|
||||
i2cInit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes buffer of data to the I2C EEPROM.
|
||||
* @param pBuffer : pointer to the buffer containing the data to be
|
||||
* @param buffer : pointer to the buffer containing the data to be
|
||||
* written to the EEPROM.
|
||||
* @param WriteAddr : EEPROM's internal address to write to.
|
||||
* @param NumByteToWrite : number of bytes to write to the EEPROM.
|
||||
* @param address : EEPROM's internal address to write to.
|
||||
* @param size : number of bytes to write to the EEPROM.
|
||||
* @retval None
|
||||
*/
|
||||
void eepromWriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite)
|
||||
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
uint8_t offset = WriteAddr % I2C_FLASH_PAGESIZE;
|
||||
uint8_t offset = address % I2C_FLASH_PAGESIZE;
|
||||
uint8_t count = I2C_FLASH_PAGESIZE - offset;
|
||||
if (NumByteToWrite < count) {
|
||||
count = NumByteToWrite;
|
||||
if (size < count) {
|
||||
count = size;
|
||||
}
|
||||
while (count > 0) {
|
||||
eepromPageWrite(pBuffer, WriteAddr, count);
|
||||
eepromPageWrite(buffer, address, count);
|
||||
eepromWaitEepromStandbyState();
|
||||
WriteAddr += count;
|
||||
pBuffer += count;
|
||||
NumByteToWrite -= count;
|
||||
address += count;
|
||||
buffer += count;
|
||||
size -= count;
|
||||
count = I2C_FLASH_PAGESIZE;
|
||||
if (NumByteToWrite < I2C_FLASH_PAGESIZE) {
|
||||
count = NumByteToWrite;
|
||||
if (size < I2C_FLASH_PAGESIZE) {
|
||||
count = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
|
||||
* @note The number of byte can't exceed the EEPROM page size.
|
||||
|
|
|
@ -25,7 +25,7 @@ if(EXISTS "${GTEST_SRCDIR}/src/gtest-all.cc")
|
|||
set(CMAKE_C_FLAGS_DEBUG "${COMMON_FLAGS} -g -O0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CPP_FLAGS} -g -O0")
|
||||
|
||||
add_executable(gtests EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp)
|
||||
add_executable(gtests EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp ../targets/simu/simueeprom.cpp)
|
||||
qt5_use_modules(gtests Core Widgets)
|
||||
add_dependencies(gtests ${FIRMWARE_DEPENDENCIES} gtests-lib)
|
||||
target_link_libraries(gtests gtests-lib pthread)
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "gtests.h"
|
||||
|
||||
extern const char * eepromFile;
|
||||
|
||||
#if !defined(EEPROM) && defined(SDCARD)
|
||||
namespace Backup {
|
||||
#define BACKUP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue