Skip to content

Commit

Permalink
1. MCU端开机内存测试功能
Browse files Browse the repository at this point in the history
2. MCU端固件自动更新
3. 支持启动光盘游戏
  • Loading branch information
tpunix committed Oct 31, 2023
1 parent 4252c5a commit 19b2e5c
Show file tree
Hide file tree
Showing 22 changed files with 755 additions and 671 deletions.
24 changes: 14 additions & 10 deletions Firm_MCU/Main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,42 +225,44 @@ int flash_update(int check)
return -1;
}
fsize = f_size(&fp);
printk("Found firm file.\n");
printk(" Size %08x\n", fsize);

if(check){
printk("Found firm file.\n");
printk(" Size %08x\n", fsize);
f_close(&fp);
return 0;
}


u32 rv;
f_read(&fp, fbuf, fsize, &rv);
f_close(&fp);


disable_irq();
int key = disable_irq();

int firm_addr = 0x08000000;
_puts("erase ...\n");
retv = flash_erase(firm_addr);
if(retv){
restore_irq(key);
_puts(" faile!\n");
f_close(&fp);
return -2;
}

_puts("write ...\n");
for(i=0; i<fsize; i+=32){
retv = flash_write32(firm_addr+i, fbuf+i);
if(retv){
restore_irq(key);
_puts(" faile!\n");
f_close(&fp);
return -3;
}
}

f_close(&fp);
_puts("done.\n");
restore_irq(key);

printk("MCU update OK!\n");
f_unlink("/SAROO/update/ssmaster.bin");
return 0;
}

Expand Down Expand Up @@ -317,10 +319,13 @@ void main_task(void *arg)

static osSemaphoreId_t sem_led;
static int led_ev = 0;
static int loop = 0;

void led_event(int ev)
{
led_ev = ev;
if(ev==0)
loop = 0;
osSemaphoreRelease(sem_led);
}

Expand All @@ -331,7 +336,6 @@ void led_task(void *arg)
int freq;
int times;
int lock;
int loop = 0;

sem_led = osSemaphoreNew(1, 0, NULL);

Expand Down Expand Up @@ -373,7 +377,7 @@ int main(void)
osThreadNew(main_task, NULL, &attr);

memset(&attr, 0, sizeof(attr));
attr.priority = osPriorityLow;
attr.priority = osPriorityHigh;
osThreadNew(led_task, NULL, &attr);

osKernelStart();
Expand Down
1 change: 1 addition & 0 deletions Firm_MCU/Main/sdio_h7.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ int sdio_init(void)
SDIO->MASK = 0;
SDIO->ICR = 0x1fe00fff;
SDIO->CLKCR = 0;
SDIO->CLKCR = 1<<16;

sd_rca = 0;
cmd_sem = osSemaphoreNew(1, 0, NULL);
Expand Down
48 changes: 30 additions & 18 deletions Firm_MCU/Main/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,40 +199,45 @@ static u16 mksum(u32 addr)
}


int mem_test(void)
int mem_test(u32 addr, int size)
{
u32 addr0 = 0x61400000;
u16 rd, sum;
int i, size=0x00100000;
int i, ecnt=0;

printk("Memory test at %08x ...", addr);

size /= 2;
for(i=0; i<size; i++){
*(u16*)(addr0) = mksum(addr0);
addr0 += 2;
*(u16*)(addr) = mksum(addr);
addr += 2;
}

for(i=0; i<size; i++){
addr0 -= 2;
sum = mksum(addr0);
rd = *(u16*)(addr0);
addr -= 2;
sum = mksum(addr);
rd = *(u16*)(addr);
if(sum!=rd){
printk("Mismatch0 at %08x! read=%08x calc=%08x\n", addr0, rd, sum);
return -1;
printk("\nMismatch0 at %08x! read=%08x calc=%08x\n", addr, rd, sum);
ecnt += 1;
}
*(u16*)(addr0) = ~sum;
*(u16*)(addr) = ~sum;

}

for(i=0; i<size; i++){
sum = ~mksum(addr0);
rd = *(u16*)(addr0);
sum = ~mksum(addr);
rd = *(u16*)(addr);
if(sum!=rd){
printk("Mismatch2 at %08x! read=%08x calc=%08x\n", addr0, rd, sum);
return -3;
printk("\nMismatch2 at %08x! read=%08x calc=%08x\n", addr, rd, sum);
ecnt += 1;
}
addr0 += 2;
addr += 2;
}

return 0;
if(ecnt==0)
printk(" OK!\n\n");

return ecnt;
}

/******************************************************************************/
Expand Down Expand Up @@ -293,8 +298,15 @@ void simple_shell(void)
}

CMD(mmt){
mem_test();
u32 addr = 0x61000000;
int size = 0x00100000;
if(argc==2){
addr = arg[0];
size = arg[1];
}
mem_test(addr, size);
}

