o add directy list
o add file selectr
This commit is contained in:
parent
3e4abc9b01
commit
c3cc5d89b8
Binary file not shown.
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#define BIT(x) ((unsigned long)1<<x)
|
#define BIT(x) ((unsigned long)1<<x)
|
||||||
|
|
||||||
// 1st LED on Keil MCB2130
|
|
||||||
#define LED1PIN 10
|
#define LED1PIN 10
|
||||||
#define LED1BIT BIT(LED1PIN)
|
#define LED1BIT BIT(LED1PIN)
|
||||||
#define LEDDIR IODIR0
|
#define LEDDIR IODIR0
|
||||||
@ -34,46 +33,6 @@
|
|||||||
#define LEDCLR IOCLR0
|
#define LEDCLR IOCLR0
|
||||||
static char LogFileName[] = "dummy.log";
|
static char LogFileName[] = "dummy.log";
|
||||||
|
|
||||||
/*
|
|
||||||
static void systemInit(void)
|
|
||||||
{
|
|
||||||
// --- enable and connect the PLL (Phase Locked Loop) ---
|
|
||||||
// a. set multiplier and divider
|
|
||||||
PLLCFG = MSEL | (1<<PSEL1) | (0<<PSEL0);
|
|
||||||
// b. enable PLL
|
|
||||||
PLLCON = (1<<PLLE);
|
|
||||||
// c. feed sequence
|
|
||||||
PLLFEED = PLL_FEED1;
|
|
||||||
PLLFEED = PLL_FEED2;
|
|
||||||
// d. wait for PLL lock (PLOCK bit is set if locked)
|
|
||||||
while (!(PLLSTAT & (1<<PLOCK)));
|
|
||||||
// e. connect (and enable) PLL
|
|
||||||
PLLCON = (1<<PLLE) | (1<<PLLC);
|
|
||||||
// f. feed sequence
|
|
||||||
PLLFEED = PLL_FEED1;
|
|
||||||
PLLFEED = PLL_FEED2;
|
|
||||||
|
|
||||||
// --- setup and enable the MAM (Memory Accelerator Module) ---
|
|
||||||
// a. start change by turning of the MAM (redundant)
|
|
||||||
MAMCR = 0;
|
|
||||||
// b. set MAM-Fetch cycle to 3 cclk as recommended for >40MHz
|
|
||||||
MAMTIM = MAM_FETCH;
|
|
||||||
// c. enable MAM
|
|
||||||
MAMCR = MAM_MODE;
|
|
||||||
|
|
||||||
// --- set VPB speed ---
|
|
||||||
VPBDIV = VPBDIV_VAL;
|
|
||||||
|
|
||||||
// --- map INT-vector ---
|
|
||||||
#if defined(RAM_RUN)
|
|
||||||
MEMMAP = MEMMAP_USER_RAM_MODE;
|
|
||||||
#elif defined(ROM_RUN)
|
|
||||||
MEMMAP = MEMMAP_USER_FLASH_MODE;
|
|
||||||
#else
|
|
||||||
#error RUN_MODE not defined!
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
static void gpioInit(void)
|
static void gpioInit(void)
|
||||||
{
|
{
|
||||||
LEDSET = BIT(LED1PIN); // set Bit = LED off (active low)
|
LEDSET = BIT(LED1PIN); // set Bit = LED off (active low)
|
||||||
@ -88,24 +47,60 @@ static void gpioInit(void)
|
|||||||
LEDSET = BIT(LED1PIN); // set Bit = LED off (active low)
|
LEDSET = BIT(LED1PIN); // set Bit = LED off (active low)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void hang(void)
|
|
||||||
{
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* */
|
|
||||||
EmbeddedFileSystem efs;
|
EmbeddedFileSystem efs;
|
||||||
EmbeddedFile filer, filew;
|
EmbeddedFile filer, filew;
|
||||||
DirList list;
|
DirList list;
|
||||||
unsigned short e;
|
unsigned short e;
|
||||||
unsigned char buf[513];
|
unsigned char buf[513];
|
||||||
|
|
||||||
|
void list_roms(){
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
rprintf("Directory of 'root':\n");
|
||||||
|
ls_openDir(&list, &(efs.myFs), "/");
|
||||||
|
while (ls_getNext(&list) == 0) {
|
||||||
|
cnt++;
|
||||||
|
list.currentEntry.FileName[LIST_MAXLENFILENAME - 1] = '\0';
|
||||||
|
rprintf("[%li] %s ( %li bytes )\n",cnt, list.currentEntry.FileName, list.currentEntry.FileSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t * get_filename(uint8_t idx){
|
||||||
|
uint8_t cnt = 0;
|
||||||
|
if (idx<1 || idx>9)
|
||||||
|
return NULL;
|
||||||
|
ls_openDir(&list, &(efs.myFs), "/");
|
||||||
|
while (ls_getNext(&list) == 0) {
|
||||||
|
cnt++;
|
||||||
|
//list.currentEntry.FileName[LIST_MAXLENFILENAME - 1] = '\0';
|
||||||
|
if (cnt==idx)
|
||||||
|
return list.currentEntry.FileName;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_filename(uint8_t * filename){
|
||||||
|
if (file_fopen(&filer, &efs.myFs, filename, 'r') == 0) {
|
||||||
|
rprintf("File %s open. Content:\n", filename);
|
||||||
|
while ((e = file_read(&filer, 512, buf)) != 0) {
|
||||||
|
buf[e] = '\0';
|
||||||
|
uart0Puts((char *) buf);
|
||||||
|
}
|
||||||
|
rprintf("\n");
|
||||||
|
file_fclose(&filer);
|
||||||
|
} else {
|
||||||
|
rprintf("Failed to open %s\n",filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int8_t res;
|
int8_t res;
|
||||||
|
uint8_t * filename;
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
gpioInit();
|
gpioInit();
|
||||||
uart0Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
|
uart0Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
|
||||||
@ -118,25 +113,13 @@ int main(void)
|
|||||||
if ((res = efs_init(&efs, 0)) != 0) {
|
if ((res = efs_init(&efs, 0)) != 0) {
|
||||||
rprintf("failed with %i\n", res);
|
rprintf("failed with %i\n", res);
|
||||||
}
|
}
|
||||||
rprintf("Press Command: d r a \n");
|
list_roms(&efs);
|
||||||
|
rprintf("Select File:\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
if ((ch = uart0Getch()) >= 0) {
|
if ((ch = uart0Getch()) >= 0) {
|
||||||
uart0Puts("You pressed : ");
|
uart0Puts("You pressed : ");
|
||||||
uart0Putch(ch);
|
uart0Putch(ch);
|
||||||
uart0Puts("\r\n");
|
uart0Puts("\r\n");
|
||||||
if (ch == 'M') {
|
|
||||||
rprintf("Creating FS\n");
|
|
||||||
fs_umount(&efs.myFs);
|
|
||||||
mkfs_makevfat(&efs.myPart);
|
|
||||||
}
|
|
||||||
if (ch == 'd') {
|
|
||||||
rprintf("Directory of 'root':\n");
|
|
||||||
ls_openDir(&list, &(efs.myFs), "/");
|
|
||||||
while (ls_getNext(&list) == 0) {
|
|
||||||
list.currentEntry.FileName[LIST_MAXLENFILENAME - 1] = '\0';
|
|
||||||
rprintf("%s ( %li bytes )\n", list.currentEntry.FileName, list.currentEntry.FileSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ch == 'r') {
|
if (ch == 'r') {
|
||||||
if (file_fopen(&filer, &efs.myFs, LogFileName, 'r') == 0) {
|
if (file_fopen(&filer, &efs.myFs, LogFileName, 'r') == 0) {
|
||||||
rprintf("File %s open. Content:\n", LogFileName);
|
rprintf("File %s open. Content:\n", LogFileName);
|
||||||
@ -147,19 +130,13 @@ int main(void)
|
|||||||
file_fclose(&filer);
|
file_fclose(&filer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ch == 'a') {
|
if (ch >='1' && ch <='9'){
|
||||||
if (file_fopen(&filew, &efs.myFs, LogFileName, 'a') == 0) {
|
|
||||||
rprintf("File %s open for append. Appending...", LogFileName);
|
filename = get_filename(ch - 48);
|
||||||
strcpy((char *) buf, "Append Dummy Data to File\r\n");
|
rprintf("Dump: %s\n",filename);
|
||||||
if (file_write(&filew, strlen((char *) buf), buf) == strlen((char *) buf)) {
|
dump_filename(filename);
|
||||||
rprintf("ok\n\n");
|
}
|
||||||
} else {
|
|
||||||
rprintf("fail\n\n");
|
|
||||||
}
|
|
||||||
file_fclose(&filew);
|
|
||||||
fs_umount(&efs.myFs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ledToggle();
|
ledToggle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user