From 6113420a02b7b258dd8ed1fdbed8bb25ea749a1a Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 29 Mar 2012 18:29:49 +0000 Subject: [PATCH] EEPROM Swap / Copy / Delete model now Ok on ErSky9x Simu target on ARM now ok --- src/Makefile | 25 ++-- src/board_ersky9x.cpp | 272 +++++++++++++++++++++--------------------- src/drivers.cpp | 4 + src/eeprom_arm.cpp | 130 +++++++++++--------- src/eeprom_avr.cpp | 2 +- src/ersky9x/sound.cpp | 11 +- src/lcd.cpp | 22 ++-- src/open9x.h | 11 +- src/simpgmspace.cpp | 38 +++++- src/simpgmspace.h | 27 +++++ src/simu.cpp | 33 +++-- 11 files changed, 331 insertions(+), 244 deletions(-) diff --git a/src/Makefile b/src/Makefile index 2a3adaae5..91e271886 100644 --- a/src/Makefile +++ b/src/Makefile @@ -112,23 +112,17 @@ REV = $(shell sh -c "svnversion | egrep -o '[[:digit:]]+[[:alpha:]]*$$'") # MCU name ifeq ($(PCB), STD) TRGT = avr- - MCU = atmega64 - BOARDSRC = board_stock.cpp - EEPROMSRC = eeprom_avr.cpp + MCU = atmega64 CPPDEFS = -DF_CPU=$(F_CPU)UL endif ifeq ($(PCB), V4) TRGT = avr- MCU = atmega2560 - BOARDSRC = board_gruvin9x.cpp - EEPROMSRC = eeprom_avr.cpp CPPDEFS = -DF_CPU=$(F_CPU)UL endif ifeq ($(PCB), ARM) TRGT = arm-none-eabi- MCU = cortex-m3 - BOARDSRC = board_ersky9x.cpp - EEPROMSRC = eeprom_arm.cpp CPPDEFS = endif @@ -256,10 +250,9 @@ ifeq ($(PCB), ARM) OPT = 2 CPPDEFS += -DPCBARM EXTRAINCDIRS += ersky9x - CPPSRC += ersky9x/core_cm3.c - CPPSRC += ersky9x/board_lowlevel.c - CPPSRC += ersky9x/crt.c - CPPSRC += ersky9x/vectors_sam3s.c + BOARDSRC = board_ersky9x.cpp + EXTRABOARDSRC = ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.c + EEPROMSRC = eeprom_arm.cpp CPPSRC += ersky9x/sound.cpp CPPSRC += beeper.cpp endif @@ -269,6 +262,8 @@ ifeq ($(PCB), V4) OPT = 2 CPPDEFS += -DPCBV4 -DAUDIO EXTRAINCDIRS += gruvin9x + BOARDSRC += board_gruvin9x.cpp + EEPROMSRC = eeprom_avr.cpp CPPSRC += audio.cpp CPPSRC += gruvin9x/gtime.cpp CPPSRC += gruvin9x/rtc.cpp @@ -296,6 +291,8 @@ ifeq ($(PCB), STD) # STD PCB, so ... OPT = s CPPDEFS += -DPCBSTD + BOARDSRC = board_stock.cpp + EEPROMSRC = eeprom_avr.cpp ifeq ($(AUDIO), YES) CPPDEFS += -DAUDIO @@ -511,7 +508,7 @@ FOXLIB=-L/usr/local/lib \ -Wl,-rpath,$(FOXPATH)/src/.libs simu: $(BOARDSRC) $(CPPSRC) Makefile simu.cpp simpgmspace.cpp *.h *.lbm eeprom.bin - g++ simu.cpp $(BOARDSRC) $(CPPFLAGS) $(CPPSRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB) -pthread + g++ simu.cpp $(CPPFLAGS) $(BOARDSRC) $(CPPSRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB) -pthread eeprom.bin: dd if=/dev/zero of=$@ bs=1 count=2048 @@ -554,9 +551,9 @@ endif $(OBJDUMP) -h -S $< > $@ # Concatenate all sources files in one big file to optimize size -allsrc.cpp: $(BOARDSRC) $(CPPSRC) +allsrc.cpp: $(BOARDSRC) $(CPPSRC) $(EXTRABOARDSRC) @echo -n > allsrc.cpp - for f in $(BOARDSRC) $(CPPSRC); do echo "# 1 \"$$f\"" >> allsrc.cpp; cat "$$f" >> allsrc.cpp; done + for f in $(BOARDSRC) $(CPPSRC) $(EXTRABOARDSRC) ; do echo "# 1 \"$$f\"" >> allsrc.cpp; cat "$$f" >> allsrc.cpp; done remallsrc: $(REMOVE) allsrc.cpp diff --git a/src/board_ersky9x.cpp b/src/board_ersky9x.cpp index 3f203181a..9fdc68afb 100644 --- a/src/board_ersky9x.cpp +++ b/src/board_ersky9x.cpp @@ -32,10 +32,9 @@ */ #include "open9x.h" -#include "AT91SAM3S2.h" -#include "core_cm3.h" uint32_t Master_frequency ; +volatile uint32_t Tenms ; /** Console baudrate 9600. */ #define CONSOLE_BAUDRATE 9600 @@ -156,6 +155,8 @@ inline void setup_switches() #endif } +#ifndef SIMU + /** * Configures a UART peripheral with the specified parameters. * @@ -316,9 +317,6 @@ inline void start_timer0() ptc->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger) } -// TODO where used -volatile uint32_t Tenms ; - extern "C" void TC2_IRQHandler() { register uint32_t dummy; @@ -327,7 +325,7 @@ extern "C" void TC2_IRQHandler() /* Clear status bit to acknowledge interrupt */ dummy = TC0->TC_CHANNEL[2].TC_SR; (void) dummy ; // Discard value - prevents compiler warning - Tenms |= 1 ; // 10 mS has passed + /* TODO if ( Buzzer_count ) { if ( --Buzzer_count == 0 ) @@ -585,9 +583,12 @@ void board_init() eeprom_init(); } + +#endif + uint16_t getTmr2MHz() { - return TC1->TC_CHANNEL[0].TC_CV ; + return TC1->TC_CHANNEL[0].TC_CV ; } // keys: @@ -601,130 +602,124 @@ uint16_t getTmr2MHz() // LCD pins 5 DOWN, 4 RIGHT, 3 LEFT, 1 UP uint32_t read_keys() { - register uint32_t x ; - register uint32_t y ; + register uint32_t x; + register uint32_t y; + + x = PIOC->PIO_PDSR << 1; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP () - x = PIOC->PIO_PDSR << 1 ; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP () #ifdef REVB - y = x & 0x00000020 ; // RIGHT - if ( x & 0x00000004 ) - { - y |= 0x00000010 ; // UP - } - if ( x & 0x00000010 ) - { - y |= 0x00000040 ; // LEFT - } - if ( x & 0x00000040 ) - { - y |= 0x00000008 ; // DOWN - } + y = x & 0x00000020; // RIGHT + if ( x & 0x00000004 ) + { + y |= 0x00000010; // UP + } + if ( x & 0x00000010 ) + { + y |= 0x00000040; // LEFT + } + if ( x & 0x00000040 ) + { + y |= 0x00000008; // DOWN + } #else - y = x & 0x00000060 ; - if ( x & 0x00000008 ) - { - y |= 0x00000010 ; - } - if ( x & 0x00000010 ) - { - y |= 0x00000008 ; - } + + y = x & 0x00000060; + if (x & 0x00000008) { + y |= 0x00000010; + } + if (x & 0x00000010) { + y |= 0x00000008; + } #endif #ifdef REVB - if ( PIOC->PIO_PDSR & 0x01000000 ) + if ( PIOC->PIO_PDSR & 0x01000000 ) #else - if ( PIOA->PIO_PDSR & 0x80000000 ) + if (PIOA->PIO_PDSR & 0x80000000) #endif - { - y |= 4 ; // EXIT - } + { + y |= 4; // EXIT + } #ifdef REVB - if ( PIOB->PIO_PDSR & 0x000000020 ) + if ( PIOB->PIO_PDSR & 0x000000020 ) #else - if ( PIOB->PIO_PDSR & 0x000000040 ) + if (PIOB->PIO_PDSR & 0x000000040) #endif - { - y |= 2 ; // MENU - } - return y ; + { + y |= 2; // MENU + } + + return y ; } uint32_t read_trims() { - uint32_t trims ; - - trims = 0 ; + uint32_t trims = 0; // TRIM_LH_DOWN PA7 (PA23) #ifdef REVB - if ( ( PIOA->PIO_PDSR & 0x00800000 ) == 0 ) + if ( ( PIOA->PIO_PDSR & 0x00800000 ) == 0 ) #else - if ( ( PIOA->PIO_PDSR & 0x0080 ) == 0 ) + if ((PIOA->PIO_PDSR & 0x0080) == 0) #endif - { - trims |= 1 ; - } + { + trims |= 1; + } // TRIM_LH_UP PB4 - if ( ( PIOB->PIO_PDSR & 0x10 ) == 0 ) - { - trims |= 2 ; - } + if ((PIOB->PIO_PDSR & 0x10) == 0) { + trims |= 2; + } // TRIM_LV_DOWN PA27 (PA24) #ifdef REVB - if ( ( PIOA->PIO_PDSR & 0x01000000 ) == 0 ) + if ( ( PIOA->PIO_PDSR & 0x01000000 ) == 0 ) #else - if ( ( PIOA->PIO_PDSR & 0x08000000 ) == 0 ) + if ((PIOA->PIO_PDSR & 0x08000000) == 0) #endif - { - trims |= 4 ; - } + { + trims |= 4; + } // TRIM_LV_UP PC28 - if ( ( PIOC->PIO_PDSR & 0x10000000 ) == 0 ) - { - trims |= 8 ; - } + if ((PIOC->PIO_PDSR & 0x10000000) == 0) { + trims |= 8; + } // TRIM_RV_DOWN PC10 - if ( ( PIOC->PIO_PDSR & 0x00000400 ) == 0 ) - { - trims |= 0x10 ; - } + if ((PIOC->PIO_PDSR & 0x00000400) == 0) { + trims |= 0x10; + } // TRIM_RV_UP PA30 (PA1) #ifdef REVB - if ( ( PIOA->PIO_PDSR & 0x00000002 ) == 0 ) + if ( ( PIOA->PIO_PDSR & 0x00000002 ) == 0 ) #else - if ( ( PIOA->PIO_PDSR & 0x40000000 ) == 0 ) + if ((PIOA->PIO_PDSR & 0x40000000) == 0) #endif - { - trims |= 0x20 ; - } + { + trims |= 0x20; + } // TRIM_RH_DOWN PA29 (PA0) #ifdef REVB - if ( ( PIOA->PIO_PDSR & 0x00000001 ) == 0 ) + if ( ( PIOA->PIO_PDSR & 0x00000001 ) == 0 ) #else - if ( ( PIOA->PIO_PDSR & 0x20000000 ) == 0 ) + if ((PIOA->PIO_PDSR & 0x20000000) == 0) #endif - { - trims |= 0x40 ; - } + { + trims |= 0x40; + } // TRIM_RH_UP PC9 - if ( ( PIOC->PIO_PDSR & 0x00000200 ) == 0 ) - { - trims |= 0x80 ; - } + if ((PIOC->PIO_PDSR & 0x00000200) == 0) { + trims |= 0x80; + } - return trims ; + return trims ; } - uint8_t keyDown() { return ~read_keys() & 0x7E ; @@ -732,53 +727,63 @@ uint8_t keyDown() extern uint32_t keyState(EnumKeys enuk) { - CPU_UINT xxx = 0 ; - if(enuk < (int)DIM(keys)) return keys[enuk].state() ? 1 : 0; + CPU_UINT xxx = 0; - switch((uint8_t)enuk) - { + if (enuk < (int) DIM(keys)) return keys[enuk].state() ? 1 : 0; + + switch ((uint8_t) enuk) { #ifdef REVB - case SW_ElevDR : xxx = PIOC->PIO_PDSR & 0x80000000 ; // ELE_DR PC31 + case SW_ElevDR : xxx = PIOC->PIO_PDSR & 0x80000000; // ELE_DR PC31 #else - case SW_ElevDR : xxx = PIOA->PIO_PDSR & 0x00000100 ; // ELE_DR PA8 + case SW_ElevDR: + xxx = PIOA->PIO_PDSR & 0x00000100; // ELE_DR PA8 #endif - break ; + break; - case SW_AileDR : xxx = PIOA->PIO_PDSR & 0x00000004 ; // AIL-DR PA2 - break ; + case SW_AileDR: + xxx = PIOA->PIO_PDSR & 0x00000004; // AIL-DR PA2 + break; - case SW_RuddDR : xxx = PIOA->PIO_PDSR & 0x00008000 ; // RUN_DR PA15 - break ; + case SW_RuddDR: + xxx = PIOA->PIO_PDSR & 0x00008000; // RUN_DR PA15 + break; // INP_G_ID1 INP_E_ID2 // id0 0 1 // id1 1 1 // id2 1 0 - case SW_ID0 : xxx = ~PIOC->PIO_PDSR & 0x00004000 ; // SW_IDL1 PC14 - break ; - case SW_ID1 : xxx = (PIOC->PIO_PDSR & 0x00004000) ; if ( xxx ) xxx = (PIOC->PIO_PDSR & 0x00000800); - break ; - case SW_ID2 : xxx = ~PIOC->PIO_PDSR & 0x00000800 ; // SW_IDL2 PC11 - break ; + case SW_ID0: + xxx = ~PIOC->PIO_PDSR & 0x00004000; // SW_IDL1 PC14 + break; + case SW_ID1: + xxx = (PIOC->PIO_PDSR & 0x00004000); + if (xxx) xxx = (PIOC->PIO_PDSR & 0x00000800); + break; + case SW_ID2: + xxx = ~PIOC->PIO_PDSR & 0x00000800; // SW_IDL2 PC11 + break; - - case SW_Gear : xxx = PIOC->PIO_PDSR & 0x00010000 ; // SW_GEAR PC16 - break ; + case SW_Gear: + xxx = PIOC->PIO_PDSR & 0x00010000; // SW_GEAR PC16 + break; #ifdef REVB - case SW_ThrCt : xxx = PIOC->PIO_PDSR & 0x00100000 ; // SW_TCUT PC20 + case SW_ThrCt : xxx = PIOC->PIO_PDSR & 0x00100000; // SW_TCUT PC20 #else - case SW_ThrCt : xxx = PIOA->PIO_PDSR & 0x10000000 ; // SW_TCUT PA28 + case SW_ThrCt: + xxx = PIOA->PIO_PDSR & 0x10000000; // SW_TCUT PA28 #endif - break ; + break; - case SW_Trainer: xxx = PIOC->PIO_PDSR & 0x00000100 ; // SW-TRAIN PC8 - break ; - default:; + case SW_Trainer: + xxx = PIOC->PIO_PDSR & 0x00000100; // SW-TRAIN PC8 + break; + + default: + break; } - if ( xxx ) - { - return 1 ; + if (xxx) { + return 1; } return 0; } @@ -827,25 +832,22 @@ void read_9_adc() void readKeysAndTrims() { -register uint32_t i ; + register uint32_t i; -if ( PIOC->PIO_ODSR & 0x00080000 ) -{ - PIOC->PIO_CODR = 0x00200000L ; // Set bit C19 OFF -} -else -{ - PIOC->PIO_SODR = 0x00200000L ; // Set bit C19 ON -} + if (PIOC->PIO_ODSR & 0x00080000) { + PIOC->PIO_CODR = 0x00200000L; // Set bit C19 OFF + } + else { + PIOC->PIO_SODR = 0x00200000L; // Set bit C19 ON + } -uint8_t enuk = KEY_MENU; -uint8_t in = ~read_keys() ; -for( i=1; i<7; i++) -{ + uint8_t enuk = KEY_MENU; + uint8_t in = ~read_keys(); + for (i = 1; i < 7; i++) { //INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6 -keys[enuk].input(in & (1<TC_CHANNEL[0].TC_IDR = TC_IDR0_LDRAS ; NVIC_DisableIRQ(TC3_IRQn) ; } + diff --git a/src/drivers.cpp b/src/drivers.cpp index 3e27cc530..a362510c9 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -137,6 +137,10 @@ void per10ms() g_tmr10ms++; g_blinkTmr10ms++; +#if defined (PCBARM) + Tenms |= 1 ; // 10 mS has passed +#endif + #if defined (PCBV4) /* Update gloabal Date/Time every 100 per10ms cycles */ if (++g_ms100 == 100) diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index fe8fb8ea9..de9649acc 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -87,6 +87,7 @@ uint32_t Update_timer ; //#define E_WRITEWAITING 5 //#define E_32ACTIVE 6 +// TODO use these constants everywhere #define EE_WAIT 0 #define EE_NO_WAIT 1 @@ -101,8 +102,8 @@ void eeDirty(uint8_t msk) void handle_serial( void ) ; uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ; -uint32_t read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) ; -uint32_t write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) ; +void read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) ; +void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) ; void ee32_read_model_names( void ) ; void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) ; @@ -177,23 +178,25 @@ void eeSwapModels(uint8_t id1, uint8_t id2) { // eeCheck(true) should have been called before entering here - uint16_t id1_size = File_system[id1+1].size; - uint32_t id1_block_no = File_system[id1+1].block_no; + uint16_t id2_size = File_system[id2+1].size; + uint32_t id2_block_no = File_system[id2+1].block_no; - eeCopyModel(id1, id2); + eeCopyModel(id2, id1); // block_no(id1) has been shifted now, but we have the size - read32_eeprom_data( (id1_block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, id1_size, 0 ) ; // TODO flash saving with function above ... - if (id1_size > sizeof(g_model.name)) - memcpy(ModelNames[id2], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); - else - memset(ModelNames[id2], 0, sizeof(g_model.name)); + 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, 0 ); + memcpy(ModelNames[id1], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); + } + else { + memset(ModelNames[id1], 0, sizeof(g_model.name)); + } Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here - Eeprom32_data_size = id1_size ; // This much - Eeprom32_file_index = id2 + 1 ; // This file system entry + Eeprom32_data_size = id2_size ; // This much + Eeprom32_file_index = id1 + 1 ; // This file system entry Eeprom32_process_state = E32_BLANKCHECK ; eeWaitFinished(); } @@ -254,6 +257,7 @@ uint32_t spi_PDC_action( register uint8_t *command, register uint8_t *tx, regist uint32_t eeprom_write_one( uint8_t byte, uint8_t count ) { +#ifndef SIMU register Spi *spiptr; register uint32_t result; @@ -285,6 +289,9 @@ uint32_t eeprom_write_one( uint8_t byte, uint8_t count ) } spiptr->SPI_CR = 2; // Disable return spiptr->SPI_RDR ; +#else + return !Spi_complete; +#endif } void eeprom_write_enable() @@ -298,56 +305,56 @@ uint32_t eeprom_read_status() } // Read eeprom data starting at random address -uint32_t read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) +void read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) { - register uint8_t *p ; - register uint32_t x ; - - p = Spi_tx_buf ; +#ifdef SIMU + assert(size); + eeprom_pointer = eeAddress; + eeprom_buffer_data = (char*)buffer; + eeprom_buffer_size = size; + eeprom_read_operation = true; + Spi_complete = false; + sem_post(&eeprom_write_sem); +#else + register uint8_t *p = Spi_tx_buf ; *p = 3 ; // Read command *(p+1) = eeAddress >> 16 ; *(p+2) = eeAddress >> 8 ; *(p+3) = eeAddress ; // 3 bytes address spi_PDC_action( p, 0, buffer, 4, size ) ; +#endif - if ( immediate ) - { - return 0 ; - } - for ( x = 0 ; x < 100000 ; x += 1 ) - { - // TODO while + ERROR_TIMEOUT - if ( Spi_complete ) - { - break ; - } - } - return x ; + if (immediate ) + return ; + + while (!Spi_complete) ; } -uint32_t write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) +void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) { - register uint8_t *p; - register uint32_t x; - +#ifdef SIMU + assert(size); + eeprom_pointer = eeAddress; + eeprom_buffer_data = (char*)buffer; + eeprom_buffer_size = size+1; + eeprom_read_operation = false; + Spi_complete = false; + sem_post(&eeprom_write_sem); +#else eeprom_write_enable(); - p = Spi_tx_buf; + register uint8_t *p = Spi_tx_buf; *p = 2; // Write command *(p + 1) = eeAddress >> 16; *(p + 2) = eeAddress >> 8; *(p + 3) = eeAddress; // 3 bytes address spi_PDC_action(p, buffer, 0, 4, size); +#endif - if (immediate) { - return 0; - } - for (x = 0; x < 100000; x += 1) { - if (Spi_complete) { - break; - } - } - return x ; + if (immediate) + return; + + while (!Spi_complete) ; } uint8_t byte_checksum( uint8_t *p, uint32_t size ) @@ -453,22 +460,22 @@ bool ee32LoadGeneral() memset(&g_eeGeneral, 0, sizeof(EEGeneral)); - if ( size > sizeof(EEGeneral) ) { + if (size > sizeof(EEGeneral)) { size = sizeof(EEGeneral) ; } - if ( size ) { + if (size) { read32_eeprom_data( ( File_system[0].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&g_eeGeneral, size, 0 ) ; } - /*if(g_eeGeneral.myVers(sizeof(EEGeneral)-20)) for(uint8_t i=0; i<12;i++) sum+=g_eeGeneral.calibMid[i]; - return g_eeGeneral.chkSum == sum; + return false; } void eeLoadModel(uint8_t id) @@ -640,6 +647,7 @@ void init_spi() spi_operation( p, spi_buf, 2 ) ; } +#ifndef SIMU extern "C" void SPI_IRQHandler() { register Spi *spiptr ; @@ -655,6 +663,7 @@ extern "C" void SPI_IRQHandler() // Power save // PMC->PMC_PCER0 &= ~0x00200000L ; // Disable peripheral clock to SPI } +#endif void end_spi() { @@ -747,6 +756,9 @@ void ee32_process() else { #endif +#ifdef SIMU + Eeprom32_process_state = E32_WRITESTART ; +#else eeAddress = Eeprom32_address ; eeprom_write_enable() ; p = Spi_tx_buf ; @@ -757,6 +769,7 @@ void ee32_process() spi_PDC_action( p, 0, 0, 4, 0 ) ; Eeprom32_process_state = E32_ERASESENDING ; Eeprom32_state_after_erase = E32_WRITESTART ; +#endif // } // } } @@ -772,10 +785,8 @@ void ee32_process() *q++ = *p++; // Copy the data to temp buffer } } - Eeprom_buffer.header.sequence_no = - ++File_system[Eeprom32_file_index].sequence_no; - File_system[Eeprom32_file_index].size = Eeprom_buffer.header.data_size = - Eeprom32_data_size; + Eeprom_buffer.header.sequence_no = ++File_system[Eeprom32_file_index].sequence_no; + File_system[Eeprom32_file_index].size = Eeprom_buffer.header.data_size = Eeprom32_data_size; Eeprom_buffer.header.flags = 0; Eeprom_buffer.header.hcsum = byte_checksum((uint8_t *) &Eeprom_buffer, 7); total_size = Eeprom32_data_size + sizeof(struct t_eeprom_header); @@ -820,9 +831,10 @@ void ee32_process() } else { + File_system[Eeprom32_file_index].block_no ^= 1 ; // This is now the current block #if 0 // now erase the other block - File_system[Eeprom32_file_index].block_no ^= 1 ; // This is now the current block + File_system[Eeprom32_file_index].block_no ^= 1 ; // This is now the current block eeAddress = Eeprom32_address ^ 0x00001000 ; // Address of block to erase eeprom_write_enable() ; p = Spi_tx_buf ; @@ -875,7 +887,9 @@ void ee32_read_model_names() void eeprom_init() { +#ifndef SIMU init_spi() ; +#endif fill_file_index() ; Eeprom32_process_state = E32_IDLE ; } diff --git a/src/eeprom_avr.cpp b/src/eeprom_avr.cpp index ed7f90fc5..eb0410310 100644 --- a/src/eeprom_avr.cpp +++ b/src/eeprom_avr.cpp @@ -249,7 +249,7 @@ void EeFsFormat() s_sync_write = false; } -bool EeFsOpen() +bool EeFsOpen() // TODO inline? { eeprom_read_block(&eeFs,0,sizeof(eeFs)); diff --git a/src/ersky9x/sound.cpp b/src/ersky9x/sound.cpp index 4ba0d719c..cd25b7508 100644 --- a/src/ersky9x/sound.cpp +++ b/src/ersky9x/sound.cpp @@ -32,14 +32,7 @@ * ****************************************************************************/ - - -#include - -#include "AT91SAM3S2.h" -#include "core_cm3.h" - -#include "sound.h" +#include "open9x.h" void start_sound( void ) ; void buzzer_on( void ) ; @@ -58,7 +51,7 @@ extern "C" void TWI0_IRQHandler (void) ; void audioDefevent( uint8_t e ) ; -extern uint32_t Master_frequency ; +extern uint32_t Master_frequency ; // TODO in a .h? volatile uint32_t Tone_timer ; // Modified in interrupt routine volatile uint8_t Buzzer_count ; diff --git a/src/lcd.cpp b/src/lcd.cpp index d181a3b67..6ee875aa9 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -574,8 +574,6 @@ void putsTrimMode(uint8_t x, uint8_t y, uint8_t phase, uint8_t idx, uint8_t att) #ifdef PCBARM -#include "AT91SAM3S2.h" - // LCD i/o pins // LCD_RES PC27 // LCD_CS1 PC26 @@ -725,6 +723,7 @@ void lcd_init() void lcdSetRefVolt(uint8_t val) { +#ifndef SIMU register Pio *pioptr ; pioptr = PIOC ; @@ -746,8 +745,10 @@ void lcdSetRefVolt(uint8_t val) pioptr->PIO_PUER = 0x0000003CL ; // Set bits 2, 3, 4, 5 with pullups pioptr->PIO_ODSR = 0 ; // Drive D0 low #endif +#endif } +#ifndef SIMU void refreshDisplay() { register Pio *pioptr; @@ -827,6 +828,7 @@ void refreshDisplay() #endif pioptr->PIO_ODSR = 0 ; // Drive D0 low } +#endif #else @@ -885,12 +887,9 @@ void lcdSetRefVolt(uint8_t val) lcdSendCtl(val); } +#ifndef SIMU void refreshDisplay() { -#ifdef SIMU - memcpy(lcd_buf, displayBuf, sizeof(displayBuf)); - lcd_refresh = true; -#else uint8_t *p=displayBuf; for(uint8_t y=0; y < 8; y++) { lcdSendCtl(0x04); @@ -910,7 +909,16 @@ void refreshDisplay() PORTC_LCD_CTRL |= (1<PWM_CH_NUM[0].PWM_CDTY = 0/*TODO g_eeGeneral.bright*/) #define BACKLIGHT_OFF (PWM->PWM_CH_NUM[0].PWM_CDTY = 100) +#else +#define BACKLIGHT_ON +#define BACKLIGHT_OFF +#endif #ifdef REVB #define NUMBER_ANALOG 9 #else diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index ba3461406..9cd00a441 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -31,11 +31,7 @@ * */ -#include -#include "simpgmspace.h" -#include "lcd.h" #include "open9x.h" -#include "menus.h" volatile uint8_t pinb=0, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0; uint8_t portb, portc, porth=0, dummyport; @@ -43,8 +39,20 @@ uint16_t dummyport16; const char *eepromFile = NULL; FILE *fp = NULL; +#if defined(PCBARM) +Pio Pioa; +Pio Piob; +Pio Pioc; +uint32_t eeprom_pointer; +char* eeprom_buffer_data; +volatile int32_t eeprom_buffer_size; +bool eeprom_read_operation; +#define EESIZE (128*4048) +#else extern uint16_t eeprom_pointer; extern const char* eeprom_buffer_data; +#endif + uint8_t eeprom[EESIZE]; sem_t eeprom_write_sem; @@ -59,6 +67,7 @@ void setSwitch(int8_t swtch) break; case DSW_ID2: ping &= ~(1< 0); if (fp) { @@ -79,7 +95,9 @@ void *eeprom_write_function(void *) perror("error in fseek"); if (fwrite(eeprom_buffer_data, 1, 1, fp) != 1) perror("error in fwrite"); +#if !defined(PCBARM) sleep(5/*ms*/); +#endif } else { memcpy(&eeprom[eeprom_pointer], eeprom_buffer_data, 1); @@ -91,6 +109,10 @@ void *eeprom_write_function(void *) fflush(fp); } } +#if defined(PCBARM) + } + Spi_complete = 1; +#endif } return 0; @@ -109,13 +131,19 @@ void *main_thread(void *) g_menuStack[0] = menuMainView; g_menuStack[1] = menuProcModelSelect; +#ifdef PCBARM + eeprom_init(); +#endif + eeReadAll(); //load general setup and selected model if (main_thread_running == 1) { #ifdef SPLASH doSplash(); #endif +#if !defined(PCBARM) checkLowEEPROM(); +#endif checkTHR(); checkSwitches(); checkAlarm(); diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 8d1d2e4dd..3d414f049 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -95,6 +95,24 @@ typedef const int16_t pm_int16_t; typedef const int8_t pm_int8_t; extern sem_t eeprom_write_sem; +#if defined(PCBARM) +extern Pio Pioa, Piob, Pioc; +#undef PIOA +#define PIOA (&Pioa) +#undef PIOB +#define PIOB (&Piob) +#undef PIOC +#define PIOC (&Pioc) +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; +#else +#define PIOA 0 +#define PIOB 0 +#define PIOC 0 +#endif #define loop_until_bit_is_set( port, bitnum) \ while ( 0/*! ( (port) & (1 << (bitnum)) )*/ ) ; @@ -218,6 +236,15 @@ extern sem_t eeprom_write_sem; #define WGM12 0 #define CS10 0 +#if defined(PCBARM) +extern volatile uint32_t Tenms; +extern uint32_t Master_frequency; +#define NVIC_EnableIRQ(x) +#define NVIC_DisableIRQ(x) +#define __disable_irq() +#define __enable_irq() +#endif + extern volatile unsigned char pinb,pinc,pind,pine,ping,pinh,pinj,pinl; extern uint8_t portb, portc, porth, dummyport; extern uint16_t dummyport16; diff --git a/src/simu.cpp b/src/simu.cpp index 44a082f7f..1c4dfe008 100644 --- a/src/simu.cpp +++ b/src/simu.cpp @@ -35,7 +35,6 @@ #include "FXExpression.h" #include "FXPNGImage.h" #include -#include "simpgmspace.h" #include "fxkeys.h" #include "open9x.h" #include "menus.h" @@ -273,25 +272,33 @@ void Open9xSim::refreshDiplay() } if(hasFocus()) { - static FXuint keys1[]={ - KEY_Return, INP_B_KEY_MEN, INP_P_KEY_MEN, - KEY_Page_Up, INP_B_KEY_MEN, INP_P_KEY_MEN, - KEY_KP_1, INP_B_KEY_MEN, INP_P_KEY_MEN, - KEY_Page_Down, INP_B_KEY_EXT, INP_P_KEY_EXT, - KEY_BackSpace, INP_B_KEY_EXT, INP_P_KEY_EXT, - KEY_KP_0, INP_B_KEY_EXT, INP_P_KEY_EXT, - KEY_Down, INP_B_KEY_DWN, INP_P_KEY_DWN, - KEY_Up, INP_B_KEY_UP, INP_P_KEY_UP, - KEY_Right, INP_B_KEY_RGT, INP_P_KEY_RGT, - KEY_Left, INP_B_KEY_LFT, INP_P_KEY_LFT + static uint64_t keys1[]={ + KEY_Return, INP_B_KEY_MEN, INP_P_KEY_MEN, (uint64_t)PIOB, 0x40, + KEY_Page_Up, INP_B_KEY_MEN, INP_P_KEY_MEN, (uint64_t)PIOB, 0x40, + KEY_KP_1, INP_B_KEY_MEN, INP_P_KEY_MEN, (uint64_t)PIOB, 0x40, + KEY_Page_Down, INP_B_KEY_EXT, INP_P_KEY_EXT, (uint64_t)PIOA, 0x80000000, + KEY_BackSpace, INP_B_KEY_EXT, INP_P_KEY_EXT, (uint64_t)PIOA, 0x80000000, + KEY_KP_0, INP_B_KEY_EXT, INP_P_KEY_EXT, (uint64_t)PIOA, 0x80000000, + KEY_Down, INP_B_KEY_DWN, INP_P_KEY_DWN, (uint64_t)PIOC, 0x10 >> 1, + KEY_Up, INP_B_KEY_UP, INP_P_KEY_UP, (uint64_t)PIOC, 0x08 >> 1, + KEY_Right, INP_B_KEY_RGT, INP_P_KEY_RGT, (uint64_t)PIOC, 0x20 >> 1, + KEY_Left, INP_B_KEY_LFT, INP_P_KEY_LFT, (uint64_t)PIOC, 0x40 >> 1, }; pinb &= ~ 0x7e; pinl &= ~ 0x3f; // for v4 - for(unsigned i=0; iPIO_PDSR = 0xFFFFFFFF; + PIOB->PIO_PDSR = 0xFFFFFFFF; + PIOA->PIO_PDSR = 0xFFFFFFFF; +#endif + for(unsigned i=0; igetKeyState(keys1[i])) { pinb |= (1<PIO_PDSR &= ~(keys1[i+4]); +#endif } }