]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
fatfs f_mount now allways done globally at start up
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 15 May 2015 12:59:49 +0000 (14:59 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 15 May 2015 12:59:49 +0000 (14:59 +0200)
avr/cli.c
avr/cmd_fat.c
avr/cmd_loadcpm3.c
avr/cmd_misc.c
avr/command_tbl.c
avr/main.c
avr/z180-serv.c
avr/z80-if.c

index 52c85db1b4b17c1f192f008730e655cb6f986d2c..6b26b6f09cc77d09542271af3eb54999837f9379 100644 (file)
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -27,6 +27,9 @@
 #include "con-utils.h"
 #include "cli.h"
 
+
+/* FIXME: Quoting problems */
+
 #define DEBUG_PARSER   0       /* set to 1 to debug */
 
 #define debug_parser(fmt, args...)             \
@@ -46,7 +49,7 @@ static int cli_parse_line(char *line, char *argv[])
                        inp++) {
 
                switch (state) {
-               case 0:
+               case 0:                                         /* before arg string, waiting for arg start */
                        if (isblank(c))
                                continue;
 
@@ -55,7 +58,7 @@ static int cli_parse_line(char *line, char *argv[])
                        state = 1;
                        /* fall thru */
 
-               case 1:
+               case 1:                                         /* in arg string, waiting for end of arg string */
                        if (c == '\\') {
                                ++state;
                                continue;
@@ -71,7 +74,7 @@ static int cli_parse_line(char *line, char *argv[])
                        }
                        break;
 
-               case 3:
+               case 3:                                         /* in quote */
                        if (c == '\\' && quote == '\"') {
                                ++state;
                                continue;
@@ -82,7 +85,7 @@ static int cli_parse_line(char *line, char *argv[])
                        }
                        break;
 
-               case 2:
+               case 2:                                         /* waiting for next char */
                case 4:
                        --state;
                        break;
@@ -252,12 +255,13 @@ static int cli_run_command(const char *cmd, int flag)
                 */
                for (inquotes = 0, sep = str; *sep; sep++) {
                        if ((*sep == '\'') &&
-                           (*(sep - 1) != '\\'))
+                           (sep != str) &&                             /* past string start */
+                           (*(sep - 1) != '\\'))               /* and NOT escaped */
                                inquotes = !inquotes;
 
                        if (!inquotes &&
-                           (*sep == ';' || *sep == '\n') &&    /* separator            */
-                           (sep != str) &&                     /* past string start    */
+                           (*sep == ';' || *sep == '\n') &&    /* separator */
+                           (sep != str) &&                             /* past string start */
                            (*(sep - 1) != '\\'))               /* and NOT escaped */
                                break;
                }
index c5791e55eed2fcda1d4e30bc062ec6be5a32f40e..af2f77253092198d04dfe74b0b0267a9937158bf 100644 (file)
@@ -157,7 +157,7 @@ FRESULT scan_files (
  */
 command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       FATFS *FatFs, *fs;
+       FATFS *fs;
        DWORD nfreeclst;
        FRESULT res;
        char *path;
@@ -165,64 +165,57 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
 
        (void) cmdtp; (void) flag; (void) argc;
 
-       FatFs = (FATFS *) malloc(sizeof (FATFS));
        path = (char *) malloc(BUFFER_SIZE);
-       if (FatFs == NULL || path == NULL) {
+       if (path == NULL) {
                printf_P(PSTR("fatstat: Out of Memory!\n"));
                free(path);
-               free(FatFs);
                return CMD_RET_FAILURE;
        }
 
-       res = f_mount(FatFs, argv[1], 0);
+       res = f_getfree(argv[1], &nfreeclst, &fs);
        if (!res) {
-               res = f_getfree(argv[1], &nfreeclst, &fs);
-               if (!res) {
-                       printf_P(PSTR(
-                                               "FAT type:                %u\n"
-                                               "Bytes/Cluster:           %lu\n"
-                                               "Number of FATs:          %u\n"
-                                               "Root DIR entries:        %u\n"
-                                               "Sectors/FAT:             %lu\n"
-                                               "Number of clusters:      %lu\n"
-                                               "FAT start (lba):         %lu\n"
-                                               "DIR start (lba,cluster): %lu\n"
-                                               "Data start (lba):        %lu\n"),
-                                       fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats,
-                                       fs->n_rootdir, fs->fsize, fs->n_fatent - 2,
-                                       fs->fatbase, fs->dirbase, fs->database);
+               printf_P(PSTR(
+                                       "FAT type:                %u\n"
+                                       "Bytes/Cluster:           %lu\n"
+                                       "Number of FATs:          %u\n"
+                                       "Root DIR entries:        %u\n"
+                                       "Sectors/FAT:             %lu\n"
+                                       "Number of clusters:      %lu\n"
+                                       "FAT start (lba):         %lu\n"
+                                       "DIR start (lba,cluster): %lu\n"
+                                       "Data start (lba):        %lu\n"),
+                               fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats,
+                               fs->n_rootdir, fs->fsize, fs->n_fatent - 2,
+                               fs->fatbase, fs->dirbase, fs->database);
 
 #if _USE_LABEL
-                       TCHAR label[12];
-                       DWORD serial;
-                       res = f_getlabel(argv[1], label, &serial);
-                       if (!res) {
-                               printf_P(PSTR(
-                                                       "Volume name:             %s\n"
-                                                       "Volume S/N:              %04X-%04X\n"),
-                                               label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF));
-                       }
+               TCHAR label[12];
+               DWORD serial;
+               res = f_getlabel(argv[1], label, &serial);
+               if (!res) {
+                       printf_P(PSTR(
+                                               "Volume name:             %s\n"
+                                               "Volume S/N:              %04X-%04X\n"),
+                                       label, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF));
+               }
 #endif
-                       if (!res) {
-                               my_puts_P(PSTR("\nCounting...  "));
-                               statp.AccSize = statp.AccFiles = statp.AccDirs = 0;
-                               strcpy(path, argv[1]);
+               if (!res) {
+                       my_puts_P(PSTR("\nCounting...  "));
+                       statp.AccSize = statp.AccFiles = statp.AccDirs = 0;
+                       strcpy(path, argv[1]);
 
-                               res = scan_files(path, &statp);
-                       }
-                       if (!res) {
-                               printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n"
-                                                        "%lu KB total disk space.\n%lu KB available.\n"),
-                                               statp.AccFiles, statp.AccSize, statp.AccDirs,
-                                               (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2)
-                               );
-                       }
+                       res = scan_files(path, &statp);
+               }
+               if (!res) {
+                       printf_P(PSTR("\r%u files, %lu bytes.\n%u folders.\n"
+                                                "%lu KB total disk space.\n%lu KB available.\n"),
+                                       statp.AccFiles, statp.AccSize, statp.AccDirs,
+                                       (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2)
+                       );
                }
        }
 
        free(path);
