forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
27
applications/user_api/switch_api/Makefile
Normal file
27
applications/user_api/switch_api/Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
ifeq ($(CONFIG_SEPARATE_COMPILE),y)
|
||||
SRC_FILES :=user_print_info.c user_task.c user_mem.c
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_SEMAPHORE),y)
|
||||
SRC_FILES += user_semaphore.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_MUTEX),y)
|
||||
SRC_FILES += user_mutex.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_EVENT),y)
|
||||
SRC_FILES += user_event.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
|
||||
SRC_FILES += user_msg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FS_VFS),y)
|
||||
SRC_FILES += user_fs.c
|
||||
endif
|
||||
else
|
||||
SRC_FILES :=
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
247
applications/user_api/switch_api/user_api.h
Normal file
247
applications/user_api/switch_api/user_api.h
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_api.h
|
||||
* @brief: the priviate user api for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XS_USER_API_H
|
||||
#define XS_USER_API_H
|
||||
|
||||
|
||||
// #include <xiuos.h>
|
||||
|
||||
#include <xsconfig.h>
|
||||
#include "../../../kernel/include/xs_service.h"
|
||||
#include "../../../kernel/include/xs_base.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "../../../arch/kswitch.h"
|
||||
#include <libc.h>
|
||||
|
||||
|
||||
#ifdef SEPARATE_COMPILE
|
||||
|
||||
#define TASK_INFO 1
|
||||
#define MEM_INFO 2
|
||||
#define SEM_INFO 3
|
||||
#define EVENT_INFO 4
|
||||
#define MUTEX_INFO 5
|
||||
#define MEMPOOL_INFO 6
|
||||
#define MSGQUEUE_INFO 7
|
||||
#define DEVICE_INFO 8
|
||||
#define TIMER_INFO 9
|
||||
|
||||
int UserPrintInfo(unsigned long i);
|
||||
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
int32_t stack_size;
|
||||
uint8_t prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
|
||||
typedef void DIR;
|
||||
|
||||
int32_t UserTaskCreate(utask_x utask);
|
||||
|
||||
x_err_t UserTaskStartup(int32_t id);
|
||||
x_err_t UserTaskDelete(int32_t id);
|
||||
void UserTaskQuit(void);
|
||||
x_err_t UserTaskDelay(int32_t ms);
|
||||
x_err_t UserGetTaskName(int32_t id ,char *name);
|
||||
int32_t UserGetTaskID(void);
|
||||
uint8_t UserGetTaskStat(int32_t id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
x_err_t UserTaskCoreCombine(int32_t id,uint8_t core_id);
|
||||
x_err_t UserTaskCoreUnCombine(int32_t id);
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id);
|
||||
uint8_t UserGetTaskRunningCore(int32_t id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id);
|
||||
uint8_t UserGetTaskPriority(int32_t id);
|
||||
|
||||
|
||||
void *UserMalloc(size_t size);
|
||||
void *UserRealloc(void *pointer, size_t size);
|
||||
void *UserCalloc(size_t count, size_t size);
|
||||
void UserFree(void *pointer);
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
int32_t UserMutexCreate();
|
||||
void UserMutexDelete(int32_t mutex);
|
||||
int32_t UserMutexObtain(int32_t mutex, int32_t wait_time);
|
||||
int32_t UserMutexAbandon(int32_t mutex);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
typedef int32 sem_t;
|
||||
sem_t UserSemaphoreCreate(uint16_t val);
|
||||
x_err_t UserSemaphoreDelete(sem_t sem);
|
||||
x_err_t UserSemaphoreObtain(sem_t sem, int32_t wait_time);
|
||||
x_err_t UserSemaphoreAbandon(sem_t sem);
|
||||
x_err_t UserSemaphoreSetValue(sem_t sem, uint16_t val);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
typedef int32 EventIdType;
|
||||
EventIdType UserEventCreate(uint8_t flag);
|
||||
void UserEventDelete(EventIdType event);
|
||||
x_err_t UserEventTrigger(EventIdType event, uint32_t set);
|
||||
x_err_t UserEventProcess(EventIdType event, uint32_t set, uint8_t option,
|
||||
int32_t wait_time, uint32_t *Recved);
|
||||
x_err_t UserEventReinit(EventIdType event);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
int32_t UserMsgQueueCreate(size_t msg_size, size_t max_msgs);
|
||||
x_err_t UserMsgQueueDelete(int32_t mq );
|
||||
x_err_t UserMsgQueueSendwait(int32_t mq, const void *buffer,
|
||||
size_t size, int32_t wait_time);
|
||||
x_err_t UserMsgQueueSend(int32_t mq, const void *buffer, size_t size);
|
||||
x_err_t UserMsgQueueUrgentSend(int32_t mq, const void *buffer, size_t size);
|
||||
x_err_t UserMsgQueueRecv(int32_t mq, void *buffer, size_t size,int32_t wait_time);
|
||||
x_err_t UserMsgQueueReinit(int32_t mq);
|
||||
#endif
|
||||
|
||||
int open(const char *path, int flags, ...);
|
||||
int read(int fd, void *buf, size_t len);
|
||||
int write(int fd, const void *buf, size_t len);
|
||||
int close(int fd);
|
||||
int ioctl(int fd, int cmd, void *args);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int rename(const char *from, const char *to);
|
||||
int unlink(const char *path);
|
||||
int stat(const char *path, struct stat *buf);
|
||||
int fstat(int fd, struct stat *buf);
|
||||
int fsync(int fd);
|
||||
int ftruncate(int fd, off_t length);
|
||||
|
||||
int mkdir(const char *path, mode_t mode);
|
||||
DIR *opendir(const char *path);
|
||||
int closedir(DIR *dirp);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int rmdir(const char *path);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
long telldir(DIR *dirp);
|
||||
void seekdir(DIR *dirp, off_t offset);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
#ifdef FS_VFS
|
||||
struct statfs {
|
||||
size_t f_bsize;
|
||||
size_t f_blocks;
|
||||
size_t f_bfree;
|
||||
};
|
||||
|
||||
int statfs(const char *path, struct statfs *buf);
|
||||
#endif
|
||||
|
||||
void Userprintf(const char *fmt, ...);
|
||||
|
||||
#define printf Userprintf
|
||||
|
||||
#else
|
||||
|
||||
#ifdef FS_VFS
|
||||
#include <iot-vfs_posix.h>
|
||||
#endif
|
||||
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
int32_t stack_size;
|
||||
uint8_t prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
int32_t UserTaskCreate(utask_x utask);
|
||||
|
||||
#define UserTaskStartup StartupKTask
|
||||
#define UserTaskDelete KTaskDelete
|
||||
#define UserTaskQuit KTaskQuit
|
||||
#define UserTaskDelay MdelayKTask
|
||||
|
||||
x_err_t UserGetTaskName(int32_t id ,char *name);
|
||||
int32_t UserGetTaskID(void);
|
||||
uint8_t UserGetTaskStat(int32_t id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
#define UserTaskCoreCombine KTaskCoreCombine
|
||||
#define UserTaskCoreUnCombine KTaskCoreUnCombine
|
||||
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id);
|
||||
uint8_t UserGetTaskRunningCore(int32_t id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id);
|
||||
uint8_t UserGetTaskPriority(int32_t id);
|
||||
|
||||
#define UserMalloc x_malloc
|
||||
#define UserRealloc x_realloc
|
||||
#define UserCalloc x_calloc
|
||||
#define UserFree x_free
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
#define UserMutexCreate KMutexCreate
|
||||
#define UserMutexDelete KMutexDelete
|
||||
#define UserMutexObtain KMutexObtain
|
||||
#define UserMutexAbandon KMutexAbandon
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
#define UserSemaphoreCreate KSemaphoreCreate
|
||||
#define UserSemaphoreDelete KSemaphoreDelete
|
||||
#define UserSemaphoreObtain KSemaphoreObtain
|
||||
#define UserSemaphoreAbandon KSemaphoreAbandon
|
||||
#define UserSemaphoreSetValue KSemaphoreSetValue
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
#define UserEventCreate KEventCreate
|
||||
#define UserEventDelete KEventDelete
|
||||
#define UserEventTrigger KEventTrigger
|
||||
#define UserEventProcess KEventProcess
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
#define UserMsgQueueCreate KCreateMsgQueue
|
||||
#define UserMsgQueueDelete KDeleteMsgQueue
|
||||
#define UserMsgQueueSendwait KMsgQueueSendwait
|
||||
#define UserMsgQueueSend KMsgQueueSend
|
||||
#define UserMsgQueueUrgentSend KMsgQueueUrgentSend
|
||||
#define UserMsgQueueRecv KMsgQueueRecv
|
||||
#define UserMsgQueueReinit KMsgQueueReinit
|
||||
#endif
|
||||
|
||||
#define UserPrintf KPrintf
|
||||
#define printf KPrintf
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
73
applications/user_api/switch_api/user_event.c
Normal file
73
applications/user_api/switch_api/user_event.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_event.c
|
||||
* @brief: the priviate user api of event for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* This function will create a event.
|
||||
*
|
||||
* @param flag the trigger way of event.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
EventIdType UserEventCreate(uint8_t flag){
|
||||
return (EventIdType)KSwitch1(KS_USER_EVENT_CREATE,(uintptr_t)flag );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will delete a event.
|
||||
*
|
||||
* @param event the id number of event.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void UserEventDelete(EventIdType event){
|
||||
KSwitch1(KS_USER_EVENT_DELETE,(uintptr_t)event);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will trigger the event
|
||||
*
|
||||
* @param event the id number of event
|
||||
* @param set trigger way & events flag
|
||||
*
|
||||
* @return EOK on success.
|
||||
*/
|
||||
x_err_t UserEventTrigger(EventIdType event, uint32_t set){
|
||||
return (x_err_t)KSwitch2(KS_USER_EVENT_TRIGGER,(uintptr_t)event, (uintptr_t)set );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will get the event and process this event
|
||||
*
|
||||
* @param event the id number of event
|
||||
* @param set events flag
|
||||
* @param option trigger way
|
||||
* @param wait_time timeout
|
||||
* @param Recved event processed flag
|
||||
*
|
||||
* @return EOK on success.
|
||||
*/
|
||||
x_err_t UserEventProcess(EventIdType event, uint32_t set, uint8_t option,
|
||||
int32_t wait_time, uint32_t *Recved){
|
||||
return (x_err_t)KSwitch5(KS_USER_EVENT_PROCESS,(uintptr_t)event, (uintptr_t)set, (uintptr_t)option, (uintptr_t)wait_time, (uintptr_t)Recved);
|
||||
}
|
||||
|
||||
144
applications/user_api/switch_api/user_fs.c
Normal file
144
applications/user_api/switch_api/user_fs.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_fs.c
|
||||
* @brief: the priviate user api of fs for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#define stdio 1
|
||||
#define CONSOLEBUF_SIZE 128
|
||||
|
||||
int open(const char *path, int flags, ...){
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
return (int)(KSwitch3(KS_USER_OPEN,(uintptr_t)path,(uintptr_t)flags,(uintptr_t)mode));
|
||||
}
|
||||
|
||||
int read(int fd, void *buf, size_t len){
|
||||
return (int)(KSwitch3(KS_USER_READ,(uintptr_t)fd,(uintptr_t)buf,(uintptr_t)len));
|
||||
}
|
||||
|
||||
int write(int fd, const void *buf, size_t len){
|
||||
return (int)(KSwitch3(KS_USER_WRITE,(uintptr_t)fd,(uintptr_t)buf,(uintptr_t)len));
|
||||
}
|
||||
|
||||
int close(int fd){
|
||||
return (int)(KSwitch1(KS_USER_CLOSE,(uintptr_t)fd));
|
||||
}
|
||||
|
||||
int ioctl(int fd, int cmd, void *args){
|
||||
return (int)(KSwitch3(KS_USER_IOCTL,(uintptr_t)fd,(uintptr_t)cmd,(uintptr_t)args));
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence){
|
||||
return (off_t)(KSwitch3(KS_USER_LSEEK,(uintptr_t)fd,(uintptr_t)offset,(uintptr_t)whence));
|
||||
}
|
||||
|
||||
int rename(const char *from, const char *to){
|
||||
return (int)(KSwitch2(KS_USER_RENAME,(uintptr_t)from,(uintptr_t)to));
|
||||
}
|
||||
|
||||
int unlink(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_UNLINK,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf){
|
||||
return (int)(KSwitch2(KS_USER_STAT,(uintptr_t)path,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf){
|
||||
return (int)(KSwitch2(KS_USER_FS_STAT,(uintptr_t)fd,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
int fsync(int fd){
|
||||
return (int)(KSwitch1(KS_USER_FS_SYNC,(uintptr_t)fd));
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length){
|
||||
return (int)(KSwitch2(KS_USER_FTRUNCATE,(uintptr_t)fd,(uintptr_t)length));
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode){
|
||||
return (int)(KSwitch2(KS_USER_MKDIR,(uintptr_t)path,(uintptr_t)mode));
|
||||
}
|
||||
|
||||
DIR *opendir(const char *path){
|
||||
return (DIR *)(KSwitch1(KS_USER_OPENDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int closedir(DIR *dirp){
|
||||
return (int)(KSwitch1(KS_USER_CLOSEDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dirp){
|
||||
return (struct dirent *)(KSwitch1(KS_USER_READDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
int rmdir(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_RMDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int chdir(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_CHDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
char *getcwd(char *buf, size_t size){
|
||||
return (char *)(KSwitch2(KS_USER_GETCWD,(uintptr_t)buf,(uintptr_t)size ));
|
||||
}
|
||||
|
||||
long telldir(DIR *dirp){
|
||||
return (long)(KSwitch1(KS_USER_TELLDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
void seekdir(DIR *dirp, off_t offset){
|
||||
return (void)(KSwitch2(KS_USER_SEEKDIR,(uintptr_t)dirp,(uintptr_t)offset));
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dirp){
|
||||
return (void)(KSwitch1(KS_USER_REWIND_DIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf){
|
||||
return (int)(KSwitch2(KS_USER_STAT_FS,(uintptr_t)path,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
void Userprintf(const char *fmt, ...)
|
||||
{
|
||||
if(stdio != NONE)
|
||||
{
|
||||
va_list args;
|
||||
size_t length;
|
||||
static char logbuf[CONSOLEBUF_SIZE];
|
||||
|
||||
va_start(args, fmt);
|
||||
|
||||
length = vsnprintf(logbuf, sizeof(logbuf) - 1, fmt, args);
|
||||
if (length > CONSOLEBUF_SIZE - 1)
|
||||
length = CONSOLEBUF_SIZE - 1;
|
||||
|
||||
write(stdio, logbuf, length);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
103
applications/user_api/switch_api/user_mem.c
Normal file
103
applications/user_api/switch_api/user_mem.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_mem.c
|
||||
* @brief: the priviate user api of mem for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* This function is provided to allocate memory block.
|
||||
*
|
||||
* @param size the memory size to be allocated
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserMalloc(size_t size){
|
||||
return (void *)(KSwitch1(KS_USER_MALLOC,(uintptr_t)size));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is provided to release memory block.
|
||||
*
|
||||
* @param pointer the memory to be released
|
||||
*/
|
||||
void UserFree(void *pointer){
|
||||
KSwitch1(KS_USER_FREE,(uintptr_t)pointer);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is provided to re-allocate memory block.
|
||||
*
|
||||
* @param pointer the old memory pointer
|
||||
* @param size the memory size to be re-allocated
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserRealloc(void *pointer, size_t size){
|
||||
x_size_t newsize = 0;
|
||||
x_size_t oldsize = 0;
|
||||
void *newmem = NONE;
|
||||
|
||||
/* the given pointer is NULL */
|
||||
if (pointer == NONE)
|
||||
return UserMalloc(size);
|
||||
|
||||
/* parameter detection */
|
||||
if (size == 0) {
|
||||
UserFree(pointer);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/* allocate new memory */
|
||||
newmem = UserMalloc(size);
|
||||
if(newmem == NONE) {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/* copy the old memory and then release old memory pointer */
|
||||
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
|
||||
UserFree(pointer);
|
||||
|
||||
return newmem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will allocate memory blocks and then clear the memory.
|
||||
*
|
||||
* @param count the number of memory blocks
|
||||
* @param size the size of a memory block
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserCalloc(size_t count, size_t size){
|
||||
void *p = NONE;
|
||||
|
||||
/* calls x_malloc to allocate count * size memory */
|
||||
p = UserMalloc(count * size);
|
||||
|
||||
/* zero the memory */
|
||||
if (p)
|
||||
memset((char*)p, 0, count * size);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
120
applications/user_api/switch_api/user_msg.c
Normal file
120
applications/user_api/switch_api/user_msg.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_msg.c
|
||||
* @brief: the priviate user api of msg queue for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* This function will create a msg queue.
|
||||
*
|
||||
* @param msg_size the length of the msg queue.
|
||||
* @param max_msgs the max length of the msg queue.
|
||||
*
|
||||
* @return id on success;ENOMEMORY/ERROR on failure
|
||||
*/
|
||||
int32_t UserMsgQueueCreate( size_t msg_size,
|
||||
size_t max_msgs){
|
||||
return (int32_t)KSwitch2(KS_USER_MSGQUEUE_CREATE, (uintptr_t)msg_size, (uintptr_t)max_msgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* a dynamic messagequeue will be deleted from the manage list
|
||||
*
|
||||
* @param id the message id
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueDelete(int32_t mq ){
|
||||
return (x_err_t)KSwitch1(KS_USER_MSGQUEUE_DELETE, (uintptr_t)mq);
|
||||
}
|
||||
|
||||
/**
|
||||
* send message with waiting time,current suspend task will be resumed
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
* @param timeout waiting time
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueSendwait(int32_t mq, const void *buffer,
|
||||
size_t size, int32_t wait_time){
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_SEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
}
|
||||
|
||||
/**
|
||||
* send message without waiting time,current suspend task will be resumed
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueSend(int32_t mq, const void *buffer, size_t size){
|
||||
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_SEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
|
||||
}
|
||||
/**
|
||||
* send urgent message without waiting time, this message will be inserted to the head of the queue
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueUrgentSend(int32_t mq, const void *buffer, size_t size){
|
||||
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_URGENTSEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
}
|
||||
|
||||
/**
|
||||
* receive message with some waiting time
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
* @param timeout time needed waiting
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueRecv(int32_t mq, void *buffer,
|
||||
size_t size,int32_t wait_time){
|
||||
return (x_err_t)KSwitch4(KS_USER_MSGQUEUE_RECV ,(uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size, (uintptr_t)wait_time );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will reset a event.
|
||||
*
|
||||
* @param id the id number of event.
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*/
|
||||
x_err_t UserMsgQueueReinit(int32_t mq){
|
||||
return (x_err_t)KSwitch1(KS_USER_MSGQUEUE_REINIT ,(uintptr_t)mq );
|
||||
}
|
||||
71
applications/user_api/switch_api/user_mutex.c
Normal file
71
applications/user_api/switch_api/user_mutex.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_mutex.c
|
||||
* @brief: the priviate user api of mutex for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* a mutex will be inited in static way,then this mutex will be inserted to the manage list
|
||||
*
|
||||
* @param mutex the mutex descriptor
|
||||
* @param name mutex name
|
||||
* @param flag mutex flag
|
||||
*
|
||||
* @return EOK on success
|
||||
*
|
||||
*/
|
||||
int32_t UserMutexCreate(){
|
||||
return (int32_t)KSwitch0(KS_USER_MUTEX_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* a dynamic mutex will be deleted from the manage list
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
*
|
||||
*/
|
||||
void UserMutexDelete(int32_t mutex){
|
||||
KSwitch1(KS_USER_MUTEX_DELETE,(uintptr_t)mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* a mutex will be taken when mutex is available
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
* @param msec the time needed waiting
|
||||
*
|
||||
* @return EOK on success;ERROR on failure
|
||||
*
|
||||
*/
|
||||
int32_t UserMutexObtain(int32_t mutex, int32_t wait_time){
|
||||
return (int32_t)KSwitch2(KS_USER_MUTEX_OBTAIN,(uintptr_t)mutex, (uintptr_t)wait_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* release the mutex and resume corresponding suspended task
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
*
|
||||
* @return EOK on success;ERROR on failure
|
||||
*/
|
||||
int32_t UserMutexAbandon(int32_t mutex){
|
||||
return (int32_t)KSwitch1(KS_USER_MUTEX_ABANDON,(uintptr_t)mutex);
|
||||
}
|
||||
|
||||
28
applications/user_api/switch_api/user_print_info.c
Normal file
28
applications/user_api/switch_api/user_print_info.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_print_info.c
|
||||
* @brief: the priviate user api of user info print for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/* for debug */
|
||||
int UserPrintInfo(unsigned long i){
|
||||
return (int)KSwitch1(KS_USER_PRINT_INFO,i);
|
||||
}
|
||||
|
||||
73
applications/user_api/switch_api/user_semaphore.c
Normal file
73
applications/user_api/switch_api/user_semaphore.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_semaphore.c
|
||||
* @brief: the priviate user api of semphore for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* Create a new semaphore with specified initial value.
|
||||
*
|
||||
* @param val initial value
|
||||
* @return id of the semaphore
|
||||
*/
|
||||
sem_t UserSemaphoreCreate(uint16_t val){
|
||||
return (sem_t)KSwitch1(KS_USER_SEMAPHORE_CREATE,(uintptr_t)val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a semaphore and wakeup all pending tasks on it.
|
||||
*
|
||||
* @param id id of the semaphore to be deleted
|
||||
*/
|
||||
x_err_t UserSemaphoreDelete(sem_t sem){
|
||||
return (x_err_t)KSwitch1(KS_USER_SEMAPHORE_DELETE,(uintptr_t)sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a semaphore when its value is greater than 0; pend on it otherwise.
|
||||
*
|
||||
* @param id id of the semaphore to be obtained
|
||||
* @param msec wait time in millisecond
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreObtain(sem_t sem, int32_t wait_time){
|
||||
return (x_err_t)KSwitch2(KS_USER_SEMAPHORE_OBTAIN,(uintptr_t)sem,(uintptr_t)wait_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandon a semaphore and wakeup a pending task if any.
|
||||
*
|
||||
* @param id id of the semaphore to be abandoned
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreAbandon(sem_t sem){
|
||||
return (x_err_t)KSwitch1(KS_USER_SEMAPHORE_ABANDON,(uintptr_t)sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a semaphore, wakeup all pending tasks if new value is positive.
|
||||
*
|
||||
* @param id id of the semaphore for which to set value
|
||||
* @param val new value
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreSetValue(sem_t sem, uint16_t val){
|
||||
return (x_err_t)KSwitch2(KS_USER_SEMAPHORE_SETVALUE,(uintptr_t)sem,(uintptr_t)val);
|
||||
}
|
||||
128
applications/user_api/switch_api/user_task.c
Normal file
128
applications/user_api/switch_api/user_task.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: user_task.c
|
||||
* @brief: the priviate user api of task for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* This function init a user task in dynamic way .
|
||||
*
|
||||
* @param name task name
|
||||
* @param parameter task process function
|
||||
* @param parameter task arg
|
||||
* @param stack_size task stack size
|
||||
* @param priority task priority
|
||||
* @param tick task time slice
|
||||
*
|
||||
* @return EOK on success; ENOMEMORY/EEMPTY on failure
|
||||
*/
|
||||
int32_t UserTaskCreate(utask_x utask){
|
||||
return (int32_t) KSwitch5(KS_USER_TASK_CREATE,(uintptr_t)utask.name,(uintptr_t)utask.func_entry,(uintptr_t)utask.func_param,(uintptr_t)utask.stack_size,(uintptr_t)utask.prio);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will insert task to ready queue then schedule
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK on success; EINVALED on failure
|
||||
*/
|
||||
x_err_t UserTaskStartup(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_STARTUP,(uintptr_t)id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will remove a dynamic task out of the task manage list.
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK on success; EINVALED on failure
|
||||
*/
|
||||
x_err_t UserTaskDelete(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_DELETE,(uintptr_t)id);
|
||||
}
|
||||
|
||||
void UserTaskQuit(void){
|
||||
KSwitch0(KS_USER_TASK_EXECEXIT);
|
||||
return ;
|
||||
}
|
||||
/**
|
||||
* This function will delay current task running with some ticks.
|
||||
*
|
||||
* @param tick delay ticks
|
||||
* @return EOK on success; EINVALED/EEMPTY on failure
|
||||
*/
|
||||
x_err_t UserTaskDelay(int32_t ms){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_DELAY,(uintptr_t)ms);
|
||||
}
|
||||
|
||||
x_err_t UserGetTaskName( int32_t id, char *name){
|
||||
return (x_err_t)KSwitch2(KS_USER_GET_TASK_NAME,(uintptr_t)id, (uintptr_t)name);
|
||||
}
|
||||
|
||||
int32_t UserGetTaskID(void){
|
||||
return (int32_t)KSwitch0(KS_USER_GET_TASK_ID);
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskStat(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_STAT,(uintptr_t)id );
|
||||
}
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
/**
|
||||
* This function binds a task to cpu core.
|
||||
*
|
||||
* @param id task id
|
||||
* @param coreid cpu core id
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
x_err_t UserTaskCoreCombine(int32_t id,uint8_t core_id){
|
||||
return (x_err_t)KSwitch2(KS_USER_TASK_CORE_COMBINE,(uintptr_t)id,core_id);
|
||||
}
|
||||
/**
|
||||
* This function unbinds a task with cpu core.
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
x_err_t UserTaskCoreUnCombine(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_CORE_UNCOMBINE,(uintptr_t)id);
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_COMBINEED_CORE,(uintptr_t)id );
|
||||
}
|
||||
|
||||
uint8 UserGetTaskRunningCore(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_RUNNING_CORE,(uintptr_t)id );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_GET_TASK_ERROR_STATUS,(uintptr_t)id );
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskPriority(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_PRIORITY,(uintptr_t)id );
|
||||
}
|
||||
Reference in New Issue
Block a user