generated from Embedded_Projects/Landzo_K60Z_LwIP
73 lines
1.2 KiB
C
73 lines
1.2 KiB
C
#include "FreeRTOS.h"
|
|
#include "ff.h"
|
|
#include "lwip/apps/fs.h"
|
|
#include "task.h"
|
|
|
|
#define ROOT_PATH "0:/WEBROOT"
|
|
|
|
int fs_open_custom(struct fs_file *file, const char *name) {
|
|
FIL *f = pvPortMalloc(sizeof(FIL));
|
|
if (f == NULL) {
|
|
goto err_out;
|
|
}
|
|
|
|
file->pextension = f;
|
|
|
|
char *pathname = pvPortMalloc(255);
|
|
if (pathname == NULL) {
|
|
goto err_out_f;
|
|
}
|
|
|
|
snprintf(pathname, 255, ROOT_PATH "%s", name);
|
|
|
|
if (f_open(f, _T(pathname), FA_READ) != FR_OK) {
|
|
goto err_out_p;
|
|
}
|
|
|
|
FILINFO finfo;
|
|
if(f_stat(_T(pathname), &finfo) != FR_OK) {
|
|
goto err_out_p;
|
|
}
|
|
|
|
file->len = finfo.fsize;
|
|
|
|
return 1;
|
|
|
|
err_out_p:
|
|
vPortFree(pathname);
|
|
err_out_f:
|
|
vPortFree(f);
|
|
err_out:
|
|
return 0;
|
|
}
|
|
|
|
void fs_close_custom(struct fs_file *file) {
|
|
FIL *f = file->pextension;
|
|
|
|
if (f == NULL) {
|
|
return;
|
|
}
|
|
|
|
f_close(f);
|
|
|
|
vPortFree(f);
|
|
}
|
|
|
|
int fs_read_custom(struct fs_file *file, char *buffer, int count) {
|
|
FIL *f = file->pextension;
|
|
|
|
if (f == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
unsigned int actual_read = 0U;
|
|
|
|
FRESULT ret = f_read(f, buffer, count, &actual_read);
|
|
if (ret != FR_OK) {
|
|
return 0;
|
|
}
|
|
|
|
file->index += actual_read;
|
|
|
|
return actual_read;
|
|
} |