support zynq7000-zc702
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# Automatically generated file; DO NOT EDIT.
|
||||
# XiZi_AIoT Project Configuration
|
||||
#
|
||||
CONFIG_BOARD_IMX6Q_SABRELITE=y
|
||||
CONFIG_ARCH_ARM=y
|
||||
|
||||
#
|
||||
# imx6q sabrelite feature
|
||||
#
|
||||
|
||||
#
|
||||
# Lib
|
||||
#
|
||||
CONFIG_LIB=y
|
||||
CONFIG_LIB_POSIX=y
|
||||
CONFIG_LIB_NEWLIB=y
|
||||
# CONFIG_LIB_MUSLLIB is not set
|
||||
@@ -0,0 +1,25 @@
|
||||
mainmenu "XiZi_AIoT Project Configuration"
|
||||
|
||||
config BSP_DIR
|
||||
string
|
||||
option env="BSP_ROOT"
|
||||
default "."
|
||||
|
||||
config KERNEL_DIR
|
||||
string
|
||||
option env="KERNEL_ROOT"
|
||||
default "../.."
|
||||
|
||||
config BOARD_IMX6Q_SABRELITE
|
||||
bool
|
||||
select ARCH_ARM
|
||||
default y
|
||||
|
||||
source "$KERNEL_DIR/hardkernel/arch/Kconfig"
|
||||
|
||||
menu "imx6q sabrelite feature"
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
source "$KERNEL_DIR/Kconfig"
|
||||
@@ -0,0 +1,63 @@
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
toolchain ?= arm-none-eabi-
|
||||
user_ldflags = --specs=nosys.specs -Wl,-Map=user.map,-cref -N
|
||||
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -no-pie
|
||||
endif
|
||||
ifeq ($(BOARD), zynq7000-zc702)
|
||||
toolchain ?= arm-xilinx-eabi-
|
||||
user_ldflags = -Wl,--start-group,-lgcc,-lc,--end-group -N
|
||||
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||
board_specs = stub.o
|
||||
#cflags = -Wall -g -std=c11
|
||||
endif
|
||||
|
||||
cc = ${toolchain}gcc
|
||||
ld = ${toolchain}g++
|
||||
objdump = ${toolchain}objdump
|
||||
c_useropts = -O0
|
||||
|
||||
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
all: init simple_client simple_server shell fs_server test_priority readme.txt | bin
|
||||
../tools/mkfs/mkfs ./fs.img $^
|
||||
@mv $(filter-out readme.txt, $^) bin
|
||||
@mv *.o bin
|
||||
@mv *.asm bin
|
||||
|
||||
bin:
|
||||
@mkdir -p bin
|
||||
|
||||
shell: shell_port.o libserial.o shell_cmd_list.o shell.o shell_ext.o libfs_to_client.o libipc.o session.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
simple_server: simple_server.o libserial.o libipc.o session.o simple_service.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
fs_server: fs_server.o libfs_to_client.o fs.o libserial.o libipc.o session.o block_io.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_priority: test_priority.o libserial.o usyscall.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
%.o: %.c
|
||||
@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $<
|
||||
|
||||
%.o: %.S
|
||||
@${cc} ${cflags} ${c_useropts} -o $@ -c $<
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
// init: The initial user-level program
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "libfs_to_client.h"
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct Session session;
|
||||
connect_session(&session, "MemFS", 8092);
|
||||
|
||||
int fd;
|
||||
char* shell_task_param[2] = { "/shell", 0 };
|
||||
if ((fd = open(&session, shell_task_param[0])) < 0) {
|
||||
printf("Open %s failed\n", shell_task_param[0]);
|
||||
exit();
|
||||
}
|
||||
|
||||
if (spawn(&session, fd, read, shell_task_param[0], shell_task_param) < 0) {
|
||||
printf("Syscall Spawn shell failed\n");
|
||||
}
|
||||
|
||||
close(&session, fd);
|
||||
|
||||
exit();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Xiuos-AIoT
|
||||
This is User FS
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @file shell_port.c
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2019-02-22
|
||||
*
|
||||
* @copyright (c) 2019 Letter
|
||||
*
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "session.h"
|
||||
#include "shell.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
Shell shell;
|
||||
char shellBuffer[512];
|
||||
struct Session session_fs;
|
||||
|
||||
signed short userShellWrite(char* data, unsigned short len)
|
||||
{
|
||||
unsigned short length = len;
|
||||
while (length--) {
|
||||
printf("%c", *data++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
signed short userShellRead(char* data, unsigned short len)
|
||||
{
|
||||
unsigned short length = len;
|
||||
static char cur_read;
|
||||
while (length--) {
|
||||
cur_read = getc();
|
||||
if (cur_read == 0xff) {
|
||||
yield();
|
||||
}
|
||||
// *data++ = getc();
|
||||
*data++ = cur_read;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
shell.write = userShellWrite;
|
||||
shell.read = userShellRead;
|
||||
|
||||
shellInit(&shell, shellBuffer, 512);
|
||||
|
||||
connect_session(&session_fs, "MemFS", 8092);
|
||||
if (!session_fs.buf) {
|
||||
printf("session connect faield\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
shellTask(&shell);
|
||||
|
||||
free_session(&session_fs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libfs_to_client.h"
|
||||
#include "libserial.h"
|
||||
#include "simple_service.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
int string_to_integer(const char* str)
|
||||
{
|
||||
assert(str);
|
||||
while (*str == ' ') {
|
||||
str++;
|
||||
}
|
||||
int is_positive = 1; // 默认是正
|
||||
if (*str - '+' == 0) {
|
||||
is_positive = 1;
|
||||
str++;
|
||||
}
|
||||
if (*str - '-' == 0) {
|
||||
is_positive = 0;
|
||||
str++;
|
||||
}
|
||||
long long result = 0; // int可能存不下 改为long long较为合适虽然返回值会丢失精度但感觉不要紧
|
||||
while ('0' <= *str && *str <= '9') {
|
||||
result *= 10;
|
||||
result += *str - '0'; // 如'1' ascii的值为 49 '0'的ascii的值为48 相减得到1
|
||||
|
||||
if (result > INT32_MAX || result < INT32_MIN) // 可能出现的溢出问题
|
||||
{
|
||||
return result > INT32_MAX ? INT32_MAX : INT32_MIN;
|
||||
}
|
||||
|
||||
str++;
|
||||
}
|
||||
return is_positive ? (result) : -result;
|
||||
}
|
||||
|
||||
void itoa(int num, char* str, int radix)
|
||||
{
|
||||
int i = 0;
|
||||
int sum;
|
||||
unsigned int num1 = num; // 如果是负数求补码,必须将他的绝对值放在无符号位中在进行求反码
|
||||
char str1[33] = { 0 };
|
||||
if (num < 0) { // 求出负数的补码
|
||||
num = -num;
|
||||
num1 = ~num;
|
||||
num1 += 1;
|
||||
}
|
||||
if (num == 0) {
|
||||
str1[i] = '0';
|
||||
|
||||
i++;
|
||||
}
|
||||
while (num1 != 0) { // 进行进制运算
|
||||
sum = num1 % radix;
|
||||
str1[i] = (sum > 9) ? (sum - 10) + 'a' : sum + '0';
|
||||
num1 = num1 / radix;
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
int j = 0;
|
||||
for (i; i >= 0; i--) { // 逆序输出
|
||||
str[i] = str1[j];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int id = 1;
|
||||
if (argc >= 2) {
|
||||
id = string_to_integer(argv[1]);
|
||||
}
|
||||
printf("This is Simple Client %d, size is 0x%x\n", id, task_heap_base());
|
||||
|
||||
struct Session session_wait;
|
||||
struct Session session_nowait;
|
||||
if (connect_session(&session_wait, "SimpleServer", 4096) < 0 || connect_session(&session_nowait, "SimpleServer", 4096) < 0) {
|
||||
printf("connect session failed\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
char *buf1 = NULL, *buf2 = NULL;
|
||||
struct IpcMsg* msg1 = hello_string_nowait(&session_nowait, &buf1, 32);
|
||||
struct IpcMsg* msg2 = hello_string_nowait(&session_nowait, &buf2, 128);
|
||||
|
||||
int ret = add(&session_wait, 17, 22);
|
||||
printf("ipc_add 17 + 22 = %d\n", ret);
|
||||
char buf[32];
|
||||
ret = add(&session_wait, 9, 9);
|
||||
printf("ipc_add 9 + 9 = %d\n", ret);
|
||||
|
||||
struct Session session;
|
||||
static char id_buf[33] = { 0 };
|
||||
if (id > 1) {
|
||||
if (connect_session(&session, "MemFS", 8092) < 0) {
|
||||
printf("connect session failed\n");
|
||||
} else {
|
||||
int fd;
|
||||
itoa(id - 1, id_buf, 10);
|
||||
char* shell_task_param[3] = { "/simple_client", id_buf, 0 };
|
||||
if ((fd = open(&session, shell_task_param[0])) >= 0) {
|
||||
if (spawn(&session, fd, read, shell_task_param[0], shell_task_param) < 0) {
|
||||
printf("Syscall Spawn simple_client failed\n");
|
||||
}
|
||||
if (spawn(&session, fd, read, shell_task_param[0], shell_task_param) < 0) {
|
||||
printf("Syscall Spawn simple_client failed\n");
|
||||
}
|
||||
close(&session, fd);
|
||||
} else {
|
||||
printf("Open %s failed\n", shell_task_param[0]);
|
||||
}
|
||||
free_session(&session);
|
||||
}
|
||||
}
|
||||
|
||||
ipc_session_wait(&session_nowait);
|
||||
printf("buf1: %s\n", buf1);
|
||||
ipc_session_forward(&session_nowait);
|
||||
|
||||
ipc_session_wait(&session_nowait);
|
||||
printf("buf2: %s\n", buf2);
|
||||
ipc_session_forward(&session_nowait);
|
||||
|
||||
free_session(&session_wait);
|
||||
free_session(&session_nowait);
|
||||
|
||||
exit();
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "simple_service.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
int IPC_DO_SERVE_FUNC(Ipc_add)(int* a, int* b)
|
||||
{
|
||||
return *a + *b;
|
||||
}
|
||||
|
||||
int IPC_DO_SERVE_FUNC(Ipc_hello_string)(char* buf, int* len)
|
||||
{
|
||||
static char hello_string[] = "Hello, This is server!";
|
||||
int copy_len = sizeof(hello_string) > *len ? *len : sizeof(hello_string);
|
||||
memcpy(buf, hello_string, copy_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
IPC_SERVER_INTERFACE(Ipc_add, 2);
|
||||
IPC_SERVER_INTERFACE(Ipc_hello_string, 2);
|
||||
IPC_SERVER_REGISTER_INTERFACES(IpcSimpleServer, 2, Ipc_hello_string, Ipc_add);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (register_server("SimpleServer") < 0) {
|
||||
printf("register server name: %s failed.\n", "SimpleServer");
|
||||
exit();
|
||||
}
|
||||
ipc_server_loop(&IpcSimpleServer);
|
||||
|
||||
// never reached
|
||||
exit();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include "simple_service.h"
|
||||
|
||||
IPC_INTERFACE(Ipc_add, 2, a, b, sizeof(int), sizeof(int));
|
||||
int add(struct Session* session, int a, int b)
|
||||
{
|
||||
return IPC_CALL(Ipc_add)(session, &a, &b);
|
||||
}
|
||||
|
||||
IPC_INTERFACE(Ipc_hello_string, 2, buf, len, *(int*)len, sizeof(int));
|
||||
int hello_string(struct Session* session, char* buf, int len)
|
||||
{
|
||||
return IPC_CALL(Ipc_hello_string)(session, buf, &len);
|
||||
}
|
||||
|
||||
struct IpcMsg* hello_string_nowait(struct Session* session, char** buf, int len)
|
||||
{
|
||||
struct IpcMsg* msg = IPC_CREATE_MSG_FUNC(Ipc_hello_string)(session, *buf, &len);
|
||||
*buf = ipc_msg_get_nth_arg_buf(msg, 0);
|
||||
ipc_msg_set_nth_arg(msg, 1, &len, sizeof(int));
|
||||
ipc_msg_set_opcode(msg, Ipc_hello_string);
|
||||
ipc_msg_send_nowait(msg);
|
||||
return msg;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libipc.h"
|
||||
|
||||
IPC_SERVICES(IpcSimpleServer, Ipc_add, Ipc_hello_string);
|
||||
|
||||
int add(struct Session* session, int a, int b);
|
||||
int hello_string(struct Session* session, char* buf, int len);
|
||||
struct IpcMsg* hello_string_nowait(struct Session* session, char** buf, int len);
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
// test_fs: Test the file io control of fs
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "libfs_to_client.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
printf("file system test\n");
|
||||
|
||||
struct Session session;
|
||||
connect_session(&session, "MemFS", 4096);
|
||||
|
||||
register_server("TEST_FS");
|
||||
|
||||
int fd;
|
||||
char* fd_path = "/readme.txt";
|
||||
fd = open(&session, fd_path);
|
||||
/// @todo support malloc for user
|
||||
char buffer[BLOCK_SIZE] = { 0 };
|
||||
read(&session, fd, buffer, 0, BLOCK_SIZE);
|
||||
printf("file content: %s\n", buffer);
|
||||
|
||||
char* write_data = "hello world\n";
|
||||
write(&session, fd, write_data, 0, strlen(write_data) + 1);
|
||||
memset(buffer, 0, BLOCK_SIZE);
|
||||
read(&session, fd, buffer, 0, BLOCK_SIZE);
|
||||
printf("file content: %s\n", buffer);
|
||||
|
||||
close(&session, fd);
|
||||
|
||||
free_session(&session);
|
||||
|
||||
exit();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
// test_priority: Test the priority scheduler of task
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
static void count_down()
|
||||
{
|
||||
int time = 500000000;
|
||||
while (time >= 0) {
|
||||
if (time % 10000000 == 0) {
|
||||
printf("Priority-based preempting, time remained %d\n", time);
|
||||
}
|
||||
time--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// set priority
|
||||
sys_state_info info;
|
||||
info.priority = 0;
|
||||
set_priority(&info);
|
||||
|
||||
// test function
|
||||
count_down();
|
||||
|
||||
exit();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include "usyscall.h"
|
||||
|
||||
static int
|
||||
syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
__asm__ volatile(
|
||||
"mov r0, %1;\
|
||||
mov r1, %2;\
|
||||
mov r2, %3;\
|
||||
mov r3, %4;\
|
||||
mov r4, %5;\
|
||||
swi 0;\
|
||||
dsb;\
|
||||
isb;\
|
||||
mov %0, r0"
|
||||
: "=r"(ret)
|
||||
: "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4)
|
||||
: "memory", "r0", "r1", "r2", "r3", "r4");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, char* name, char** argv)
|
||||
{
|
||||
struct KernReadTool read_tool = {
|
||||
.session = session,
|
||||
.fd = fd,
|
||||
.ipc_read = ipc_read,
|
||||
};
|
||||
return syscall(SYSCALL_SPAWN, (intptr_t)&read_tool, (intptr_t)name, (intptr_t)argv, 0);
|
||||
}
|
||||
|
||||
int exit()
|
||||
{
|
||||
return syscall(SYSCALL_EXIT, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int yield()
|
||||
{
|
||||
return syscall(SYSCALL_YIELD, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int register_server(char* name)
|
||||
{
|
||||
return syscall(SYSCALL_SERVER, (intptr_t)name, 0, 0, 0);
|
||||
}
|
||||
|
||||
int session(char* path, int capacity, struct Session* user_session)
|
||||
{
|
||||
return syscall(SYSCALL_SESSION, (intptr_t)path, (intptr_t)capacity, (intptr_t)user_session, 0);
|
||||
}
|
||||
|
||||
int poll_session(struct Session* userland_session_arr, int arr_capacity)
|
||||
{
|
||||
return syscall(SYSCALL_POLL_SESSION, (intptr_t)userland_session_arr, (intptr_t)arr_capacity, 0, 0);
|
||||
}
|
||||
|
||||
int close_session(struct Session* session)
|
||||
{
|
||||
return syscall(SYSCALL_CLOSE_SESSION, (intptr_t)session, 0, 0, 0);
|
||||
}
|
||||
|
||||
int get_memblock_info(sys_state_info* info)
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_MEMBLOCK_INFO, (intptr_t)info, 0, 0);
|
||||
}
|
||||
|
||||
int set_priority(sys_state_info* info)
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SET_TASK_PRIORITY, (intptr_t)info, 0, 0);
|
||||
}
|
||||
|
||||
int task_heap_base()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_GET_HEAP_BASE, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_task()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_TASKS, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_mem()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_MEM_INFO, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_cpu()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_CPU_INFO, 0, 0, 0);
|
||||
}
|
||||
|
||||
int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev)
|
||||
{
|
||||
return syscall(SYSCALL_MMAP, vaddr, paddr, (intptr_t)len, (intptr_t)is_dev);
|
||||
}
|
||||
|
||||
int register_irq(int irq, int opcode)
|
||||
{
|
||||
return syscall(SYSCALL_REGISTER_IRQ, (intptr_t)irq, (intptr_t)opcode, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "session.h"
|
||||
|
||||
// clang-format off
|
||||
#define SYSCALL_TEST 0
|
||||
#define SYSCALL_SPAWN 1 // generate a brand new task to run elf
|
||||
#define SYSCALL_EXIT 2 // exit task, delete the task cb
|
||||
#define SYSCALL_YIELD 3 // yield task, go to scheduler
|
||||
|
||||
#define SYSCALL_MMAP 4 // map a virt page to phy page
|
||||
#define SYSCALL_SERVER 5 // register current task as a server
|
||||
#define SYSCALL_SESSION 6 // create a session to a server
|
||||
#define SYSCALL_POLL_SESSION 7 // server poll for it's server sessions
|
||||
#define SYSCALL_CLOSE_SESSION 8 // client close it's client sessions
|
||||
|
||||
#define SYSCALL_EXEC 9 // run elf using current task
|
||||
#define SYSCALL_SYS_STATE 10 // run system state
|
||||
#define SYSCALL_REGISTER_IRQ 11 //
|
||||
// clang-format on
|
||||
|
||||
typedef enum {
|
||||
SYS_STATE_TEST = 0,
|
||||
SYS_STATE_SET_TASK_PRIORITY,
|
||||
SYS_STATE_GET_HEAP_BASE,
|
||||
SYS_STATE_MEMBLOCK_INFO,
|
||||
SYS_STATE_SHOW_TASKS,
|
||||
SYS_STATE_SHOW_MEM_INFO,
|
||||
SYS_STATE_SHOW_CPU_INFO,
|
||||
} sys_state_option;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uintptr_t memblock_start;
|
||||
uintptr_t memblock_end;
|
||||
} memblock_info;
|
||||
int priority;
|
||||
} sys_state_info;
|
||||
|
||||
typedef int (*ipc_read_fn)(struct Session* session, int fd, char* dst, int offset, int len);
|
||||
typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len);
|
||||
|
||||
struct KernReadTool {
|
||||
struct Session* session;
|
||||
int fd;
|
||||
ipc_read_fn ipc_read;
|
||||
};
|
||||
|
||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, char* name, char** argv);
|
||||
int exit();
|
||||
int yield();
|
||||
int register_server(char* name);
|
||||
int session(char* path, int capacity, struct Session* user_session);
|
||||
int poll_session(struct Session* userland_session_arr, int arr_capacity);
|
||||
int close_session(struct Session* session);
|
||||
int task_heap_base();
|
||||
int get_memblock_info(sys_state_info* info);
|
||||
int set_priority(sys_state_info* info);
|
||||
int show_task();
|
||||
int show_mem();
|
||||
int show_cpu();
|
||||
int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev);
|
||||
int register_irq(int irq, int opcode);
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef XS_CONFIG_H__
|
||||
#define XS_CONFIG_H__
|
||||
|
||||
/* Automatically generated file; DO NOT EDIT. */
|
||||
/* XiZi_AIoT Project Configuration */
|
||||
|
||||
#define BOARD_IMX6Q_SABRELITE
|
||||
#define ARCH_ARM
|
||||
|
||||
/* imx6q sabrelite feature */
|
||||
|
||||
/* Lib */
|
||||
|
||||
#define LIB
|
||||
#define LIB_POSIX
|
||||
#define LIB_NEWLIB
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user