static struct fat_file_struct *log_fd = NULL;
-uint8_t find_file_in_dir(struct fat_fs_struct* fs,
+static uint8_t find_file_in_dir(struct fat_fs_struct* fs,
struct fat_dir_struct* dd, const char* name,
struct fat_dir_entry_struct* dir_entry)
{
return 0;
}
-struct fat_file_struct *open_file_in_dir(struct fat_fs_struct* fs,
+static struct fat_file_struct *open_file_in_dir(struct fat_fs_struct* fs,
struct fat_dir_struct* dd, const char* name)
{
struct fat_dir_entry_struct file_entry;
return fat_open_file(fs, &file_entry);
}
-struct fat_file_struct *open_log_file(void)
+/* open the log file on the SD card */
+int8_t sd_log_open(void)
{
struct fat_file_struct *fd;
struct fat_fs_struct *fs;
#if SD_DEBUG
printf_P(PSTR("MMC/SD initialization failed\n"));
#endif
- return NULL;
+ return -1;
}
/* open first partition */
#if SD_DEBUG
printf_P(PSTR("opening partition failed\n"));
#endif
- return NULL;
+ return -1;
}
}
#if SD_DEBUG
printf_P(PSTR("opening filesystem failed\n"));
#endif
- return NULL;
+ return -1;
}
/* open root directory */
#if SD_DEBUG
printf_P(PSTR("opening root directory failed\n"));
#endif
- return NULL;
+ return -1;
}
- /* print some card information as a boot message */
- //print_disk_info(fs);
-
printf("choose log file name\n");
while (1) {
snprintf(name, sizeof(name), "log%.4d", i++);
fd = open_file_in_dir(fs, dd, name);
if (!fd) {
printf_P(PSTR("error opening "));
- return NULL;
+ return -1;
}
- return fd;
+ return 0;
+}
+
+/* log output */
+intptr_t sd_log_write(const void *buffer, uintptr_t buffer_len)
+{
+ if (log_fd == NULL)
+ return -1;
+
+ return fat_write_file(log_fd, buffer, buffer_len);
}
-struct fat_file_struct *get_log_file(void)
+uint8_t sd_log_enabled(void)
{
- return log_fd;
+ return log_fd != NULL;
}