/*
 * David Muller; Germán Alfaro
 * davehmuller@gmail.com; alfaro.germanevera@gmail.com
 */


#ifndef PHFETSOS_SDCARD_H_
#define PHFETSOS_SDCARD_H_

#include "system.h"
#include "microsd.h"
#include "user_io.h"
#include "fatfs/source/diskio.h"
#include "fatfs/source/ff.h" 	// FRESULT is defined in this file
#include "utils/cmdline.h"

// SDCard.c function prototypes:
// return 1 on success, <= 0 on error
int init_uSDCard(void);
int close_uSDCard(void);

void viewFiles(void);
// append buffer to sys_data.fileName on sd card
// buffer must be null terminated
// return 1 on success, <= 0 on error
int appendBufferToSDCard(char const * const buffer);
// append buffer to "error.log" on sd card
// buffer must be null terminated
// return 1 on success, <= 0 on error
int appendBufferToSDCardErrorLog(char const * const buffer);
int appendIsusProfileDataToSDCard(char const * const buffer);
int appendDuraProfileDataToSDCard(char const * const buffer);
const char *StringFromFresult(FRESULT fresult);  //For decoding SD card error messages
int sd_fprintf(FIL *fil, const char *format, ...);
void sd_format(void);

int get_pwd_str(char *dirStr);
//uint32_t get_storage_stat(&ulTotalSize);
FRESULT get_storage_stat(uint32_t *ulTotalSize, uint32_t *ulStorageRemaining);

/*
 * Local function prototypes
 * These return a FRESULT, eg FR_OK on success
 */
int Cmd_cat(int argc, char *argv[]);
int Cmd_cd(int argc, char *argv[]);
int Cmd_chkdsk(int argc, char *argv[]);
int Cmd_cp(int argc, char *argv[]);
int Cmd_format(int argc, char *argv[]);
int Cmd_ls(int argc, char *argv[]);
int Cmd_mkdir(int argc, char *argv[]);
int Cmd_mv(int argc, char *argv[]);
int Cmd_pwd(int argc, char *argv[]);
int Cmd_rm(int argc, char *argv[]);
int Cmd_touch(int argc, char *argv[]);


#endif /* PHFETSOS_SDCARD_H_ */
