filetest.c revisited
Rsadeika
Posts: 3,837
I am doing a test run with filetest.c. The code below is minimal amount to check and see if the SD card got loaded, and show what is on the card. I have an error for the dfs_mount() command, I can not remember how to fix the problem.
Ray
Board Type - DNA:SQI; Compiler Type - C; Memory Model - CMM; Optimization - Os Size. Nothing else checked in Compiler or Linker.
Build Status
Ray
Board Type - DNA:SQI; Compiler Type - C; Memory Model - CMM; Optimization - Os Size. Nothing else checked in Compiler or Linker.
/** * @file filetest.c * This is the main filetest program start point. */ #include <stdio.h> //#include <stdlib.h> //#include <string.h> //#include <cog.h> #include <propeller.h> //#include <unistd.h> //#include <sys/stat.h> #include <sys/sd.h> #include <dirent.h> extern _Driver _FileDriver; char *FindChar(char *ptr, int val); FILE *stdinfile; FILE *stdoutfile; void List(int argc, char **argv) { int i, j; char *ptr; char fname[13]; int32_t count = 0; uint32_t filesize; uint32_t longflag = 0; char *path; char drwx[5]; int column; int prevlen; DIR *dirp; struct dirent *entry; /* <dirent.h> */ for (j = 1; j < argc; j++) { if (argv[j][0] == '-') { if (!strcmp(argv[j], "-1")) longflag = 1; else printf("Unknown option \"%s\"\n", argv[j]); } else count++; } //List directories for (j = 1; j < argc || count == 0; j++) { if (count == 0) { count--; path = "./"; } else if (argv[j][0] == '-') continue; else path = argv[j]; if (count >= 2) fprintf(stdoutfile, "\n%s:\n", path); dirp = opendir(path); if (!dirp) { perror(path); continue; } column = 0; prevlen = 14; while (entry = readdir(dirp)) { if (entry->name[0] == '.') continue; ptr = fname; for (i = 0; i < 8; i++) { if (entry->name[i] == ' ') break; *ptr++ = tolower(entry->name[i]); } if (entry->name[8] != ' ') { *ptr++ = '.'; for (i = 8; i < 11; i++) { if (entry->name[i] == ' ') break; *ptr++ = tolower(entry->name[i]); } } *ptr = 0; filesize = entry->filesize_3; filesize = (filesize << 8) | entry->filesize_2; filesize = (filesize << 8) | entry->filesize_1; filesize = (filesize << 8) | entry->filesize_0; strcpy(drwx, "-rw-"); if (entry->attr & ATTR_READ_ONLY) drwx[2] = '-'; if (entry->attr & ATTR_ARCHIVE) drwx[3] = 'x'; if (entry->attr & ATTR_DIRECTORY) { drwx[0] = 'd'; drwx[3] = 'x'; } if (longflag) fprintf(stdoutfile, "%s %8d %s\n", drwx, filesize, fname); else if (++column == 5) { for (i = prevlen; i < 14; i++) fprintf(stdoutfile, " "); fprintf(stdoutfile, "%s\n", fname); column = 0; prevlen = 14; } else { for (i = prevlen; i < 14; i++) fprintf(stdoutfile, " "); prevlen = strlen(fname); fprintf(stdoutfile, "%s", fname); } } closedir(dirp); if (!longflag && column) fprintf(stdoutfile, "\n"); } } char *SkipChar(char *ptr, int val) { while (*ptr) { if (*ptr != val) break; ptr++; } return ptr; } char *FindChar(char *ptr, int val) { while (*ptr) { if (*ptr == val) break; ptr++; } return ptr; } int tokenize(char *ptr, char *tokens[]) { int num = 0; while (*ptr) { ptr = SkipChar(ptr, ' '); if (*ptr == 0) break; if (ptr[0] == '>') { ptr++; if (ptr[0] == '>') { tokens[num++] = ">>"; ptr++; } else tokens[num++] = ">"; continue; } if (ptr[0] == '<') { ptr++; tokens[num++] = "<"; continue; } tokens[num++] = ptr; ptr = FindChar(ptr, ' '); if (*ptr) *ptr++ = 0; } return num; } /** * Main program function. */ int main(void) { int num; char *tokens[20]; uint8_t buffer[80]; /* propeller.h */ stdinfile = stdin; stdoutfile = stdout; buffer[0] = 0; buffer[1] = 1; buffer[2] = 2; buffer[3] = 3; LoadSDDriver(buffer); dfs_mount(); waitcnt(CLKFREQ/6+CNT); while(1) { printf(">"); fflush(stdout); gets(buffer); num = tokenize(buffer, tokens); if (num == 0) continue; if (!strcmp(tokens[0], "quit")) break; else if (!strcmp(tokens[0], "ls")) List(num, tokens); else { printf("Invalid command\n"); } } printf("\nSystem Stop"); return 0; }
Build Status
Project Directory: E:/PropGCC_SimpleIDE/PropGCC/filetest/
propeller-elf-gcc.exe -o a.out -Os -mcmm -I . -fno-exceptions filetest.c
filetest.c: In function 'main':
filetest.c:199:5: error: too few arguments to function 'dfs_mount'
c:\propgcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/sys/sd.h:118:10: note: declared here
Done. Build Failed!
Click error or warning messages above to debug.
Comments
So far the Code Size is 18,584 bytes (19,372 total), not sure if this is good or bad for CMM memory model.
Ray
<edit> You may want to change the name of the file, it may get confusing with two filetest.c programs floating around. <edit>
Ray
CMM - Code Size 17,668 bytes (18,456 total)
LMM - Code Size 30,008 bytes (30,796 total)
XMMC - Code Size 33,508 bytes (34,296 total)
Again, remember that I am using the DNA board.
Ray