Files
mkrtos-real/mkrtos_user/server/fs/fatfs/main.c

64 lines
1.5 KiB
C
Raw Normal View History

2023-12-02 00:27:57 +08:00
#include "cons_cli.h"
2023-09-24 01:26:07 +08:00
#include "fs_rpc.h"
2025-02-13 13:28:16 +08:00
#include "ns_cli.h"
#include "u_env.h"
#include "u_hd_man.h"
#include "u_log.h"
#include "u_prot.h"
#include "u_rpc_svr.h"
#include <assert.h>
2023-09-24 01:26:07 +08:00
#include <ff.h>
2023-09-21 21:44:17 +08:00
#include <stdio.h>
#include <stdlib.h>
2025-02-13 13:28:16 +08:00
#include "u_hd_man.h"
2025-01-03 18:29:25 +08:00
#include <u_fast_ipc.h>
2025-02-13 13:28:16 +08:00
2025-01-03 18:29:25 +08:00
#define STACK_COM_ITME_SIZE (2048)
ATTR_ALIGN(8)
uint8_t stack_coms[STACK_COM_ITME_SIZE];
uint8_t msg_buf_coms[MSG_BUG_LEN];
2025-02-13 13:28:16 +08:00
static obj_handler_t com_th_obj;
2025-01-03 18:29:25 +08:00
void fast_ipc_init(void)
{
2025-02-13 13:28:16 +08:00
com_th_obj = handler_alloc();
assert(com_th_obj != HANDLER_INVALID);
u_fast_ipc_init(stack_coms, msg_buf_coms, 1, STACK_COM_ITME_SIZE, &com_th_obj);
2025-01-03 18:29:25 +08:00
}
2023-09-09 12:58:57 +08:00
static FATFS fs;
static MKFS_PARM defopt = {FM_ANY, 0, 0, 0};
2023-09-07 23:47:34 +08:00
2023-09-08 21:39:02 +08:00
int main(int args, char *argv[])
{
2023-12-02 22:02:56 +08:00
obj_handler_t hd;
int ret;
2025-01-03 18:29:25 +08:00
fast_ipc_init();
2023-12-02 22:02:56 +08:00
ret = rpc_meta_init(THREAD_MAIN, &hd);
assert(ret >= 0);
2023-12-02 22:02:56 +08:00
fs_svr_init();
ns_register("/mnt", hd, 0);
2023-09-09 12:58:57 +08:00
FRESULT res = f_mount(&fs, "0:", 1);
2023-09-22 00:14:27 +08:00
2025-02-13 13:28:16 +08:00
if (res != FR_OK) {
assert(sizeof(fs.win) >= FF_MAX_SS);
res = f_mkfs("0:", &defopt, (void *)(fs.win), FF_MAX_SS); // 第三个参数可以设置成NULL默认使用heap memory
2025-02-13 13:28:16 +08:00
if (res != FR_OK) {
2023-12-02 00:27:57 +08:00
cons_write_str("f_mkfs err.\n");
exit(-1);
2025-02-13 13:28:16 +08:00
} else {
2023-09-09 12:58:57 +08:00
res = f_mount(&fs, "0:", 1);
2025-02-13 13:28:16 +08:00
if (res != FR_OK) {
2023-12-02 00:27:57 +08:00
cons_write_str("f_mount err.\n");
exit(-1);
2023-09-09 12:58:57 +08:00
}
}
}
cons_write_str("fatfs mount success\n");
2023-09-24 01:26:07 +08:00
fs_svr_loop();
return 0;
2023-09-08 21:39:02 +08:00
}