mirror of
https://github.com/marqs85/ossc.git
synced 2025-01-23 07:30:14 +00:00
Merge branch 'megari-release_userdata_export' into release
This commit is contained in:
commit
2a24eb8dd7
@ -736,7 +736,7 @@ ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments
|
||||
/* make sure start and end address is less then the end address of the flash */
|
||||
if(
|
||||
start_address >= epcq_flash_info->data_end ||
|
||||
end_address >= epcq_flash_info->data_end ||
|
||||
end_address > epcq_flash_info->data_end ||
|
||||
offset < 0 ||
|
||||
length < 0
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read);
|
||||
alt_u32 I2C_read(alt_u32 base,alt_u32 last);
|
||||
alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last);
|
||||
void SPI_read(alt_u32 base, alt_u8 *rdata, int len);
|
||||
void SPI_write(alt_u32 base, alt_u8 *wdata, int len);
|
||||
void SPI_write(alt_u32 base, const alt_u8 *wdata, int len);
|
||||
#define I2C_OK (0)
|
||||
#define I2C_ACK (0)
|
||||
#define I2C_NOACK (1)
|
||||
|
@ -197,7 +197,7 @@ void SPI_read(alt_u32 base, alt_u8 *rdata, int len)
|
||||
}
|
||||
}
|
||||
|
||||
void SPI_write(alt_u32 base, alt_u8 *wdata, int len)
|
||||
void SPI_write(alt_u32 base, const alt_u8 *wdata, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -196,7 +196,7 @@ APP_CFLAGS_UNDEFINED_SYMBOLS :=
|
||||
APP_CFLAGS_OPTIMIZATION := -Os
|
||||
APP_CFLAGS_DEBUG_LEVEL :=
|
||||
APP_CFLAGS_WARNINGS := -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-function -Wno-packed-bitfield-compat
|
||||
APP_CFLAGS_USER_FLAGS := -fdata-sections -ffunction-sections -fshort-enums -fgnu89-inline
|
||||
APP_CFLAGS_USER_FLAGS := -fdata-sections -ffunction-sections -fshort-enums -fgnu89-inline -flto
|
||||
|
||||
APP_ASFLAGS_USER :=
|
||||
APP_LDFLAGS_USER := -Wl,--gc-sections
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@
|
||||
//
|
||||
|
||||
#include <io.h>
|
||||
#include <string.h>
|
||||
#include "sdcard.h"
|
||||
#include "flash.h"
|
||||
#include "lcd.h"
|
||||
@ -69,3 +70,33 @@ int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, a
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int copy_flash_to_sd(alt_u32 flash_pagenum, alt_u32 sd_blknum, alt_u32 length, alt_u8 *tmpbuf)
|
||||
{
|
||||
SDRESULTS res;
|
||||
int retval;
|
||||
alt_u32 bytes_to_rw;
|
||||
|
||||
while (length > 0) {
|
||||
bytes_to_rw = (length < SD_BLK_SIZE) ? length : SD_BLK_SIZE;
|
||||
retval = alt_epcq_controller_read(epcq_dev, flash_pagenum*PAGESIZE, tmpbuf, bytes_to_rw);
|
||||
if (retval != 0)
|
||||
return retval;
|
||||
|
||||
if (bytes_to_rw < SD_BLK_SIZE)
|
||||
memset(tmpbuf+bytes_to_rw, 0, SD_BLK_SIZE-bytes_to_rw);
|
||||
|
||||
res = SD_Write(&sdcard_dev, tmpbuf, sd_blknum);
|
||||
if (res != SD_OK) {
|
||||
printf("Failed to write to SD card\n");
|
||||
return -res;
|
||||
}
|
||||
|
||||
++sd_blknum;
|
||||
flash_pagenum += bytes_to_rw/PAGESIZE;
|
||||
length -= bytes_to_rw;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -26,5 +26,6 @@
|
||||
|
||||
int check_sdcard(alt_u8 *databuf);
|
||||
int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, alt_u8 *tmpbuf);
|
||||
int copy_flash_to_sd(alt_u32 flash_pagenum, alt_u32 sd_blknum, alt_u32 length, alt_u8 *tmpbuf);
|
||||
|
||||
#endif /* SDCARD_H_ */
|
||||
|
@ -238,8 +238,9 @@ MENU(menu_settings, P99_PROTECT({ \
|
||||
{ "OSD", OPT_AVCONFIG_SELECTION, { .sel = { &osd_enable_pre, OPT_WRAP, SETTING_ITEM(osd_enable_desc) } } },
|
||||
{ "OSD status disp.", OPT_AVCONFIG_SELECTION, { .sel = { &osd_status_timeout_pre, OPT_WRAP, SETTING_ITEM(osd_status_desc) } } },
|
||||
#ifndef DEBUG
|
||||
{ "<Import sett. >", OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
|
||||
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
|
||||
{ LNG("<Import sett. >","<セッテイヨミコミ >"), OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
|
||||
{ LNG("<Export sett. >","<セッテイカキコミ >"), OPT_FUNC_CALL, { .fun = { export_userdata, NULL } } },
|
||||
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
|
||||
#endif
|
||||
}))
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "userdata.h"
|
||||
@ -26,6 +27,7 @@
|
||||
#include "lcd.h"
|
||||
#include "controls.h"
|
||||
#include "av_controller.h"
|
||||
#include "menu.h"
|
||||
#include "altera_avalon_pio_regs.h"
|
||||
|
||||
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
|
||||
@ -42,7 +44,7 @@ extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
|
||||
extern alt_u8 osd_enable_pre, osd_status_timeout_pre;
|
||||
extern SD_DEV sdcard_dev;
|
||||
extern alt_flash_dev *epcq_dev;
|
||||
extern char menu_row2[LCD_ROW_LEN+1];
|
||||
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||
|
||||
char target_profile_name[PROFILE_NAME_LEN+1];
|
||||
|
||||
@ -315,3 +317,73 @@ sd_disable:
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int export_userdata()
|
||||
{
|
||||
int retval;
|
||||
char *errmsg;
|
||||
alt_u8 databuf[SD_BLK_SIZE];
|
||||
alt_u32 btn_vec;
|
||||
|
||||
retval = check_sdcard(databuf);
|
||||
SPI_CS_High();
|
||||
if (retval != 0) {
|
||||
retval = -retval;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
strncpy(menu_row2, "Export? 1=Y, 2=N", LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
|
||||
while (1) {
|
||||
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK;
|
||||
|
||||
if (btn_vec == rc_keymap[RC_BTN1]) {
|
||||
break;
|
||||
} else if (btn_vec == rc_keymap[RC_BTN2]) {
|
||||
retval = UDATA_EXPT_CANCELLED;
|
||||
goto failure;
|
||||
}
|
||||
|
||||
usleep(WAITLOOP_SLEEP_US);
|
||||
}
|
||||
|
||||
strncpy(menu_row2, "Exporting...", LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
|
||||
/* This may wear the SD card a bit more than necessary... */
|
||||
retval = copy_flash_to_sd(USERDATA_OFFSET/PAGESIZE, 512/SD_BLK_SIZE, (MAX_USERDATA_ENTRY + 1) * SECTORSIZE, databuf);
|
||||
if (retval != 0)
|
||||
goto failure;
|
||||
|
||||
SPI_CS_High();
|
||||
|
||||
strncpy(menu_row2, "Success", LCD_ROW_LEN+1);
|
||||
|
||||
return 1;
|
||||
|
||||
failure:
|
||||
SPI_CS_High();
|
||||
|
||||
switch (retval) {
|
||||
case SD_NOINIT:
|
||||
errmsg = "No SD card det.";
|
||||
break;
|
||||
case -EINVAL:
|
||||
errmsg = "Invalid params.";
|
||||
break;
|
||||
case UDATA_EXPT_CANCELLED:
|
||||
errmsg = "Cancelled";
|
||||
break;
|
||||
default:
|
||||
errmsg = "SD/Flash error";
|
||||
break;
|
||||
}
|
||||
strncpy(menu_row2, errmsg, LCD_ROW_LEN+1);
|
||||
|
||||
/*
|
||||
* We want the message above to remain on screen, so return a
|
||||
* positive value which nevertheless stands out when debugging.
|
||||
*/
|
||||
return 0x0dead;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
|
||||
|
||||
#define UDATA_IMPT_CANCELLED 104
|
||||
#define UDATA_EXPT_CANCELLED 105
|
||||
|
||||
typedef enum {
|
||||
UDE_INITCFG = 0,
|
||||
@ -76,5 +77,6 @@ typedef struct {
|
||||
int write_userdata(alt_u8 entry);
|
||||
int read_userdata(alt_u8 entry, int dry_run);
|
||||
int import_userdata();
|
||||
int export_userdata();
|
||||
|
||||
#endif
|
||||
|
@ -32,7 +32,7 @@ DWORD __SD_Sectors (SD_DEV *dev)
|
||||
return (((DWORD)(ftell(dev->fp)))/((DWORD)512)-1);
|
||||
}
|
||||
}
|
||||
#else // For use with uControllers
|
||||
#else // For use with uControllers
|
||||
/******************************************************************************
|
||||
Private Methods Prototypes - Direct work with SD card
|
||||
******************************************************************************/
|
||||
@ -160,15 +160,15 @@ SDRESULTS __SD_Write_Block(SD_DEV *dev, void *dat, BYTE token)
|
||||
WORD idx;
|
||||
BYTE line;
|
||||
// Send token (single or multiple)
|
||||
SPI_RW(token);
|
||||
SPI_WW(token);
|
||||
// Single block write?
|
||||
if(token != 0xFD)
|
||||
{
|
||||
// Send block data
|
||||
for(idx=0; idx!=SD_BLK_SIZE; idx++) SPI_RW(*((BYTE*)dat + idx));
|
||||
for(idx=0; idx!=SD_BLK_SIZE; idx++) SPI_WW(*((BYTE*)dat + idx));
|
||||
/* Dummy CRC */
|
||||
SPI_RW(0xFF);
|
||||
SPI_RW(0xFF);
|
||||
SPI_WW(0xFF);
|
||||
SPI_WW(0xFF);
|
||||
// If not accepted, returns the reject error
|
||||
if((SPI_RW(0xFF) & 0x1F) != 0x05) return(SD_REJECT);
|
||||
}
|
||||
@ -201,7 +201,7 @@ DWORD __SD_Sectors (SD_DEV *dev)
|
||||
BYTE READ_BL_LEN = 0;
|
||||
int timer_set;
|
||||
|
||||
if(__SD_Send_Cmd(CMD9, 0)==0)
|
||||
if(__SD_Send_Cmd(CMD9, 0)==0)
|
||||
{
|
||||
// Wait for response
|
||||
timer_set = SPI_Timer_On(5); // Wait for data packet (timeout of 5ms)
|
||||
@ -262,7 +262,7 @@ DWORD __SD_Sectors (SD_DEV *dev)
|
||||
SDRESULTS SD_Init(SD_DEV *dev)
|
||||
{
|
||||
BYTE initdata[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
#if defined(_M_IX86) // x86
|
||||
#if defined(_M_IX86) // x86
|
||||
dev->fp = fopen(dev->fn, "r+");
|
||||
if (dev->fp == NULL)
|
||||
return (SD_ERROR);
|
||||
@ -400,7 +400,7 @@ SDRESULTS SD_Read(SD_DEV *dev, void *dat, DWORD sector, WORD ofs, WORD cnt)
|
||||
} while((tkn==0xFF)&&(SPI_Timer_Status()==TRUE));
|
||||
SPI_Timer_Off();
|
||||
// Token of single block?
|
||||
if(tkn==0xFE) {
|
||||
if(tkn==0xFE) {
|
||||
// Size block (512 bytes) + CRC (2 bytes) - offset - bytes to count
|
||||
remaining = SD_BLK_SIZE + 2 - ofs - cnt;
|
||||
// Skip offset
|
||||
@ -447,9 +447,13 @@ SDRESULTS SD_Write(SD_DEV *dev, void *dat, DWORD sector)
|
||||
#else // uControllers
|
||||
// Query ok?
|
||||
if(sector > dev->last_sector) return(SD_PARERR);
|
||||
// Convert sector number to byte address (sector * SD_BLK_SIZE) for SDC1
|
||||
if (!(dev->cardtype & SDCT_BLOCK))
|
||||
sector *= SD_BLK_SIZE;
|
||||
|
||||
// Single block write (token <- 0xFE)
|
||||
// Convert sector number to bytes address (sector * SD_BLK_SIZE)
|
||||
if(__SD_Send_Cmd(CMD24, sector * SD_BLK_SIZE)==0)
|
||||
if(__SD_Send_Cmd(CMD24, sector)==0)
|
||||
return(__SD_Write_Block(dev, dat, 0xFE));
|
||||
else
|
||||
return(SD_ERROR);
|
||||
|
@ -15,7 +15,7 @@ void SPI_Init (void) {
|
||||
I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,400000);
|
||||
}
|
||||
|
||||
void SPI_W(BYTE *wd, int len) {
|
||||
void SPI_W(const BYTE *wd, int len) {
|
||||
SPI_write(SD_SPI_BASE, wd, len);
|
||||
}
|
||||
|
||||
@ -23,6 +23,10 @@ void SPI_R(BYTE *rd, int len) {
|
||||
SPI_read(SD_SPI_BASE, rd, len);
|
||||
}
|
||||
|
||||
void SPI_WW(BYTE d) {
|
||||
SPI_W(&d, 1);
|
||||
}
|
||||
|
||||
BYTE SPI_RW (BYTE d) {
|
||||
BYTE w;
|
||||
SPI_R(&w, 1);
|
||||
|
@ -33,15 +33,21 @@ void SPI_R (BYTE *rd, int len);
|
||||
\param *wd Pointer to array which holds the bytes.
|
||||
\param len Length of the array.
|
||||
*/
|
||||
void SPI_W (BYTE *wd, int len);
|
||||
void SPI_W (const BYTE *wd, int len);
|
||||
|
||||
/**
|
||||
\brief Read/Write a single byte.
|
||||
\param d Byte to send.
|
||||
\brief Read a single byte.
|
||||
\param d Byte. Ignored.
|
||||
\return Byte that arrived.
|
||||
*/
|
||||
BYTE SPI_RW (BYTE d);
|
||||
|
||||
/**
|
||||
\brief Write a single byte.
|
||||
\param d Byte to write.
|
||||
*/
|
||||
void SPI_WW(BYTE d);
|
||||
|
||||
/**
|
||||
\brief Flush of SPI buffer.
|
||||
*/
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user