Long file names, and date-time set on creation from RTC.
This commit is contained in:
parent
a5531fb1be
commit
fd80b729bd
|
@ -113,7 +113,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_LFN 0
|
#define FF_USE_LFN 1
|
||||||
#define FF_MAX_LFN 127
|
#define FF_MAX_LFN 127
|
||||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||||
/
|
/
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||||
|
|
||||||
|
|
||||||
#define FF_STR_VOLUME_ID 1
|
#define FF_STR_VOLUME_ID 2
|
||||||
// #define FF_VOLUME_STRS "SD","SD2"
|
// #define FF_VOLUME_STRS "SD","SD2"
|
||||||
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
||||||
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
||||||
|
@ -237,7 +237,7 @@
|
||||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_NORTC 1
|
#define FF_FS_NORTC 0
|
||||||
#define FF_NORTC_MON 2
|
#define FF_NORTC_MON 2
|
||||||
#define FF_NORTC_MDAY 1
|
#define FF_NORTC_MDAY 1
|
||||||
#define FF_NORTC_YEAR 2024
|
#define FF_NORTC_YEAR 2024
|
||||||
|
|
|
@ -93,3 +93,20 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff) {
|
||||||
INFO1("disk_ioctl: %d", result);
|
INFO1("disk_ioctl: %d", result);
|
||||||
return bdev_to_fatfs(result);
|
return bdev_to_fatfs(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD get_fattime(void) {
|
||||||
|
t_time time;
|
||||||
|
rtc_get_time(&time);
|
||||||
|
|
||||||
|
DWORD timestamp = (DWORD)(time.year - 1980) << 25 |
|
||||||
|
(DWORD)(time.month) << 21 |
|
||||||
|
(DWORD)time.day << 16 |
|
||||||
|
(DWORD)time.hour << 11 |
|
||||||
|
(DWORD)time.minute << 5 |
|
||||||
|
(DWORD)time.second >> 1;
|
||||||
|
|
||||||
|
INFO1("get_fattime %08lX", timestamp);
|
||||||
|
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
135
src/toolbox.c
135
src/toolbox.c
|
@ -305,26 +305,58 @@ void dump(uint8_t * buffer, int count) {
|
||||||
printf(" %s\n", char_buffer);
|
printf(" %s\n", char_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
union fatfs_date_u {
|
||||||
short result;
|
struct {
|
||||||
short i;
|
unsigned int day : 5;
|
||||||
char message[256];
|
unsigned int month : 4;
|
||||||
|
unsigned int year : 7;
|
||||||
|
} s;
|
||||||
|
short date;
|
||||||
|
};
|
||||||
|
|
||||||
initialize();
|
union fatfs_time_u {
|
||||||
|
struct {
|
||||||
|
unsigned int second : 5;
|
||||||
|
unsigned int minute : 6;
|
||||||
|
unsigned int hour : 5;
|
||||||
|
} s;
|
||||||
|
short time;
|
||||||
|
};
|
||||||
|
|
||||||
short fd = fsys_opendir("0:/");
|
void print_fatfs_datetime(short date, short time) {
|
||||||
|
union fatfs_date_u fat_date;
|
||||||
|
union fatfs_time_u fat_time;
|
||||||
|
|
||||||
|
fat_date.date = date;
|
||||||
|
fat_time.time = time;
|
||||||
|
|
||||||
|
printf("%04d-%02d-%02d %02d:%02d ", fat_date.s.year + 1980, fat_date.s.month, fat_date.s.day, fat_time.s.hour, fat_time.s.minute);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_directory() {
|
||||||
|
printf("\nDirectory for /sd0/\n");
|
||||||
|
short fd = fsys_opendir("/sd0/");
|
||||||
if (fd > -1) {
|
if (fd > -1) {
|
||||||
INFO("fsys_opendir");
|
INFO("fsys_opendir");
|
||||||
|
|
||||||
short result = fsys_readdir(fd, &dir);
|
short result = fsys_readdir(fd, &dir);
|
||||||
while (result == 0) {
|
while ((result == 0) && (dir.name[0] != 0)) {
|
||||||
if (dir.name[0] != 0) {
|
if (dir.name[0] == 0) {
|
||||||
printf("%s\n", dir.name);
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
|
if ((dir.attributes & FSYS_AM_SYS) == 0) {
|
||||||
|
print_fatfs_datetime(dir.date, dir.time);
|
||||||
|
printf(" %4ld ", dir.size);
|
||||||
|
|
||||||
result = fsys_readdir(fd, &dir);
|
if (dir.attributes & FSYS_AM_DIR) {
|
||||||
|
printf(" %s/\n", dir.name);
|
||||||
|
} else {
|
||||||
|
printf(" %s\n", dir.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = fsys_readdir(fd, &dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fsys_closedir(fd);
|
fsys_closedir(fd);
|
||||||
|
@ -332,38 +364,71 @@ int main(int argc, char * argv[]) {
|
||||||
} else {
|
} else {
|
||||||
ERROR1("Could not open directory %d", fd);
|
ERROR1("Could not open directory %d", fd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// kbd_init();
|
void create_sample_file(const char * path) {
|
||||||
// printf("\n> ");
|
printf("\nTrying to create: %s\n", path);
|
||||||
// chan_ioctrl(0, CON_IOCTRL_ECHO_OFF, 0, 0);
|
short fd = fsys_open(path, FSYS_CREATE_ALWAYS | FSYS_WRITE);
|
||||||
// while (!kbd_break()) {
|
if (fd > 0) {
|
||||||
// char c = chan_read_b(0);
|
char message[80];
|
||||||
// if (c != 0) {
|
printf("Got channel #%d\n", fd);
|
||||||
// chan_write_b(0, c);
|
sprintf(message, "Hello, world!\n");
|
||||||
// }
|
short result = chan_write(fd, (uint8_t *)message, strlen(message));
|
||||||
// }
|
printf("Wrote %d characters.\n", result);
|
||||||
|
fsys_close(fd);
|
||||||
|
|
||||||
// INFO("bdev_init");
|
} else {
|
||||||
// short status = bdev_init(BDEV_SD0);
|
printf("Could not create file: %d\n", fd);
|
||||||
// if (status) {
|
}
|
||||||
// ERROR1("bdev_init returned %d", status);
|
}
|
||||||
// }
|
|
||||||
// INFO("bdev_read");
|
void read_sample_file(const char * path) {
|
||||||
// status = bdev_read(BDEV_SD0, 97, buffer, 512);
|
printf("\nContents of %s:\n", path);
|
||||||
// if (status < 512) {
|
short fd = fsys_open(path, FSYS_READ);
|
||||||
// ERROR1("bdev_read returned %d", status);
|
if (fd >= 0) {
|
||||||
// }
|
short c = 0;
|
||||||
// INFO("Read.");
|
short status;
|
||||||
// dump(buffer, 512);
|
do {
|
||||||
|
c = chan_read_b(fd);
|
||||||
|
chan_write_b(0, (uint8_t)c);
|
||||||
|
status = chan_status(fd);
|
||||||
|
} while ((status & CDEV_STAT_EOF) == 0);
|
||||||
|
chan_close(fd);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("Could not open file: %d\n", fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char * argv[]) {
|
||||||
|
short result;
|
||||||
|
short i;
|
||||||
|
char message[256];
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
print_directory();
|
||||||
|
|
||||||
|
printf("\nfsys_rename(\"/sd0/hello.txt\", \"/sd0/renamed.txt\")");
|
||||||
|
fsys_rename("/sd0/hello.txt", "/sd0/renamed.txt");
|
||||||
|
print_directory();
|
||||||
|
|
||||||
// printf("\nDone.\n");
|
printf("\nfsys_delete(\"/sd0/renamed.txt\")");
|
||||||
|
fsys_delete("/sd0/renamed.txt");
|
||||||
|
print_directory();
|
||||||
|
|
||||||
|
printf("\nCreating /sd0/hello.txt\n");
|
||||||
|
create_sample_file("/sd0/hello.txt");
|
||||||
|
print_directory();
|
||||||
|
|
||||||
|
read_sample_file("/sd0/test.txt");
|
||||||
|
read_sample_file("/sd0/hello.txt");
|
||||||
|
|
||||||
// Attempt to start up the user code
|
// Attempt to start up the user code
|
||||||
// log(LOG_INFO, "Looking for user startup code:");
|
// log(LOG_INFO, "Looking for user startup code:");
|
||||||
// boot_launch();
|
// boot_launch();
|
||||||
|
|
||||||
INFO("Done.");
|
printf("Done.\n");
|
||||||
|
|
||||||
#ifdef _CALYPSI_MCP_DEBUGGER
|
#ifdef _CALYPSI_MCP_DEBUGGER
|
||||||
extern int CalypsiDebugger(void);
|
extern int CalypsiDebugger(void);
|
||||||
|
|
Loading…
Reference in a new issue