33333f0954c9b1a097785360f9acd1a3a8b746e3
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

1) /* flaneth - flash and ethernet
2)    Copyright (C) 2007-2012 Stefan Schuermans <stefan@schuermans.info>
3)    Copyleft: GNU public license V2 - http://www.gnu.org/copyleft/gpl.html
4)    a BlinkenArea project - http://www.blinkenarea.org/ */
5) 
6) #include <string.h>
7) 
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

8) #include "app_bbm.h"
Stefan Schuermans support for reading MAC/IP...

Stefan Schuermans authored 12 years ago

9) #include "app_cfg.h"
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

10) #include "apps.h"
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

11) #include "cf.h"
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

12) #include "debug.h"
13) #include "dosfs.h"
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

14) #include "tasks.h"
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

15) 
Stefan Schuermans support for reading MAC/IP...

Stefan Schuermans authored 12 years ago

16) /**
17)  * @brief list directory and dump file
18)  * @param[in] sectorBuf scratch buffer to store a sector
19)  * @param[in] vi volume information structure
20)  */
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

21) static void AppsListDump(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi)
22) {
23)   DIRINFO di;
24)   DIRENT de;
25)   uint8_t filename[12];
26)   FILEINFO fi;
27)   uint8_t buf[64];
28)   uint32_t len, i;
29) 
30)   // list files in root directory
31)   di.scratch = sectorBuf;
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

32)   if (DFS_OpenDir(vi, (uint8_t *)"", &di) != DFS_OK) {
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

33)     debug_apps_printf("cannot open root directory");
34)     return;
35)   }
36)   debug_apps_printf("files in root directory:");
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

37)   while (DFS_GetNext(vi, &di, &de) == DFS_OK) {
38)     if (de.name[0] == 0) {
39)       // ignore deleted files
40)     } else if (de.attr == ATTR_LONG_NAME) {
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

41)       // ignore long names
42)     } else if (de.attr & ATTR_VOLUME_ID) {
43)       debug_apps_printf("volume ID: %-11.11s", de.name);
44)     } else if (de.attr & ATTR_DIRECTORY) {
45)       debug_apps_printf("directory: %-11.11s", de.name);
46)     } else {
47)       debug_apps_printf("file: %-11.11s", de.name);
48)       memcpy(filename, de.name, 11); // remember last filename
49)       filename[11] = 0;
50)     }
51)   }
52) 
53)   // dump last file
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

54)   if (DFS_OpenFile(vi, filename, DFS_READ, sectorBuf, &fi) != DFS_OK) {
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

55)     debug_apps_printf("cannot open file %s", filename);
56)     return;
57)   }
58)   debug_apps_printf("dumping file %s (max. %u bytes):", filename, sizeof(buf));
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

59)   if (DFS_ReadFile(&fi, sectorBuf, buf, &len, sizeof(buf)) != DFS_OK)
60)     len = 0;
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

61)   for (i = 0; i < len; ++i)
62)     debug_apps_printf("%3lu: %02hX", i, buf[i]);
63)   debug_apps_printf("done", filename);
64) }
65) 
66) // run applications
67) void AppsRun(void) // (extern)
68) {
69)   uint8_t sectorBuf[SECTOR_SIZE];
70)   uint32_t partStart, partSize;
71)   uint8_t partAct, partType;
72)   VOLINFO vi;
73)   const char *sec_clus, *fstype;
74) 
75)   // get start of first partition
76)   partStart = DFS_GetPtnStart(0, sectorBuf, 0, &partAct, &partType, &partSize);
77)   if (partStart == 0xFFFFFFFF) {
78)     debug_apps_printf("cannot find first partition");
79)     return;
80)   }
81)   debug_apps_printf("partition: start %lu size %lu", partStart, partSize);
82) 
83)   // get volume info
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

84)   if (DFS_GetVolInfo(0, sectorBuf, partStart, &vi) != DFS_OK) {
Stefan Schuermans put filesystem stuff into o...

Stefan Schuermans authored 12 years ago

85)     debug_apps_printf("cannot get volume info");
86)     return;
87)   }
88)   switch (vi.filesystem) {
89)     case FAT12: sec_clus = "sector: "; fstype = "FAT12";   break;
90)     case FAT16: sec_clus = "sector: "; fstype = "FAT16";   break;
91)     case FAT32: sec_clus = "cluster:"; fstype = "FAT32";   break;
92)     default:    sec_clus = "sector: "; fstype = "unknown"; break;
93)   }
94)   debug_apps_printf("filesystem:                    %s", fstype);
95)   debug_apps_printf("volume label:                  %-11.11s", vi.label);
96)   debug_apps_printf("sector/s per cluster:          %hu", vi.secperclus);
97)   debug_apps_printf("reserved sector/s:             %hu", vi.reservedsecs);
98)   debug_apps_printf("volume total sectors:          %lu", vi.numsecs);
99)   debug_apps_printf("sectors per FAT:               %lu", vi.secperfat);
100)   debug_apps_printf("first FAT at sector:           %lu", vi.fat1);
101)   debug_apps_printf("root dir at %s           %lu", sec_clus, vi.rootdir);
102)   debug_apps_printf("root dir entries:              %hu", vi.rootentries);
103)   debug_apps_printf("data area commences at sector: %lu", vi.dataarea);
104)   debug_apps_printf("clusters in data area:         %lu", vi.numclusters);
105)   debug_apps_printf("sectors per cluster:           %hu", vi.secperclus);
106) 
107)   // list directory, dump file
108)   AppsListDump(sectorBuf, &vi);
Stefan Schuermans support for reading MAC/IP...

Stefan Schuermans authored 12 years ago

109) 
110)   // run one-short applications
111)   AppCfgRun(sectorBuf, &vi);
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

112) 
113)   // initialize applications
114)   AppBbmState bbm0 = { .sectorBuf = &sectorBuf, .vi = &vi, .no = 0 };
Stefan Schuermans added port number to BBM->M...

Stefan Schuermans authored 12 years ago

115)   AppBbmState bbm1 = { .sectorBuf = &sectorBuf, .vi = &vi, .no = 1 };
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

116)   AppBbmInit(&bbm0);
Stefan Schuermans added port number to BBM->M...

Stefan Schuermans authored 12 years ago

117)   AppBbmInit(&bbm1);
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

118) 
119)   // run applications
120)   while (CfIsPresent()) {
121)     AppBbmRun(&bbm0);
Stefan Schuermans added port number to BBM->M...

Stefan Schuermans authored 12 years ago

122)     AppBbmRun(&bbm1);
Stefan Schuermans iplemented 1st part of BBM...

Stefan Schuermans authored 12 years ago

123)     Tasks();
124)   }