#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avrio/led.h>
#include <avrio/eefile.h>
#include <avrio/assert.h>
#include <avrio/serial.h>
#define SERIAL_BAUDRATE 38400
#define SERIAL_IOS (SERIAL_DEFAULT + SERIAL_WR)
static char buf1[32];
static char buf2[32];
static const char message[] = "Hello World #%d\n";
static unsigned int test_count;
int
main (int argc, char **argv) {
int r, s;
FILE * f;
uint32_t ulMagic = 0x12345678, ulWord;
sei();
printf_P (PSTR ("\n\n** EEFILE Test **\n"
"EEPROM size: %d bytes\n\n"
"Test %d: Erase previous file > "),
EEPROM_SIZE, ++test_count);
eeprom_write_dword ( (uint32_t *) ucBufferEe, ulMagic);
ulWord = eeprom_read_dword ( (uint32_t *) ucBufferEe);
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: Checks as opening a nonexistent file in read-only returns NULL > "), ++test_count);
printf_P (PSTR ("Success\n\n"));
for (int n = 0; n < 2; n++) {
printf_P (PSTR ("Test %d: Open new file for write > "), ++test_count);
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: Writing to file...\n"), ++test_count);
for (int i = 0; i < 16; i++) {
s = sprintf (buf1, message, i);
r = fprintf (f, message, i);
printf_P (PSTR ("%s"), buf1);
}
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: Close the file... "), ++test_count);
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: Open existing file for read > "), ++test_count);
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: reading file...\n"), ++test_count);
for (int i = 0; i < 16; i++) {
sprintf (buf1, message, i);
fgets (buf2, sizeof (buf2), f);
assert (strcmp (buf1, buf2) == 0);
printf_P (PSTR ("%s"), buf2);
}
printf_P (PSTR ("Success\n\n"));
printf_P (PSTR ("Test %d: Close the file... "), ++test_count);
printf_P (PSTR ("Success\n\n"));
}
for (;;);
return 0;
}