|
|
|
@ -3,126 +3,128 @@ |
|
|
|
|
|
|
|
|
|
#include "lib/uart.h" |
|
|
|
|
#include "lib/stream.h" |
|
|
|
|
#include "lib/sd.h" |
|
|
|
|
#include "lib/sd_fat.h" |
|
|
|
|
#include "lib/sd_blockdev.h" |
|
|
|
|
|
|
|
|
|
void test_lowlevel() |
|
|
|
|
{ |
|
|
|
|
uart_puts_P(PSTR("*** SD CARD SPI TEST ***\r\n")); |
|
|
|
|
|
|
|
|
|
if (!sd_init()) |
|
|
|
|
{ |
|
|
|
|
put_str_P(uart, PSTR("Failed to init.")); |
|
|
|
|
while (1); |
|
|
|
|
} |
|
|
|
|
//void test_lowlevel()
|
|
|
|
|
//{
|
|
|
|
|
// uart_puts_P(PSTR("*** SD CARD SPI TEST ***\r\n"));
|
|
|
|
|
|
|
|
|
|
uint8_t text[512]; |
|
|
|
|
// if (!sd_init())
|
|
|
|
|
// {
|
|
|
|
|
// put_str_P(uart, PSTR("Failed to init."));
|
|
|
|
|
// while (1);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// uint8_t text[512];
|
|
|
|
|
|
|
|
|
|
put_str_P(uart, PSTR("\r\nReading...\r\n")); |
|
|
|
|
if (sd_read(0, 0, text, 0, 512)) |
|
|
|
|
{ |
|
|
|
|
put_bytes(uart, text, 512); |
|
|
|
|
put_nl(uart); |
|
|
|
|
put_nl(uart); |
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 60; i++) |
|
|
|
|
{ |
|
|
|
|
text[i] = ('A' + i); |
|
|
|
|
} |
|
|
|
|
// put_str_P(uart, PSTR("\r\nReading...\r\n"));
|
|
|
|
|
// if (sd_read(0, 0, text, 0, 512))
|
|
|
|
|
// {
|
|
|
|
|
// put_bytes(uart, text, 512);
|
|
|
|
|
// put_nl(uart);
|
|
|
|
|
// put_nl(uart);
|
|
|
|
|
|
|
|
|
|
put_str_P(uart, PSTR("\r\nWriting...\r\n")); |
|
|
|
|
sd_write(1, text); |
|
|
|
|
put_str_P(uart, PSTR("\r\nWrite done.\r\n")); |
|
|
|
|
// for (uint8_t i = 0; i < 60; i++)
|
|
|
|
|
// {
|
|
|
|
|
// text[i] = ('A' + i);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i < 512; i++) |
|
|
|
|
{ |
|
|
|
|
text[i] = 0; |
|
|
|
|
} |
|
|
|
|
// put_str_P(uart, PSTR("\r\nWriting...\r\n"));
|
|
|
|
|
// sd_write(1, text);
|
|
|
|
|
// put_str_P(uart, PSTR("\r\nWrite done.\r\n"));
|
|
|
|
|
|
|
|
|
|
if (sd_read(1, 0, text, 0, 512)) |
|
|
|
|
{ |
|
|
|
|
put_str_P(uart, PSTR("\r\nWritten, result: \r\n")); |
|
|
|
|
put_bytes(uart, text, 512); |
|
|
|
|
put_nl(uart); |
|
|
|
|
put_nl(uart); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
put_str_P(uart, PSTR("\r\nRead failed.\r\n")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
put_str_P(uart, PSTR("Failed to read.\r\n")); |
|
|
|
|
while (1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// for (uint16_t i = 0; i < 512; i++)
|
|
|
|
|
// {
|
|
|
|
|
// text[i] = 0;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (sd_read(1, 0, text, 0, 512))
|
|
|
|
|
// {
|
|
|
|
|
// put_str_P(uart, PSTR("\r\nWritten, result: \r\n"));
|
|
|
|
|
// put_bytes(uart, text, 512);
|
|
|
|
|
// put_nl(uart);
|
|
|
|
|
// put_nl(uart);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// put_str_P(uart, PSTR("\r\nRead failed.\r\n"));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// put_str_P(uart, PSTR("Failed to read.\r\n"));
|
|
|
|
|
// while (1);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
void try_reading_dirs(FAT16_FILE* f ) |
|
|
|
|
{ |
|
|
|
|
char buf[200]; |
|
|
|
|
|
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
if (!fat16_is_regular(f)) continue; |
|
|
|
|
//void try_reading_dirs(FFILE* f )
|
|
|
|
|
//{
|
|
|
|
|
// char buf[200];
|
|
|
|
|
|
|
|
|
|
if (f->type == FT_SUBDIR) |
|
|
|
|
{ |
|
|
|
|
vt_color_fg(VT_MAGENTA); |
|
|
|
|
uart_puts_P(PSTR("\r\n--- DIRECTORY: ")); |
|
|
|
|
uart_puts(fat16_dispname(f, buf)); |
|
|
|
|
uart_puts_P(PSTR(" ---\r\n")); |
|
|
|
|
vt_color_reset(); |
|
|
|
|
// do
|
|
|
|
|
// {
|
|
|
|
|
// if (!ff_is_regular(f)) continue;
|
|
|
|
|
|
|
|
|
|
FSAVEPOS p = fat16_savepos(f); |
|
|
|
|
// if (f->type == FT_SUBDIR)
|
|
|
|
|
// {
|
|
|
|
|
// vt_color_fg(VT_MAGENTA);
|
|
|
|
|
// uart_puts_P(PSTR("\r\n--- DIRECTORY: "));
|
|
|
|
|
// uart_puts(ff_dispname(f, buf));
|
|
|
|
|
// uart_puts_P(PSTR(" ---\r\n"));
|
|
|
|
|
// vt_color_reset();
|
|
|
|
|
|
|
|
|
|
if (fat16_opendir(f)) |
|
|
|
|
{ |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
if (!fat16_is_regular(f)) continue; |
|
|
|
|
// FSAVEPOS p = ff_savepos(f);
|
|
|
|
|
|
|
|
|
|
// if (ff_opendir(f))
|
|
|
|
|
// {
|
|
|
|
|
// do
|
|
|
|
|
// {
|
|
|
|
|
// if (!ff_is_regular(f)) continue;
|
|
|
|
|
|
|
|
|
|
// vt_color_fg(VT_GREEN);
|
|
|
|
|
// uart_puts_P(PSTR(">> --- File: "));
|
|
|
|
|
// uart_puts(ff_dispname(f, buf));
|
|
|
|
|
// uart_puts_P(PSTR(" ---\r\n"));
|
|
|
|
|
// vt_color_reset();
|
|
|
|
|
// }
|
|
|
|
|
// while (ff_next(f));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// ff_reopen(f, &p);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// vt_color_fg(VT_YELLOW);
|
|
|
|
|
// uart_puts_P(PSTR("--- File: "));
|
|
|
|
|
// uart_puts(ff_dispname(f, buf));
|
|
|
|
|
// uart_puts_P(PSTR(" ---\r\n"));
|
|
|
|
|
// vt_color_reset();
|
|
|
|
|
|
|
|
|
|
// uint16_t len = 0;
|
|
|
|
|
// if ((len = ff_read(f, buf, 199)))
|
|
|
|
|
// {
|
|
|
|
|
// buf[len] = 0;
|
|
|
|
|
// uart_puts(buf);
|
|
|
|
|
// put_nl(uart);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// uart_puts_P(PSTR("COULD NOT READ.\n"));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// while (ff_next(f));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
vt_color_fg(VT_GREEN); |
|
|
|
|
uart_puts_P(PSTR(">> --- File: ")); |
|
|
|
|
uart_puts(fat16_dispname(f, buf)); |
|
|
|
|
uart_puts_P(PSTR(" ---\r\n")); |
|
|
|
|
vt_color_reset(); |
|
|
|
|
} |
|
|
|
|
while (fat16_next(f)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fat16_reopen(f, &p); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
vt_color_fg(VT_YELLOW); |
|
|
|
|
uart_puts_P(PSTR("--- File: ")); |
|
|
|
|
uart_puts(fat16_dispname(f, buf)); |
|
|
|
|
uart_puts_P(PSTR(" ---\r\n")); |
|
|
|
|
vt_color_reset(); |
|
|
|
|
|
|
|
|
|
uint16_t len = 0; |
|
|
|
|
if ((len = fat16_read(f, buf, 199))) |
|
|
|
|
{ |
|
|
|
|
buf[len] = 0; |
|
|
|
|
uart_puts(buf); |
|
|
|
|
put_nl(uart); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
uart_puts_P(PSTR("COULD NOT READ.\n")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while (fat16_next(f)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Init a file pointer */
|
|
|
|
|
FAT16_FILE _f; |
|
|
|
|
FAT16_FILE* f = &_f; |
|
|
|
|
FFILE _f; |
|
|
|
|
FFILE* f = &_f; |
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
|
{ |
|
|
|
@ -135,7 +137,7 @@ void main() |
|
|
|
|
vt_color_reset(); |
|
|
|
|
vt_attr_reset(); |
|
|
|
|
|
|
|
|
|
if (!(sdfat_init())) |
|
|
|
|
if (!(sdf_init())) |
|
|
|
|
{ |
|
|
|
|
uart_puts_P(PSTR("Failed to init.\r\n")); |
|
|
|
|
while (1); |
|
|
|
@ -143,32 +145,37 @@ void main() |
|
|
|
|
|
|
|
|
|
uart_puts_P(PSTR("SD card with FAT16 inited.\r\n")); |
|
|
|
|
|
|
|
|
|
sdf_root(f); |
|
|
|
|
|
|
|
|
|
// do
|
|
|
|
|
// {
|
|
|
|
|
// ff_delete(f);
|
|
|
|
|
// }
|
|
|
|
|
// while (ff_next(f));
|
|
|
|
|
|
|
|
|
|
// Read and print disk label
|
|
|
|
|
char lbl[16]; |
|
|
|
|
sdfat_disk_label(lbl); |
|
|
|
|
put_str(uart, lbl); |
|
|
|
|
put_nl(uart); |
|
|
|
|
if (!ff_open(f, "LOG13.TXT")) |
|
|
|
|
{ |
|
|
|
|
ff_newfile(f, "LOG13.TXT"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sdfat_root(f); |
|
|
|
|
ff_seek(f, f->size); |
|
|
|
|
|
|
|
|
|
try_reading_dirs(f); |
|
|
|
|
ff_write_str(f, "\r\n--- START OF SESSION ---\n"); |
|
|
|
|
|
|
|
|
|
// if (fat16_find(f, "TESTFIL2.TXT"))
|
|
|
|
|
// {
|
|
|
|
|
// fat16_seek(f, f->size);
|
|
|
|
|
// fat16_write(f, "ONE MORE THING.\n", 16);
|
|
|
|
|
// sdfat_flush();
|
|
|
|
|
// Change size beforehand, to make write faster
|
|
|
|
|
sdf_open_stream(f); |
|
|
|
|
|
|
|
|
|
// uart_puts_P(PSTR("Write OK!\r\n"));
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// uart_puts_P(PSTR("Failed to open file.\r\n"));
|
|
|
|
|
// while (1);
|
|
|
|
|
// }
|
|
|
|
|
for (uint8_t i = 0; i < 0xFF; i++) |
|
|
|
|
{ |
|
|
|
|
put_u8(sdf_stream, i); |
|
|
|
|
put_nl(sdf_stream); |
|
|
|
|
put_u8(uart, i); |
|
|
|
|
put_nl(uart); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ff_flush_file(f); |
|
|
|
|
|
|
|
|
|
uart_puts("Done.\n"); |
|
|
|
|
|
|
|
|
|
while (1); |
|
|
|
|
} |
|
|
|
|