From fb493b54153b75d9ddda4da1f7bfc07c9cab3d57 Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 21 Jun 2012 18:40:55 +0000 Subject: [PATCH] SD-Card corrections on ersky9x board Status line FatFs on simu --- src/FatFs/ffconf.h | 4 ++-- src/Makefile | 13 ++++++----- src/eeprom_arm.cpp | 4 ++++ src/ersky9x/board.h | 10 ++------- src/ersky9x/crt.c | 10 ++++----- src/ersky9x/diskio.c | 30 ++++++++++++++++--------- src/gruvin9x/sdcard.h | 2 +- src/lcd.cpp | 2 +- src/menus.cpp | 29 ++++++++++++++++++++++++ src/menus.h | 5 +++++ src/model_menus.cpp | 10 ++++----- src/open9x.cpp | 41 +++++++++++++++++++++++++++++----- src/simpgmspace.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 168 insertions(+), 44 deletions(-) diff --git a/src/FatFs/ffconf.h b/src/FatFs/ffconf.h index 2cb786e79..534122a2c 100644 --- a/src/FatFs/ffconf.h +++ b/src/FatFs/ffconf.h @@ -57,7 +57,7 @@ / Locale and Namespace Configurations /----------------------------------------------------------------------------*/ -#define _CODE_PAGE 932 +#define _CODE_PAGE 1252 /* The _CODE_PAGE specifies the OEM code page to be used on the target system. / Incorrect setting of the code page can cause a file open failure. / @@ -90,7 +90,7 @@ */ -#define _USE_LFN 0 /* 0 to 3 */ +#define _USE_LFN 1 /* 0 to 3 */ #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ /* The _USE_LFN option switches the LFN support. / diff --git a/src/Makefile b/src/Makefile index bd7a2321d..e2796347c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -332,9 +332,9 @@ ifeq ($(PCB), ARM) CPPDEFS += -DPCBARM -DAUDIO -DHAPTIC -DPXX -DDSM2 -DDSM2_PPM EXTRAINCDIRS += ersky9x CoOS/kernel CoOS/portable BOARDSRC = board_ersky9x.cpp - SRC += ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.c + SRC += ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.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/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c - SRC += FatFs/ff.c FatFs/fattime.c ersky9x/diskio.c + SRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c ersky9x/diskio.c EEPROMSRC = eeprom_arm.cpp PULSESSRC = pulses_arm.cpp CPPSRC += ersky9x/audio.cpp haptic.cpp @@ -345,14 +345,14 @@ ifeq ($(PCB), V4) # V4 PCB, so ... OPT = 2 CPPDEFS += -DPCBV4 -DAUDIO -DHAPTIC -DROTARY_ENCODERS - EXTRAINCDIRS += gruvin9x stock FatFs + EXTRAINCDIRS += gruvin9x stock FatFs FatFs/option BOARDSRC += board_gruvin9x.cpp EEPROMSRC = eeprom_avr.cpp PULSESSRC = pulses_avr.cpp CPPSRC += stock/audio.cpp haptic.cpp ifeq ($(SDCARD), YES) - CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp FatFs/ff.c gruvin9x/diskio.cpp + CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp FatFs/ff.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp MODS:=${MODS}S endif @@ -630,8 +630,8 @@ FOXLIB=-L/usr/local/lib \ -lFOX-1.6 \ -Wl,-rpath,$(FOXPATH)/src/.libs -simu: stamp_header $(BOARDSRC) $(CPPSRC) $(SRC) Makefile simu.cpp simpgmspace.cpp *.h *.lbm eeprom.bin - g++ simu.cpp $(CPPFLAGS) $(BOARDSRC) $(CPPSRC) $(SRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB) -pthread +simu: stamp_header $(BOARDSRC) $(CPPSRC) Makefile simu.cpp simpgmspace.cpp *.h *.lbm eeprom.bin + 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 @@ -717,6 +717,7 @@ clean_list : $(REMOVE) $(TARGET).lst $(REMOVE) $(SRC:.c=.s) $(REMOVE) *.o + $(REMOVE) */*.o $(REMOVE) *.d $(REMOVE) *.lst $(REMOVE) allsrc.cpp diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index 96f2cbe44..4a0604bf2 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -982,6 +982,10 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc) f_close(&archiveFile); + strcpy(statusLineMsg, PSTR("File ")); + strcpy(statusLineMsg+5, &buf[sizeof(MODELS_PATH)]); + showStatusLine(); + return NULL; } diff --git a/src/ersky9x/board.h b/src/ersky9x/board.h index 65fdedd9f..cc6dbc3c7 100644 --- a/src/ersky9x/board.h +++ b/src/ersky9x/board.h @@ -47,11 +47,6 @@ #include "core_cm3.h" #endif -#define BOARD_MCK 64000000 - -#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 ) - - //------------------------------------------------------------------------------ // Definitions //------------------------------------------------------------------------------ @@ -91,7 +86,6 @@ #define BOARD_MAINOSC 12000000 /// Master clock frequency (when using board_lowlevel.c). -//#define BOARD_MCK 48000000 #define BOARD_MCK 64000000 //------------------------------------------------------------------------------ @@ -353,8 +347,6 @@ #define PIN_USART1_RTS {0x1 << 24, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} #define PIN_USART1_EN {0x1 << 23, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} - - /// USB VBus monitoring pin definition. #ifdef BOARD_REV_A #define PIN_USB_VBUS {1 << 23, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT} @@ -500,6 +492,8 @@ ///// MCI Card Detect pin. #define BOARD_SD_PIN_CD PIN_MCI_CD +#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 ) + /* #define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \ PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1 diff --git a/src/ersky9x/crt.c b/src/ersky9x/crt.c index d370eb281..9e3cc7e7a 100644 --- a/src/ersky9x/crt.c +++ b/src/ersky9x/crt.c @@ -86,7 +86,7 @@ extern uint32_t Master_frequency ; /***************************************************************************/ void ResetHandler (void) { - { + { register uint32_t *pSrc; register uint32_t *pDest; register uint32_t m_freq ; @@ -125,10 +125,10 @@ void ResetHandler (void) pDest = &_sbss; while(pDest < &_ebss) { - *pDest++ = 0; - } - Master_frequency = m_freq ; - } + *pDest++ = 0; + } + Master_frequency = m_freq ; + } /* * And now the main function can be called. diff --git a/src/ersky9x/diskio.c b/src/ersky9x/diskio.c index 01e108bff..381366035 100644 --- a/src/ersky9x/diskio.c +++ b/src/ersky9x/diskio.c @@ -589,6 +589,7 @@ uint32_t sd_card_ready( void ) uint32_t sd_cmd16() { +#if 0 Hsmci *phsmci = HSMCI; if (CardIsConnected()) { @@ -606,20 +607,24 @@ uint32_t sd_cmd16() else { return 0; } +#else + return 0; +#endif } uint32_t sd_read_block(uint32_t block_no, uint32_t *data) { + uint32_t result = 0; + Hsmci *phsmci = HSMCI; + if (Card_state == SD_ST_DATA) { - Hsmci *phsmci = HSMCI; if (CardIsConnected()) { - //sd_cmd16(); + sd_cmd16(); // Block size = 512, nblocks = 1 phsmci->HSMCI_BLKR = ((512) << 16) | 1; phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16); phsmci->HSMCI_RPR = (uint32_t)data; phsmci->HSMCI_RCR = 512 / 4; - phsmci->HSMCI_RNCR = 0; phsmci->HSMCI_PTCR = HSMCI_PTCR_RXTEN; phsmci->HSMCI_ARGR = block_no << 9; phsmci->HSMCI_CMDR = SD_READ_SINGLE_BLOCK; @@ -628,28 +633,31 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data) while (retry-- > 0) { CoTickDelay(1); // 2ms if (phsmci->HSMCI_SR & HSMCI_SR_ENDRX) { - return 1; + result = 1; + break; } } } } - return 0; + phsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE; + return result; } uint32_t sd_write_block( uint32_t block_no, uint32_t *data ) { + uint32_t result = 0; + Hsmci *phsmci = HSMCI; + if (Card_state == SD_ST_DATA) { - Hsmci *phsmci = HSMCI; if (CardIsConnected()) { - //sd_cmd16(); + sd_cmd16(); // Block size = 512, nblocks = 1 phsmci->HSMCI_BLKR = ((512) << 16) | 1; phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16); phsmci->HSMCI_TPR = (uint32_t)data; phsmci->HSMCI_TCR = 512 / 4; - phsmci->HSMCI_TNCR = 0; phsmci->HSMCI_ARGR = block_no << 9; phsmci->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK; phsmci->HSMCI_PTCR = HSMCI_PTCR_TXTEN; @@ -658,14 +666,16 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data ) while (retry-- > 0) { CoTickDelay(1); // 2ms if (phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) { - return 1; + result = 1; + break; } } } } - return 0; + phsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE; + return result; } /* diff --git a/src/gruvin9x/sdcard.h b/src/gruvin9x/sdcard.h index 8d73b87d2..f266428b3 100644 --- a/src/gruvin9x/sdcard.h +++ b/src/gruvin9x/sdcard.h @@ -45,7 +45,7 @@ #define LOGS_PATH "/9XLOGS" // no trailing slash = important #define LOGS_EXT ".CSV" #define MODELS_PATH "/9XMODELS" -#define MODELS_EXT ".BIN" +#define MODELS_EXT ".bin" extern char g_logFilename[21]; // "/9XLOGS/M00_000.CSV\0" max required length = 21 extern FATFS g_FATFS_Obj; diff --git a/src/lcd.cpp b/src/lcd.cpp index 7cb1ae267..fc901c345 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -778,11 +778,11 @@ void lcdSetRefVolt(uint8_t val) #else pioptr->PIO_ODR = 0x0000003CL ; // Set bits 2, 3, 4, 5 input pioptr->PIO_PUER = 0x0000003CL ; // Set bits 2, 3, 4, 5 with pullups -#endif #endif pioptr->PIO_ODSR = lcdInputs; // Drive D0 low lcdLock = 0 ; +#endif } #ifndef SIMU diff --git a/src/menus.cpp b/src/menus.cpp index 0b7912223..841cfbb02 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -604,6 +604,34 @@ const char * displayMenu(uint8_t event) return result; } + +char statusLineMsg[STATUS_LINE_LENGTH]; +uint16_t statusLineTimeout = 0; +uint8_t statusLineHeight = 0; + +void showStatusLine() +{ + statusLineHeight = 0; + statusLineTimeout = get_tmr10ms() + 3*100; /* 3 seconds */ +} + +void drawStatusLine() +{ + if (get_tmr10ms() < statusLineTimeout) { + if (statusLineHeight < 8) statusLineHeight++; + } + else if (statusLineHeight) { + statusLineHeight--; + } + else { + return; + } + + lcd_filled_rect(0, 7*FH+8-statusLineHeight, DISPLAY_W, 8, SOLID, WHITE); + lcd_putsAtt(5, 7*FH+1+8-statusLineHeight, statusLineMsg, BSS); + lcd_filled_rect(0, 7*FH+8-statusLineHeight, DISPLAY_W, 8, SOLID); +} + #endif #if defined(ROTARY_ENCODERS) @@ -632,6 +660,7 @@ void checkInFlightIncDecModel(uint8_t event, int8_t *value, int8_t i_min, int8_t } } } + #endif diff --git a/src/menus.h b/src/menus.h index b3d81fba6..68e7a874f 100644 --- a/src/menus.h +++ b/src/menus.h @@ -205,9 +205,14 @@ extern uint8_t s_menu_offset; extern bool s_menu_more; const char * displayMenu(uint8_t event); extern const pm_char * s_sdcard_error; +#define STATUS_LINE_LENGTH 22 +extern char statusLineMsg[STATUS_LINE_LENGTH]; +void showStatusLine(); +void drawStatusLine(); #else #define s_menu_count 0 #define s_sdcard_error 0 +#define displayStatusLine() #endif #endif diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 1303c04f2..04e6e476e 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -132,9 +132,9 @@ bool listSDcardModels() DIR dir; char *fn; /* This function is assuming non-Unicode cfg. */ #if _USE_LFN - static char lfn[_MAX_LFN + 1]; + TCHAR lfn[_MAX_LFN + 1]; fno.lfname = lfn; - fno.lfsize = sizeof lfn; + fno.lfsize = sizeof(lfn); #endif s_menu_count = 0; @@ -321,16 +321,16 @@ void menuProcModelSelect(uint8_t event) s_menu[s_menu_count++] = STR_SELECT_MODEL; s_menu[s_menu_count++] = STR_BACKUP_MODEL; s_menu[s_menu_count++] = STR_RESTORE_MODEL; - s_menu[s_menu_count++] = STR_DELETE_MODEL;; + s_menu[s_menu_count++] = STR_DELETE_MODEL; } else { s_menu[s_menu_count++] = STR_CREATE_MODEL; - s_menu[s_menu_count++] = STR_RESTORE_MODEL;; + s_menu[s_menu_count++] = STR_RESTORE_MODEL; } } else { s_menu[s_menu_count++] = STR_BACKUP_MODEL; - s_menu[s_menu_count++] = STR_RESTORE_MODEL;; + s_menu[s_menu_count++] = STR_RESTORE_MODEL; } #else if (g_eeGeneral.currModel != sub) { diff --git a/src/open9x.cpp b/src/open9x.cpp index 83873b982..56900c314 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -2311,7 +2311,6 @@ void perMain() // Write the raw byte out to log file, if open if (testLogOpen && (g_oLogFile.fs != 0)) f_putc(userDataRxBuffer[byt], &g_oLogFile); - } #endif @@ -2338,6 +2337,7 @@ void perMain() #endif g_menuStack[g_menuStackPtr](evt); + drawStatusLine(); refreshDisplay(); #if defined(PCBARM) @@ -2816,11 +2816,41 @@ void mixerTask(void * pdata) } } +extern "C" { +void usbMassStorage() +{ +} +} + void menusTask(void * pdata) { register uint32_t shutdown_state = 0; - while ((shutdown_state=check_soft_power()) <= e_power_trainer) { + while (1) { + shutdown_state = check_soft_power(); +#if 0 + if (shutdown_state == e_power_off) + break; + else if (shutdown_state == e_power_usb) { + const char STR_SDCARD[] = "SD Card"; + const char STR_BOOTLOADER[] = "Bootloader"; + s_menu[s_menu_count++] = STR_SDCARD; + s_menu[s_menu_count++] = STR_BOOTLOADER; + uint8_t event = getEvent(false); + const char * result = displayMenu(event); + if (result) { + if (result == STR_BOOTLOADER) + break; + else { + usbMassStorage(); + s_menu_count = 0; + } + } + } +#else + if (shutdown_state >= e_power_usb) + break; +#endif perMain(); CoTickDelay(5); // 10ms for now @@ -2829,10 +2859,6 @@ void menusTask(void * pdata) SysTick->CTRL = 0; // turn off systick -#if defined(HAPTIC) - hapticOff(); -#endif - lcd_clear() ; displayPopup(STR_SHUTDOWN); g_eeGeneral.unexpectedShutdown=0; @@ -2843,6 +2869,9 @@ void menusTask(void * pdata) #endif lcd_clear() ; refreshDisplay() ; +#if defined(HAPTIC) + hapticOff(); +#endif soft_power_off(); // Only turn power off if necessary if (shutdown_state == e_power_usb) { diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index 0394267e4..f9720fc40 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -271,3 +271,55 @@ static void EeFsDump(){ puts(""); } #endif + +#if defined(SDCARD) +#include "FatFs/ff.h" +FRESULT f_mount (BYTE, FATFS*) +{ + return FR_OK; +} + +FRESULT f_open (FIL* fil, const TCHAR*name, BYTE) +{ + //fil->fs = (FATFS*)fopen(name); + return FR_OK; +} + +FRESULT f_read (FIL*, void*, UINT, UINT*) +{ + + return FR_OK; +} + +FRESULT f_write (FIL*, const void*, UINT, UINT*) +{ + return FR_OK; +} + +FRESULT f_lseek (FIL*, DWORD) +{ + return FR_OK; +} + +FRESULT f_close (FIL*) +{ + return FR_OK; +} + +FRESULT f_opendir (DIR*, const TCHAR*) +{ + return FR_OK; +} + +FRESULT f_readdir (DIR*, FILINFO*) +{ + return FR_OK; +} + +FRESULT f_mkdir (const TCHAR*) +{ + return FR_OK; +} + +uint32_t Card_state = 8; +#endif