修复rpc bug,fatfs服务测试
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -144,7 +144,8 @@
|
|||||||
"ns_svr.h": "c",
|
"ns_svr.h": "c",
|
||||||
"u_rpc_2.h": "c",
|
"u_rpc_2.h": "c",
|
||||||
"ns_cli.h": "c",
|
"ns_cli.h": "c",
|
||||||
"fs_cli.h": "c"
|
"fs_cli.h": "c",
|
||||||
|
"u_rpc_1.h": "c"
|
||||||
},
|
},
|
||||||
"cortex-debug.showRTOS": false,
|
"cortex-debug.showRTOS": false,
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int fs_open(const char *path, int flags, int mode);
|
int fs_open(const char *path, int flags, int mode);
|
||||||
|
int fs_read(int fd, void *buf, size_t len);
|
||||||
|
int fs_write(int fd, void *buf, size_t len);
|
||||||
|
int fs_close(int fd);
|
||||||
|
int fs_lseek(int fd, int offs, int whence);
|
||||||
@@ -12,3 +12,7 @@ typedef struct fs
|
|||||||
void fs_init(fs_t *fs);
|
void fs_init(fs_t *fs);
|
||||||
|
|
||||||
int fs_svr_open(const char *path, int flags, int mode);
|
int fs_svr_open(const char *path, int flags, int mode);
|
||||||
|
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);
|
||||||
|
|||||||
@@ -9,3 +9,4 @@
|
|||||||
#define FS_CLOSE ((uint16_t)1)
|
#define FS_CLOSE ((uint16_t)1)
|
||||||
#define FS_READ ((uint16_t)2)
|
#define FS_READ ((uint16_t)2)
|
||||||
#define FS_WRITE ((uint16_t)3)
|
#define FS_WRITE ((uint16_t)3)
|
||||||
|
#define FS_LSEEK ((uint16_t)4)
|
||||||
|
|||||||
@@ -14,7 +14,176 @@ RPC_GENERATION_CALL3(fs_t, FS_OPEN, open,
|
|||||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
||||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
|
||||||
|
// RPC_GENERATION_CALL3(fs_t, FS_READ, read,
|
||||||
|
// rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf,
|
||||||
|
// rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
msg_tag_t fs_t_read_call(obj_handler_t hd, rpc_int_t *var0, rpc_ref_array_uint32_t_uint8_t_32_t *var1, rpc_int_t *var2)
|
||||||
|
{
|
||||||
|
void *buf;
|
||||||
|
ipc_msg_t *msg_ipc;
|
||||||
|
thread_msg_buf_get(2, (umword_t *)(&buf), ((void *)0));
|
||||||
|
msg_ipc = (ipc_msg_t *)buf;
|
||||||
|
int off = 0;
|
||||||
|
int off_buf = 0;
|
||||||
|
int ret = -1;
|
||||||
|
size_t op_val = ((uint16_t)2);
|
||||||
|
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val));
|
||||||
|
off += rpc_align(sizeof(op_val), __alignof(((uint16_t)2)));
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_int_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_int_t(var0, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_buf = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (2 == 1 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (2 == 1 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var1, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_buf = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_int_t(var2, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_msg_to_buf_rpc_int_t(var2, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_buf = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
msg_tag_t tag = ipc_call(hd, ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = ((((off_buf) / ((sizeof(void *)))) + (((off_buf) % ((sizeof(void *)))) ? 1 : 0))), .prot = (0)}), ipc_timeout_create2(0, 0));
|
||||||
|
if (((int16_t)((tag).prot)) < 0)
|
||||||
|
{
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
off = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_buf_to_msg_rpc_int_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (2 == 2 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_buf_to_msg_rpc_ref_array_uint32_t_uint8_t_32_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_cli_buf_to_msg_rpc_int_t(var2, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
RPC_GENERATION_CALL3(fs_t, FS_WRITE, write,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, buf,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
|
||||||
|
RPC_GENERATION_CALL1(fs_t, FS_CLOSE, close,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd)
|
||||||
|
RPC_GENERATION_CALL3(fs_t, FS_LSEEK, lseek,
|
||||||
|
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,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, whence)
|
||||||
int fs_open(const char *path, int flags, int mode)
|
int fs_open(const char *path, int flags, int mode)
|
||||||
{
|
{
|
||||||
obj_handler_t hd;
|
obj_handler_t hd;
|
||||||
@@ -44,3 +213,137 @@ int fs_open(const char *path, int flags, int mode)
|
|||||||
|
|
||||||
return msg_tag_get_val(tag);
|
return msg_tag_get_val(tag);
|
||||||
}
|
}
|
||||||
|
int fs_read(int fd, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
obj_handler_t hd;
|
||||||
|
int ret = ns_query("fs", &hd);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_int_t rpc_fd = {
|
||||||
|
.data = fd,
|
||||||
|
};
|
||||||
|
|
||||||
|
int rlen = 0;
|
||||||
|
while (rlen < len)
|
||||||
|
{
|
||||||
|
int r_once_len = 0;
|
||||||
|
|
||||||
|
r_once_len = MIN(32, len - rlen);
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t rpc_buf = {
|
||||||
|
.data = buf + rlen,
|
||||||
|
.len = r_once_len,
|
||||||
|
};
|
||||||
|
rpc_int_t rpc_len = {
|
||||||
|
.data = r_once_len,
|
||||||
|
};
|
||||||
|
msg_tag_t tag = fs_t_read_call(hd, &rpc_fd, &rpc_buf, &rpc_len);
|
||||||
|
|
||||||
|
if (msg_tag_get_val(tag) < 0)
|
||||||
|
{
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
|
rlen += msg_tag_get_val(tag);
|
||||||
|
if (msg_tag_get_val(tag) != r_once_len)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fs_write(int fd, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
obj_handler_t hd;
|
||||||
|
int ret = ns_query("fs", &hd);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_int_t rpc_fd = {
|
||||||
|
.data = fd,
|
||||||
|
};
|
||||||
|
int wlen = 0;
|
||||||
|
while (wlen < len)
|
||||||
|
{
|
||||||
|
int w_once_len = 0;
|
||||||
|
|
||||||
|
w_once_len = MIN(32, len - wlen);
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t rpc_buf = {
|
||||||
|
.data = buf + wlen,
|
||||||
|
.len = w_once_len,
|
||||||
|
};
|
||||||
|
rpc_int_t rpc_len = {
|
||||||
|
.data = w_once_len,
|
||||||
|
};
|
||||||
|
msg_tag_t tag = fs_t_write_call(hd, &rpc_fd, &rpc_buf, &rpc_len);
|
||||||
|
|
||||||
|
if (msg_tag_get_val(tag) < 0)
|
||||||
|
{
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
|
wlen += msg_tag_get_val(tag);
|
||||||
|
if (msg_tag_get_val(tag) != w_once_len)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wlen;
|
||||||
|
}
|
||||||
|
int fs_close(int fd)
|
||||||
|
{
|
||||||
|
obj_handler_t hd;
|
||||||
|
int ret = ns_query("fs", &hd);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_int_t rpc_fd = {
|
||||||
|
.data = fd,
|
||||||
|
};
|
||||||
|
msg_tag_t tag = fs_t_close_call(hd, &rpc_fd);
|
||||||
|
|
||||||
|
if (msg_tag_get_val(tag) < 0)
|
||||||
|
{
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
|
int fs_lseek(int fd, int offs, int whence)
|
||||||
|
{
|
||||||
|
obj_handler_t hd;
|
||||||
|
int ret = ns_query("fs", &hd);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_int_t rpc_fd = {
|
||||||
|
.data = fd,
|
||||||
|
};
|
||||||
|
rpc_int_t rpc_offs = {
|
||||||
|
.data = offs,
|
||||||
|
};
|
||||||
|
rpc_int_t rpc_whence = {
|
||||||
|
.data = whence,
|
||||||
|
};
|
||||||
|
msg_tag_t tag = fs_t_lseek_call(hd, &rpc_fd, &rpc_offs, &rpc_whence);
|
||||||
|
|
||||||
|
if (msg_tag_get_val(tag) < 0)
|
||||||
|
{
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg_tag_get_val(tag);
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "fs_svr.h"
|
#include "fs_svr.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*open*/
|
||||||
RPC_GENERATION_OP3(fs_t, FS_OPEN, open,
|
RPC_GENERATION_OP3(fs_t, FS_OPEN, open,
|
||||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
||||||
@@ -19,8 +20,231 @@ RPC_GENERATION_DISPATCH3(fs_t, FS_OPEN, open,
|
|||||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
|
||||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
|
||||||
|
/*read*/
|
||||||
|
RPC_GENERATION_OP3(fs_t, FS_READ, read,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
{
|
||||||
|
int ret = fs_svr_read(fd->data, buf->data, len->data);
|
||||||
|
|
||||||
RPC_DISPATCH1(fs_t, typeof(FS_OPEN), FS_OPEN, open)
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
buf->len = ret;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RPC_GENERATION_DISPATCH3(fs_t, FS_READ, read,
|
||||||
|
// rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf,
|
||||||
|
// rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
msg_tag_t fs_t_read_dispatch(fs_t *obj, msg_tag_t tag, ipc_msg_t *ipc_msg)
|
||||||
|
{
|
||||||
|
rpc_int_t var0;
|
||||||
|
rpc_array_uint32_t_uint8_t_32_t var1;
|
||||||
|
rpc_int_t var2;
|
||||||
|
size_t op_val;
|
||||||
|
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf);
|
||||||
|
int off = 0;
|
||||||
|
rpc_var_rpc_int_t_init(&var0);
|
||||||
|
rpc_var_rpc_array_uint32_t_uint8_t_32_t_init(&var1);
|
||||||
|
rpc_var_rpc_int_t_init(&var2);
|
||||||
|
op_val = *((typeof(((uint16_t)2)) *)value);
|
||||||
|
if (op_val != ((uint16_t)2))
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (-71)});
|
||||||
|
}
|
||||||
|
off += sizeof(typeof(((uint16_t)2)));
|
||||||
|
off = rpc_align(off, __alignof(typeof(((uint16_t)2))));
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_buf_to_msg_rpc_int_t(&var0, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (2 == 1 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_buf_to_msg_rpc_array_uint32_t_uint8_t_32_t(&var1, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 1 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_buf_to_msg_rpc_int_t(&var2, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
short ret_val = fs_t_read_op(obj, &var0, &var1, &var2);
|
||||||
|
if (ret_val < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret_val)});
|
||||||
|
}
|
||||||
|
off = 0;
|
||||||
|
int off_map = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_int_t(&var0, (uint8_t *)(value), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (2 == 2 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var1, (uint8_t *)(value), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 1)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_int_t(&var2, (uint8_t *)(value), off);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_int_t(&var0, (uint8_t *)(ipc_msg->map_buf), off_map);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_map = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (2 == 2 || 2 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var1, (uint8_t *)(ipc_msg->map_buf), off_map);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_map = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (1 == 2)
|
||||||
|
{
|
||||||
|
if (1 == 2 || 1 == 4)
|
||||||
|
{
|
||||||
|
int ret = rpc_svr_msg_to_buf_rpc_int_t(&var2, (uint8_t *)(ipc_msg->map_buf), off_map);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||||
|
}
|
||||||
|
off_map = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
return ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = ((((off_map) / ((sizeof(void *)))) + (((off_map) % ((sizeof(void *)))) ? 1 : 0))), .prot = (ret_val)});
|
||||||
|
}
|
||||||
|
/*write*/
|
||||||
|
RPC_GENERATION_OP3(fs_t, FS_WRITE, write,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, buf,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
{
|
||||||
|
int ret = fs_svr_write(fd->data, buf->data, len->data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
RPC_GENERATION_DISPATCH3(fs_t, FS_WRITE, write,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||||
|
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, buf,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||||
|
|
||||||
|
/*close*/
|
||||||
|
RPC_GENERATION_OP1(fs_t, FS_CLOSE, close,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd)
|
||||||
|
{
|
||||||
|
fs_svr_close(fd->data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RPC_GENERATION_DISPATCH1(fs_t, FS_CLOSE, close,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd)
|
||||||
|
|
||||||
|
/*lseek*/
|
||||||
|
RPC_GENERATION_OP3(fs_t, FS_LSEEK, lseek,
|
||||||
|
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,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, whence)
|
||||||
|
{
|
||||||
|
int ret = fs_svr_lseek(fd->data, offs->data, whence->data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
RPC_GENERATION_DISPATCH3(fs_t, FS_LSEEK, lseek,
|
||||||
|
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, len,
|
||||||
|
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, whence)
|
||||||
|
|
||||||
|
/*dispatch*/
|
||||||
|
RPC_DISPATCH5(fs_t, typeof(FS_OPEN), FS_OPEN, open, FS_READ, read,
|
||||||
|
FS_WRITE, write, FS_CLOSE, close, FS_LSEEK, lseek)
|
||||||
|
|
||||||
void fs_init(fs_t *fs)
|
void fs_init(fs_t *fs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -198,7 +198,8 @@ int ns_query(const char *path, obj_handler_t *svr_hd)
|
|||||||
newfd = find_hd(path);
|
newfd = find_hd(path);
|
||||||
if (newfd != HANDLER_INVALID)
|
if (newfd != HANDLER_INVALID)
|
||||||
{
|
{
|
||||||
return newfd;
|
*svr_hd = newfd;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
newfd = handler_alloc();
|
newfd = handler_alloc();
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
|||||||
RPC_ARRAY_TYPE_DEF(len_type, data_type, length); \
|
RPC_ARRAY_TYPE_DEF(len_type, data_type, length); \
|
||||||
RPC_SVR_MSG_TO_BUF_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
RPC_SVR_MSG_TO_BUF_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) > IPC_MSG_SIZE) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > \
|
||||||
|
IPC_MSG_SIZE) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -214,7 +215,8 @@ RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
|||||||
} \
|
} \
|
||||||
RPC_SVR_BUF_TO_MSG_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
RPC_SVR_BUF_TO_MSG_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) > max) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > \
|
||||||
|
max) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -235,7 +237,8 @@ RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
|||||||
} \
|
} \
|
||||||
RPC_CLI_MSG_TO_BUF_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
RPC_CLI_MSG_TO_BUF_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) > IPC_MSG_SIZE) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > \
|
||||||
|
IPC_MSG_SIZE) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -256,7 +259,8 @@ RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
|||||||
} \
|
} \
|
||||||
RPC_CLI_BUF_TO_MSG_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
RPC_CLI_BUF_TO_MSG_WITHOUT_IMPL(rpc_array_##len_type##_##data_type##_##length##_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) > max) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > \
|
||||||
|
max) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -304,7 +308,7 @@ RPC_ARRAY_DEF(uint32_t, uint8_t, 32)
|
|||||||
RPC_REF_ARRAY_TYPE_DEF(len_type, data_type, length); \
|
RPC_REF_ARRAY_TYPE_DEF(len_type, data_type, length); \
|
||||||
RPC_CLI_MSG_TO_BUF_WITHOUT_IMPL(rpc_ref_array_##len_type##_##data_type##_##length##_t, int) \
|
RPC_CLI_MSG_TO_BUF_WITHOUT_IMPL(rpc_ref_array_##len_type##_##data_type##_##length##_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) >= IPC_MSG_SIZE) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > IPC_MSG_SIZE) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -325,13 +329,14 @@ RPC_ARRAY_DEF(uint32_t, uint8_t, 32)
|
|||||||
} \
|
} \
|
||||||
RPC_CLI_BUF_TO_MSG_WITHOUT_IMPL(rpc_ref_array_uint32_t_uint8_t_32_t, int) \
|
RPC_CLI_BUF_TO_MSG_WITHOUT_IMPL(rpc_ref_array_uint32_t_uint8_t_32_t, int) \
|
||||||
{ \
|
{ \
|
||||||
if (rpc_align(d->len, __alignof(d->len) + sizeof(d->len)) > max) \
|
if (rpc_align(len, __alignof(d->len)) + d->len > \
|
||||||
|
max) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
len = rpc_align(len, __alignof(d->len)); \
|
len = rpc_align(len, __alignof(d->len)); \
|
||||||
d->len = *((typeof(d->len) *)(&buf[len])); \
|
d->len = *((typeof(d->len) *)(&buf[len])); \
|
||||||
if (rpc_align(d->len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) >= max) \
|
if (rpc_align(d->len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) > max) \
|
||||||
{ \
|
{ \
|
||||||
return -ETOLONG; \
|
return -ETOLONG; \
|
||||||
} \
|
} \
|
||||||
@@ -557,7 +562,6 @@ RPC_TYPE_INIT_WITHOUT_IMPL(rpc_obj_handler_t_t)
|
|||||||
return tag; \
|
return tag; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define RPC_DISPATCH2(struct_type, op_type, func0_op, func0_name, func1_op, func1_name) \
|
#define RPC_DISPATCH2(struct_type, op_type, func0_op, func0_name, func1_op, func1_name) \
|
||||||
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
|
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
|
||||||
{ \
|
{ \
|
||||||
@@ -609,6 +613,78 @@ RPC_TYPE_INIT_WITHOUT_IMPL(rpc_obj_handler_t_t)
|
|||||||
return tag; \
|
return tag; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define RPC_DISPATCH4(struct_type, op_type, func0_op, func0_name, func1_op, func1_name, func2_op, func2_name, func3_op, func3_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; \
|
||||||
|
} \
|
||||||
|
return tag; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RPC_DISPATCH5(struct_type, op_type, func0_op, func0_name, func1_op, func1_name, \
|
||||||
|
func2_op, func2_name, func3_op, func3_name, \
|
||||||
|
func4_op, func4_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; \
|
||||||
|
} \
|
||||||
|
return tag; \
|
||||||
|
}
|
||||||
|
|
||||||
#include "u_rpc_1.h"
|
#include "u_rpc_1.h"
|
||||||
#include "u_rpc_2.h"
|
#include "u_rpc_2.h"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
|
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
|
||||||
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_map); \
|
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_map); \
|
||||||
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), 0), msg_ipc);*/ \
|
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), 0), msg_ipc);*/ \
|
||||||
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), \
|
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), 0), \
|
||||||
ipc_timeout_create2(0, 0)); \
|
ipc_timeout_create2(0, 0)); \
|
||||||
\
|
\
|
||||||
if (msg_tag_get_val(tag) < 0) \
|
if (msg_tag_get_val(tag) < 0) \
|
||||||
|
|||||||
@@ -56,11 +56,12 @@ int app_load(const char *name, uenv_t *cur_env)
|
|||||||
|
|
||||||
app_info_t *app = app_info_get((void *)addr);
|
app_info_t *app = app_info_get((void *)addr);
|
||||||
|
|
||||||
if (app == NULL) {
|
if (app == NULL)
|
||||||
|
{
|
||||||
printf("app format is error.\n");
|
printf("app format is error.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("app addr is 0x%x\n", app);
|
printf("%s addr is 0x%x\n", name, app);
|
||||||
umword_t ram_base;
|
umword_t ram_base;
|
||||||
obj_handler_t hd_task = handler_alloc();
|
obj_handler_t hd_task = handler_alloc();
|
||||||
obj_handler_t hd_thread = handler_alloc();
|
obj_handler_t hd_thread = handler_alloc();
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ typedef struct file_desc
|
|||||||
FIL fp;
|
FIL fp;
|
||||||
} file_desc_t;
|
} file_desc_t;
|
||||||
|
|
||||||
#define FILE_DESC_NR 16
|
#define FILE_DESC_NR 3
|
||||||
static file_desc_t files[FILE_DESC_NR];
|
static file_desc_t files[FILE_DESC_NR];
|
||||||
|
|
||||||
file_desc_t *alloc_file(int *fd)
|
static file_desc_t *alloc_file(int *fd)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < FILE_DESC_NR; i++)
|
for (int i = 0; i < FILE_DESC_NR; i++)
|
||||||
{
|
{
|
||||||
@@ -30,10 +30,19 @@ file_desc_t *alloc_file(int *fd)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void free_file(int fd)
|
static void free_file(int fd)
|
||||||
{
|
{
|
||||||
files[fd].fp.obj.fs = NULL;
|
files[fd].fp.obj.fs = NULL;
|
||||||
}
|
}
|
||||||
|
static file_desc_t *file_get(int fd)
|
||||||
|
{
|
||||||
|
if (fd < 0 || fd >= FILE_DESC_NR)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return files + fd;
|
||||||
|
}
|
||||||
|
|
||||||
int fs_svr_open(const char *path, int flags, int mode)
|
int fs_svr_open(const char *path, int flags, int mode)
|
||||||
{
|
{
|
||||||
printf("open %s.\n", path);
|
printf("open %s.\n", path);
|
||||||
@@ -55,6 +64,90 @@ int fs_svr_open(const char *path, int flags, int mode)
|
|||||||
return -ret;
|
return -ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fs_svr_read(int fd, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
UINT br;
|
||||||
|
file_desc_t *file = file_get(fd);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
FRESULT ret = f_read(&file->fp, buf, len, &br);
|
||||||
|
|
||||||
|
if (ret != FR_OK)
|
||||||
|
{
|
||||||
|
return -ret;
|
||||||
|
}
|
||||||
|
return br;
|
||||||
|
}
|
||||||
|
int fs_svr_write(int fd, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
UINT bw;
|
||||||
|
file_desc_t *file = file_get(fd);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
FRESULT ret = f_write(&file->fp, buf, len, &bw);
|
||||||
|
|
||||||
|
if (ret != FR_OK)
|
||||||
|
{
|
||||||
|
return -ret;
|
||||||
|
}
|
||||||
|
return bw;
|
||||||
|
}
|
||||||
|
void fs_svr_close(int fd)
|
||||||
|
{
|
||||||
|
file_desc_t *file = file_get(fd);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
f_close(&file->fp);
|
||||||
|
}
|
||||||
|
int fs_svr_lseek(int fd, int offs, int whence)
|
||||||
|
{
|
||||||
|
UINT bw;
|
||||||
|
file_desc_t *file = file_get(fd);
|
||||||
|
int new_offs = 0;
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
switch (whence)
|
||||||
|
{
|
||||||
|
case SEEK_SET:
|
||||||
|
new_offs = offs;
|
||||||
|
break;
|
||||||
|
case SEEK_END:
|
||||||
|
{
|
||||||
|
new_offs = f_size(&file->fp) + offs;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SEEK_CUR:
|
||||||
|
{
|
||||||
|
new_offs = offs + f_tell(&file->fp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
if (new_offs > f_size(&file->fp))
|
||||||
|
{
|
||||||
|
new_offs = f_size(&file->fp);
|
||||||
|
}
|
||||||
|
if (new_offs < 0)
|
||||||
|
{
|
||||||
|
new_offs = 0;
|
||||||
|
}
|
||||||
|
FRESULT ret = f_lseek(&file->fp, new_offs);
|
||||||
|
|
||||||
|
return -ret;
|
||||||
|
}
|
||||||
void fs_svr_loop(void)
|
void fs_svr_loop(void)
|
||||||
{
|
{
|
||||||
rpc_loop(fs.ipc, &fs.svr);
|
rpc_loop(fs.ipc, &fs.svr);
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
void fs_svr_init(obj_handler_t ipc);
|
void fs_svr_init(obj_handler_t ipc);
|
||||||
void fs_svr_loop(void);
|
void fs_svr_loop(void);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#define HEAP_SIZE 4
|
#define HEAP_SIZE 4
|
||||||
#define STACK_SIZE 1024 * 2
|
#define STACK_SIZE 1024 * 3
|
||||||
|
|
||||||
#if defined(__CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||||
|
|||||||
@@ -97,49 +97,3 @@ void namespace_loop(void)
|
|||||||
{
|
{
|
||||||
rpc_loop(ns.ipc_hd, &ns.svr);
|
rpc_loop(ns.ipc_hd, &ns.svr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// msg_tag_t ns_dispatch(ipc_msg_t *msg)
|
|
||||||
// {
|
|
||||||
// msg_tag_t tag = msg_tag_init4(0, 0, 0, -ENOSYS);
|
|
||||||
// assert(msg);
|
|
||||||
|
|
||||||
// switch (msg->msg_buf[0])
|
|
||||||
// {
|
|
||||||
// case OP_REGISTER: //!< 服务注册
|
|
||||||
// {
|
|
||||||
// size_t len = msg->msg_buf[1];
|
|
||||||
// if (len > NAMESPACE_PATH_LEN)
|
|
||||||
// {
|
|
||||||
// tag = msg_tag_init4(0, 0, 0, -EINVAL);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// ((char *)&(msg->msg_buf[2]))[len] = 0;
|
|
||||||
// int ret = ns_register((char *)(&msg->msg_buf[2]), pre_alloc_hd);
|
|
||||||
// ns_pre_alloc_map_fd(msg);
|
|
||||||
// tag = msg_tag_init4(0, 0, 0, ret);
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// case OP_QUERY: //!< 服务申请
|
|
||||||
// {
|
|
||||||
// obj_handler_t hd;
|
|
||||||
// int ret = ns_query(((char *)&(msg->msg_buf[2])), &hd);
|
|
||||||
// if (ret < 0)
|
|
||||||
// {
|
|
||||||
// tag = msg_tag_init4(0, 0, 0, ret);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// size_t len = msg->msg_buf[1];
|
|
||||||
|
|
||||||
// msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
|
|
||||||
// printf("query..\n");
|
|
||||||
// tag = msg_tag_init4(0, 0, 1, ret);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// tag = msg_tag_init4(0, 0, 0, -ENOSYS);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// return tag;
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -64,7 +64,17 @@ void ns_test(void)
|
|||||||
#include "fs_cli.h"
|
#include "fs_cli.h"
|
||||||
void fs_test(void)
|
void fs_test(void)
|
||||||
{
|
{
|
||||||
fs_open("/test", 0, 0);
|
char tmp[4] = "123";
|
||||||
|
int fd = fs_open("/test", 0, 0x1 | 0x2 | 0x8);
|
||||||
|
assert(fd >= 0);
|
||||||
|
int wlen = fs_write(fd, tmp, 4);
|
||||||
|
assert(wlen == 4);
|
||||||
|
int ret = fs_lseek(fd, 0, SEEK_SET);
|
||||||
|
assert(ret >= 0);
|
||||||
|
int rlen = fs_read(fd, tmp, 4);
|
||||||
|
assert(rlen == 4);
|
||||||
|
assert(strcmp(tmp, "123") == 0);
|
||||||
|
fs_close(fd);
|
||||||
}
|
}
|
||||||
int main(int argc, char *args[])
|
int main(int argc, char *args[])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user