CMD(memset){
if(argc>=3){
memset((void*)arg[0], arg[1], arg[2]);
Expand Down
6 changes: 3 additions & 3 deletions Firm_MCU/Main/spi1_fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ int fpga_update(int check)
printk("No FPGA config file.\n");
return -1;
}

fsize = f_size(&fp);
printk("Found FPGA config file.\n");
printk(" Size %08x\n", fsize);

if(check){
printk("Found FPGA config file.\n");
printk(" Size %08x\n", fsize);
f_close(&fp);
return 0;
}
Expand All @@ -272,6 +271,7 @@ int fpga_update(int check)
f_close(&fp);

printk("FPGA update OK!\n");
f_unlink("/SAROO/update/SSMaster.rbf");
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions Firm_MCU/Saturn/cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#define SSCMD_FILEWR 0x0007
#define SSCMD_LISTBIN 0x0008
#define SSCMD_SSAVE 0x0009
#define SSCMD_LSAVE 0x000a


#define MSF_TO_FAD(m,s,f) ((m * 4500) + (s * 75) + f)
Expand Down Expand Up @@ -280,6 +281,7 @@ extern int in_isr;

extern int lang_id;
extern int debug_flags;
extern int auto_update;
extern int sector_delay;
extern int sector_delay_force;
extern int play_delay;
Expand Down
52 changes: 48 additions & 4 deletions Firm_MCU/Saturn/saturn_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ int sector_delay = 0;
int sector_delay_force = -1;
int play_delay = 0;
int play_delay_force = -1;
int auto_update = 0;

int log_mask = LOG_MASK_DEFAULT;

Expand Down Expand Up @@ -525,6 +526,12 @@ void ss_cmd_handle(void)
SS_ARG = retv;
SS_CMD = 0;
break;
case SSCMD_LSAVE:
// 加载指定SAVE
retv = load_savefile((char*)(TMPBUFF_ADDR+0x10));
SS_ARG = retv;
SS_CMD = 0;
break;
default:
SSLOG(_INFO, "[SS] unkonw cmd: %04x\n", cmd);
break;
Expand Down Expand Up @@ -691,11 +698,48 @@ void saturn_config(void)
u32 rv;

parse_config("/saroocfg.txt", NULL);

if(auto_update){
int fp, fl;

fp = fpga_update(1);
fl = flash_update(1);
if(fp==-1 && fl==-1){
// 没有升级文件
led_event(LEDEV_NONE);
}else{
led_event(LEDEV_BUSY);
if(fp==0){
fpga_update(0);
}
if(fl==0){
fl = flash_update(0);
if(fl<-1){
led_event(LEDEV_FILE_ERROR);
return;
}
}
led_event(LEDEV_OK);
return;
}
}





if(debug_flags&0xc0000000){
led_event(LEDEV_BUSY);
int cnt = 0;
while(1){
retv = mem_test(0x61000000, 0x00800000);
if(retv){
led_event(LEDEV_SDRAM_ERROR);
//return;
}
if((debug_flags&0x40000000)==0)
break;
cnt += 1;
printk(" times: %d\n", cnt);
}
led_event(LEDEV_NONE);
}


// 检查是否有bootrom. 如果有,就加载到FPGA中
Expand Down
1 change: 1 addition & 0 deletions Firm_MCU/Saturn/saturn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ typedef struct {
CFGARG arg_list [] = {
{"sector_delay", ARG_DEC, &sector_delay},
{"play_delay", ARG_DEC, &play_delay},
{"auto_update", ARG_DEC, &auto_update},
{"exmem_", ARG_NON, config_exmem},
{"M_", ARG_NON, config_wrmem},
{"lang_id", ARG_DEC, &lang_id},
Expand Down
5 changes: 5 additions & 0 deletions Firm_MCU/inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ u32 get_build_date(void);
void *malloc(uint32_t size);
void free(void *p);
void memcpy32(void *dst, void *src, int len);
int mem_test(u32 addr, int size);


void uart4_init(void);
u8 _getc(void);
Expand Down Expand Up @@ -66,13 +68,16 @@ int fpga_update(int check);

#define MAKE_LEDEVENT(freq, times, flag) (((flag)<<16) | ((times)<<8) | (freq))

#define LEDEV_NONE 0
#define LEDEV_SD_ERROR MAKE_LEDEVENT(10, 10, 2)
#define LEDEV_FPGA_ERROR MAKE_LEDEVENT(10, 20, 2)
#define LEDEV_SDRAM_ERROR MAKE_LEDEVENT(15, 8, 2)
#define LEDEV_NOFIRM MAKE_LEDEVENT(15, 3, 1)
#define LEDEV_FILE_ERROR MAKE_LEDEVENT(15, 5, 1)
#define LEDEV_SCFG_ERROR MAKE_LEDEVENT(15, 4, 1)
#define LEDEV_CSCT MAKE_LEDEVENT(7, 1, 0)
#define LEDEV_BUSY MAKE_LEDEVENT(50, 1, 1)
#define LEDEV_OK MAKE_LEDEVENT(13, 2, 1)


void led_event(int ev);
Expand Down
Loading

0 comments on commit 19b2e5c

Please sign in to comment.