Exemple #1
0
void bootFile(const char * filename){
	FIL file;
	UINT readbytes;
	FRESULT res;

	res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
	if(res!=F_OK){
		lcdPrintln("FOPEN ERROR");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
	uint8_t *destination=&_app_start;
#define BLOCK 1024 * 128
	do {
		res=f_read(&file, destination, BLOCK, &readbytes); 
		destination+=readbytes;
	}while(res==F_OK && readbytes==BLOCK);

	lcdDisplay();
	if(res!=F_OK){
		lcdPrint("Read Error:");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};

	systick_interrupt_disable(); /* TODO: maybe disable all interrupts? */
	boot((void*)&_app_start);
};
Exemple #2
0
int saveConfig(void){
    FIL file;            /* File object */
    UINT writebytes;
    UINT allwrite=0;
    int res;
#if DEBUG
    lcdClear();
#endif

	res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE);
#if DEBUG
	lcdPrint("create:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};

    CONF_ITER{
        res = f_write(&file, &the_config[i].value, sizeof(uint8_t), &writebytes);
        allwrite+=writebytes;
        if(res){
#if DEBUG
            lcdPrint("write:");
            lcdPrintln(f_get_rc_string(res));
#endif
            return 1;
        };
    };
#if DEBUG
	lcdPrint("write:");
	lcdPrintln(f_get_rc_string(res));
	lcdPrint(" (");
	lcdPrintInt(allwrite);
	lcdPrintln("b)");
#endif

	res=f_close(&file);
#if DEBUG
	lcdPrint("close:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};
	return 0;
}
Exemple #3
0
//# MENU cpld
void cpld_menu(){
	getInputWaitRelease();
	SETUPgout(EN_1V8);
	ON(EN_1V8);
	delayNop(1000000); /* wait until cpld boot */
	cpu_clock_set(204);

	lcdClear();
	lcdPrintln("CPLD");
	lcdNl();
	lcdNl();
	bytes=0;
	lcdPrint(IntToStr(bytes,5,F_LONG));
	lcdPrint(" bytes...");
	lcdNl();

	#define WAIT_LOOP_DELAY (6000000)
	#define ALL_LEDS  (PIN_LED1|PIN_LED2|PIN_LED3)
	int i;
	int error;
	FRESULT res;

	res=f_open(&file, "cpld.xsv", FA_OPEN_EXISTING|FA_READ);
	if(res!=FR_OK){
	    lcdPrintln("FOPEN ERROR");
	    lcdPrintln(f_get_rc_string(res));
	    lcdDisplay();
	    getInputWait();
	    return;
	};
	refill_cpld_buffer_fs();

	error = cpld_jtag_program(sizeof(cpld_xsvf_buffer),
				  cpld_xsvf_buffer,
				  refill_cpld_buffer_fs);
	if(error){
	    lcdPrintln("Programming failed!");
	    lcdPrintln(IntToStr(error,5,0));
	    lcdDisplay();
	    /* LED3 (Red) steady on error */
	    ON(LED3);
	    while (1);
	};


	lcdPrintln("Success.");
	lcdDisplay();

	for (res=0;res<10;res++){
	    /* blink LED1, LED2, and LED3 on success */
	    TOGGLE(LED1);
	    TOGGLE(LED2);
	    TOGGLE(LED3);
	    for (i = 0; i < WAIT_LOOP_DELAY; i++)  /* Wait a bit. */
		__asm__("nop");
	};
	/* XXX: Maybe power toggle needed to start CPLD? */
	OFF(EN_1V8);
};
Exemple #4
0
void bootFile(const char * filename, uint8_t write){
	FIL file;
	UINT readbytes;
	FRESULT res;

	res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
	if(res!=F_OK){
		lcdPrintln("FOPEN ERROR");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
	uint8_t *destination=&_app_start;
#define BLOCK 1024 * 128
	do {
		res=f_read(&file, destination, BLOCK, &readbytes); 
		destination+=readbytes;
	}while(res==F_OK && readbytes==BLOCK);

	lcdDisplay();
	if(res!=F_OK){
		lcdPrint("Read Error:");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
	if(write){
		res=writeFile(BOOTCFG, filename, strlen(filename)+1);
		if(res<0){
			lcdPrint("write Error:");
			lcdPrintln(f_get_rc_string(-res));
			lcdDisplay();
			getInputWait();
		};
		lcdPrint("write Done:");
		lcdPrintln(IntToStr(res,3,0));
		lcdPrintln(IntToStr(strlen(filename),3,0));
		lcdDisplay();
		getInputWait();
	};
	boot((void*)&_app_start);
};
Exemple #5
0
void do_image(char * filename){
	FATFS FatFs;
	FRESULT res;
	int i;
	FIL file;
	UINT readbytes;

	res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
	if(res!=F_OK){
		lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect();
		lcdPrintln("FOPEN ERROR");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};

#define BLOCK 1024
	uint8_t idata[BLOCK];
	lcd_select();
	lcdWrite(TYPE_CMD,0x2C);
	lcd_deselect();
	do {
		res=f_read(&file, idata, BLOCK, &readbytes); 
		lcd_select();
		for (i=0;i<readbytes;i++)
			lcdWrite(TYPE_DATA,idata[i]);
		lcd_deselect();
	}while(res==F_OK && readbytes==BLOCK);

	if(res!=F_OK){
		lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect();
		lcdPrint("Read Error:");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
};
Exemple #6
0
static void refill_cpld_buffer_fs(void) {
    FRESULT res;
    UINT readbytes;

    res=f_read(&file, cpld_xsvf_buffer, BLOCK, &readbytes); 
    lcdMoveCrsr(0,-8);
    bytes+=readbytes;
    lcdPrint(IntToStr(bytes,5,F_LONG));
    lcdPrint(" bytes...");
    if (res!=FR_OK){
	    lcdPrintln(f_get_rc_string(res));
    };
    lcdNl();
    lcdDisplay();
}
Exemple #7
0
void fsInit(){
	FRESULT res;
	res=f_mount(&FatFs,"/",0);
	if(res == FR_OK){
		DIR dir;                /* Directory object */
		res = f_opendir(&dir, "0:");
	};
	if(res != FR_OK){
		lcdPrintln("FS init error");
		lcdPrintln(f_get_rc_string(res));
		lcdDisplay();
		getInputWait();
		return;
	};
}
Exemple #8
0
void doRealExec(int silent){
	char filename[FLEN];
	FATFS FatFs;
	FRESULT res;
	int sres;

	sres=selectFile(filename,"B1N");
	if(sres<0){
	    if(!silent){
		lcdPrintln("Select ERROR");
		lcdDisplay();
		getInputWait();
	    };
	    return;
	};
	if(sres==0){
	    lcdPrintln("set as default:");
	    res=writeFile(BOOTCFG, filename, strlen(filename)+1);
        if(res<0){
            lcdPrint("write Error:");
            lcdPrintln(IntToStr(-res,3,0));
            lcdPrintln(f_get_rc_string(res));
            lcdDisplay();
            getInputWait();
        }else{
		lcdPrint("wrote ");
		lcdPrint(IntToStr(res,3,0));
		lcdPrintln(" bytes.");
		lcdDisplay();
	    };
	};
	lcdPrintln("Loading:");
	lcdPrintln(filename);
	lcdDisplay();
	bootFile(filename);
};
Exemple #9
0
uint8_t execute_file (const char * fname){
    FRESULT res;
    FIL file;
    UINT readbytes;
    void (*dst)(void);
    uint32_t version=0;

    res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ);
    if (res!=FR_OK){
	lcdPrintln(f_get_rc_string(res));
	lcdDisplay();
	return -1;
    };

    res = f_read(&file, &version, sizeof(uint32_t), &readbytes);
    if(res!=FR_OK){
	lcdPrintln(f_get_rc_string(res));
	lcdDisplay();
        return -1;
    };

    if (version>jumptable_len){
	lcdPrintln("l0dable incompat.");
	lcdPrint(IntToStr(jumptable_len,4,F_HEX));
	lcdPrint(" < ");
	lcdPrintln(IntToStr(version,4,F_HEX));
	lcdDisplay();
        return -1;
    };

    res = f_read(&file, &dst, sizeof(uint32_t), &readbytes);
    if(res!=FR_OK){
	lcdPrintln(f_get_rc_string(res));
	lcdDisplay();
        return -1;
    };

    if ((uintptr_t)dst<l0dable_start || (uintptr_t)dst>(l0dable_start+l0dable_len)){
	lcdPrintln("l0daddr illegal");
	lcdPrint(IntToStr((uintptr_t)dst,8,F_HEX));
	lcdDisplay();
        return -1;
    };


    res = f_read(&file, (uint8_t *)l0dable_start, l0dable_len, &readbytes);
    if(res!=FR_OK){
	lcdPrintln(f_get_rc_string(res));
	lcdDisplay();
        return -1;
    };

    if(readbytes>=l0dable_len){
	lcdPrintln("l0dable too long.");
	lcdDisplay();
	return -1;
    };

    lcdPrint(IntToStr(readbytes,5,F_LONG));
    lcdPrintln(" bytes...");

    dst=(void (*)(void)) ((uintptr_t)dst|1); // Enable Thumb mode!

#if 0
    lcdPrint("dst= "); lcdPrint(IntToStr((uintptr_t)dst,8,F_HEX)); lcdNl();
    lcdPrint("len= "); lcdPrint(IntToStr((uintptr_t)&_l0dable_len,8,F_HEX)); lcdNl();
    lcdPrint("jt=  "); lcdPrint(IntToStr(jumptable_len,8,F_HEX)); lcdNl();
    lcdPrint("ver= "); lcdPrint(IntToStr(version,8,F_HEX)); lcdNl();
    lcdDisplay();
#endif

    dst();
    return 0;
}
Exemple #10
0
int lcdShowImage(FIL* file) {
    uint8_t idata[BLOCK];
    FRESULT res;
    UINT readbytes;

    image_t type=IMG_NONE;
    int len;
    res=f_read(file, &type, 1, &readbytes); 

    switch(type){
        case IMG_RAW_8:
            lcd_select();
            lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2);
            lcd_deselect();
            len=RESX*RESY;
            break;
        case IMG_RAW_12:
            lcd_select();
            lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3);
            lcd_deselect();
            len=RESX*RESY*3/2;
            break;
        case IMG_RAW_16:
            lcd_select();
            lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5);
            lcd_deselect();
            len=RESX*RESY*2;
            break;
        default:
            lcdPrint("ERR: Image Type=");
            lcdPrintln(IntToStr(type,3,0));
            lcdDisplay();
            getInputWait();
            return 1;
    };

    lcd_select();
    lcdWrite(TYPE_CMD,0x2C);
    lcd_deselect();
    int rb;
    do {
        rb=BLOCK;
        if (len<BLOCK)
            rb=len;
        res=f_read(file, idata, rb, &readbytes); 
        lcd_select();
        for (int i=0;i<readbytes;i++)
            lcdWrite(TYPE_DATA,idata[i]);
        lcd_deselect();
        len-=readbytes;
    }while(res==FR_OK && len>0 && rb==readbytes);

    if(res!=FR_OK){
        lcdPrint("Read Error:");
        lcdPrintln(f_get_rc_string(res));
        lcdDisplay();
        getInputWait();
        return 1;
    };
    return 0;
}
Exemple #11
0
/* retrieve filelist.
 * not (yet) sorted.
 * flen+2 because optional slash and nullbyte
 */
static int retrieve_files(char files[][FLEN+2],
                          uint8_t count, uint16_t skip,
                          char *ext,
                          char *cwd,
                          int *total) {
	if (strlen(cwd) > FLEN) {
		lcdPrintln("cwd too long");
		lcdRefresh();
		return 0;
	}

	char path[FLEN+3];
	path[0] = '0';
	path[1] = ':';
	strcpy(path + 2, cwd);
	path[2 + strlen(cwd)] = 0;

	/* remove trailing slash, otherwise INVALID_NAME */
	if (path[2 + strlen(cwd) - 1] == '/') {
		path[2 + strlen(cwd) - 1] = 0;
	}

	DIR dir;
	FILINFO fileinfo;
	FRESULT res;

	res = f_opendir(&dir, path);
	if (res) {
		lcdPrintln("E[f_opendir]");
		lcdPrintln(path);
		lcdPrintln(f_get_rc_string(res));
		lcdRefresh();
		return 0;
	}

	int pos = 0;
	int extlen = strlen(ext);
	if (total) {
		(*total) = 0;
	}
	while (f_readdir(&dir, &fileinfo) == FR_OK && fileinfo.fname[0]) {
		int len = strlen(fileinfo.fname);

		if (extlen && !(fileinfo.fattrib & AM_DIR)) {
			if (len < extlen) {
				continue;
			}

			/* fixme, proper ext check */
			if (strcmp(fileinfo.fname + len - extlen, ext) != 0) {
				continue;
			}
		}

		if (total) {
			(*total)++;
		}

		if (skip > 0) {
			skip--;
			continue;
		}

		if (pos < count) {
			strcpy(files[pos], fileinfo.fname);
			if (fileinfo.fattrib & AM_DIR) {
				files[pos][len]     = '/';
				files[pos][len + 1] = 0;
			}
			pos++;
		}
	}

	return pos;
}