add mr-library
This commit is contained in:
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@@ -192,7 +192,14 @@
|
||||
"cstdlib": "c",
|
||||
"locale": "c",
|
||||
"uart4.h": "c",
|
||||
"u_queue.h": "c"
|
||||
"u_queue.h": "c",
|
||||
"dirent.h": "c",
|
||||
"iosfwd": "c",
|
||||
"drv_adc.h": "c",
|
||||
"mrboard.h": "c",
|
||||
"mrapi.h": "c",
|
||||
"device_port.h": "c",
|
||||
"spi.h": "c"
|
||||
},
|
||||
"cortex-debug.showRTOS": false,
|
||||
"cortex-debug.variableUseNaturalFormat": false,
|
||||
|
||||
201
mkrtos_doc/coding_style.md
Normal file
201
mkrtos_doc/coding_style.md
Normal file
@@ -0,0 +1,201 @@
|
||||
## 格式与风格
|
||||
|
||||
### 缩进与换行
|
||||
|
||||
1. 仅使用4个空格进行代码缩进,禁止使用tab键。
|
||||
2. 每行代码长度控制在120个字符内,超过换行,下一行缩进4个空格。
|
||||
3. 大括号`{`与`}`单独占一行。
|
||||
例如:
|
||||
|
||||
```c
|
||||
if (condition)
|
||||
{
|
||||
do_something();
|
||||
}
|
||||
|
||||
void func(void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### 空格与空行
|
||||
|
||||
1. 操作符两边各加一个空格,自加自减不加空格。
|
||||
例如:
|
||||
|
||||
```c
|
||||
x = 1;
|
||||
a + b;
|
||||
i++;
|
||||
```
|
||||
|
||||
2. 逗号`,`后加一个空格。
|
||||
例如:
|
||||
|
||||
```c
|
||||
void foo(int a, char b);
|
||||
```
|
||||
|
||||
### 头文件
|
||||
|
||||
1. 头文件为避免重复包含,使用`_FILE_H_`宏进行保护。
|
||||
2. 头文件按字母顺序导入,库文件优先。库头文件使用`<>`导入,其余头文件使用`""`导入。
|
||||
例如:
|
||||
|
||||
```c
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "bar.h"
|
||||
#include "foo.h"
|
||||
```
|
||||
|
||||
## 命名规范
|
||||
|
||||
### 类型
|
||||
|
||||
1. 枚举类型命名全部小写,下划线分隔,枚举常量首字母大写。
|
||||
例如:
|
||||
|
||||
```c
|
||||
enum color_type
|
||||
{
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
Light_Pink,
|
||||
};
|
||||
```
|
||||
|
||||
2. 结构体、联合体、类型定义命名小写,下划线分隔。
|
||||
例如:
|
||||
|
||||
```c
|
||||
struct foo
|
||||
{
|
||||
char *name;
|
||||
union coordinate
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### 函数与变量
|
||||
|
||||
1. 函数命名小写,下划线分隔。
|
||||
例如:
|
||||
|
||||
```c
|
||||
void do_something(int arg1, char arg2)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
2. 变量命名小写,下划线分隔
|
||||
例如:
|
||||
|
||||
```c
|
||||
int num_times;
|
||||
char *pointer;
|
||||
```
|
||||
|
||||
3. 宏定义全部大写,下划线分隔。宏函数遵守函数命名规则。
|
||||
例如:
|
||||
|
||||
```c
|
||||
#define PI 3.14
|
||||
```
|
||||
|
||||
4. typedef定义使用类型名加`_t`后缀, 结构体等默认`_t`为指针类型。
|
||||
例如:
|
||||
|
||||
```c
|
||||
typedef unsigned int mr_uint32_t;
|
||||
typedef struct mr_object *mr_object_t;
|
||||
```
|
||||
|
||||
### 文件名
|
||||
|
||||
1. 文件名使用小写字母和下划线,不使用大写字母,配置文件以`config`结尾。
|
||||
例如:
|
||||
|
||||
```c
|
||||
foo_bar.c
|
||||
test_case.h
|
||||
mrconfig.h
|
||||
```
|
||||
|
||||
### 宏
|
||||
|
||||
1. 宏定义全部大写,下划线分隔,用户可修改的宏配置需加`CFG`标识。
|
||||
例如:
|
||||
|
||||
```c
|
||||
#define MR_CFG_OBJECT_NAME_SIZE 15
|
||||
```
|
||||
|
||||
## 注释规范
|
||||
|
||||
1. 单行注释使用`/* */`,多行注释使用:
|
||||
|
||||
```c
|
||||
/*
|
||||
* 多行注释
|
||||
* 第二行
|
||||
*/
|
||||
```
|
||||
|
||||
2. 函数注释使用Doxygen风格:
|
||||
|
||||
```c
|
||||
/**
|
||||
* @brief This function change the type of the object.
|
||||
*
|
||||
* @param object The object to be changed.
|
||||
* @param type The type of the object.
|
||||
*
|
||||
* @return MR_ERR_OK on success, otherwise an error code.
|
||||
*/
|
||||
mr_err_t mr_object_add(mr_object_t object, const char *name, enum mr_object_type type)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
3. 结构体,宏等定义需添加注释:
|
||||
|
||||
```c
|
||||
/**
|
||||
* @struct Object
|
||||
*/
|
||||
struct mr_object
|
||||
{
|
||||
char name[MR_CFG_OBJECT_NAME_SIZE];
|
||||
enum mr_object_type type;
|
||||
struct mr_list list;
|
||||
};
|
||||
|
||||
/**
|
||||
* @def Null pointer
|
||||
*/
|
||||
#define MR_NULL (void *)0
|
||||
```
|
||||
|
||||
4. 函数声明时需用注释将所有同类函数包含:
|
||||
|
||||
```c
|
||||
/**
|
||||
* @addtogroup Object
|
||||
* @{
|
||||
*/
|
||||
mr_object_container_t mr_object_container_find(enum mr_object_type type);
|
||||
mr_object_t mr_object_find(const char *name, enum mr_object_type type);
|
||||
mr_err_t mr_object_add(mr_object_t object, const char *name, enum mr_object_type type);
|
||||
mr_err_t mr_object_remove(mr_object_t object);
|
||||
mr_err_t mr_object_change_type(mr_object_t object, enum mr_object_type type);
|
||||
void mr_object_rename(mr_object_t object, char *name);
|
||||
/** @} */
|
||||
```
|
||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
# -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w \
|
||||
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
# add_subdirectory(dietlibc)
|
||||
@@ -15,4 +15,5 @@ add_subdirectory(libc_backend)
|
||||
add_subdirectory(mlibc)
|
||||
add_subdirectory(cpio)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(mr-library)
|
||||
# add_subdirectory(at_device)
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
2
mkrtos_user/lib/mlibc/configure
vendored
2
mkrtos_user/lib/mlibc/configure
vendored
@@ -576,7 +576,7 @@ tryldflag LDFLAGS_AUTO -Wl,--sort-common
|
||||
|
||||
# When linking shared library, drop dummy weak definitions that were
|
||||
# replaced by strong definitions from other translation units.
|
||||
tryldflag LDFLAGS_AUTO -Wl,--gc-sections
|
||||
tryldflag LDFLAGS_AUTO
|
||||
|
||||
# Some patched GCC builds have these defaults messed up...
|
||||
tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
1
mkrtos_user/lib/mr-library
Submodule
1
mkrtos_user/lib/mr-library
Submodule
Submodule mkrtos_user/lib/mr-library added at 6c804ce5f6
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_STDPERIPH_DRIVER=1 -DSTM32F10X_XL \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef struct app_info
|
||||
|
||||
static inline app_info_t *app_info_get(void *addr)
|
||||
{
|
||||
app_info_t *app = (app_info_t *)addr;
|
||||
app_info_t *app = (app_info_t *)((umword_t)addr & (~0x3UL));
|
||||
const char *magic = APP_MAGIC;
|
||||
for (int i = 0; i < sizeof(app->magic) - 1; i++)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "u_rpc_svr.h"
|
||||
#include "u_types.h"
|
||||
|
||||
#include "u_rpc.h"
|
||||
typedef struct fs
|
||||
{
|
||||
rpc_svr_obj_t svr;
|
||||
@@ -16,3 +16,10 @@ int fs_svr_read(int fd, void *buf, size_t len);
|
||||
int fs_svr_write(int fd, void *buf, size_t len);
|
||||
void fs_svr_close(int fd);
|
||||
int fs_svr_lseek(int fd, int offs, int whence);
|
||||
int fs_svr_ftruncate(int fd, off_t off);
|
||||
void fs_svr_sync(int fd);
|
||||
int fs_svr_readdir(int fd, dirent_t *dir);
|
||||
int fs_svr_mkdir(char *path);
|
||||
int fs_svr_unlink(char *path);
|
||||
int fs_svr_renmae(char *oldname, char *newname);
|
||||
int fs_svr_fstat(int fd, stat_t *stat);
|
||||
|
||||
@@ -5,8 +5,22 @@
|
||||
#define NS_QUERY_OP ((uint16_t)1) //!< ns请求
|
||||
|
||||
#define FS_PROT 0x0002
|
||||
#define FS_OPEN ((uint16_t)0)
|
||||
#define FS_CLOSE ((uint16_t)1)
|
||||
#define FS_READ ((uint16_t)2)
|
||||
#define FS_WRITE ((uint16_t)3)
|
||||
#define FS_LSEEK ((uint16_t)4)
|
||||
#define FS_OPEN ((uint16_t)0) //!< 打开文件
|
||||
#define FS_CLOSE ((uint16_t)1) //!< 关闭文件
|
||||
#define FS_READ ((uint16_t)2) //!< 读取文件
|
||||
#define FS_WRITE ((uint16_t)3) //!< 写入文件
|
||||
#define FS_LSEEK ((uint16_t)4) //!< 写入文件位置
|
||||
#define FS_FTRUNCATE ((uint16_t)5) //!< 文件截断
|
||||
#define FS_SYNC ((uint16_t)6) //!< 文件同步
|
||||
#define FS_OPENDIR ((uint16_t)7) //!< 打开目录,应该使用open打开,保留该接口*
|
||||
#define FS_CLOSEDIR ((uint16_t)8) //!< 关闭目录,应该使用closedir,保留该接口*
|
||||
#define FS_READDIR ((uint16_t)9) //!< 读取目录
|
||||
#define FS_MKDIR ((uint16_t)10) //!< 新建目录
|
||||
#define FS_UNLINK ((uint16_t)11) //!< 删除目录或者文件
|
||||
#define FS_RENAME ((uint16_t)12) //!< 重命名
|
||||
#define FS_STAT ((uint16_t)13) //!< 获取文件状态
|
||||
#define FS_CHMOD ((uint16_t)14) //!< 改变权限 暂不实现*
|
||||
#define FS_UTIME ((uint16_t)15) //!< 修改时间 暂不实现*
|
||||
#define FS_CHDIR ((uint16_t)16) //!< 进入某个目录,可在客户端实现 暂不实现*
|
||||
#define FS_CWDIR ((uint16_t)17) //!< 获取当前目录,可在客户端实现 暂不实现*
|
||||
#define FS_MOUNT ((uint16_t)18) //!< 挂载节点 暂不实现*
|
||||
|
||||
@@ -81,9 +81,91 @@ RPC_GENERATION_DISPATCH3(fs_t, FS_LSEEK, lseek,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, whence)
|
||||
|
||||
/*ftruncate*/
|
||||
RPC_GENERATION_OP2(fs_t, FS_FTRUNCATE, ftruncate,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, offs)
|
||||
{
|
||||
int ret = fs_svr_ftruncate(fd->data, offs->data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_FTRUNCATE, ftruncate,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, offs)
|
||||
|
||||
/*fsync*/
|
||||
RPC_GENERATION_OP1(fs_t, FS_SYNC, fsync,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd)
|
||||
{
|
||||
fs_svr_sync(fd->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH1(fs_t, FS_SYNC, fsync,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd)
|
||||
/*readdir*/
|
||||
RPC_GENERATION_OP2(fs_t, FS_READDIR, readdir,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_dirent_t_t, rpc_dirent_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, dir)
|
||||
{
|
||||
return fs_svr_readdir(fd, &dir->data);
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_READDIR, readdir,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_dirent_t_t, rpc_dirent_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, dir)
|
||||
|
||||
/*mkdir*/
|
||||
RPC_GENERATION_OP1(fs_t, FS_MKDIR, mkdir,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path)
|
||||
{
|
||||
path->data[path->len - 1] = 0;
|
||||
return fs_svr_mkdir(path->data);
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH1(fs_t, FS_MKDIR, mkdir,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path)
|
||||
/*unlink*/
|
||||
RPC_GENERATION_OP1(fs_t, FS_UNLINK, unlink,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path)
|
||||
{
|
||||
path->data[path->len - 1] = 0;
|
||||
return fs_svr_unlink(path->data);
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH1(fs_t, FS_UNLINK, unlink,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path)
|
||||
/*rename*/
|
||||
RPC_GENERATION_OP2(fs_t, FS_RENAME, rename,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, oldpath,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, newpath)
|
||||
{
|
||||
oldpath->data[oldpath->len - 1] = 0;
|
||||
newpath->data[newpath->len - 1] = 0;
|
||||
return fs_svr_renmae((char *)(oldpath->data), (char *)(newpath->data));
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_RENAME, rename,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, oldpath,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, newpath)
|
||||
|
||||
/*fstat*/
|
||||
RPC_GENERATION_OP2(fs_t, FS_STAT, fstat,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, stat)
|
||||
{
|
||||
return fs_svr_fstat(fd->data, &stat->data);
|
||||
}
|
||||
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_STAT, fstat,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, stat)
|
||||
|
||||
/*dispatch*/
|
||||
RPC_DISPATCH5(fs_t, typeof(FS_OPEN), FS_OPEN, open, FS_READ, read,
|
||||
FS_WRITE, write, FS_CLOSE, close, FS_LSEEK, lseek)
|
||||
RPC_DISPATCH12(fs_t, typeof(FS_OPEN), FS_OPEN, open, FS_READ, read,
|
||||
FS_WRITE, write, FS_CLOSE, close, FS_LSEEK, lseek, FS_FTRUNCATE, ftruncate,
|
||||
FS_SYNC, fsync, FS_READDIR, readdir, FS_MKDIR, mkdir, FS_UNLINK, unlink, FS_RENAME, rename, FS_STAT, fstat)
|
||||
|
||||
void fs_init(fs_t *fs)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef struct stat stat_t;
|
||||
typedef struct dirent dirent_t;
|
||||
|
||||
extern msg_tag_t dispatch_test(msg_tag_t tag, ipc_msg_t *msg);
|
||||
|
||||
/*rpc变量定义宏*/
|
||||
@@ -172,7 +178,9 @@ static inline void rpc_memcpy(void *dst, void *src, size_t size)
|
||||
RPC_TYPE_INIT(rpc_##type##_t) \
|
||||
RPC_CLI_TYPE_TRAN_TO_SVR_TYPE(rpc_##type##_t, rpc_##type##_t)
|
||||
|
||||
RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
||||
RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
||||
RPC_TYPE_DEF_ALL(dirent_t) //!< 目录类型
|
||||
RPC_TYPE_DEF_ALL(stat_t)
|
||||
|
||||
/**
|
||||
* @brief 数组类型的rpc类型定义
|
||||
@@ -695,7 +703,84 @@ RPC_TYPE_INIT_WITHOUT_IMPL(rpc_obj_handler_t_t)
|
||||
} \
|
||||
return tag; \
|
||||
}
|
||||
|
||||
#define RPC_DISPATCH12(struct_type, op_type, func0_op, func0_name, func1_op, func1_name, \
|
||||
func2_op, func2_name, func3_op, func3_name, \
|
||||
func4_op, func4_name, func5_op, func5_name, func6_op, func6_name, \
|
||||
func7_op, func7_name, func8_op, func8_name, func9_op, func9_name, \
|
||||
func10_op, func10_name, func11_op, func11_name) \
|
||||
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
|
||||
{ \
|
||||
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EPROTO); \
|
||||
size_t op_val; \
|
||||
\
|
||||
op_val = *((op_type *)(ipc_msg->msg_buf)); \
|
||||
switch (op_val) \
|
||||
{ \
|
||||
case func0_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func0_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func1_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func1_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func2_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func2_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func3_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func3_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func4_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func4_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func5_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func5_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func6_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func6_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func7_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func7_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func8_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func8_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func9_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func9_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func10_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func10_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
case func11_op: \
|
||||
{ \
|
||||
tag = struct_type##_##func11_name##_dispatch(obj, in_tag, ipc_msg); \
|
||||
} \
|
||||
break; \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
return tag; \
|
||||
}
|
||||
#include "u_rpc_1.h"
|
||||
#include "u_rpc_2.h"
|
||||
#include "u_rpc_3.h"
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
# -msingle-pic-base -mno-pic-data-is-text-relative
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
")
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
@@ -14,4 +14,5 @@ add_subdirectory(init)
|
||||
add_subdirectory(app)
|
||||
add_subdirectory(fs)
|
||||
add_subdirectory(hello)
|
||||
add_subdirectory(drv)
|
||||
# add_subdirectory(path_manager)
|
||||
|
||||
4
mkrtos_user/server/drv/CMakeLists.txt
Normal file
4
mkrtos_user/server/drv/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
|
||||
add_subdirectory(mr_drv)
|
||||
74
mkrtos_user/server/drv/misc/CMakeLists.txt
Normal file
74
mkrtos_user/server/drv/misc/CMakeLists.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_STDPERIPH_DRIVER=1 -DSTM32F10X_XL ")
|
||||
|
||||
file(
|
||||
GLOB deps
|
||||
)
|
||||
|
||||
|
||||
add_executable(
|
||||
drv_fw.elf
|
||||
${deps}
|
||||
)
|
||||
target_link_libraries(
|
||||
drv_fw.elf
|
||||
PUBLIC
|
||||
start
|
||||
muslc
|
||||
sys
|
||||
sys_util
|
||||
sys_svr
|
||||
stm32f1_bsp
|
||||
${GCC_LIB_PATH}/libgcc.a
|
||||
)
|
||||
target_include_directories(
|
||||
drv_fw.elf
|
||||
PUBLIC
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
|
||||
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
|
||||
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/server/drv/misc/vfs_lib/inc
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/server/drv/misc/fs_lib/inc
|
||||
)
|
||||
add_dependencies(
|
||||
drv_fw.elf
|
||||
start
|
||||
muslc
|
||||
sys
|
||||
sys_util
|
||||
stm32f1_bsp
|
||||
)
|
||||
set_target_properties(
|
||||
drv_fw.elf PROPERTIES LINK_FLAGS
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section -no-dynamic-linker "
|
||||
#--no-warn-rwx-segments
|
||||
)
|
||||
add_custom_target(
|
||||
drv_fw_dump ALL
|
||||
COMMAND
|
||||
${CMAKE_OBJDUMP} -s -S drv_fw.elf > ${CMAKE_SOURCE_DIR}/build/output/drv_fw.S
|
||||
COMMAND
|
||||
${CMAKE_READELF} -a drv_fw.elf > ${CMAKE_SOURCE_DIR}/build/output/drv_fw.txt
|
||||
COMMAND
|
||||
${CMAKE_OBJCOPY} -O binary -S drv_fw.elf drv_fw.bin
|
||||
COMMAND
|
||||
${CMAKE_SIZE} drv_fw.elf
|
||||
COMMAND
|
||||
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
||||
COMMAND
|
||||
cp drv_fw.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/drv_fw
|
||||
COMMAND
|
||||
cp drv_fw.elf ${CMAKE_SOURCE_DIR}/build/output/drv_fw.elf
|
||||
)
|
||||
|
||||
add_dependencies(drv_fw_dump drv_fw.elf)
|
||||
|
||||
6
mkrtos_user/server/drv/misc/fs_lib/inc/fs_inode.h
Normal file
6
mkrtos_user/server/drv/misc/fs_lib/inc/fs_inode.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct fs_inode
|
||||
{
|
||||
|
||||
} fs_inode_t;
|
||||
45
mkrtos_user/server/drv/misc/fs_lib/src/fs_dir.c
Normal file
45
mkrtos_user/server/drv/misc/fs_lib/src/fs_dir.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <fs.h>
|
||||
|
||||
static int fs_readdir(struct inode *inode, struct file *filp,
|
||||
struct dirent *dirent, int count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
static int file_fsync (struct inode *inode, struct file *filp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static struct file_operations sp_dir_operations = {
|
||||
.lseek = NULL, /* lseek - default */
|
||||
.read = NULL, /* read */
|
||||
.write = NULL, /* write - bad */
|
||||
.readdir = fs_readdir, /* readdir */
|
||||
.select = NULL, /* select - default */
|
||||
.ioctl = NULL, /* ioctl - default */
|
||||
.mmap = NULL, /* mmap */
|
||||
.mumap = NULL,
|
||||
.open = NULL, /* no special open code */
|
||||
.release = NULL, /* no special release code */
|
||||
.fsync = file_fsync /* default fsync */
|
||||
};
|
||||
|
||||
/*
|
||||
* directories can handle most operations...
|
||||
*/
|
||||
struct inode_operations sp_dir_inode_operations = {
|
||||
&sp_dir_operations, /* default directory file-ops */
|
||||
.create = sp_create, /* create */
|
||||
.lookup = sp_lookup, /* lookup */
|
||||
.link = sp_link, /* link */
|
||||
.unlink = sp_unlink, /* unlink */
|
||||
.symlink = sp_symlink, /* symlink */
|
||||
.mkdir = sp_mkdir, /* mkdir */
|
||||
.rmdir = sp_rmdir, /* rmdir */
|
||||
.mknod = sp_mknod, /* mknod */
|
||||
.rename = sp_rename, /* rename */
|
||||
.readlink = NULL, /* readlink */
|
||||
.follow_link = NULL, /* follow_link */
|
||||
.bmap = NULL, /* bmap */
|
||||
.truncate = sp_truncate, /* truncate */
|
||||
.permission = NULL /* permission */
|
||||
};
|
||||
57
mkrtos_user/server/drv/misc/fs_lib/src/fs_file.c
Normal file
57
mkrtos_user/server/drv/misc/fs_lib/src/fs_file.c
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#include <fs.h>
|
||||
|
||||
static int fs_ioctl(struct inode *ino, struct file *fd, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fs_file_read(struct inode *inode, struct file *filp, char *buf, int count)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
int fs_file_write(struct inode *inode, struct file *filp, char *buf, int count)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int fs_sync_file(struct inode *inode, struct file *file)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
static struct file_operations fs_file_operations = {
|
||||
.lseek = NULL, /* lseek - default */
|
||||
.read = fs_file_read, /* read */
|
||||
.write = fs_file_write, /* write */
|
||||
.readdir = NULL, /* readdir */
|
||||
.select = NULL, /* select - default */
|
||||
.ioctl = fs_ioctl, /* ioctl */
|
||||
.mmap = NULL, /* mmap */
|
||||
.mumap = NULL, /*mumap*/
|
||||
.open = NULL, /* no special open code */
|
||||
.release = NULL, /* no special release code */
|
||||
.fsync = fs_sync_file /* default fsync */
|
||||
};
|
||||
|
||||
/*
|
||||
* directories can handle most operations...
|
||||
*/
|
||||
struct inode_operations fs_file_inode_operations = {
|
||||
&fs_file_operations, /* default directory file-ops */
|
||||
.create = NULL, /* create */
|
||||
.lookup = NULL, /* lookup */
|
||||
.link = NULL, /* link */
|
||||
.unlink = NULL, /* unlink */
|
||||
.symlink = NULL, /* symlink */
|
||||
.mkdir = NULL, /* mkdir */
|
||||
.rmdir = NULL, /* rmdir */
|
||||
.mknod = NULL, /* mknod */
|
||||
.rename = NULL, /* rename */
|
||||
.readlink = NULL, /* readlink */
|
||||
.follow_link = NULL, /* follow_link */
|
||||
.bmap = NULL, /* bmap */
|
||||
.truncate = NULL, /* truncate */
|
||||
.permission = NULL /* permission */
|
||||
};
|
||||
19
mkrtos_user/server/drv/misc/fs_lib/src/fs_link.c
Normal file
19
mkrtos_user/server/drv/misc/fs_lib/src/fs_link.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <fs.h>
|
||||
|
||||
struct inode_operations sp_symlink_inode_operations = {
|
||||
NULL, /* no file-operations */
|
||||
NULL, /* create */
|
||||
NULL, /* lookup */
|
||||
NULL, /* link */
|
||||
NULL, /* unlink */
|
||||
NULL, /* symlink */
|
||||
NULL, /* mkdir */
|
||||
NULL, /* rmdir */
|
||||
NULL, /* mknod */
|
||||
NULL, /* rename */
|
||||
sp_readlink, /* readlink */
|
||||
sp_follow_link, /* follow_link */
|
||||
NULL, /* bmap */
|
||||
NULL, /* truncate */
|
||||
NULL /* permission */
|
||||
};
|
||||
78
mkrtos_user/server/drv/misc/fs_lib/src/fs_super.c
Normal file
78
mkrtos_user/server/drv/misc/fs_lib/src/fs_super.c
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
#include "fs.h"
|
||||
#include "fs_inode.h"
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
struct inode *fs_alloc_inode(struct inode *p_inode)
|
||||
{
|
||||
fs_inode_t *sp_ino;
|
||||
|
||||
p_inode->i_priv_data = malloc(sizeof(fs_inode_t));
|
||||
if (p_inode->i_priv_data == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(sp_ino, 0, sizeof(fs_inode_t));
|
||||
return p_inode;
|
||||
}
|
||||
|
||||
void fs_free_inode(struct inode *p_inode)
|
||||
{
|
||||
free(p_inode->i_priv_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取一个inode
|
||||
* @param inode
|
||||
* @return
|
||||
*/
|
||||
int fs_read_inode(struct inode *inode)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* @brief 写入inode
|
||||
*
|
||||
* @param i_node
|
||||
*/
|
||||
void fs_write_inode(struct inode *i_node)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param i_node
|
||||
*/
|
||||
void fs_put_inode(struct inode *i_node)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param sb
|
||||
*/
|
||||
void fs_write_super(struct super_block *sb)
|
||||
{
|
||||
}
|
||||
void fs_statfs(struct super_block *sb, struct statfs *s_fs)
|
||||
{
|
||||
}
|
||||
int fs_remount_fs(struct super_block *sb, int *a, char *b)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
static struct super_operations fs_sb = {
|
||||
.alloc_inode = fs_alloc_inode,
|
||||
.free_inode = fs_free_inode,
|
||||
.read_inode = fs_read_inode,
|
||||
.notify_change = NULL,
|
||||
.write_inode = fs_write_inode,
|
||||
.put_inode = fs_put_inode,
|
||||
.put_super = NULL,
|
||||
.write_super = fs_write_super,
|
||||
.statfs = fs_statfs,
|
||||
.remount_fs = fs_remount_fs,
|
||||
};
|
||||
72
mkrtos_user/server/drv/misc/fs_rpc.c
Normal file
72
mkrtos_user/server/drv/misc/fs_rpc.c
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "u_rpc.h"
|
||||
#include "u_rpc_svr.h"
|
||||
#include "fs_svr.h"
|
||||
#include "ff.h"
|
||||
#include "u_log.h"
|
||||
#include "u_env.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
static fs_t fs;
|
||||
|
||||
void fs_svr_init(obj_handler_t ipc)
|
||||
{
|
||||
fs_init(&fs);
|
||||
fs.ipc = ipc;
|
||||
}
|
||||
typedef struct file_desc
|
||||
{
|
||||
|
||||
} file_desc_t;
|
||||
|
||||
int fs_svr_open(const char *path, int flags, int mode)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int fs_svr_read(int fd, void *buf, size_t len)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_write(int fd, void *buf, size_t len)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
void fs_svr_close(int fd)
|
||||
{
|
||||
}
|
||||
int fs_svr_lseek(int fd, int offs, int whence)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_ftruncate(int fd, off_t off)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
void fs_svr_sync(int fd)
|
||||
{
|
||||
}
|
||||
int fs_svr_readdir(int fd, dirent_t *dir)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_mkdir(char *path)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_unlink(char *path)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_renmae(char *oldname, char *newname)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_fstat(int fd, stat_t *stat)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
void fs_svr_loop(void)
|
||||
{
|
||||
rpc_loop(fs.ipc, &fs.svr);
|
||||
}
|
||||
7
mkrtos_user/server/drv/misc/fs_rpc.h
Normal file
7
mkrtos_user/server/drv/misc/fs_rpc.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <u_types.h>
|
||||
|
||||
void fs_svr_init(obj_handler_t ipc);
|
||||
void fs_svr_loop(void);
|
||||
void *file_temp_buf_get(void);
|
||||
17
mkrtos_user/server/drv/misc/heap_stack.c
Normal file
17
mkrtos_user/server/drv/misc/heap_stack.c
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#define HEAP_SIZE 0
|
||||
#define STACK_SIZE 1024 * 2
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||
#define STACK_ATTR SECTION("STACK") __attribute__((zero_init))
|
||||
#elif defined(__GNUC__)
|
||||
#define HEAP_ATTR __attribute__((__section__(".bss.heap")))
|
||||
#define STACK_ATTR __attribute__((__section__(".bss.stack")))
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#define HEAP_ATTR
|
||||
#define STACK_ATTR
|
||||
#endif
|
||||
|
||||
__attribute__((used)) HEAP_ATTR static char heap[HEAP_SIZE];
|
||||
__attribute__((used)) STACK_ATTR static char stack[STACK_SIZE];
|
||||
119
mkrtos_user/server/drv/misc/link.lds
Normal file
119
mkrtos_user/server/drv/misc/link.lds
Normal file
@@ -0,0 +1,119 @@
|
||||
ENTRY(_start_)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
. = ALIGN(4);
|
||||
__text_start__ = .;
|
||||
KEEP(*(.first))
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
KEEP(*(.init))
|
||||
KEEP(*(.fini))
|
||||
|
||||
/* .ctors */
|
||||
*crtbegin.o(.ctors)
|
||||
*crtbegin?.o(.ctors)
|
||||
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
|
||||
*(SORT(.ctors.*))
|
||||
*(.ctors)
|
||||
|
||||
/* .dtors */
|
||||
*crtbegin.o(.dtors)
|
||||
*crtbegin?.o(.dtors)
|
||||
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
|
||||
*(SORT(.dtors.*))
|
||||
*(.dtors)
|
||||
|
||||
*(SORT(.rodata.*))
|
||||
*(.rodata)
|
||||
|
||||
KEEP(*(.eh_frame*))
|
||||
|
||||
. = ALIGN(4);
|
||||
__rel_start__ = .;
|
||||
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
|
||||
__rel_end__ = .;
|
||||
}
|
||||
.ARM.exidx : {
|
||||
. = ALIGN(4);
|
||||
__exdix_start = .;
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
__exdix_end = .;
|
||||
}
|
||||
|
||||
.permissions_table : {
|
||||
. = ALIGN(4);
|
||||
__permissions_table_start__ = .;
|
||||
KEEP(*(.permissions_table))
|
||||
__permissions_table_end__ = .;
|
||||
}
|
||||
|
||||
|
||||
PROVIDE(__ram_size__ = __bss_end__ - __data_start__);
|
||||
.data : {
|
||||
. = ALIGN(4);
|
||||
__data_start__ = .;
|
||||
__got_start__ = .;
|
||||
*(.got)
|
||||
__got_end__ = .;
|
||||
. = ALIGN(4);
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
*(vtable)
|
||||
*(.data*)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* preinit data */
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP(*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* init data */
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP(*(SORT(.init_array.*)))
|
||||
KEEP(*(.init_array))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* finit data */
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP(*(SORT(.fini_array.*)))
|
||||
KEEP(*(.fini_array))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* All data end */
|
||||
__data_end__ = .;
|
||||
}
|
||||
|
||||
PROVIDE(__heap_size__ = __heap_end__ - __heap_start__);
|
||||
PROVIDE(__stack_size__ = __stack_end__ - __stack_start__);
|
||||
.bss : {
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
__heap_start__ = .;
|
||||
KEEP(*(.bss.heap))
|
||||
__heap_end__ = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__stack_start__ = .;
|
||||
KEEP(*(.bss.stack))
|
||||
__stack_end__ = .;
|
||||
|
||||
*(.bss.*)
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
}
|
||||
_end = .;
|
||||
}
|
||||
24
mkrtos_user/server/drv/misc/main.c
Normal file
24
mkrtos_user/server/drv/misc/main.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "u_log.h"
|
||||
#include "ns_cli.h"
|
||||
#include "u_rpc_svr.h"
|
||||
#include "u_prot.h"
|
||||
#include "u_env.h"
|
||||
#include "u_drv.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int args, char *argv[])
|
||||
{
|
||||
obj_handler_t ipc_hd;
|
||||
int ret;
|
||||
|
||||
u_drv_init();
|
||||
ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ns_register("/dev", ipc_hd);
|
||||
fs_svr_init(ipc_hd);
|
||||
ulog_write_str(u_get_global_env()->log_hd, "drv framework success\n");
|
||||
fs_svr_loop();
|
||||
return 0;
|
||||
}
|
||||
92
mkrtos_user/server/drv/misc/vfs_lib/inc/fs.h
Normal file
92
mkrtos_user/server/drv/misc/vfs_lib/inc/fs.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include <u_types.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define FS_FILE_NR 16 //!< 最大数量
|
||||
|
||||
typedef struct file
|
||||
{
|
||||
off_t f_off; //!< 文件读写偏移
|
||||
umword_t f_flags; //!< flags.
|
||||
void *priv_data; //!< 私有数据
|
||||
} file_t;
|
||||
|
||||
typedef struct inode
|
||||
{
|
||||
mode_t i_mode; //!< 权限信息
|
||||
size_t i_size; //!< 文件大小
|
||||
ino_t i_no; //!< inode编号
|
||||
size_t i_hlink; //!< 硬连接数
|
||||
void *i_priv_data; //!< inode的私有数据
|
||||
} inode_t;
|
||||
|
||||
typedef struct super_operations
|
||||
{
|
||||
|
||||
struct inode *(*alloc_inode)(struct inode *p_inode); //!< 申请指定文件系统的inode
|
||||
void (*free_inode)(struct inode *p_inode); //!< 释放指定文件系统的inode
|
||||
|
||||
int32_t (*read_inode)(struct inode *p_r_ino);
|
||||
int (*notify_change)(int flags, struct inode *);
|
||||
void (*write_inode)(struct inode *);
|
||||
void (*put_inode)(struct inode *);
|
||||
void (*put_super)(struct super_block *);
|
||||
void (*write_super)(struct super_block *);
|
||||
void (*statfs)(struct super_block *, struct statfs *);
|
||||
int (*remount_fs)(struct super_block *, int *, char *);
|
||||
} super_operations_t;
|
||||
|
||||
typedef struct super_block
|
||||
{
|
||||
struct inode *root_inode; //!< 根节点
|
||||
super_operations_t *sb_ops; //!< super_block的操作
|
||||
umword_t s_magic;
|
||||
} super_block_t;
|
||||
|
||||
/**
|
||||
* file对文件的操作
|
||||
*/
|
||||
struct file_operations
|
||||
{
|
||||
int (*lseek)(struct inode *, struct file *, off_t, int);
|
||||
int (*read)(struct inode *, struct file *, char *, int);
|
||||
int (*write)(struct inode *, struct file *, char *, int);
|
||||
int (*readdir)(struct inode *, struct file *, struct dirent *, int);
|
||||
int (*select)(struct inode *, struct file *, int, uint32_t *);
|
||||
int (*poll)(struct inode *inode, struct file *fp, void *wait_tb,
|
||||
struct timeval *timeout);
|
||||
int (*ioctl)(struct inode *, struct file *, unsigned int, unsigned long);
|
||||
int (*mmap)(struct inode *inode, struct file *fp, unsigned long addr,
|
||||
size_t len, int mask, unsigned long off);
|
||||
int (*mumap)(struct inode *inode, void *start, size_t len);
|
||||
int (*open)(struct inode *inode, struct file *fp);
|
||||
void (*release)(struct inode *ino, struct file *f);
|
||||
int (*fsync)(struct inode *, struct file *);
|
||||
};
|
||||
|
||||
/**
|
||||
* inode对应的操作
|
||||
*/
|
||||
struct inode_operations
|
||||
{
|
||||
struct file_operations *default_file_ops;
|
||||
int (*create)(struct inode *dir, const char *name, int len, int mode,
|
||||
struct inode **result);
|
||||
int (*lookup)(struct inode *dir, const char *file_name, int len,
|
||||
struct inode **ret_inode);
|
||||
int (*link)(struct inode *, struct inode *, const char *, int);
|
||||
int (*unlink)(struct inode *, const char *, int);
|
||||
int (*symlink)(struct inode *, const char *, int, const char *);
|
||||
int (*mkdir)(struct inode *, const char *, int, int);
|
||||
int (*rmdir)(struct inode *, const char *, int);
|
||||
int (*mknod)(struct inode *, const char *, int, int, int);
|
||||
int (*rename)(struct inode *, const char *, int, struct inode *, const char *,
|
||||
int);
|
||||
int (*readlink)(struct inode *, char *, int);
|
||||
int (*follow_link)(struct inode *, struct inode *, int, int, struct inode **);
|
||||
int (*bmap)(struct inode *, int);
|
||||
void (*truncate)(struct inode *, int);
|
||||
int (*permission)(struct inode *, int);
|
||||
};
|
||||
0
mkrtos_user/server/drv/misc/vfs_lib/inc/inode.h
Normal file
0
mkrtos_user/server/drv/misc/vfs_lib/inc/inode.h
Normal file
5
mkrtos_user/server/drv/misc/vfs_lib/src/fs.c
Normal file
5
mkrtos_user/server/drv/misc/vfs_lib/src/fs.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <fs.h>
|
||||
|
||||
static file_t file[FS_FILE_NR];
|
||||
|
||||
|
||||
7
mkrtos_user/server/drv/misc/vfs_lib/src/inode.c
Normal file
7
mkrtos_user/server/drv/misc/vfs_lib/src/inode.c
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <u_types.h>
|
||||
|
||||
78
mkrtos_user/server/drv/mr_drv/CMakeLists.txt
Normal file
78
mkrtos_user/server/drv/mr_drv/CMakeLists.txt
Normal file
@@ -0,0 +1,78 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_STDPERIPH_DRIVER=1 -DSTM32F10X_XL ")
|
||||
|
||||
file(
|
||||
GLOB_RECURSE deps *.c *.C *.s *.S
|
||||
)
|
||||
|
||||
add_executable(
|
||||
mr_drv.elf
|
||||
${deps}
|
||||
)
|
||||
target_link_libraries(
|
||||
mr_drv.elf
|
||||
PUBLIC
|
||||
start
|
||||
muslc
|
||||
sys
|
||||
sys_util
|
||||
sys_svr
|
||||
stm32f1_bsp
|
||||
--whole-archive
|
||||
mr
|
||||
--no-whole-archive
|
||||
${GCC_LIB_PATH}/libgcc.a
|
||||
)
|
||||
target_include_directories(
|
||||
mr_drv.elf
|
||||
PUBLIC
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
|
||||
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
|
||||
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/server/drv/mr_drv/inc
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mr-library/include
|
||||
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mr-library
|
||||
)
|
||||
add_dependencies(
|
||||
mr_drv.elf
|
||||
start
|
||||
muslc
|
||||
sys
|
||||
sys_util
|
||||
stm32f1_bsp
|
||||
mr
|
||||
)
|
||||
set_target_properties(
|
||||
mr_drv.elf PROPERTIES LINK_FLAGS
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section -no-dynamic-linker "
|
||||
#--no-warn-rwx-segments
|
||||
)
|
||||
add_custom_target(
|
||||
mr_drv_dump ALL
|
||||
COMMAND
|
||||
${CMAKE_OBJDUMP} -s -S mr_drv.elf > ${CMAKE_SOURCE_DIR}/build/output/mr_drv.S
|
||||
COMMAND
|
||||
${CMAKE_READELF} -a mr_drv.elf > ${CMAKE_SOURCE_DIR}/build/output/mr_drv.txt
|
||||
COMMAND
|
||||
${CMAKE_OBJCOPY} -O binary -S mr_drv.elf mr_drv.bin
|
||||
COMMAND
|
||||
${CMAKE_SIZE} mr_drv.elf
|
||||
COMMAND
|
||||
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
||||
COMMAND
|
||||
cp mr_drv.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/mr_drv
|
||||
COMMAND
|
||||
cp mr_drv.elf ${CMAKE_SOURCE_DIR}/build/output/mr_drv.elf
|
||||
)
|
||||
|
||||
add_dependencies(mr_drv_dump mr_drv.elf)
|
||||
|
||||
124
mkrtos_user/server/drv/mr_drv/link.lds
Normal file
124
mkrtos_user/server/drv/mr_drv/link.lds
Normal file
@@ -0,0 +1,124 @@
|
||||
ENTRY(_start_)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
. = ALIGN(4);
|
||||
__text_start__ = .;
|
||||
KEEP(*(.first))
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4);
|
||||
_mr_auto_init_start = .;
|
||||
KEEP(*(SORT(.auto_init*)))
|
||||
_mr_auto_init_end = .;
|
||||
|
||||
KEEP(*(.init))
|
||||
KEEP(*(.fini))
|
||||
|
||||
/* .ctors */
|
||||
*crtbegin.o(.ctors)
|
||||
*crtbegin?.o(.ctors)
|
||||
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
|
||||
*(SORT(.ctors.*))
|
||||
*(.ctors)
|
||||
|
||||
/* .dtors */
|
||||
*crtbegin.o(.dtors)
|
||||
*crtbegin?.o(.dtors)
|
||||
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
|
||||
*(SORT(.dtors.*))
|
||||
*(.dtors)
|
||||
|
||||
*(SORT(.rodata.*))
|
||||
*(.rodata)
|
||||
|
||||
KEEP(*(.eh_frame*))
|
||||
|
||||
. = ALIGN(4);
|
||||
__rel_start__ = .;
|
||||
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
|
||||
__rel_end__ = .;
|
||||
}
|
||||
.ARM.exidx : {
|
||||
. = ALIGN(4);
|
||||
__exdix_start = .;
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
__exdix_end = .;
|
||||
}
|
||||
|
||||
.permissions_table : {
|
||||
. = ALIGN(4);
|
||||
__permissions_table_start__ = .;
|
||||
KEEP(*(.permissions_table))
|
||||
__permissions_table_end__ = .;
|
||||
}
|
||||
|
||||
|
||||
PROVIDE(__ram_size__ = __bss_end__ - __data_start__);
|
||||
.data : {
|
||||
. = ALIGN(4);
|
||||
__data_start__ = .;
|
||||
__got_start__ = .;
|
||||
*(.got)
|
||||
__got_end__ = .;
|
||||
. = ALIGN(4);
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
*(vtable)
|
||||
*(.data*)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* preinit data */
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP(*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* init data */
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP(*(SORT(.init_array.*)))
|
||||
KEEP(*(.init_array))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* finit data */
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP(*(SORT(.fini_array.*)))
|
||||
KEEP(*(.fini_array))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
/* All data end */
|
||||
__data_end__ = .;
|
||||
}
|
||||
|
||||
PROVIDE(__heap_size__ = __heap_end__ - __heap_start__);
|
||||
PROVIDE(__stack_size__ = __stack_end__ - __stack_start__);
|
||||
.bss : {
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
__heap_start__ = .;
|
||||
KEEP(*(.bss.heap))
|
||||
__heap_end__ = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__stack_start__ = .;
|
||||
KEEP(*(.bss.stack))
|
||||
__stack_end__ = .;
|
||||
|
||||
*(.bss.*)
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
}
|
||||
_end = .;
|
||||
}
|
||||
17
mkrtos_user/server/drv/mr_drv/src/heap_stack.c
Normal file
17
mkrtos_user/server/drv/mr_drv/src/heap_stack.c
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#define HEAP_SIZE 2048
|
||||
#define STACK_SIZE 1024 * 2
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||
#define STACK_ATTR SECTION("STACK") __attribute__((zero_init))
|
||||
#elif defined(__GNUC__)
|
||||
#define HEAP_ATTR __attribute__((__section__(".bss.heap")))
|
||||
#define STACK_ATTR __attribute__((__section__(".bss.stack")))
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#define HEAP_ATTR
|
||||
#define STACK_ATTR
|
||||
#endif
|
||||
|
||||
__attribute__((used)) HEAP_ATTR static char heap[HEAP_SIZE];
|
||||
__attribute__((used)) STACK_ATTR static char stack[STACK_SIZE];
|
||||
43
mkrtos_user/server/drv/mr_drv/src/main.c
Normal file
43
mkrtos_user/server/drv/mr_drv/src/main.c
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "mrapi.h"
|
||||
#include "device/spi.h"
|
||||
#define SPI_DEVICE0_CS_NUMBER 10
|
||||
#define SPI_DEVICE1_CS_NUMBER 20
|
||||
struct mr_spi_device spi_device0, spi_device1;
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
printf("mr drv init...\n");
|
||||
|
||||
mr_auto_init();
|
||||
/* 添加SPI设备 */
|
||||
mr_spi_device_add(&spi_device0, "spi10", SPI_DEVICE0_CS_NUMBER);
|
||||
mr_spi_device_add(&spi_device1, "spi11", SPI_DEVICE1_CS_NUMBER);
|
||||
|
||||
/* 查找SPI设备 */
|
||||
mr_device_t spi0_device = mr_device_find("spi10");
|
||||
mr_device_t spi1_device = mr_device_find("spi11");
|
||||
|
||||
/* 挂载总线 */
|
||||
mr_device_ioctl(spi0_device, MR_DEVICE_CTRL_CONNECT, "spi1");
|
||||
mr_device_ioctl(spi1_device, MR_DEVICE_CTRL_CONNECT, "spi1");
|
||||
|
||||
/* 以可读可写的方式打开SPI设备 */
|
||||
mr_device_open(spi0_device, MR_DEVICE_OFLAG_RDWR);
|
||||
mr_device_open(spi1_device, MR_DEVICE_OFLAG_RDWR);
|
||||
|
||||
/* 写入数据 */
|
||||
char buffer0[] = "hello";
|
||||
char buffer1[] = "world";
|
||||
mr_device_write(spi0_device, -1, buffer0, sizeof(buffer0) - 1);
|
||||
mr_device_write(spi1_device, -1, buffer1, sizeof(buffer1) - 1);
|
||||
|
||||
/* 读取数据 */
|
||||
mr_device_read(spi0_device, -1, buffer0, sizeof(buffer0) - 1);
|
||||
mr_device_read(spi1_device, -1, buffer1, sizeof(buffer1) - 1);
|
||||
|
||||
/* 关闭设备 */
|
||||
mr_device_close(spi0_device);
|
||||
mr_device_close(spi1_device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ FRESULT delete_node (
|
||||
{
|
||||
UINT i, j;
|
||||
FRESULT fr;
|
||||
DIR dir;
|
||||
FATFS_DIR dir;
|
||||
|
||||
|
||||
fr = f_opendir(&dir, path); /* Open the sub-directory to make it empty */
|
||||
|
||||
@@ -943,7 +943,7 @@ static void unlock_volume (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT chk_share ( /* Check if the file can be accessed */
|
||||
DIR* dp, /* Directory object pointing the file to be checked */
|
||||
FATFS_DIR* dp, /* Directory object pointing the file to be checked */
|
||||
int acc /* Desired access type (0:Read mode open, 1:Write mode open, 2:Delete or rename) */
|
||||
)
|
||||
{
|
||||
@@ -979,7 +979,7 @@ static int enq_share (void) /* Check if an entry is available for a new object *
|
||||
|
||||
|
||||
static UINT inc_share ( /* Increment object open counter and returns its index (0:Internal error) */
|
||||
DIR* dp, /* Directory object pointing the file to register or increment */
|
||||
FATFS_DIR* dp, /* Directory object pointing the file to register or increment */
|
||||
int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
|
||||
)
|
||||
{
|
||||
@@ -1695,7 +1695,7 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DIR* dp, /* Pointer to directory object */
|
||||
FATFS_DIR* dp, /* Pointer to directory object */
|
||||
DWORD ofs /* Offset of directory table */
|
||||
)
|
||||
{
|
||||
@@ -1743,7 +1743,7 @@ static FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
|
||||
DIR* dp, /* Pointer to the directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the directory object */
|
||||
int stretch /* 0: Do not stretch table, 1: Stretch table if needed */
|
||||
)
|
||||
{
|
||||
@@ -1804,7 +1804,7 @@ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DEN
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DIR* dp, /* Pointer to the directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the directory object */
|
||||
UINT n_ent /* Number of contiguous entries to allocate */
|
||||
)
|
||||
{
|
||||
@@ -2128,7 +2128,7 @@ static DWORD xsum32 ( /* Returns 32-bit checksum */
|
||||
/*------------------------------------*/
|
||||
|
||||
static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */
|
||||
DIR* dp /* Reading directory object pointing top of the entry block to load */
|
||||
FATFS_DIR* dp /* Reading directory object pointing top of the entry block to load */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -2197,7 +2197,7 @@ static void init_alloc_info (
|
||||
/*------------------------------------------------*/
|
||||
|
||||
static FRESULT load_obj_xdir (
|
||||
DIR* dp, /* Blank directory object to be used to access containing directory */
|
||||
FATFS_DIR* dp, /* Blank directory object to be used to access containing directory */
|
||||
const FFOBJID* obj /* Object with its containing directory information */
|
||||
)
|
||||
{
|
||||
@@ -2226,7 +2226,7 @@ static FRESULT load_obj_xdir (
|
||||
/*----------------------------------------*/
|
||||
|
||||
static FRESULT store_xdir (
|
||||
DIR* dp /* Pointer to the directory object */
|
||||
FATFS_DIR* dp /* Pointer to the directory object */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -2304,7 +2304,7 @@ static void create_xdir (
|
||||
#define DIR_READ_LABEL(dp) dir_read(dp, 1)
|
||||
|
||||
static FRESULT dir_read (
|
||||
DIR* dp, /* Pointer to the directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the directory object */
|
||||
int vol /* Filtered by 0:file/directory or 1:volume label */
|
||||
)
|
||||
{
|
||||
@@ -2382,7 +2382,7 @@ static FRESULT dir_read (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
|
||||
DIR* dp /* Pointer to the directory object with the file name */
|
||||
FATFS_DIR* dp /* Pointer to the directory object with the file name */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -2463,7 +2463,7 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
|
||||
DIR* dp /* Target directory with object name to be created */
|
||||
FATFS_DIR* dp /* Target directory with object name to be created */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -2490,7 +2490,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
|
||||
res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */
|
||||
if (res != FR_OK) return res;
|
||||
if (dp->obj.sclust != 0) { /* Is it a sub-directory? */
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
|
||||
res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */
|
||||
if (res != FR_OK) return res;
|
||||
@@ -2569,7 +2569,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
|
||||
DIR* dp /* Directory object pointing the entry to be removed */
|
||||
FATFS_DIR* dp /* Directory object pointing the entry to be removed */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -2615,7 +2615,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static void get_fileinfo (
|
||||
DIR* dp, /* Pointer to the directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the directory object */
|
||||
FILINFO* fno /* Pointer to the file information to be filled */
|
||||
)
|
||||
{
|
||||
@@ -2845,7 +2845,7 @@ static int pattern_match ( /* 0:mismatched, 1:matched */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */
|
||||
DIR* dp, /* Pointer to the directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the directory object */
|
||||
const TCHAR** path /* Pointer to pointer to the segment in the path string */
|
||||
)
|
||||
{
|
||||
@@ -3049,7 +3049,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
|
||||
DIR* dp, /* Directory object to return last directory and found object */
|
||||
FATFS_DIR* dp, /* Directory object to return last directory and found object */
|
||||
const TCHAR* path /* Full-path string to find a file or directory */
|
||||
)
|
||||
{
|
||||
@@ -3071,7 +3071,7 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
|
||||
dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */
|
||||
#if FF_FS_RPATH != 0
|
||||
if (fs->fs_type == FS_EXFAT && dp->obj.sclust) { /* exFAT: Retrieve the sub-directory's status */
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
|
||||
dp->obj.c_scl = fs->cdc_scl;
|
||||
dp->obj.c_size = fs->cdc_size;
|
||||
@@ -3532,7 +3532,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
|
||||
if (nrsv == 0) return FR_NO_FILESYSTEM; /* (Must not be 0) */
|
||||
|
||||
/* Determine the FAT sub type */
|
||||
sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + DIR */
|
||||
sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + FATFS_DIR */
|
||||
if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */
|
||||
nclst = (tsect - sysect) / fs->csize; /* Number of clusters */
|
||||
if (nclst == 0) return FR_NO_FILESYSTEM; /* (Invalid volume size) */
|
||||
@@ -3611,7 +3611,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */
|
||||
FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/DIR structure, to check validity */
|
||||
FFOBJID* obj, /* Pointer to the FFOBJID, the 1st member in the FIL/FATFS_DIR structure, to check validity */
|
||||
FATFS** rfs /* Pointer to pointer to the owner filesystem object to return */
|
||||
)
|
||||
{
|
||||
@@ -3721,7 +3721,7 @@ FRESULT f_open (
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
FATFS *fs;
|
||||
#if !FF_FS_READONLY
|
||||
DWORD cl, bcs, clst, tm;
|
||||
@@ -3764,7 +3764,7 @@ FRESULT f_open (
|
||||
mode |= FA_CREATE_ALWAYS; /* File is created */
|
||||
}
|
||||
else { /* Any object with the same name is already existing */
|
||||
if (dj.obj.attr & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */
|
||||
if (dj.obj.attr & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or FATFS_DIR) */
|
||||
res = FR_DENIED;
|
||||
} else {
|
||||
if (mode & FA_CREATE_NEW) res = FR_EXIST; /* Cannot create as new file */
|
||||
@@ -4160,7 +4160,7 @@ FRESULT f_sync (
|
||||
res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */
|
||||
}
|
||||
if (res == FR_OK) {
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
DEF_NAMBUF
|
||||
|
||||
INIT_NAMBUF(fs);
|
||||
@@ -4274,7 +4274,7 @@ FRESULT f_chdir (
|
||||
UINT i;
|
||||
#endif
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
FATFS *fs;
|
||||
DEF_NAMBUF
|
||||
|
||||
@@ -4334,7 +4334,7 @@ FRESULT f_getcwd (
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
FATFS *fs;
|
||||
UINT i, n;
|
||||
DWORD ccl;
|
||||
@@ -4595,7 +4595,7 @@ FRESULT f_lseek (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
FRESULT f_opendir (
|
||||
DIR* dp, /* Pointer to directory object to create */
|
||||
FATFS_DIR* dp, /* Pointer to directory object to create */
|
||||
const TCHAR* path /* Pointer to the directory path */
|
||||
)
|
||||
{
|
||||
@@ -4661,7 +4661,7 @@ FRESULT f_opendir (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
FRESULT f_closedir (
|
||||
DIR *dp /* Pointer to the directory object to be closed */
|
||||
FATFS_DIR *dp /* Pointer to the directory object to be closed */
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
@@ -4691,7 +4691,7 @@ FRESULT f_closedir (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
FRESULT f_readdir (
|
||||
DIR* dp, /* Pointer to the open directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the open directory object */
|
||||
FILINFO* fno /* Pointer to file information to return */
|
||||
)
|
||||
{
|
||||
@@ -4727,7 +4727,7 @@ FRESULT f_readdir (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
FRESULT f_findnext (
|
||||
DIR* dp, /* Pointer to the open directory object */
|
||||
FATFS_DIR* dp, /* Pointer to the open directory object */
|
||||
FILINFO* fno /* Pointer to the file information structure */
|
||||
)
|
||||
{
|
||||
@@ -4752,7 +4752,7 @@ FRESULT f_findnext (
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
FRESULT f_findfirst (
|
||||
DIR* dp, /* Pointer to the blank directory object */
|
||||
FATFS_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 */
|
||||
@@ -4784,7 +4784,7 @@ FRESULT f_stat (
|
||||
)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@@ -4965,7 +4965,7 @@ FRESULT f_unlink (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj, sdj;
|
||||
FATFS_DIR dj, sdj;
|
||||
DWORD dclst = 0;
|
||||
#if FF_FS_EXFAT
|
||||
FFOBJID obj;
|
||||
@@ -5059,7 +5059,7 @@ FRESULT f_mkdir (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
FFOBJID sobj;
|
||||
DWORD dcl, pcl, tm;
|
||||
DEF_NAMBUF
|
||||
@@ -5144,7 +5144,7 @@ FRESULT f_rename (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR djo, djn;
|
||||
FATFS_DIR djo, djn;
|
||||
BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
|
||||
LBA_t sect;
|
||||
DEF_NAMBUF
|
||||
@@ -5191,7 +5191,7 @@ FRESULT f_rename (
|
||||
#endif
|
||||
{ /* At FAT/FAT32 volume */
|
||||
memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
|
||||
memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
|
||||
memcpy(&djn, &djo, sizeof (FATFS_DIR)); /* Duplicate the directory object */
|
||||
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
|
||||
if (res == FR_OK) { /* Is new name already in use by any other object? */
|
||||
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
|
||||
@@ -5255,7 +5255,7 @@ FRESULT f_chmod (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@@ -5301,7 +5301,7 @@ FRESULT f_utime (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
DEF_NAMBUF
|
||||
|
||||
|
||||
@@ -5349,7 +5349,7 @@ FRESULT f_getlabel (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
UINT si, di;
|
||||
WCHAR wc;
|
||||
|
||||
@@ -5448,7 +5448,7 @@ FRESULT f_setlabel (
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs;
|
||||
DIR dj;
|
||||
FATFS_DIR dj;
|
||||
BYTE dirvn[22];
|
||||
UINT di;
|
||||
WCHAR wc;
|
||||
|
||||
@@ -221,7 +221,7 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
/* Directory object structure (FATFS_DIR) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
@@ -236,7 +236,7 @@ typedef struct {
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR;
|
||||
} FATFS_DIR;
|
||||
|
||||
|
||||
|
||||
@@ -308,11 +308,11 @@ FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data t
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (FATFS_DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "u_env.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
static fs_t fs;
|
||||
|
||||
void fs_svr_init(obj_handler_t ipc)
|
||||
@@ -15,11 +16,16 @@ void fs_svr_init(obj_handler_t ipc)
|
||||
}
|
||||
typedef struct file_desc
|
||||
{
|
||||
FIL fp;
|
||||
union
|
||||
{
|
||||
FIL fp;
|
||||
FATFS_DIR dir;
|
||||
};
|
||||
uint8_t type; //!< 0:file 1:dir
|
||||
} file_desc_t;
|
||||
|
||||
#define FILE_DESC_NR 8
|
||||
static file_desc_t files[FILE_DESC_NR];
|
||||
#define FILE_DESC_NR 8 //!< 最多同时可以打开多少个文件
|
||||
static file_desc_t files[FILE_DESC_NR]; //!< 预先设置的文件描述符
|
||||
|
||||
static file_desc_t *alloc_file(int *fd)
|
||||
{
|
||||
@@ -45,7 +51,36 @@ static file_desc_t *file_get(int fd)
|
||||
}
|
||||
return files + fd;
|
||||
}
|
||||
|
||||
static int fatfs_err_conv(FRESULT res)
|
||||
{
|
||||
switch (res)
|
||||
{
|
||||
case FR_OK:
|
||||
return 0;
|
||||
case FR_DISK_ERR:
|
||||
return -EIO;
|
||||
case FR_NO_FILE:
|
||||
return -ENOENT;
|
||||
case FR_NO_PATH:
|
||||
return -ENOENT;
|
||||
case FR_INVALID_NAME:
|
||||
return -EINVAL;
|
||||
case FR_DENIED:
|
||||
return -EPERM;
|
||||
case FR_EXIST:
|
||||
return -EEXIST;
|
||||
case FR_WRITE_PROTECTED:
|
||||
return -EIO;
|
||||
case FR_TIMEOUT:
|
||||
return -ETIMEDOUT;
|
||||
case FR_NOT_ENOUGH_CORE:
|
||||
return -ENOMEM;
|
||||
case FR_INVALID_PARAMETER:
|
||||
return -EINVAL;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
int fs_svr_open(const char *path, int flags, int mode)
|
||||
{
|
||||
// printf("open %s.\n", path);
|
||||
@@ -88,11 +123,27 @@ int fs_svr_open(const char *path, int flags, int mode)
|
||||
|
||||
if (ret != FR_OK)
|
||||
{
|
||||
ulog_write_str(u_get_global_env()->log_hd, "open fail..\n");
|
||||
free_file(fd);
|
||||
if (ret == FR_NO_FILE)
|
||||
{
|
||||
// 打开的是一个目录,则作为一个目录打开
|
||||
ret = f_opendir(&file->dir, path);
|
||||
if (ret != FR_OK)
|
||||
{
|
||||
ulog_write_str(u_get_global_env()->log_hd, "open fail..\n");
|
||||
free_file(fd);
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
file->type = 1;
|
||||
ulog_write_str(u_get_global_env()->log_hd, "open dir..\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
file->type = 0;
|
||||
ulog_write_str(u_get_global_env()->log_hd, "open file..\n");
|
||||
}
|
||||
|
||||
return -ret;
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
|
||||
int fs_svr_read(int fd, void *buf, size_t len)
|
||||
@@ -104,11 +155,15 @@ int fs_svr_read(int fd, void *buf, size_t len)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
if (file->type != 0)
|
||||
{
|
||||
return -EACCES;
|
||||
}
|
||||
FRESULT ret = f_read(&file->fp, buf, len, &br);
|
||||
|
||||
if (ret != FR_OK)
|
||||
{
|
||||
return -ret;
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
return br;
|
||||
}
|
||||
@@ -121,11 +176,15 @@ int fs_svr_write(int fd, void *buf, size_t len)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
if (file->type != 0)
|
||||
{
|
||||
return -EACCES;
|
||||
}
|
||||
FRESULT ret = f_write(&file->fp, buf, len, &bw);
|
||||
|
||||
if (ret != FR_OK)
|
||||
{
|
||||
return -ret;
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
return bw;
|
||||
}
|
||||
@@ -137,7 +196,15 @@ void fs_svr_close(int fd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
f_close(&file->fp);
|
||||
switch (file->type)
|
||||
{
|
||||
case 0:
|
||||
f_close(&file->fp);
|
||||
break;
|
||||
case 1:
|
||||
f_closedir(&file->dir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int fs_svr_lseek(int fd, int offs, int whence)
|
||||
{
|
||||
@@ -149,6 +216,10 @@ int fs_svr_lseek(int fd, int offs, int whence)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
if (file->type != 0)
|
||||
{
|
||||
return -EACCES;
|
||||
}
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
@@ -177,8 +248,64 @@ int fs_svr_lseek(int fd, int offs, int whence)
|
||||
}
|
||||
FRESULT ret = f_lseek(&file->fp, new_offs);
|
||||
|
||||
return -ret;
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
int fs_svr_ftruncate(int fd, off_t off)
|
||||
{
|
||||
file_desc_t *file = file_get(fd);
|
||||
|
||||
if (!file)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
if (file->type != 0)
|
||||
{
|
||||
return -EACCES;
|
||||
}
|
||||
FRESULT ret = f_truncate(&file->fp);
|
||||
|
||||
return fatfs_err_conv(ret);
|
||||
}
|
||||
void fs_svr_sync(int fd)
|
||||
{
|
||||
file_desc_t *file = file_get(fd);
|
||||
|
||||
if (!file)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (file->type != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
f_sync(&file->fp);
|
||||
}
|
||||
int fs_svr_readdir(int fd, dirent_t *dir)
|
||||
{
|
||||
file_desc_t *file = file_get(fd);
|
||||
|
||||
if (!file)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
int fs_svr_mkdir(char *path)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_unlink(char *path)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_renmae(char *oldname, char *newname)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
int fs_svr_fstat(int fd, stat_t *stat)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
void fs_svr_loop(void)
|
||||
{
|
||||
rpc_loop(fs.ipc, &fs.svr);
|
||||
|
||||
@@ -16,6 +16,7 @@ target_link_libraries(hello.elf
|
||||
sys
|
||||
sys_util
|
||||
sys_svr
|
||||
mr
|
||||
${GCC_LIB_PATH}/libgcc.a
|
||||
)
|
||||
target_include_directories(
|
||||
@@ -64,4 +65,5 @@ add_custom_target(
|
||||
add_dependencies(shell_dump hello.elf)
|
||||
add_dependencies(shell_dump sys)
|
||||
add_dependencies(shell_dump sys_util)
|
||||
add_dependencies(shell_dump mr)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// #include <stdio.h>
|
||||
#include "u_log.h"
|
||||
#include "u_env.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
// printf("Hello world.\n");
|
||||
|
||||
@@ -44,22 +44,22 @@ int main(int argc, char *args[])
|
||||
env.ns_hd = ipc_hd;
|
||||
namespace_init(ipc_hd);
|
||||
u_sleep_init();
|
||||
ret = app_load("app", &env);
|
||||
// ret = app_load("app", &env);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// printf("app load fail, 0x%x\n", ret);
|
||||
// // ulog_write_str(LOG_PROT, "app load fail.\n");
|
||||
// }
|
||||
ret = app_load("mr_drv", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
// ulog_write_str(LOG_PROT, "app load fail.\n");
|
||||
}
|
||||
// ret = app_load("hello", &env);
|
||||
// ret = app_load("fatfs", &env);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// printf("app load fail, 0x%x\n", ret);
|
||||
// }
|
||||
ret = app_load("fatfs", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
}
|
||||
// u_sleep_ms(500);
|
||||
// u_sleep_ms(500);
|
||||
|
||||
|
||||
@@ -20,22 +20,22 @@ set(CMAKE_SIZE "${CROSS_COMPILE}size" CACHE PATH "" FORCE)
|
||||
|
||||
|
||||
# -mfloat-abi=soft -u _printf_float
|
||||
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g3 -lc -lrdimon -msoft-float -u _printf_float \
|
||||
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g3 -lc -lrdimon -msoft-float -u _printf_float -D=MKRTOS \
|
||||
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||
--gc-sections -fno-stack-protector \
|
||||
-fno-stack-protector -Wl,--gc-sections \
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-mcpu=cortex-m3 -mthumb -mno-thumb-interwork \
|
||||
set(CMAKE_CXX_FLAGS "-mcpu=cortex-m3 -mthumb -mno-thumb-interwork -D=MKRTOS \
|
||||
-mfix-cortex-m3-ldrd -O0 -g -std=c++11 \
|
||||
-fmessage-length=0 -Xlinker --print-map -Wall -W -fno-stack-protector -g \
|
||||
-mfloat-abi=soft -lc -lrdimon -u _printf_float \
|
||||
-ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker -Wl,-gc-sections \
|
||||
-ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
set(CMAKE_ASM_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g -mfloat-abi=soft -lc -lrdimon \
|
||||
set(CMAKE_ASM_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g -mfloat-abi=soft -lc -lrdimon -D=MKRTOS \
|
||||
-u _printf_float -std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker --gc-sections -fno-stack-protector \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker -fno-stack-protector \
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
set(BOARD_NAME "$ENV{BOARD}")
|
||||
|
||||
Reference in New Issue
Block a user