[X9D] EEPROM support

[X9D] LCD greyscale support when writing chars on screen
[stock] Flash saving in EEPROM read function
[gruvin9x] TX_CADDY little optimization
This commit is contained in:
bsongis
2013-01-04 22:18:35 +00:00
parent e406021828
commit 532848849c
17 changed files with 361 additions and 334 deletions
+2 -2
View File
@@ -469,7 +469,7 @@ RUN_FROM_FLASH = 1
ifeq ($(PCB), ACT)
# ACT radio
OPT = 2
CPPDEFS += -DPCBACT -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 -DLCD260 -DSTM32F10X_LD
CPPDEFS += -DPCBACT -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 -DLCD260 -DSTM32F10X_HD
EXTRAINCDIRS += sky9x CoOS/kernel CoOS/portable
EXTRAINCDIRS += act/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc act/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x
BOARDSRC = x9d/board_x9d.cpp
@@ -491,7 +491,7 @@ ifeq ($(PCB), X9D)
BOARDSRC = x9d/board_x9d.cpp
EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c_ee.c
SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c
EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp
EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp
PULSESSRC = pulses_arm.cpp
CPPSRC += sky9x/audio.cpp
CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/audio_driver.cpp
+25 -28
View File
@@ -40,7 +40,7 @@ volatile uint32_t Spi_complete; // TODO in the driver ?
uint8_t s_eeDirtyMsk;
uint16_t s_eeDirtyTime10ms;
// Logic for storing to EERPOM/loading from EEPROM
// Logic for storing to EEPROM/loading from EEPROM
// If main needs to wait for the eeprom, call mainsequence without actioning menus
// General configuration
// 'main' set flag STORE_GENERAL
@@ -63,8 +63,6 @@ uint8_t Spi_rx_buf[24] ;
struct t_file_entry File_system[MAX_MODELS+1] ;
char ModelNames[MAX_MODELS][sizeof(g_model.name)] ; // Allow for general
// TODO check everything here
uint8_t Eeprom32_process_state = E32_IDLE;
uint8_t Eeprom32_state_after_erase ;
@@ -89,8 +87,8 @@ void handle_serial( void ) ;
uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ;
void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ;
void ee32_read_model_names( void ) ;
void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) ;
void eeLoadModelNames( void ) ;
uint16_t eeLoadModelName(uint8_t id, char *name);
// New file system
@@ -118,7 +116,7 @@ void eeDeleteModel(uint8_t id)
{
eeCheck(true);
memset(ModelNames[id], 0, sizeof(g_model.name));
memset(modelNames[id], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&g_model ; // Get data from here
Eeprom32_data_size = 0 ; // This much
@@ -135,9 +133,9 @@ bool eeCopyModel(uint8_t dst, uint8_t src)
read32_eeprom_data( (File_system[src+1].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, size) ;
if (size > sizeof(g_model.name))
memcpy(ModelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
memcpy(modelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
else
memset(ModelNames[dst], 0, sizeof(g_model.name));
memset(modelNames[dst], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here
Eeprom32_data_size = sizeof(g_model) ; // This much
@@ -161,10 +159,10 @@ void eeSwapModels(uint8_t id1, uint8_t id2)
// TODO flash saving with function above ...
if (id2_size > sizeof(g_model.name)) {
read32_eeprom_data( (id2_block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, id2_size);
memcpy(ModelNames[id1], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
memcpy(modelNames[id1], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
}
else {
memset(ModelNames[id1], 0, sizeof(g_model.name));
memset(modelNames[id1], 0, sizeof(g_model.name));
}
Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here
@@ -403,8 +401,7 @@ void eeLoadModel(uint8_t id)
resetAll();
if (pulsesStarted()) {
checkTHR();
checkSwitches();
checkAll();
resumePulses();
clearKeyEvents();
}
@@ -438,15 +435,24 @@ bool eeModelExists(uint8_t id)
return ( File_system[id+1].size > 0 ) ;
}
void ee32LoadModelName(uint8_t id, char *buf, uint8_t len)
uint16_t eeLoadModelName(uint8_t id, char *name)
{
memclear(name, sizeof(g_model.name));
if (id < MAX_MODELS) {
id += 1;
memset(buf, 0, len);
if (File_system[id].size > sizeof(g_model.name) ) {
read32_eeprom_data( ( File_system[id].block_no << 12) + 8, ( uint8_t *)buf, sizeof(g_model.name)) ;
read32_eeprom_data( ( File_system[id].block_no << 12) + 8, ( uint8_t *)name, sizeof(g_model.name));
return File_system[id].size;
}
}
return 0;
}
void eeLoadModelNames()
{
for (uint32_t i=0; i<MAX_MODELS; i++) {
eeLoadModelName(i, modelNames[i]);
}
}
void fill_file_index()
@@ -483,9 +489,8 @@ void eeReadAll()
STORE_MODELVARS;
}
}
else
{
ee32_read_model_names() ;
else {
eeLoadModelNames() ;
}
stickMode = g_eeGeneral.stickMode; // TODO common!
@@ -687,14 +692,6 @@ void ee32_process()
}
}
void ee32_read_model_names()
{
for (uint32_t i=0; i<MAX_MODELS; i++)
{
ee32LoadModelName(i, ModelNames[i], sizeof(g_model.name));
}
}
#if defined(SDCARD)
const pm_char * eeBackupModel(uint8_t i_fileSrc)
{
@@ -805,9 +802,9 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
// TODO flash saving ...
if (read > sizeof(g_model.name))
memcpy(ModelNames[i_fileDst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
memcpy(modelNames[i_fileDst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name));
else
memset(ModelNames[i_fileDst], 0, sizeof(g_model.name));
memset(modelNames[i_fileDst], 0, sizeof(g_model.name));
Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here
Eeprom32_data_size = sizeof(g_model); // This much
-1
View File
@@ -74,7 +74,6 @@ struct t_eeprom_header
};
extern struct t_file_entry File_system[] ;
extern char ModelNames[][sizeof(g_model.name)] ; // Allow for general
extern EEGeneral g_eeGeneral;
extern ModelData g_model;
+141 -115
View File
@@ -37,12 +37,11 @@
#include "string.h"
uint8_t s_write_err = 0; // error reasons
uint8_t s_sync_write = false;
uint8_t s_eeDirtyMsk;
uint16_t s_eeDirtyTime10ms;
RlcFile theFile; //used for any file operation
EeFs eeFs;
RlcFile theFile; //used for any file operation
EeFs eeFs;
void eeDirty(uint8_t msk)
{
@@ -50,16 +49,18 @@ void eeDirty(uint8_t msk)
s_eeDirtyTime10ms = get_tmr10ms();
}
#if !defined(CPUARM)
uint8_t s_sync_write = false;
uint16_t eeprom_pointer;
const char* eeprom_buffer_data;
const char * 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 (PCBGRUVIN9X)
EECR |= 1<<EEMPE;
EECR |= 1<<EEPE;
@@ -84,7 +85,6 @@ ISR(EE_READY_vect)
#endif
}
}
#endif
void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_t size)
@@ -107,11 +107,14 @@ void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_
while (eeprom_buffer_size > 0) wdt_reset();
}
}
#endif
static uint8_t EeFsRead(uint8_t blk, uint8_t ofs)
static uint8_t EeFsRead(blkid_t blk, uint8_t ofs)
{
uint8_t ret;
#ifdef SIMU
#if defined(PCBX9D)
eeprom_read_block(&ret, (uint16_t)(blk*BS+ofs+BLOCKS_OFFSET), 1);
#elif defined(SIMU)
eeprom_read_block(&ret, (const void*)(uint64_t)(blk*BS+ofs+BLOCKS_OFFSET), 1);
#else
eeprom_read_block(&ret, (const void*)(blk*BS+ofs+BLOCKS_OFFSET), 1);
@@ -119,47 +122,53 @@ static uint8_t EeFsRead(uint8_t blk, uint8_t ofs)
return ret;
}
static uint8_t EeFsGetLink(uint8_t blk)
static blkid_t EeFsGetLink(blkid_t blk)
{
#if defined(CPUARM)
blkid_t ret;
eeprom_read_block((uint8_t *)&ret, blk*BS+BLOCKS_OFFSET, sizeof(blkid_t));
return ret;
#else
return EeFsRead(blk, 0);
#endif
}
static void EeFsSetLink(uint8_t blk, uint8_t val)
static void EeFsSetLink(blkid_t blk, blkid_t val)
{
static uint8_t s_link; // we write asynchronously, then nothing on the stack!
static blkid_t s_link; // we write asynchronously, then nothing on the stack!
s_link = val;
eeWriteBlockCmp(&s_link, (blk*BS)+BLOCKS_OFFSET, 1);
eeWriteBlockCmp((uint8_t *)&s_link, (blk*BS)+BLOCKS_OFFSET, sizeof(blkid_t));
}
static uint8_t EeFsGetDat(uint8_t blk,uint8_t ofs)
static uint8_t EeFsGetDat(blkid_t blk, uint8_t ofs)
{
return EeFsRead(blk, ofs+1);
return EeFsRead(blk, ofs+sizeof(blkid_t));
}
static void EeFsSetDat(uint8_t blk,uint8_t ofs,uint8_t*buf,uint8_t len)
static void EeFsSetDat(blkid_t blk, uint8_t ofs, uint8_t *buf, uint8_t len)
{
eeWriteBlockCmp(buf, blk*BS+ofs+1+BLOCKS_OFFSET, len);
eeWriteBlockCmp(buf, (blk*BS)+ofs+sizeof(blkid_t)+BLOCKS_OFFSET, len);
}
static void EeFsFlushFreelist()
{
eeWriteBlockCmp(&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList));
eeWriteBlockCmp((uint8_t *)&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList));
}
static void EeFsFlushDirEnt(uint8_t i_fileId)
{
eeWriteBlockCmp(&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt));
eeWriteBlockCmp((uint8_t *)&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt));
}
static void EeFsFlush()
{
eeWriteBlockCmp(&eeFs, 0, sizeof(eeFs));
eeWriteBlockCmp((uint8_t *)&eeFs, 0, sizeof(eeFs));
}
uint16_t EeFsGetFree()
{
int16_t ret = 0;
uint8_t i = eeFs.freeList;
blkid_t i = eeFs.freeList;
while (i) {
ret += BS-1;
i = EeFsGetLink(i);
@@ -170,10 +179,10 @@ uint16_t EeFsGetFree()
}
/// free one or more blocks
static void EeFsFree(uint8_t blk)
static void EeFsFree(blkid_t blk)
{
uint8_t i = blk;
uint8_t tmp;
blkid_t i = blk;
blkid_t tmp;
while ((tmp=EeFsGetLink(i))) i = tmp;
EeFsSetLink(i, eeFs.freeList);
eeFs.freeList = blk; //chain in front
@@ -182,16 +191,15 @@ static void EeFsFree(uint8_t blk)
int8_t EeFsck()
{
s_sync_write = true;
ENABLE_SYNC_WRITE(true);
uint8_t *bufp = reusableBuffer.eefs_buffer;
memclear(bufp, BLOCKS);
uint8_t blk ;
int8_t ret = 0;
blkid_t blk ;
for(uint8_t i = 0; i <= MAXFILES; i++) {
uint8_t *startP = (i==MAXFILES ? &eeFs.freeList : &eeFs.files[i].startBlk);
uint8_t lastBlk = 0;
for (uint8_t i=0; i<=MAXFILES; i++) {
blkid_t *startP = (i==MAXFILES ? &eeFs.freeList : &eeFs.files[i].startBlk);
blkid_t lastBlk = 0;
blk = *startP;
while (blk) {
if (blk < FIRSTBLK || // bad blk index
@@ -222,31 +230,31 @@ int8_t EeFsck()
}
}
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
return ret;
return 0;
}
void EeFsFormat()
{
s_sync_write = true;
ENABLE_SYNC_WRITE(true);
memclear(&eeFs, sizeof(eeFs));
eeFs.version = EEFS_VERS;
eeFs.mySize = sizeof(eeFs);
eeFs.freeList = 0;
eeFs.bs = BS;
for(uint8_t i = FIRSTBLK; i < BLOCKS-1; i++) EeFsSetLink(i,i+1);
for (blkid_t i=FIRSTBLK; i<BLOCKS-1; i++) EeFsSetLink(i, i+1);
EeFsSetLink(BLOCKS-1, 0);
eeFs.freeList = FIRSTBLK;
EeFsFlush();
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
}
inline bool EeFsOpen()
{
eeprom_read_block(&eeFs, 0, sizeof(eeFs));
eeprom_read_block((uint8_t *)&eeFs, 0, sizeof(eeFs));
#ifdef SIMU
if (eeFs.version != EEFS_VERS) {
@@ -276,20 +284,20 @@ void EFile::swap(uint8_t i_fileId1, uint8_t i_fileId2)
eeFs.files[i_fileId1] = eeFs.files[i_fileId2];
eeFs.files[i_fileId2] = tmp;
s_sync_write = true;
ENABLE_SYNC_WRITE(true);
EeFsFlushDirEnt(i_fileId1);
EeFsFlushDirEnt(i_fileId2);
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
}
void EFile::rm(uint8_t i_fileId)
{
uint8_t i = eeFs.files[i_fileId].startBlk;
blkid_t i = eeFs.files[i_fileId].startBlk;
memclear(&eeFs.files[i_fileId], sizeof(eeFs.files[i_fileId]));
s_sync_write = true;
ENABLE_SYNC_WRITE(true);
EeFsFlushDirEnt(i_fileId);
if (i) EeFsFree(i); //chain in
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
}
uint16_t EFile::size()
@@ -317,72 +325,59 @@ void RlcFile::openRlc(uint8_t i_fileId)
m_bRlc = 0;
}
uint8_t EFile::read(uint8_t*buf,uint16_t i_len)
uint8_t EFile::read(uint8_t *buf, uint8_t i_len)
{
uint16_t len = eeFs.files[m_fileId].size - m_pos;
if(len < i_len) i_len = len;
len = i_len;
while(len)
{
if(!m_currBlk) break;
if (i_len > len) i_len = len;
uint8_t remaining = i_len;
while (remaining) {
if (!m_currBlk) break;
*buf++ = EeFsGetDat(m_currBlk, m_ofs++);
if(m_ofs>=(BS-1)){
m_ofs=0;
m_currBlk=EeFsGetLink(m_currBlk);
if (m_ofs >= BS-sizeof(blkid_t)) {
m_ofs = 0;
m_currBlk = EeFsGetLink(m_currBlk);
}
len--;
remaining--;
}
m_pos += i_len - len;
return i_len - len;
i_len -= remaining;
m_pos += i_len;
return i_len;
}
/*
* Read runlength (RLE) compressed bytes into buf.
*/
#ifdef TRANSLATIONS
uint16_t RlcFile::readRlc12(uint8_t*buf,uint16_t i_len, bool rlc2)
#else
uint16_t RlcFile::readRlc(uint8_t *buf,uint16_t i_len)
#endif
uint16_t RlcFile::readRlc(uint8_t *buf, uint16_t i_len)
{
uint16_t i=0;
for( ; 1; ){
uint8_t l = min<uint16_t>(m_zeroes,i_len-i);
memclear(&buf[i], l);
i += l;
m_zeroes -= l;
if(m_zeroes) break;
uint16_t i = 0;
for( ; 1; ) {
uint8_t ln = min<uint16_t>(m_zeroes, i_len-i);
memclear(&buf[i], ln);
i += ln;
m_zeroes -= ln;
if (m_zeroes) break;
l=min<uint16_t>(m_bRlc,i_len-i);
uint8_t lr = read(&buf[i],l);
ln = min<uint16_t>(m_bRlc, i_len-i);
uint8_t lr = read(&buf[i], ln);
i += lr ;
m_bRlc -= lr;
if(m_bRlc) break;
if(read(&m_bRlc,1)!=1) break; //read how many bytes to read
if (read(&m_bRlc, 1) !=1) break; // read how many bytes to read
assert(m_bRlc & 0x7f);
#ifdef TRANSLATIONS
if (rlc2) {
#endif
if(m_bRlc&0x80){ // if contains high byte
m_zeroes =(m_bRlc>>4) & 0x7;
m_bRlc = m_bRlc & 0x0f;
}
else if(m_bRlc&0x40){
m_zeroes = m_bRlc & 0x3f;
m_bRlc = 0;
}
//else m_bRlc
#ifdef TRANSLATIONS
if (m_bRlc&0x80) { // if contains high byte
m_zeroes =(m_bRlc>>4) & 0x7;
m_bRlc = m_bRlc & 0x0f;
}
else {
if(m_bRlc&0x80){ // if contains high byte
m_zeroes = m_bRlc & 0x7f;
m_bRlc = 0;
}
else if(m_bRlc&0x40) {
m_zeroes = m_bRlc & 0x3f;
m_bRlc = 0;
}
#endif
}
return i;
}
@@ -400,7 +395,7 @@ void RlcFile::write(uint8_t *buf, uint8_t i_len)
do {
nextWriteStep();
} while (s_sync_write && m_write_len && !s_write_err);
} while (IS_SYNC_WRITE_ENABLE() && m_write_len && !s_write_err);
}
void RlcFile::nextWriteStep()
@@ -426,9 +421,9 @@ void RlcFile::nextWriteStep()
s_write_err = ERR_FULL;
break;
}
if (m_ofs >= (BS-1)) {
if (m_ofs >= (BS-sizeof(blkid_t))) {
m_ofs = 0;
uint8_t nextBlk = EeFsGetLink(m_currBlk);
blkid_t nextBlk = EeFsGetLink(m_currBlk);
if (!nextBlk) {
if (!eeFs.freeList) {
s_write_err = ERR_FULL;
@@ -452,7 +447,7 @@ void RlcFile::nextWriteStep()
EeFsSetLink(m_currBlk, 0);
return;
}
uint8_t tmp = BS-1-m_ofs; if(tmp>m_write_len) tmp=m_write_len;
uint8_t tmp = BS-sizeof(blkid_t)-m_ofs; if(tmp>m_write_len) tmp = m_write_len;
m_write_buf += tmp;
m_write_len -= tmp;
m_ofs += tmp;
@@ -467,7 +462,7 @@ void RlcFile::nextWriteStep()
m_write_len = 0;
m_cur_rlc_len = 0;
}
else if (!s_sync_write) {
else if (!IS_SYNC_WRITE_ENABLE()) {
nextRlcWriteStep();
}
}
@@ -479,7 +474,7 @@ void RlcFile::create(uint8_t i_fileId, uint8_t typ, uint8_t sync_write)
eeFs.files[FILE_TMP].typ = typ;
eeFs.files[FILE_TMP].size = 0;
m_fileId = i_fileId;
s_sync_write = sync_write;
ENABLE_SYNC_WRITE(sync_write);
}
/*
@@ -491,18 +486,19 @@ bool RlcFile::copy(uint8_t i_fileDst, uint8_t i_fileSrc)
theFile2.openRd(i_fileSrc);
create(i_fileDst, FILE_TYP_MODEL/*optimization, only model files are copied. should be eeFs.files[i_fileSrc].typ*/, true);
uint8_t buf[15];
uint8_t buf[BS-sizeof(blkid_t)];
uint8_t len;
while ((len=theFile2.read(buf, 15)))
while ((len=theFile2.read(buf, BS-sizeof(blkid_t))))
{
write(buf, len);
if (write_errno() != 0) {
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
return false;
}
}
uint8_t fri=0;
blkid_t fri=0;
if (m_currBlk && (fri=EeFsGetLink(m_currBlk)))
EeFsSetLink(m_currBlk, 0);
@@ -644,21 +640,21 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
do {
result = f_read(&g_oLogFile, (uint8_t *)buf, 15, &read);
if (result != FR_OK) {
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
f_close(&g_oLogFile);
return SDCARD_ERROR(result);
}
if (read > 0) {
theFile.write((uint8_t *)buf, read);
if (write_errno() != 0) {
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
f_close(&g_oLogFile);
return STR_EEPROMOVERFLOW;
}
}
} while (read == 15);
uint8_t fri=0;
blkid_t fri=0;
if (theFile.m_currBlk && (fri=EeFsGetLink(theFile.m_currBlk)))
EeFsSetLink(theFile.m_currBlk, 0);
@@ -672,7 +668,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
}
#endif
void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_len, uint8_t sync_write)
void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t *buf, uint16_t i_len, uint8_t sync_write)
{
create(i_fileId, typ, sync_write);
@@ -686,7 +682,7 @@ void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_le
do {
nextRlcWriteStep();
} while (s_sync_write && m_write_step && !s_write_err);
} while (IS_SYNC_WRITE_ENABLE() && m_write_step && !s_write_err);
}
void RlcFile::nextRlcWriteStep()
@@ -704,14 +700,14 @@ void RlcFile::nextRlcWriteStep()
return;
}
bool run0 = m_rlc_buf[0] == 0;
bool run0 = (m_rlc_buf[0] == 0);
if(m_rlc_len==0) goto close;
if (m_rlc_len==0) goto close;
for (i=1; 1; i++) // !! laeuft ein byte zu weit !!
{
bool cur0 = m_rlc_buf[i] == 0;
if (cur0 != run0 || cnt==0x3f || (cnt0 && cnt==0xf)|| i==m_rlc_len){
if (cur0 != run0 || cnt==0x3f || (cnt0 && cnt==0x0f) || i==m_rlc_len) {
if (run0) {
assert(cnt0==0);
if (cnt<8 && i!=m_rlc_len)
@@ -747,10 +743,10 @@ void RlcFile::nextRlcWriteStep()
switch(m_write_step) {
case WRITE_START_STEP:
{
uint8_t fri=0;
blkid_t fri=0;
if (m_currBlk && (fri=EeFsGetLink(m_currBlk))) {
uint8_t prev_freeList = eeFs.freeList;
blkid_t prev_freeList = eeFs.freeList;
eeFs.freeList = fri;
while( EeFsGetLink(fri)) fri = EeFsGetLink(fri);
m_write_step = WRITE_FREE_UNUSED_BLOCKS_STEP1;
@@ -790,17 +786,19 @@ void RlcFile::nextRlcWriteStep()
}
}
#if !defined(CPUARM)
void RlcFile::flush()
{
while (eeprom_buffer_size > 0) wdt_reset();
s_sync_write = true;
ENABLE_SYNC_WRITE(true);
while (m_write_len && !s_write_err)
nextWriteStep();
while (isWriting() && !s_write_err)
nextRlcWriteStep();
s_sync_write = false;
ENABLE_SYNC_WRITE(false);
}
#endif
#if defined (EEPROM_PROGRESS_BAR)
void RlcFile::DisplayProgressBar(uint8_t x)
@@ -843,7 +841,7 @@ bool eeLoadGeneral()
uint16_t eeLoadModelName(uint8_t id, char *name)
{
memclear(name, sizeof(g_model.name));
if (id<MAX_MODELS) {
if (id < MAX_MODELS) {
theFile.openRlc(FILE_MODEL(id));
if (theFile.readRlc((uint8_t*)name, sizeof(g_model.name)) == sizeof(g_model.name)) {
return theFile.size();
@@ -852,16 +850,29 @@ uint16_t eeLoadModelName(uint8_t id, char *name)
return 0;
}
#if defined(CPUARM)
// TODO same function in eeprom_arm.cpp
void eeLoadModelNames()
{
for (uint32_t i=0; i<MAX_MODELS; i++) {
modelSizes[i] = eeLoadModelName(i, modelNames[i]);
}
}
#else
#define eeLoadModelNames()
#endif
bool eeModelExists(uint8_t id)
{
return EFile::exists(FILE_MODEL(id));
}
// TODO Now the 2 functions in eeprom_avr.cpp and eeprom_arm.cpp are really close, should be merged.
void eeLoadModel(uint8_t id)
{
if (id<MAX_MODELS) {
#ifdef SDCARD
#if defined(SDCARD)
closeLogs();
#endif
@@ -869,6 +880,8 @@ void eeLoadModel(uint8_t id)
pausePulses();
}
pauseMixerCalculations();
theFile.openRlc(FILE_MODEL(id));
uint16_t sz = theFile.readRlc((uint8_t*)&g_model, sizeof(g_model));
@@ -894,7 +907,7 @@ void eeLoadModel(uint8_t id)
activeFunctions = 0;
activeFunctionSwitches = 0;
#if defined(PCBGRUVIN9X)
#if !defined(PCBSTD)
for (uint8_t i=0; i<MAX_TIMERS; i++) {
if (g_model.timers[i].remanent) {
s_timerVal[i] = g_model.timers[i].value;
@@ -902,17 +915,27 @@ void eeLoadModel(uint8_t id)
}
#endif
resumeMixerCalculations();
// TODO pulses should be started after mixer calculations ...
#if defined(FRSKY)
FRSKY_setModelAlarms();
#endif
#if defined(SDCARD)
refreshModelAudioFiles();
#endif
LOAD_MODEL_BITMAP();
}
}
// TODO merge this code with eeprom_arm.cpp one
void eeReadAll()
{
if(!EeFsOpen() ||
EeFsck() < 0 ||
!eeLoadGeneral())
if (!EeFsOpen() ||
EeFsck() < 0 ||
!eeLoadGeneral())
{
generalDefault();
@@ -921,12 +944,15 @@ void eeReadAll()
EeFsFormat();
theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL,(uint8_t*)&g_eeGeneral,sizeof(EEGeneral), true);
theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), true);
modelDefault(0);
theFile.writeRlc(FILE_MODEL(0), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), true);
}
else {
eeLoadModelNames();
}
stickMode = g_eeGeneral.stickMode;
eeLoadModel(g_eeGeneral.currModel);
+48 -36
View File
@@ -45,33 +45,40 @@
extern uint8_t s_eeDirtyMsk;
extern uint16_t s_eeDirtyTime10ms;
//
// bs=16 128 blocks verlust link:128 16files:16*8 128 sum 256
// bs=32 64 blocks verlust link: 64 16files:16*16 256 sum 320
//
#if defined(PCBGRUVIN9X) || defined(CPUM128)
#if defined(CPUARM)
#define blkid_t uint16_t
#define EESIZE (32*1024)
#define EEFS_VERS 5
#define MAXFILES 62
#define BS 64
#elif defined(PCBGRUVIN9X) || 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
#endif
#define BS 16
PACK(struct DirEnt{
uint8_t startBlk;
blkid_t startBlk;
uint16_t size:12;
uint16_t typ:4;
});
PACK(struct EeFs{
uint8_t version;
uint8_t mySize;
uint8_t freeList;
blkid_t mySize;
blkid_t freeList;
uint8_t bs;
#if defined(CPUARM)
uint8_t spare[2];
#endif
DirEnt files[MAXFILES];
});
@@ -84,23 +91,25 @@ PACK(struct EeFs{
#define FILE_MODEL(n) (1+(n))
#define FILE_TMP (1+MAX_MODELS)
#define RESV sizeof(EeFs) //reserv for eeprom header with directory (eeFs)
#define RESV sizeof(EeFs) //reserv for eeprom header with directory (eeFs)
#if defined(PCBGRUVIN9X) || defined(CPUM128)
#define FIRSTBLK 1
#define BLOCKS (1+(EESIZE-RESV)/BS)
#define BLOCKS_OFFSET (RESV-BS)
#else
#if defined(CPUM64)
#define FIRSTBLK (RESV/BS)
#define BLOCKS (EESIZE/BS)
#define BLOCKS_OFFSET 0
#else
#define FIRSTBLK 1
#define BLOCKS (1+(EESIZE-RESV)/BS)
#define BLOCKS_OFFSET (RESV-BS)
#endif
int8_t EeFsck();
void EeFsFormat();
uint16_t EeFsGetFree();
#if !defined(CPUARM)
extern volatile int8_t eeprom_buffer_size;
#endif
class EFile
{
@@ -110,7 +119,7 @@ class EFile
static void rm(uint8_t i_fileId);
///swap contents of file1 with them of file2
static void swap(uint8_t i_fileId1,uint8_t i_fileId2);
static void swap(uint8_t i_fileId1, uint8_t i_fileId2);
///return true if the file with given fileid exists
static bool exists(uint8_t i_fileId);
@@ -121,20 +130,28 @@ class EFile
///open file for reading, no close necessary
void openRd(uint8_t i_fileId);
uint8_t read(uint8_t*buf, uint16_t i_len);
uint8_t read(uint8_t *buf, uint8_t len);
// protected:
uint8_t m_fileId; //index of file in directory = filename
uint16_t m_pos; //over all filepos
uint8_t m_currBlk; //current block.id
blkid_t m_currBlk; //current block.id
uint8_t m_ofs; //offset inside of the current block
};
#define ERR_NONE 0
#define ERR_FULL 1
extern uint8_t s_write_err; // error reasons
#if defined(CPUARM)
#define ENABLE_SYNC_WRITE(val)
#define IS_SYNC_WRITE_ENABLE() true
#else
extern uint8_t s_sync_write;
#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; }
@@ -170,32 +187,24 @@ public:
void create(uint8_t i_fileId, uint8_t typ, uint8_t sync_write);
///copy contents of i_fileSrc to i_fileDst
/// copy contents of i_fileSrc to i_fileDst
bool copy(uint8_t i_fileDst, uint8_t i_fileSrc);
inline bool isWriting() { return m_write_step != 0; }
void write(uint8_t*buf, uint8_t i_len);
void write(uint8_t *buf, uint8_t i_len);
void write1(uint8_t b);
void nextWriteStep();
void nextRlcWriteStep();
void writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t *buf, uint16_t i_len, uint8_t sync_write);
void flush();
///read from opened file and decode rlc-coded data
#ifdef TRANSLATIONS
uint16_t readRlc12(uint8_t*buf,uint16_t i_len,bool rlc2);
inline uint16_t readRlc1(uint8_t*buf,uint16_t i_len)
{
return readRlc12(buf,i_len,false);
}
inline uint16_t readRlc(uint8_t*buf, uint16_t i_len)
{
return readRlc12(buf,i_len,true);
}
#else
uint16_t readRlc(uint8_t*buf, uint16_t i_len); // TODO should be like writeRlc?
#if !defined(CPUARM)
// flush the current write operation if any
void flush();
#endif
// read from opened file and decode rlc-coded data
uint16_t readRlc(uint8_t *buf, uint16_t i_len);
#if defined (EEPROM_PROGRESS_BAR)
void DisplayProgressBar(uint8_t x);
#endif
@@ -203,7 +212,11 @@ public:
extern RlcFile theFile; //used for any file operation
#if defined(CPUARM)
#define eeFlush()
#else
inline void eeFlush() { theFile.flush(); }
#endif
#if defined (EEPROM_PROGRESS_BAR)
#define DISPLAY_PROGRESS_BAR(x) theFile.DisplayProgressBar(x)
@@ -223,4 +236,3 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
#endif
#endif
/*eof*/
+41 -29
View File
@@ -75,7 +75,21 @@ void lcd_img(xcoord_t x, uint8_t y, const pm_uchar * img, uint8_t idx, LcdFlags
uint8_t lcdLastPos;
void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
#if defined(PCBX9D)
#define LCD_BYTE_FILTER(p, keep, add) \
do { \
ASSERT_IN_DISPLAY(p); \
ASSERT_IN_DISPLAY(p+DISPLAY_W); \
if (!(flags & GREY1)) \
*(p) = (*(p) & (keep)) + (add); \
if (!(flags & GREY2)) \
*(p+DISPLAY_PLAN_SIZE) = (*(p+DISPLAY_PLAN_SIZE) & (keep)) + (add); \
} while (0)
#else
#define LCD_BYTE_FILTER(p, keep, add) *(p) = (*(p) & (keep)) + (add)
#endif
void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags)
{
uint8_t *p = &displayBuf[ y / 8 * DISPLAY_W + x ];
@@ -86,24 +100,24 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
#endif
bool inv = false;
if (mode & BLINK) {
if (flags & BLINK) {
if (BLINK_ON_PHASE) {
if (mode & INVERS)
if (flags & INVERS)
inv = true;
else
return;
}
}
else if (mode & INVERS) {
else if (flags & INVERS) {
inv = true;
}
if (mode & DBLSIZE) {
if (flags & DBLSIZE) {
/* each letter consists of ten top bytes followed by
* by ten bottom bytes (20 bytes per * char) */
q = &font_10x14[((uint16_t)c-0x20)*20];
for (int8_t i=11; i>=0; i--) {
if (mode & CONDENSED && i<=1) break;
if (flags & CONDENSED && i<=1) break;
uint8_t b1=0, b2=0;
if (i>1) {
b1 = pgm_read_byte(q++); /*top byte*/
@@ -123,76 +137,72 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
}
}
#if defined(PCBX9D)
else if (mode & MIDSIZE) {
else if (flags & MIDSIZE) {
/* each letter consists of ten top bytes followed by
* by ten bottom bytes (20 bytes per * char) */
q = &font_8x10[((uint16_t)c-0x20)*16];
for (int8_t i=9; i>=0; i--) {
uint8_t b1=0, b2=0;
if (mode & CONDENSED && i<=1) break;
if (flags & CONDENSED && i<=1) break;
if (i!=0 && i!=9) {
b1 = pgm_read_byte(q++); /*top byte*/
b2 = pgm_read_byte(q++); /*top byte*/
}
if (inv) {
b1=~b1;
b2=~b2;
b1 = ~b1;
b2 = ~b2;
}
uint8_t ym8 = (y % 8);
if (&p[DISPLAY_W+1] < DISPLAY_END) {
ASSERT_IN_DISPLAY(p);
ASSERT_IN_DISPLAY(p+DISPLAY_W);
*p = (*p & (~(0xff << ym8))) + (b1 << ym8);
LCD_BYTE_FILTER(p, ~(0xff << ym8), b1 << ym8);
uint8_t *r = p + DISPLAY_W;
if (r<DISPLAY_END) {
if (ym8)
*r = (*r & (~(0xff >> (8-ym8)))) + (b1 >> (8-ym8));
*r = (*r & (~(0x0f << ym8))) + ((b2&0x0f) << ym8);
LCD_BYTE_FILTER(r, ~(0xff >> (8-ym8)), b1 >> (8-ym8));
LCD_BYTE_FILTER(r, ~(0x0f << ym8), (b2&0x0f) << ym8);
if (ym8) {
r = r + DISPLAY_W;
if (r<DISPLAY_END)
*r = (*r & (~(0x0f >> (8-ym8)))) + ((b2&0x0f) >> (8-ym8));
LCD_BYTE_FILTER(r, ~(0x0f >> (8-ym8)), (b2&0x0f) >> (8-ym8));
}
}
p++;
}
}
}
else if (mode & SMLSIZE) {
else if (flags & SMLSIZE) {
q = &font_4x6[((uint16_t)c-0x20)*5+4];
uint8_t ym8 = (y % 8);
p += 4;
for (int8_t i=4; i>=0; i--) {
uint8_t b = pgm_read_byte(q--);
if (inv) b = ~b & 0x7f;
if (p<DISPLAY_END) {
ASSERT_IN_DISPLAY(p);
*p = (*p & (~(0x7f << ym8))) + (b << ym8);
LCD_BYTE_FILTER(p, ~(0x7f << ym8), b << ym8);
if (ym8) {
uint8_t *r = p + DISPLAY_W;
if (r<DISPLAY_END)
*r = (*r & (~(0x7f >> (8-ym8)))) + (b >> (8-ym8));
LCD_BYTE_FILTER(r, ~(0x7f >> (8-ym8)), b >> (8-ym8));
}
}
p--;
}
}
else if (mode & TINSIZE) {
else if (flags & TINSIZE) {
q = &font_3x5[((uint16_t)c-0x2D)*3+2];
uint8_t ym8 = (y % 8);
p += 2;
for (int8_t i=2; i>=0; i--) {
uint8_t b = pgm_read_byte(q--);
if (inv) b = ~b & 0x3f;
if (p<DISPLAY_END) {
ASSERT_IN_DISPLAY(p);
*p = (*p & (~(0x3f << ym8))) + (b << ym8);
LCD_BYTE_FILTER(p, ~(0x3f << ym8), b << ym8);
if (ym8) {
uint8_t *r = p + DISPLAY_W;
if (r<DISPLAY_END)
*r = (*r & (~(0x3f >> (8-ym8)))) + (b >> (8-ym8));
LCD_BYTE_FILTER(r, ~(0x3f >> (8-ym8)), b >> (8-ym8));
}
}
p--;
@@ -202,7 +212,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
else {
uint8_t condense=0;
if (mode & CONDENSED) {
if (flags & CONDENSED) {
*p = inv ? ~0 : 0;
condense=1;
}
@@ -220,14 +230,14 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
if (p<DISPLAY_END) {
ASSERT_IN_DISPLAY(p);
*p = (*p & (~(0xff << ym8))) + (b << ym8);
LCD_BYTE_FILTER(p, ~(0xff << ym8), b << ym8);
if (ym8) {
uint8_t *r = p + DISPLAY_W;
if (r<DISPLAY_END)
*r = (*r & (~(0xff >> (8-ym8)))) + (b >> (8-ym8));
LCD_BYTE_FILTER(r, ~(0xff >> (8-ym8)), b >> (8-ym8));
}
#ifdef BOLD_FONT
if (mode & BOLD) {
if (flags & BOLD) {
ASSERT_IN_DISPLAY(p+1);
if (inv)
*(p+1) &= (b << ym8);
@@ -431,8 +441,10 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags, uint8_t
if (xn) {
if (midsize) {
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE))
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) {
lcd_vline(xn, y, 12);
lcd_vline(xn+1, y, 12);
}
lcd_hline(xn, y+9, 2);
lcd_hline(xn, y+10, 2);
}
+7 -6
View File
@@ -216,13 +216,14 @@ void menuModelSelect(uint8_t event)
{
TITLE(STR_MENUMODELSEL);
#if defined(CPUARM)
#if defined(PCBSKY9X)
#define REFRESH(x)
#elif defined(PCBGRUVIN9X) && defined(SDCARD)
static bool refresh = true;
#define REFRESH(x) refresh = (x)
#else
#define refresh event
#define refresh event
#define REFRESH(x)
#endif
if (s_warning_result) {
@@ -430,7 +431,7 @@ void menuModelSelect(uint8_t event)
}
#if !defined(CPUARM)
#if !defined(PCBSKY9X)
lcd_puts(9*FW-(LEN_FREE-4)*FW, 0, STR_FREE);
if (refresh) reusableBuffer.models.eepromfree = EeFsGetFree();
lcd_outdezAtt(17*FW, 0, reusableBuffer.models.eepromfree, 0);
@@ -470,7 +471,7 @@ void menuModelSelect(uint8_t event)
if (eeModelExists(k)) {
#if defined(CPUARM)
putsModelName(4*FW, y, ModelNames[k], k, 0);
putsModelName(4*FW, y, modelNames[k], k, 0);
#else
uint16_t & size = reusableBuffer.models.listsizes[i];
char * name = reusableBuffer.models.listnames[i];
@@ -489,7 +490,7 @@ void menuModelSelect(uint8_t event)
if (s_warning) {
#if defined(CPUARM)
s_warning_info = ModelNames[sub];
s_warning_info = modelNames[sub];
#else
char * name = reusableBuffer.models.mainname;
if (refresh) eeLoadModelName(sub, name);
@@ -666,7 +667,7 @@ void menuModelSetup(uint8_t event)
case ITEM_MODEL_NAME:
editName(MODEL_SETUP_2ND_COLUMN, y, g_model.name, sizeof(g_model.name), event, attr, m_posHorz);
#if defined(CPUARM)
memcpy(ModelNames[g_eeGeneral.currModel], g_model.name, sizeof(g_model.name));
memcpy(modelNames[g_eeGeneral.currModel], g_model.name, sizeof(g_model.name));
#endif
break;
+11 -1
View File
@@ -64,8 +64,14 @@ OS_FlagID audioFlag;
OS_MutexID audioMutex;
OS_MutexID mixerMutex;
char modelNames[MAX_MODELS][sizeof(g_model.name)];
#if defined(PCBX9D)
uint16_t modelSizes[MAX_MODELS];
#endif
#endif // defined(CPUARM)
#if defined(SPLASH)
const pm_uchar splashdata[] PROGMEM = { 'S','P','S',0,
#if defined(PCBACT)
@@ -2870,11 +2876,15 @@ void perMain()
}
#endif
#if defined(CPUARM)
// TODO merge these 2 branches
#if defined(PCBSKY9X)
if (Eeprom32_process_state != E32_IDLE)
ee32_process();
else if (TIME_TO_WRITE)
eeCheck();
#elif defined(CPUARM)
if (TIME_TO_WRITE)
eeCheck();
#else
if (!eeprom_buffer_size) {
if (theFile.isWriting())
+16 -4
View File
@@ -212,10 +212,23 @@ extern void boardInit();
#endif
#if defined(CPUARM)
extern char modelNames[MAX_MODELS][sizeof(g_model.name)];
#endif
#if defined(PCBX9D)
extern uint16_t modelSizes[MAX_MODELS];
#endif
// TODO try to merge the 2 include files
#if defined(PCBSKY9X)
#include "eeprom_arm.h"
#include "pulses_arm.h"
#else
#include "eeprom_avr.h"
#endif
#if defined(CPUARM)
#include "pulses_arm.h"
#else
#include "pulses_avr.h"
#endif
@@ -1000,7 +1013,6 @@ void saveTimers();
#define saveTimers()
#endif
void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_t size);
void eeDirty(uint8_t msk);
void eeCheck(bool immediately=false);
void eeReadAll();
@@ -1287,7 +1299,7 @@ union ReusableBuffer
{
/* 128 bytes on stock */
#if !defined(CPUARM)
#if !defined(PCBSKY9X)
uint8_t eefs_buffer[BLOCKS]; // 128bytes used by EeFsck
#endif
@@ -1333,7 +1345,7 @@ void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t
#if defined(CPUARM)
uint8_t zlen(const char *str, uint8_t size);
char * strcat_zchar(char * dest, char * name, uint8_t size, const char *defaultName, uint8_t defaultNameSize, uint8_t defaultIdx);
#define strcat_modelname(dest, idx) strcat_zchar(dest, ModelNames[idx], LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1)
#define strcat_modelname(dest, idx) strcat_zchar(dest, modelNames[idx], LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1)
#define strcat_phasename_default(dest, idx) strcat_zchar(dest, NULL, 0, STR_FP, PSIZE(TR_FP), idx)
#define strcat_phasename_nodefault(dest, idx) strcat_zchar(dest, g_model.phaseData[idx].name, LEN_FP_NAME, NULL, 0, 0)
#define strcat_mixername_nodefault(dest, idx) strcat_zchar(dest, g_model.mixData[idx].name, LEN_EXPOMIX_NAME, NULL, 0, 0)
+6 -6
View File
@@ -732,18 +732,18 @@ void setupPulses()
PORTH |= 0x80; // PORTH:7 LOW->HIGH signals start of setupPulses()
#endif
#if defined (PCBGRUVIN9X) && defined(TX_CADDY)
if (s_pulses_paused)
required_protocol = PROTO_NONE;
if (s_current_protocol != required_protocol) {
#if defined(PCBGRUVIN9X) && defined(TX_CADDY)
if (required_protocol == PROTO_DSM2)
PORTH &= ~0x80;
else
PORTH |= 0x80;
#endif
if (s_pulses_paused)
required_protocol = PROTO_NONE;
if (s_current_protocol != required_protocol) {
#if defined(DSM2_SERIAL) && defined(FRSKY)
if (s_current_protocol == 255 || s_current_protocol == PROTO_DSM2) {
FRSKY_Init();
+33 -7
View File
@@ -58,7 +58,7 @@ Dacc dacc;
Adc Adc0;
#endif
#if defined(CPUARM)
#if defined(PCBSKY9X)
uint32_t eeprom_pointer;
char* eeprom_buffer_data;
volatile int32_t eeprom_buffer_size;
@@ -257,6 +257,7 @@ uint16_t getTmr16KHz()
return get_tmr10ms() * 160;
}
#if !defined(PCBX9D)
bool eeprom_thread_running = true;
void *eeprom_write_function(void *)
{
@@ -300,6 +301,7 @@ void *eeprom_write_function(void *)
}
return 0;
}
#endif
uint8_t main_thread_running = 0;
char * main_thread_error = NULL;
@@ -385,33 +387,57 @@ void StartEepromThread(const char *filename)
eeprom_write_sem = (sem_t *)malloc(sizeof(sem_t));
sem_init(eeprom_write_sem, 0, 0);
#endif
#if !defined(PCBX9D)
eeprom_thread_running = true;
assert(!pthread_create(&eeprom_thread_pid, NULL, &eeprom_write_function, NULL));
#endif
}
void StopEepromThread()
{
#if !defined(PCBX9D)
eeprom_thread_running = false;
sem_post(eeprom_write_sem);
pthread_join(eeprom_thread_pid, NULL);
#endif
}
void eeprom_read_block (void *pointer_ram,
const void *pointer_eeprom,
size_t size)
#if defined(PCBX9D)
void eeprom_read_block (void *pointer_ram, uint16_t pointer_eeprom, size_t size)
#else
void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t size)
#endif
{
assert(size);
if (fp) {
memset(pointer_ram, 0, size);
if (fseek(fp, (long) pointer_eeprom, SEEK_SET)==-1) perror("error in seek");
if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in read");
// printf("EEPROM read (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout);
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(PCBX9D)
void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size)
{
assert(size);
if (fp) {
// printf("EEPROM write (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout);
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
#if defined(CPUARM)
uint16_t stack_free(uint8_t)
#else
+10 -4
View File
@@ -137,12 +137,16 @@ extern Pwm pwm;
#endif
extern sem_t *eeprom_write_sem;
#if defined(CPUARM)
#if defined(PCBSKY9X)
extern uint32_t eeprom_pointer;
extern char* eeprom_buffer_data;
extern volatile int32_t eeprom_buffer_size;
extern bool eeprom_read_operation;
extern volatile uint32_t Spi_complete;
#endif
#if defined(CPUARM)
extern void startPdcUsartReceive() ;
extern uint32_t txPdcUsart( uint8_t *buffer, uint32_t size );
extern uint32_t txPdcPending();
@@ -313,9 +317,11 @@ void StartMainThread(bool tests=true);
void StartEepromThread(const char *filename="eeprom.bin");
extern const char *eepromFile;
void eeprom_read_block (void *pointer_ram,
const void *pointer_eeprom,
size_t size);
#if defined(PCBX9D)
void eeprom_read_block (void *pointer_ram, uint16_t pointer_eeprom, size_t size);
#else
void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t size);
#endif
#define wdt_reset() sleep(1/*ms*/)
#define boardInit()
+7 -1
View File
@@ -50,7 +50,6 @@
#define SD_IS_HC() (1)
#endif
extern "C" {
extern void init_SDcard();
extern void sdInit();
@@ -114,4 +113,11 @@ uint32_t check_soft_power();
#define udelay(x) do { uint32_t temp; temp=((x+0)<<3); while(--temp); } while (0)
#define delayUsec(x) udelay(x)
#if !defined(SIMU)
#define eeprom_read_block I2C_EE_BufferRead
#define eeWriteBlockCmp I2C_EE_BufferWrite
#else
void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size);
#endif
#endif
-14
View File
@@ -39,17 +39,3 @@ void eepromInit()
I2C_EE_Init();
#endif
}
void eeprom_write_enable()
{
}
uint32_t eeprom_read_status()
{
return !Spi_complete;
}
uint32_t spi_PDC_action( register uint8_t *command, register uint8_t *tx, register uint8_t *rx, register uint32_t comlen, register uint32_t count )
{
return 0;
}
+3 -23
View File
@@ -167,30 +167,10 @@
#define AudioFreq I2S_AudioFreq_44k
// EEPROM and CAT5137
#define EE_M24C08 /* Support the device: M24C08. */
//#define EE_M24C64_32 /* Support the devices: M24C32 and M24C64 */
#define I2C_Speed 200000
#if defined (EE_M24C08)
#define I2C_FLASH_PAGESIZE (16)
#elif defined (EE_M24C64_32)
#define I2C_FLASH_PAGESIZE (32)
#endif
#ifdef EE_M24C64_32
#define EEPROM_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */
#elif defined (EE_M24C08)
//#define EEPROM_Block0_ADDRESS 0xA0 /* 000*/
#define EEPROM_Block1_ADDRESS 0xA2 /* E3 E2 E1= 001 */
//#define EEPROM_Block2_ADDRESS 0xA4 /* 010 */
//#define EEPROM_Block3_ADDRESS 0xA6 /* 011 */
#endif
#define USE_CAT5137 /*Support the Volume Control*/
#ifdef USE_CAT5137
#define I2C_CAT5137_ADDRESS 0x5C//0101110
#endif
#define I2C_FLASH_PAGESIZE (64)
#define I2C_EEPROM_ADDRESS 0xA0
#define I2C_CAT5137_ADDRESS 0x5C //0101110
// SD card----SPI2
// demo uses a command line option to define this (see Makefile):
+11 -54
View File
@@ -12,15 +12,12 @@
#include "../open9x.h"
uint16_t EEPROM_ADDRESS;
/**
* @brief Configure the used I/O ports pin
* @param None
* @retval None
*/
static
void I2C_GPIO_Configuration(void)
static void I2C_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
@@ -41,17 +38,6 @@ void I2C_GPIO_Configuration(void)
GPIO_Init(I2C_EE_GPIO, &GPIO_InitStructure);
}
/**
* @brief I2C Configuration
* @param None
* @retval None
*/
//when use harware I2C
void I2C_Configuration(void)
{
}
short I2C_START()
{
SDA_H;
@@ -173,32 +159,6 @@ void I2C_EE_Init()
/* GPIO configuration */
I2C_GPIO_Configuration();
#if defined (EE_M24C64_32)
/* Select the EEPROM address according to the state of E0, E1, E2 pins */
EEPROM_ADDRESS = EEPROM_HW_ADDRESS;
#elif defined (EE_M24C08)
/* depending on the EEPROM Address selected in the i2c_ee.h file */
#ifdef EEPROM_Block0_ADDRESS
/* Select the EEPROM Block0 to write on */
EEPROM_ADDRESS = EEPROM_Block0_ADDRESS;
#endif
#ifdef EEPROM_Block1_ADDRESS
/* Select the EEPROM Block1 to write on */
EEPROM_ADDRESS = EEPROM_Block1_ADDRESS;
#endif
#ifdef EEPROM_Block2_ADDRESS
/* Select the EEPROM Block2 to write on */
EEPROM_ADDRESS = EEPROM_Block2_ADDRESS;
#endif
#ifdef EEPROM_Block3_ADDRESS
/* Select the EEPROM Block3 to write on */
EEPROM_ADDRESS = EEPROM_Block3_ADDRESS;
#endif
#endif /* EE_M24C64_32 */
}
/**
@@ -211,12 +171,12 @@ void I2C_EE_Init()
void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_WRITE);
I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
#else
I2C_SEND_DATA((uint8_t)((WriteAddr&0xFF00)>>8) );
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr&0xFF));
@@ -238,13 +198,12 @@ void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr)
void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS |EE_CMD_WRITE);
I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
#ifdef EE_M24C08
I2C_SEND_DATA(ReadAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
#else
I2C_SEND_DATA((uint8_t)((ReadAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(ReadAddr & 0x00FF));
@@ -253,7 +212,7 @@ void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRe
I2C_STOP();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_READ);
I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_READ);
I2C_WAIT_ACK();
while (NumByteToRead) {
if (NumByteToRead == 1) {
@@ -369,13 +328,13 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo
void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
#else
I2C_SEND_DATA((uint8_t)((WriteAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr & 0x00FF));
@@ -398,11 +357,9 @@ void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWri
*/
void I2C_EE_WaitEepromStandbyState(void)
{
/*__IO*/ volatile uint16_t SR1_Tmp = 0;
do {
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE);
} while (0 == I2C_WAIT_ACK());
I2C_STOP();
-3
View File
@@ -22,9 +22,6 @@
#ifndef __I2C_EE_H
#define __I2C_EE_H
// #include "stm32f2xx.h"
// #include "stm32f2xx_conf.h"
#define EE_CMD_WRITE (0)
#define EE_CMD_READ (1)
#define I2C_delay() do { delayUsec(5); } while(0)