Stefan Schuermans commited on 2012-05-04 18:56:53
Showing 5 changed files, with 123 additions and 86 deletions.
| ... | ... |
@@ -60,7 +60,8 @@ SRC = $(TARGET).c |
| 60 | 60 |
|
| 61 | 61 |
# If there is more than one source file, append them above, or modify and |
| 62 | 62 |
# uncomment the following: |
| 63 |
-SRC += arp.c bus.c cf.c checksum.c config.c dhcp.c dosfs.c dosfs_user.c \ |
|
| 63 |
+SRC += apps.c \ |
|
| 64 |
+ arp.c bus.c cf.c checksum.c config.c dhcp.c dosfs.c dosfs_user.c \ |
|
| 64 | 65 |
eeprom.c ethernet.c http.c icmp.c ip.c random.c rtl8019.c \ |
| 65 | 66 |
ser62500.c status.c tasks.c tcp.c timing.c uart.c udp.c \ |
| 66 | 67 |
xtea.c |
| ... | ... |
@@ -0,0 +1,100 @@ |
| 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 |
+ |
|
| 8 |
+#include "apps.h" |
|
| 9 |
+#include "debug.h" |
|
| 10 |
+#include "dosfs.h" |
|
| 11 |
+ |
|
| 12 |
+// list files and |
|
| 13 |
+static void AppsListDump(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi) |
|
| 14 |
+{
|
|
| 15 |
+ DIRINFO di; |
|
| 16 |
+ DIRENT de; |
|
| 17 |
+ uint8_t filename[12]; |
|
| 18 |
+ FILEINFO fi; |
|
| 19 |
+ uint8_t buf[64]; |
|
| 20 |
+ uint32_t len, i; |
|
| 21 |
+ |
|
| 22 |
+ // list files in root directory |
|
| 23 |
+ di.scratch = sectorBuf; |
|
| 24 |
+ if (DFS_OpenDir(vi, (uint8_t *)"", &di) != 0) {
|
|
| 25 |
+ debug_apps_printf("cannot open root directory");
|
|
| 26 |
+ return; |
|
| 27 |
+ } |
|
| 28 |
+ debug_apps_printf("files in root directory:");
|
|
| 29 |
+ while (DFS_GetNext(vi, &di, &de) == 0) {
|
|
| 30 |
+ if (de.attr == ATTR_LONG_NAME) {
|
|
| 31 |
+ // ignore long names |
|
| 32 |
+ } else if (de.attr & ATTR_VOLUME_ID) {
|
|
| 33 |
+ debug_apps_printf("volume ID: %-11.11s", de.name);
|
|
| 34 |
+ } else if (de.attr & ATTR_DIRECTORY) {
|
|
| 35 |
+ debug_apps_printf("directory: %-11.11s", de.name);
|
|
| 36 |
+ } else {
|
|
| 37 |
+ debug_apps_printf("file: %-11.11s", de.name);
|
|
| 38 |
+ memcpy(filename, de.name, 11); // remember last filename |
|
| 39 |
+ filename[11] = 0; |
|
| 40 |
+ } |
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ // dump last file |
|
| 44 |
+ if (DFS_OpenFile(vi, filename, DFS_READ, sectorBuf, &fi) != 0) {
|
|
| 45 |
+ debug_apps_printf("cannot open file %s", filename);
|
|
| 46 |
+ return; |
|
| 47 |
+ } |
|
| 48 |
+ debug_apps_printf("dumping file %s (max. %u bytes):", filename, sizeof(buf));
|
|
| 49 |
+ len = 0; |
|
| 50 |
+ DFS_ReadFile(&fi, sectorBuf, buf, &len, sizeof(buf)); |
|
| 51 |
+ for (i = 0; i < len; ++i) |
|
| 52 |
+ debug_apps_printf("%3lu: %02hX", i, buf[i]);
|
|
| 53 |
+ debug_apps_printf("done", filename);
|
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+// run applications |
|
| 57 |
+void AppsRun(void) // (extern) |
|
| 58 |
+{
|
|
| 59 |
+ uint8_t sectorBuf[SECTOR_SIZE]; |
|
| 60 |
+ uint32_t partStart, partSize; |
|
| 61 |
+ uint8_t partAct, partType; |
|
| 62 |
+ VOLINFO vi; |
|
| 63 |
+ const char *sec_clus, *fstype; |
|
| 64 |
+ |
|
| 65 |
+ // get start of first partition |
|
| 66 |
+ partStart = DFS_GetPtnStart(0, sectorBuf, 0, &partAct, &partType, &partSize); |
|
| 67 |
+ if (partStart == 0xFFFFFFFF) {
|
|
| 68 |
+ debug_apps_printf("cannot find first partition");
|
|
| 69 |
+ return; |
|
| 70 |
+ } |
|
| 71 |
+ debug_apps_printf("partition: start %lu size %lu", partStart, partSize);
|
|
| 72 |
+ |
|
| 73 |
+ // get volume info |
|
| 74 |
+ if (DFS_GetVolInfo(0, sectorBuf, partStart, &vi) != 0) {
|
|
| 75 |
+ debug_apps_printf("cannot get volume info");
|
|
| 76 |
+ return; |
|
| 77 |
+ } |
|
| 78 |
+ switch (vi.filesystem) {
|
|
| 79 |
+ case FAT12: sec_clus = "sector: "; fstype = "FAT12"; break; |
|
| 80 |
+ case FAT16: sec_clus = "sector: "; fstype = "FAT16"; break; |
|
| 81 |
+ case FAT32: sec_clus = "cluster:"; fstype = "FAT32"; break; |
|
| 82 |
+ default: sec_clus = "sector: "; fstype = "unknown"; break; |
|
| 83 |
+ } |
|
| 84 |
+ debug_apps_printf("filesystem: %s", fstype);
|
|
| 85 |
+ debug_apps_printf("volume label: %-11.11s", vi.label);
|
|
| 86 |
+ debug_apps_printf("sector/s per cluster: %hu", vi.secperclus);
|
|
| 87 |
+ debug_apps_printf("reserved sector/s: %hu", vi.reservedsecs);
|
|
| 88 |
+ debug_apps_printf("volume total sectors: %lu", vi.numsecs);
|
|
| 89 |
+ debug_apps_printf("sectors per FAT: %lu", vi.secperfat);
|
|
| 90 |
+ debug_apps_printf("first FAT at sector: %lu", vi.fat1);
|
|
| 91 |
+ debug_apps_printf("root dir at %s %lu", sec_clus, vi.rootdir);
|
|
| 92 |
+ debug_apps_printf("root dir entries: %hu", vi.rootentries);
|
|
| 93 |
+ debug_apps_printf("data area commences at sector: %lu", vi.dataarea);
|
|
| 94 |
+ debug_apps_printf("clusters in data area: %lu", vi.numclusters);
|
|
| 95 |
+ debug_apps_printf("sectors per cluster: %hu", vi.secperclus);
|
|
| 96 |
+ |
|
| 97 |
+ // list directory, dump file |
|
| 98 |
+ AppsListDump(sectorBuf, &vi); |
|
| 99 |
+} |
|
| 100 |
+ |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 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 |
+#ifndef INC_apps |
|
| 7 |
+#define INC_apps |
|
| 8 |
+ |
|
| 9 |
+// run applications |
|
| 10 |
+extern void AppsRun(void); |
|
| 11 |
+ |
|
| 12 |
+#endif // #ifndef INC_apps |
|
| 13 |
+ |
| ... | ... |
@@ -22,25 +22,24 @@ |
| 22 | 22 |
#define DEBUG_DHCP 1 |
| 23 | 23 |
#define DEBUG_TCP 1 |
| 24 | 24 |
#define DEBUG_HTTP 1 |
| 25 |
+#define DEBUG_APPS 1 |
|
| 25 | 26 |
|
| 26 | 27 |
// debug version of printf |
| 27 | 28 |
#ifdef DEBUG |
| 28 |
-#define debug_printf_nolf( fmt, arg... ) \ |
|
| 29 |
+#define debug_printf( fmt, arg... ) \ |
|
| 29 | 30 |
do { \
|
| 30 |
- static const PROGMEM char fmt_pgm[] = fmt; \ |
|
| 31 |
+ static const PROGMEM char fmt_pgm[] = fmt"\r\n"; \ |
|
| 31 | 32 |
char fmt_buf[sizeof( fmt_pgm )]; \ |
| 32 | 33 |
for( int i = 0; i < sizeof( fmt_pgm ); i++ ) \ |
| 33 | 34 |
fmt_buf[i] = (char)pgm_read_byte_near( (uint16_t)fmt_pgm + i ); \ |
| 34 | 35 |
printf( fmt_buf, ##arg ); \ |
| 35 | 36 |
} while (0) |
| 36 |
-#define debug_printf( fmt, arg... ) debug_printf_nolf( fmt"\r\n", ##arg ) |
|
| 37 | 37 |
#else |
| 38 |
-#define debug_printf_nolf( fmt, arg... ) { }
|
|
| 39 | 38 |
#define debug_printf( fmt, arg... ) { }
|
| 40 | 39 |
#endif |
| 41 | 40 |
|
| 42 | 41 |
// specialized debug versions of printf |
| 43 |
-#define debug_specialized_printf( enabled, fmt, arg... ) { if( enabled ) debug_printf( fmt, ##arg ); }
|
|
| 42 |
+#define debug_specialized_printf(enabled, fmt, arg...) do { if(enabled) debug_printf(fmt, ##arg); } while (0)
|
|
| 44 | 43 |
#define debug_init_printf(fmt, arg...) debug_specialized_printf(DEBUG_INIT, "init: "fmt, ##arg) |
| 45 | 44 |
#define debug_eeprom_printf(fmt, arg...) debug_specialized_printf(DEBUG_EEPROM, "eeprom: "fmt, ##arg) |
| 46 | 45 |
#define debug_cf_printf(fmt, arg...) debug_specialized_printf(DEBUG_CF, "cf: "fmt, ##arg) |
| ... | ... |
@@ -53,5 +52,6 @@ |
| 53 | 52 |
#define debug_dhcp_printf(fmt, arg...) debug_specialized_printf(DEBUG_DHCP, "dhcp: "fmt, ##arg) |
| 54 | 53 |
#define debug_tcp_printf(fmt, arg...) debug_specialized_printf(DEBUG_TCP, "tcp: "fmt, ##arg) |
| 55 | 54 |
#define debug_http_printf(fmt, arg...) debug_specialized_printf(DEBUG_HTTP, "http: "fmt, ##arg) |
| 55 |
+#define debug_apps_printf(fmt, arg...) debug_specialized_printf(DEBUG_APPS, "apps: "fmt, ##arg) |
|
| 56 | 56 |
|
| 57 | 57 |
#endif // #ifndef INC_debug |
| ... | ... |
@@ -5,13 +5,12 @@ |
| 5 | 5 |
|
| 6 | 6 |
#include <avr/interrupt.h> |
| 7 | 7 |
#include <avr/wdt.h> |
| 8 |
-#include <string.h> |
|
| 9 | 8 |
|
| 9 |
+#include "apps.h" |
|
| 10 | 10 |
#include "arp.h" |
| 11 | 11 |
#include "bus.h" |
| 12 | 12 |
#include "cf.h" |
| 13 | 13 |
#include "debug.h" |
| 14 |
-#include "dosfs.h" |
|
| 15 | 14 |
#include "eeprom.h" |
| 16 | 15 |
#include "http.h" |
| 17 | 16 |
#include "random.h" |
| ... | ... |
@@ -26,17 +25,6 @@ |
| 26 | 25 |
static void mainWorkCf(void) |
| 27 | 26 |
{
|
| 28 | 27 |
unsigned long sectors; |
| 29 |
- uint8_t sectorBuf[SECTOR_SIZE]; |
|
| 30 |
- uint32_t partStart, partSize; |
|
| 31 |
- uint8_t partAct, partType; |
|
| 32 |
- VOLINFO vi; |
|
| 33 |
- const char *sec_clus, *fstype; |
|
| 34 |
- DIRINFO di; |
|
| 35 |
- DIRENT de; |
|
| 36 |
- uint8_t filename[12]; |
|
| 37 |
- FILEINFO fi; |
|
| 38 |
- uint8_t buf[16]; |
|
| 39 |
- uint32_t len, i; |
|
| 40 | 28 |
|
| 41 | 29 |
// reset card |
| 42 | 30 |
if (CfReset() != 0) |
| ... | ... |
@@ -46,73 +34,8 @@ static void mainWorkCf(void) |
| 46 | 34 |
if (CfIdentify(§ors) != 0) |
| 47 | 35 |
return; |
| 48 | 36 |
|
| 49 |
- // get start of first partition |
|
| 50 |
- partStart = DFS_GetPtnStart(0, sectorBuf, 0, &partAct, &partType, &partSize); |
|
| 51 |
- if (partStart == 0xFFFFFFFF) {
|
|
| 52 |
- debug_printf("cannot find first partition");
|
|
| 53 |
- return; |
|
| 54 |
- } |
|
| 55 |
- debug_printf("partition: start %lu size %lu", partStart, partSize);
|
|
| 56 |
- |
|
| 57 |
- // get volume info |
|
| 58 |
- if (DFS_GetVolInfo(0, sectorBuf, partStart, &vi) != 0) {
|
|
| 59 |
- debug_printf("cannot get volume info");
|
|
| 60 |
- return; |
|
| 61 |
- } |
|
| 62 |
- switch (vi.filesystem) {
|
|
| 63 |
- case FAT12: sec_clus = "sector: "; fstype = "FAT12"; break; |
|
| 64 |
- case FAT16: sec_clus = "sector: "; fstype = "FAT16"; break; |
|
| 65 |
- case FAT32: sec_clus = "cluster:"; fstype = "FAT32"; break; |
|
| 66 |
- default: sec_clus = "sector: "; fstype = "unknown"; break; |
|
| 67 |
- } |
|
| 68 |
- debug_printf("filesystem: %s", fstype);
|
|
| 69 |
- debug_printf("volume label: %-11.11s", vi.label);
|
|
| 70 |
- debug_printf("sector/s per cluster: %hu", vi.secperclus);
|
|
| 71 |
- debug_printf("reserved sector/s: %hu", vi.reservedsecs);
|
|
| 72 |
- debug_printf("volume total sectors: %lu", vi.numsecs);
|
|
| 73 |
- debug_printf("sectors per FAT: %lu", vi.secperfat);
|
|
| 74 |
- debug_printf("first FAT at sector: %lu", vi.fat1);
|
|
| 75 |
- debug_printf("root dir at %s %lu", sec_clus, vi.rootdir);
|
|
| 76 |
- debug_printf("root dir entries: %hu", vi.rootentries);
|
|
| 77 |
- debug_printf("data area commences at sector: %lu", vi.dataarea);
|
|
| 78 |
- debug_printf("clusters in data area: %lu", vi.numclusters);
|
|
| 79 |
- debug_printf("sectors per cluster: %hu", vi.secperclus);
|
|
| 80 |
- |
|
| 81 |
- // list files in root directory |
|
| 82 |
- di.scratch = sectorBuf; |
|
| 83 |
- if (DFS_OpenDir(&vi, (uint8_t *)"", &di) != 0) {
|
|
| 84 |
- debug_printf("cannot open root directory");
|
|
| 85 |
- return; |
|
| 86 |
- } |
|
| 87 |
- debug_printf("files in root directory:");
|
|
| 88 |
- while (DFS_GetNext(&vi, &di, &de) == 0) {
|
|
| 89 |
- if (de.attr == ATTR_LONG_NAME) {
|
|
| 90 |
- // ignore long names |
|
| 91 |
- } else if (de.attr & ATTR_VOLUME_ID) {
|
|
| 92 |
- debug_printf("volume ID: %-11.11s", de.name);
|
|
| 93 |
- } else if (de.attr & ATTR_DIRECTORY) {
|
|
| 94 |
- debug_printf("directory: %-11.11s", de.name);
|
|
| 95 |
- } else {
|
|
| 96 |
- debug_printf("file: %-11.11s", de.name);
|
|
| 97 |
- memcpy(filename, de.name, 11); // remember last filename |
|
| 98 |
- filename[11] = 0; |
|
| 99 |
- } |
|
| 100 |
- } |
|
| 101 |
- |
|
| 102 |
- // dump last file |
|
| 103 |
- if (DFS_OpenFile(&vi, filename, DFS_READ, sectorBuf, &fi) != 0) {
|
|
| 104 |
- debug_printf("cannot open file %s", filename);
|
|
| 105 |
- return; |
|
| 106 |
- } |
|
| 107 |
- debug_printf("dumping file %s:", filename);
|
|
| 108 |
- while (fi.pointer < fi.filelen) {
|
|
| 109 |
- len = 0; |
|
| 110 |
- DFS_ReadFile(&fi, sectorBuf, buf, &len, sizeof(buf)); |
|
| 111 |
- for (i = 0; i < len; ++i) |
|
| 112 |
- debug_printf_nolf(" %02X", buf[i]);
|
|
| 113 |
- debug_printf("");
|
|
| 114 |
- } |
|
| 115 |
- debug_printf("done", filename);
|
|
| 37 |
+ // run applications |
|
| 38 |
+ AppsRun(); |
|
| 116 | 39 |
} |
| 117 | 40 |
|
| 118 | 41 |
// wait for CF card and work with it |
| 119 | 42 |