altos: Reduce stack usage of FAT driver and logger
authorKeith Packard <keithp@keithp.com>
Wed, 1 May 2013 01:57:53 +0000 (18:57 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 03:08:00 +0000 (20:08 -0700)
Move some large stack arrays to static storage.
Also eliminates some printf error messages which don't seem that
useful except for debugging.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_fat.c
src/drivers/ao_log_fat.c

index afd645cdec579a9f40063c5d006dce8c83a13a51..1a1b8eb02444007565e15bcf1622dc78dfb0c6c9 100644 (file)
@@ -1052,7 +1052,7 @@ static int8_t
 _ao_fat_open(char name[11], uint8_t mode)
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int8_t                  status;
 
        if (_ao_fat_setup() != AO_FAT_FILESYSTEM_SUCCESS)
@@ -1214,12 +1214,11 @@ ao_fat_map_current(struct ao_file *file, int len, cluster_offset_t *offsetp, clu
        offset = file->offset & SECTOR_MASK;
        sector = _ao_fat_current_sector(file);
        if (sector == 0xffffffff) {
-               printf ("invalid sector at offset %d\n", file->offset);
                return NULL;
        }
        buf = _ao_fat_sector_get(sector);
        if (!buf)
-               printf ("sector get failed. Sector %d. Partition end %d\n", sector, partition_end);
+               return NULL;
        if (offset + len < SECTOR_SIZE)
                *this_time = len;
        else
@@ -1259,7 +1258,6 @@ ao_fat_read(int8_t fd, void *dst, int len)
        while (len) {
                buf = ao_fat_map_current(file, len, &offset, &this_time);
                if (!buf) {
-                       printf ("map_current failed\n");
                        ret = -AO_FAT_EIO;
                        break;
                }
@@ -1307,7 +1305,6 @@ ao_fat_write(int8_t fd, void *src, int len)
        while (len) {
                buf = ao_fat_map_current(file, len, &offset, &this_time);
                if (!buf) {
-                       printf ("map_current failed\n");
                        ret = -AO_FAT_EIO;
                        break;
                }
@@ -1375,7 +1372,7 @@ int8_t
 ao_fat_unlink(char name[11])
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int8_t                  ret;
 
        ao_mutex_get(&ao_fat_mutex);
@@ -1492,7 +1489,7 @@ static void
 ao_fat_list_cmd(void)
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int                     i;
        int8_t                  status;
 
@@ -1535,10 +1532,10 @@ ao_fat_parse_name(char name[11])
 static void
 ao_fat_dump_cmd(void)
 {
-       char            name[11];
+       static char     name[11];
        int8_t          fd;
        int             cnt, i;
-       char            buf[32];
+       static char     buf[32];
 
        ao_fat_parse_name(name);
        if (name[0] == '\0') {
@@ -1561,10 +1558,10 @@ ao_fat_dump_cmd(void)
 static void
 ao_fat_write_cmd(void)
 {
-       char            name[11];
+       static char     name[11];
        int8_t          fd;
        int             cnt, i;
-       char            buf[64];
+       static char     buf[64];
        char            c;
        int             status;
 
index af77401ce9ce4c052887c80fde329388ed3eadff..45b670120436e3eee2c015b06b216289b6cd9b80 100644 (file)
@@ -27,7 +27,7 @@ static uint8_t        log_mutex;
 static void
 ao_log_open(void)
 {
-       char    name[12];
+       static char     name[12];
        int8_t  status;
 
        sprintf(name,"%04d%02d%02dLOG", 2000 + log_year, log_month, log_day);
@@ -38,7 +38,7 @@ ao_log_open(void)
                log_open = 1;
        } else if (status == -AO_FAT_ENOENT) {
                status = ao_fat_creat(name);
-               if (status == AO_FAT_SUCCESS) {
+               if (status >= 0) {
                        log_fd = status;
                        log_open = 1;
                }