-       free(FatFs);
-       f_mount(NULL, argv[1], 0);
        if (res) {
                put_rc(res);
                return CMD_RET_FAILURE;
@@ -237,7 +230,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
  */
 command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       FATFS FatFs, *fs;
+       FATFS *fs;
        DIR Dir;                                        /* Directory object */
        FILINFO Finfo;
        unsigned long p1;
@@ -251,9 +244,7 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 
        (void) cmdtp; (void) flag; (void) argc;
 
-       res = f_mount(&FatFs, argv[1], 0);
-       if (!res)
-               res = f_opendir(&Dir, argv[1]);
+       res = f_opendir(&Dir, argv[1]);
        if (res) {
                put_rc(res);
                return CMD_RET_FAILURE;
@@ -341,7 +332,6 @@ FRESULT mkpath(TCHAR *path)
  */
 command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       FATFS *FatFs;
        FIL File;
        uint32_t addr;
        unsigned long bytes;
@@ -376,21 +366,15 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        if (addr + bytes > MAX_MEMORY)
                bytes = MAX_MEMORY - addr;
 
-       FatFs = (FATFS *) malloc(sizeof (FATFS));
        buffer = (uint8_t *) malloc(BUFFER_SIZE);
-       if (FatFs == NULL || buffer == NULL) {
+       if (buffer == NULL) {
                printf_P(PSTR("fatstat: Out of Memory!\n"));
-               free(FatFs);
                free(buffer);
                return CMD_RET_FAILURE;
        }
 
-       res = f_mount(FatFs, argv[1], 0);
-
-       if (!res) {
-               if (dowrite) {
-                       res = mkpath(argv[1]);
-               }
+       if (dowrite) {
+               res = mkpath(argv[1]);
        }
        if (!res) {
                res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS
@@ -451,11 +435,9 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
                                                        bytes_rw, bytes_rw, timer ? (bytes_rw * 1000 / timer) : 0);
                        }
                }
-               f_mount(NULL, argv[1], 0);
        }
 
        free(buffer);
-       free(FatFs);
 
        if (buserr)
                my_puts_P(PSTR("Bus timeout\n"));
index f2a30f1e0a2f1faa0af692ea34c829e4ea323df3..fd685b2e48c3ebb45b4c0ef11011a81b4a016fc2 100644 (file)
@@ -65,7 +65,6 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
        uint16_t osentry_adr = 0;
        long offset = 0;
        char *fname;
-       FATFS FatFs;
        FIL File;
        /* TODO: put CONFIG_PATH_CPM3SYS in flash */
        char default_fname[] = CONFIG_PATH_CPM3SYS;
@@ -88,12 +87,9 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
        if (fname == NULL || *fname == '\0')
                fname = default_fname;
 
-       res = f_mount(&FatFs, fname, 0);
-       if (!res)
-               res = f_open(&File, fname, FA_READ );
+       res = f_open(&File, fname, FA_READ );
        if (res) {
                printf_P(PSTR("Error: failed to open '%s'\n"), fname);
-               f_mount(NULL, fname, 0);
                return CMD_RET_FAILURE;
        }
 
@@ -132,7 +128,6 @@ command_ret_t do_loadcpm3(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
 
 out:
        f_close(&File);
-       f_mount(NULL, fname, 0);
 
        if (res) {
                printf_P(PSTR("Error: failed to read '%s'\n"), fname);
index b29aedddce4c3dee0bd39db617ad822e802127fe..c9a3c4529e255957940bb9f699237d25c1838004 100644 (file)
@@ -9,46 +9,43 @@
 
 #include "common.h"
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include "command.h"
 #include "timer.h"
 #include "con-utils.h"
+#include "getopt-min.h"
 
 
 command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       uint_fast8_t putnl = 1;
+       bool put_newline = true;
 
        (void) cmdtp; (void) flag;
 
-       for (uint_fast8_t i = 1; i < argc; i++) {
+       /* reset getopt() */
+       optind = 1;
+
+       int opt;
+       while ((opt = getopt(argc, argv, PSTR("n"))) != -1) {
+               switch (opt) {
+               case 'n':
+                       put_newline = false;
+                       break;
+               default: /* '?' */
+                       return CMD_RET_USAGE;
+               }
+       }
 
-               uint_fast8_t backslash = 0;
-               char *p = argv[i];
-               char c;
+       for (uint_fast8_t i = optind; i < argc; i++) {
 
-               if (i != 1)
+               if (i != optind)
                        putchar(' ');
-               while ((c = *p++) != '\0') {
-
-                       if(backslash) {
-                               backslash = 0;
-                               if (c == 'c') {
-                                       putnl = 0;
-                                       continue;
-                               } else
-                                       putchar('\\');
-                       } else {
-                               if (c == '\\') {
-                                       backslash = 1;
-                                       continue;
-                               }
-                       }
-                       putchar(c);
-               }
+
+               my_puts(argv[i]);
        }
 
-       if (putnl)
+       if (put_newline)
                putchar('\n');
 
        return CMD_RET_SUCCESS;
index 238f132012b811466f69e8346cbde6ec4f4dfdca..f030b54c816eec3ef9cfa62e4fdc48e01970953a 100644 (file)
@@ -76,9 +76,10 @@ CMD_TBL_ITEM(
 ),
 CMD_TBL_ITEM(
        echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
-       "echo args to console",
-       "[args..]\n"
-       "     - echo args to console; \\c suppresses newline"
+       "display a line of text",
+       "[-n] [argument ...]\n"
+       "     - echo the argument(s) to console.\n"
+       "       -n  do not output the trailing newline"
 ),
 CMD_TBL_ITEM(
        sleep ,    2,    1,     do_sleep,
index 8bffef991971c64c9b443773016b19f984e2203d..5a0d7928ea4b45aa9c7822d04dc84c1cd7ed1fe4 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdio.h>
 
 #include "config.h"
-#include "debug.h"
+#include "ff.h"
 #include "z80-if.h"
 #include "i2c.h"
 #include "con-utils.h"
@@ -23,6 +23,7 @@
 #include "gpio.h"
 #include "time.h"
 #include "rtc.h"
+#include "debug.h"
 
 static uint8_t mcusr;
 
@@ -138,6 +139,17 @@ void setup_system_time(void)
        set_system_time(mk_gmtime(&rtc_time) );
 }
 
+
+
+static void setup_fatfs(void)
+{
+       static FATFS FatFs0;
+       static FATFS FatFs1;
+
+       f_mount(&FatFs0, "0:", 0);
+       f_mount(&FatFs1, "1:", 0);
+}
+
 /*--------------------------------------------------------------------------*/
 
 /* Stored value of bootdelay, used by autoboot_command() */
@@ -254,14 +266,9 @@ int main(void)
        print_reset_reason();
 #endif
 
-#if DEBUG
-       unsigned long i_speed = getenv_ulong(PSTR("i2c_clock"), 10, CONFIG_SYS_I2C_CLOCK);
-       debug("### Setting I2C clock Frequency to %lu Hz.\n", i_speed);
-       i2c_init(i_speed);
-#else
        i2c_init(CONFIG_SYS_I2C_CLOCK);
-#endif
        setup_system_time();
+       setup_fatfs();
 
        printf_P(PSTR("\nATMEGA1281+Z8S180 Stamp Monitor\n\n"));
 
index c80daeb4da407b2c2e06aae214d05525afa2977a..22dafe10484e6c7f49d4c74e8528a4c94a762599 100644 (file)
@@ -104,15 +104,9 @@ void do_msg_echo(uint8_t subf, int len, uint8_t * msg)
 
 /* ---------------------------------------------------------------------------*/
 
-#define MAX_DEVICE     2
 #define MAX_DRIVE      2
 #define BLOCK_SIZE     512
 
-struct fat_device_s {
-       FATFS dd;
-       bool active;
-};
-
 
 struct cpm_drive_s {
        uint8_t drv;
@@ -122,7 +116,6 @@ struct cpm_drive_s {
 };
 
 static uint8_t disk_buffer[BLOCK_SIZE];
-static struct fat_device_s device_table[MAX_DEVICE];
 static struct cpm_drive_s drv_table[MAX_DRIVE];
 
 /*
@@ -158,17 +151,6 @@ void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg)
                goto out;
        }
 
-       /* TODO: this has to be done somewhere globaly */
-
-       if (!device_table[0].active) {
-               f_mount(&device_table[0].dd, "0:", 0);
-               device_table[0].active = true;
-       }
-       if (!device_table[1].active) {
-               f_mount(&device_table[1].dd, "1:", 0);
-               device_table[1].active = true;
-       }
-
 /*
        uint32_t dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2];
 */
@@ -489,11 +471,6 @@ void restart_z180_serv(void)
                z80_memfifo_init(i, 0);
        bg_setstat(handle_msg_handling, 0);
 
-       f_mount(NULL, "0:", 0);
-       device_table[0].active = false;
-       f_mount(NULL, "1:", 0);
-       device_table[1].active = false;
-
 }
 
 /*--------------------------------------------------------------------------*/
index d5dc2d75c8a0cfe78b6f75f8d67ac2c9d877e979..21ffeac87e054da19880689744560ae12628a514 100644 (file)
@@ -560,10 +560,9 @@ void z80_memfifo_init(const fifo_t f, uint32_t addr)
 {
        fifo_dsc[f].base = addr;
 
-       if (addr != 0) {
-
 DBG_P(2, "z80_memfifo_init: %i, %lx\n", f, addr);
 
+       if (addr != 0) {
                z80_bus_cmd(Request);
                fifo_dsc[f].mask = z80_read(addr + FIFO_BUFSIZE_MASK);
                fifo_dsc[f].idx_in = z80_read(addr + FIFO_INDEX_IN);