276 lines
9.4 KiB
C
276 lines
9.4 KiB
C
//
|
|
// Created by cfif on 27.12.22.
|
|
//
|
|
#include "fs_interface.h"
|
|
//#include "stream.h"
|
|
#include <SystemDelayInterface.h>
|
|
#include "stdlib.h"
|
|
|
|
#define LOGGER env->logger
|
|
#define LOG_SIGN "Файловая система"
|
|
|
|
const char dir_inbox[] = "1:/INBOX/";
|
|
const char dir_outbox[] = "1:/OUTBOX/";
|
|
const char dir_sentbox[] = "1:/SENTBOX/";
|
|
const char dir_temp[] = "1:/TMP/";
|
|
const char dir_rep_out[] = "1:/REPOUT/";
|
|
|
|
const char dir_frag_inbox[] = "1:/FRAGIN/";
|
|
|
|
const char dir_tracert[] = "1:/TRACERT/";
|
|
const char dir_kvitin[] = "1:/KVITIN/";
|
|
|
|
|
|
const char dir_web[] = "1:/WEB/";
|
|
const char dir_almhs[] = "1:/ALMHS/";
|
|
const char dir_logs[] = "1:/LOG/";
|
|
const char dir_logs2[] = "1:/LOG2/";
|
|
|
|
const char file_cur_almhs[] = "1:/ALMHS/CURALM.DAT";
|
|
const char file_tmp_almhs[] = "1:/ALMHS/TMPALM.DAT";
|
|
|
|
const char file_dir_proc[] = "1:/TMP/PROC.JSON";
|
|
|
|
const char file_dir_tmp[] = "1:/TMP/DIR.JSON";
|
|
const char file_setup[] = "1:/SETUP.INI";
|
|
const char file_counter[] = "1:/COUNTER.INI";
|
|
|
|
void FS_Init(tFs *env) {
|
|
// env->logger = slog;
|
|
|
|
//nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
|
//nvic_irq_enable(SDIO1_IRQn, 2, 0);
|
|
|
|
nvic_irq_enable(SDIO1_IRQn, 1, 0);
|
|
NVIC_SetPriority((IRQn_Type) SDIO1_IRQn, 0x0);
|
|
|
|
BYTE work[FF_MAX_SS];
|
|
FRESULT ret;
|
|
DWORD fre_clust, fre_sect, tot_sect;
|
|
FATFS *pt_fs;
|
|
|
|
/*
|
|
ret = f_mkfs("1:", 0, work, sizeof(work));
|
|
if (ret) {
|
|
LoggerPrintf(LOGGER,"Ошибка монтирования файловой системы: %d.\r\n", ret);
|
|
} else {
|
|
LoggerPrintf(LOGGER,"Файловая система создана успешно.\r\n");
|
|
}
|
|
|
|
*/
|
|
|
|
ret = f_mount(&env->fs, "1:", 1);
|
|
if (ret) {
|
|
// LoggerPrintf(LOGGER, "Ошибка монтирования файловой системы: %d.\r\n", ret);
|
|
if (ret == FR_NO_FILESYSTEM) {
|
|
// LoggerPrintf(LOGGER, "Создание файловой системы...\r\n");
|
|
ret = f_mkfs("1:", 0, work, sizeof(work));
|
|
if (ret) {
|
|
// LoggerPrintf(LOGGER, "Ошибка монтирования файловой системы: %d.\r\n", ret);
|
|
} else {
|
|
// LoggerPrintf(LOGGER, "Файловая система создана успешно.\r\n");
|
|
}
|
|
ret = f_mount(NULL, "1:", 1);
|
|
ret = f_mount(&env->fs, "1:", 1);
|
|
if (ret) {
|
|
// LoggerPrintf(LOGGER, "Ошибка монтирования файловой системы: %d.\r\n", ret);
|
|
} else {
|
|
// LoggerPrintf(LOGGER, "Файловая система смонтирована успешно.\r\n");
|
|
}
|
|
} else {
|
|
}
|
|
} else {
|
|
// LoggerPrintf(LOGGER, "Файловая система смонтирована успешно.\r\n");
|
|
}
|
|
|
|
pt_fs = &env->fs;
|
|
ret = f_getfree("1:", &fre_clust, &pt_fs);
|
|
if (ret == FR_OK) {
|
|
tot_sect = (pt_fs->n_fatent - 2) * pt_fs->csize;
|
|
fre_sect = fre_clust * pt_fs->csize;
|
|
// LoggerPrintf(LOGGER, "%10u кб всего на носителе.\r\n%10u кб свободно.\r\n", tot_sect / 2, fre_sect / 2);
|
|
}
|
|
|
|
}
|
|
|
|
void fatTimeToTimeStamp(uint32_t fatTime, struct tm *timestampTM, int32_t grn) {
|
|
tFatTime *pFatTime = (tFatTime *)&fatTime;
|
|
|
|
memset(timestampTM, 0, sizeof(struct tm));
|
|
|
|
timestampTM->tm_year = pFatTime->year + 80;
|
|
timestampTM->tm_mon = pFatTime->month - 1;
|
|
timestampTM->tm_mday = pFatTime->day;
|
|
timestampTM->tm_hour = pFatTime->hour;
|
|
timestampTM->tm_min = pFatTime->minute;
|
|
timestampTM->tm_sec = pFatTime->second >> 1;
|
|
|
|
time_t timestamp = mktime(timestampTM);
|
|
timestamp += grn * 3600;
|
|
|
|
localtime_r(×tamp, timestampTM);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Open or Create a File */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_open_i(
|
|
tFs *fs,
|
|
FIL *fp, /* Pointer to the blank file object */
|
|
const TCHAR *path, /* Pointer to the file name */
|
|
BYTE mode /* Access mode and open mode flags */
|
|
) {
|
|
return f_open(fp, path, mode);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Write File */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_write_i(
|
|
tFs *fs,
|
|
FIL *fp, /* Open file to be written */
|
|
const void *buff, /* Data to be written */
|
|
UINT btw, /* Number of bytes to write */
|
|
UINT *bw /* Number of bytes written */
|
|
) {
|
|
return f_write(fp, buff, btw, bw);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Read File */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_read_i(
|
|
tFs *fs,
|
|
FIL *fp, /* Open file to be read */
|
|
void *buff, /* Data buffer to store the read data */
|
|
UINT btr, /* Number of bytes to read */
|
|
UINT *br /* Number of bytes read */
|
|
) {
|
|
return f_read(fp, buff, btr, br);
|
|
}
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Seek File Read/Write Pointer */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_lseek_i(
|
|
tFs *fs,
|
|
FIL *fp, /* Pointer to the file object */
|
|
FSIZE_t ofs /* File pointer from top of file */
|
|
) {
|
|
return f_lseek(fp, ofs);
|
|
}
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Create a Directory */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_mkdir_i(
|
|
tFs *fs,
|
|
const TCHAR *path
|
|
) {
|
|
return f_mkdir(path);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Close File */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_close_i(
|
|
tFs *fs,
|
|
FIL *fp /* Open file to be closed */
|
|
) {
|
|
return f_close(fp);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Close Directory */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_closedir_i(
|
|
tFs *fs,
|
|
DIR *dp /* Pointer to the directory object to be closed */
|
|
) {
|
|
return f_closedir(dp);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Delete a File/Directory */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_unlink_i(
|
|
tFs *fs,
|
|
const TCHAR *path /* Pointer to the file or directory path */
|
|
) {
|
|
return f_unlink(path);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Read Directory Entries in Sequence */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_readdir_i(
|
|
tFs *fs,
|
|
DIR *dp, /* Pointer to the open directory object */
|
|
FILINFO *fno /* Pointer to file information to return */
|
|
) {
|
|
|
|
return f_readdir(dp, fno);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Create a Directory Object */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_opendir_i(
|
|
tFs *fs,
|
|
DIR *dp, /* Pointer to directory object to create */
|
|
const TCHAR *path /* Pointer to the directory path */
|
|
) {
|
|
return f_opendir(dp, path);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Rename a File/Directory */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_rename_i(
|
|
tFs *fs,
|
|
const TCHAR *path_old, /* Pointer to the object name to be renamed */
|
|
const TCHAR *path_new /* Pointer to the new name */
|
|
) {
|
|
return f_rename(path_old, path_new);
|
|
}
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Find First File */
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
FRESULT f_findfirst_i(
|
|
tFs *fs,
|
|
DIR *dp, /* Pointer to the blank directory object */
|
|
FILINFO *fno, /* Pointer to the file information structure */
|
|
const TCHAR *path, /* Pointer to the directory to open */
|
|
const TCHAR *pattern /* Pointer to the matching pattern */
|
|
) {
|
|
return f_findfirst(dp, fno, path, pattern);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
/* Find Next File */
|
|
/*-----------------------------------------------------------------------*/
|
|
FRESULT f_findnext_i(
|
|
tFs *fs,
|
|
DIR *dp, /* Pointer to the open directory object */
|
|
FILINFO *fno /* Pointer to the file information structure */
|
|
) {
|
|
|
|
return f_findnext(dp, fno);
|
|
}
|