First commit XiUOS

This commit is contained in:
xuetest
2021-04-28 17:49:18 +08:00
commit 6001051eb7
1331 changed files with 433955 additions and 0 deletions

247
kernel/include/user_api.h Normal file
View 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

50
kernel/include/xiuos.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* 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: xiuos.h
* @brief: all header files of kernel
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XIUOS_H
#define XIUOS_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_mutex.h>
#include <xs_sem.h>
#include <xs_event.h>
#include <xs_msg.h>
#include <xs_ktask.h>
#include <xs_timer.h>
#include <xs_klist.h>
#include <xs_isr.h>
#include <string.h>
#include <stdio.h>
#include <xs_memory.h>
#include <xs_id.h>
#include <xs_ktick.h>
#include <xs_kdevice.h>
#include <xs_init.h>
#include <xs_assign.h>
#include <xs_banner.h>
#include <xs_poll.h>
#include <xs_workqueue.h>
#include <xs_circular_area.h>
#include <xs_dataqueue.h>
#endif

138
kernel/include/xs_assign.h Normal file
View File

@@ -0,0 +1,138 @@
/*
* 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: xs_assign.h
* @brief: function declaration and structure defintion of system assign
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_ASSIGN_H
#define XS_ASSIGN_H
#include <xs_base.h>
#include <xs_ktask.h>
#include <xs_klist.h>
#include <xs_spinlock.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MERGE_FLAG(src, flag) *(src) |= flag
#define CLEAR_FLAG(src, flag) *(src) &= ~flag
extern struct Assign Assign;
struct PriorityReadyVectorDone
{
void (*init)(struct OsAssignReadyVector *ready_vector);
void (*insert)(struct TaskDescriptor *task);
void (*remove)(struct TaskDescriptor *task);
};
#ifdef ARCH_SMP
struct smp_assign_done
{
x_ubase (*GetHighest)(void);
struct TaskDescriptor* (*select)(void);
void (*SwitchToNew)(struct TaskDescriptor* old_task, struct TaskDescriptor* new_task);
void (*SwitchToFirst)(struct TaskDescriptor* task);
void (*SetSystemTask)(struct TaskDescriptor* task);
void (*SmpInit)(void);
};
struct Assign
{
struct OsAssignReadyVector os_assign_read_vector;
struct OsAssignReadyVector smp_os_assign_ready_rector[CPU_NUMBERS];
struct TaskDescriptor *smp_os_running_task[CPU_NUMBERS];
struct PriorityReadyVectorDone *ready_vector_done;
struct smp_assign_done *smp_assign_done;
uint8 current_priority[CPU_NUMBERS];
uint16 assign_lock[CPU_NUMBERS];
};
void SwitchKtaskContext(x_ubase from, x_ubase to, struct TaskDescriptor *to_task);
void SwitchKtaskContextTo(x_ubase to, struct TaskDescriptor *to_task);
void HwInterruptcontextSwitch( x_ubase from, x_ubase to,struct TaskDescriptor *to_task , void *context);
#else
struct Assign
{
struct OsAssignReadyVector os_assign_read_vector;
struct TaskDescriptor *os_running_task;
struct PriorityReadyVectorDone *ready_vector_done;
uint8 current_priority;
};
void SwitchKtaskContext(x_ubase from, x_ubase to , struct TaskDescriptor *to_task);
void SwitchKtaskContextTo(x_ubase to, struct TaskDescriptor *to_task);
void HwInterruptcontextSwitch( x_ubase from, x_ubase to, struct TaskDescriptor *to_task ,void *context);
#endif
void KTaskInsertToReadyVector(struct TaskDescriptor *task);
int PrioCaculate(uint32 bitmap);
void SysInitOsAssign(void);
void ResetCriticalAreaLock(void );
void StartupOsAssign(void);
x_base CriticalAreaLock(void);
void CriticalAreaUnLock(x_base lock);
uint16 GetOsAssignLockLevel(void);
int32 JudgeAssignReadyBitmapIsEmpty(struct OsAssignReadyVector *ready_vector);
void OsAssignReadyVectorInit(struct OsAssignReadyVector *ready_vector);
void AssignPolicyInsert(struct TaskDescriptor *task, struct OsAssignReadyVector* ready_table);
struct TaskDescriptor * ChooseTaskWithHighestPrio(struct OsAssignReadyVector *ready_vector);
#ifdef KERNEL_STACK_OVERFLOW_CHECK
void _KTaskOsAssignStackCheck(struct TaskDescriptor *task);
#endif
#ifdef ARCH_SMP
extern HwSpinlock AssignSpinLock;
#define DO_KTASK_ASSIGN \
do \
{ \
NOT_IN_CRITICAL_AREA; \
x_base lock; \
lock = DISABLE_INTERRUPT(); \
HwLockSpinlock(&AssignSpinLock); \
KTaskOsAssign(); \
HwUnlockSpinlock(&AssignSpinLock); \
ENABLE_INTERRUPT(lock); \
} while (0);
#else
#define DO_KTASK_ASSIGN \
do \
{ \
NOT_IN_CRITICAL_AREA; \
x_base lock; \
lock = DISABLE_INTERRUPT(); \
KTaskOsAssign(); \
ENABLE_INTERRUPT(lock); \
} while (0);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,66 @@
/*
* 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: xs_avltree.h
* @brief: function declaration and structure defintion of avl tree
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef AVL_TREE_H
#define AVL_TREE_H
#include <xs_base.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef KERNEL_AVL_TREE
struct AvlNode
{
int32 data;
uint32 height;
struct AvlNode *left;
struct AvlNode *right;
};
typedef struct AvlNode *AvlNodeType;
#ifndef AVL_MAX
#define AVL_MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef AVL_ABS
#define AVL_ABS(a) ((a > 0) ? (a) : (-a))
#endif
/*This function will insert data to the avl tree*/
AvlNodeType AvlTreeInsertNode(AvlNodeType avl_node, int32 data);
/*This function will delete data from the avl tree*/
AvlNodeType AvlTreeDeleteNode(AvlNodeType avl_node, int32 data);
/*This function will modify certain data of the avl tree*/
AvlNodeType AvlNodeModifyNode(AvlNodeType avl_node, int32 src_data, int32 dst_data);
/*This function will return the avl node which has the data*/
AvlNodeType AvlNodeSearchNode(AvlNodeType avl_node, int32 data);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,29 @@
/*
* 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: xs_banner.h
* @brief: function declaration of system banner
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_BANNER_H
#define XS_BANNER_H
#include <xs_base.h>
void ShowBanner(void);
#endif

133
kernel/include/xs_base.h Normal file
View File

@@ -0,0 +1,133 @@
/*
* 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: xs_base.h
* @brief: basic data type defintions
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_BASE_H
#define XS_BASE_H
/* import board special configuration */
#include <xsconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* the basic types of date*/
#ifdef ARCH_CPU_64BIT
typedef unsigned long int size_t;
typedef signed long int ssize_t;
#else
typedef unsigned int size_t;
typedef signed int ssize_t;
#endif
#endif
#ifndef CONFIG_ARCH_DATA_TYPE
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#ifdef ARCH_CPU_64BIT
typedef signed long int64;
typedef unsigned long uint64;
#else
typedef signed long long int64;
typedef unsigned long long uint64;
#endif
#endif
typedef int x_bool;
typedef long x_base;
typedef unsigned long x_ubase;
typedef x_base x_err_t;
typedef uint32 x_time_t;
typedef uint32 x_ticks_t;
typedef x_base x_flag_t;
typedef x_ubase x_size_t;
typedef x_ubase x_dev_t;
typedef x_base x_OffPos;
#define RET_TRUE 1
#define RET_FALSE 0
#define UINT8_SIZE_MAX 0xff
#define UINT16_SIZE_MAX 0xffff
#define UINT32_SIZE_MAX 0xffffffff
#define TICK_SIZE_MAX UINT32_SIZE_MAX
/* the type of components*/
#define Cmpt_KindN_Null 0
#define Cmpt_KindN_Task 1
#define Cmpt_KindN_Semaphore 2
#define Cmpt_KindN_Mutex 3
#define Cmpt_KindN_Event 4
#define Cmpt_KindN_MessageQueue 5
#define Cmpt_KindN_MemPool 6
#define Cmpt_KindN_Timer 7
#define Cmpt_KindN_Bus 8
#define Cmpt_KindN_Static 0x80
/* the type of error */
#define EOK 0
#define ERROR 1
#define ETIMEOUT 2
#define EFULL 3
#define EEMPTY 4
#define ENOMEMORY 5
#define ENONESYS 6
#define EDEV_BUSY 7
#define EPIO 8
#define EINTER 9
#define EINVALED 10
#define INVALID_TASK_ERROR 11
#define ALIGN_MEN_UP(size, align) ((((size) + (align) - 1) /(align))*(align))
#define ALIGN_MEN_DOWN(size, align) ((size)/(align)*(align))
#define NONE (0)
#ifndef SECTION
#if defined(__GNUC__)
#define SECTION(x) __attribute__((section(x)))
#else
#define SECTION(x)
#endif
#endif
#define WAITING_FOREVER -1
void KPrintf(const char *fmt, ...);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,88 @@
/*
* 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: xs_circular_area.h
* @brief: function declaration and structure defintion of circular area
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef CIRCULAR_AREA_H
#define CIRCULAR_AREA_H
#include <xs_base.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef KERNEL_CIRCULAR_AREA
typedef struct CircularArea *CircularAreaType;
struct CircularAreaOps
{
uint32 (*read) (CircularAreaType circular_area, uint8 *output_buffer, uint32 data_length);
uint32 (*write) (CircularAreaType circular_area, uint8 *input_buffer, uint32 data_length, x_bool b_force);
void (*release) (CircularAreaType circular_area);
void (*reset) (CircularAreaType circular_area);
};
struct CircularArea
{
uint8 *data_buffer;
uint8 readidx;
uint8 writeidx;
uint8 *p_head;
uint8 *p_tail;
uint32 area_length;
x_bool b_status;
struct CircularAreaOps *CircularAreaOperations;
};
/*This function will return whether the circular_area is full or not*/
x_bool CircularAreaIsFull(CircularAreaType circular_area);
/*This function will return whether the circular_area is empty or not*/
x_bool CircularAreaIsEmpty(CircularAreaType circular_area);
/*This function will reset the circular_area and set the descriptor to default*/
void CircularAreaReset(CircularAreaType circular_area);
/*This function will release the circular_area descriptor and free the memory*/
void CircularAreaRelease(CircularAreaType circular_area);
/*This function will read data from the circular_area*/
uint32 CircularAreaRead(CircularAreaType circular_area, uint8 *output_buffer, uint32 data_length);
/*This function will write data to the circular_area*/
uint32 CircularAreaWrite(CircularAreaType circular_area, uint8 *input_buffer, uint32 data_length, x_bool b_force);
/*This function will get the circual_area max length*/
uint32 CircularAreaGetMaxLength(CircularAreaType circular_area);
/*This function will get the data length of the circular_area*/
uint32 CircularAreaGetDataLength(CircularAreaType circular_area);
/*This function will initialize the circular_area*/
CircularAreaType CircularAreaInit(uint32 circular_area_length);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,69 @@
/*
* 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: xs_dataqueue.h
* @brief: function declaration and structure defintion of circular area
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef DATAQUEUE_H
#define DATAQUEUE_H
#include <xs_ktask.h>
#include <xs_timer.h>
#include <xs_sem.h>
#include <xs_queue_manager.h>
typedef struct
{
const void *data; ///< data pointer
x_size_t length; ///< data length
}DataElemType;
typedef struct
{
uint16 front;
uint16 rear;
uint16 max_len;
DataElemType *base;
int sem_blank;
int sem_data;
}DataQueueType;
x_err_t InitDataqueue(DataQueueType *p_queue, uint16 NodeNumber);
x_err_t PushDataqueue(DataQueueType *queue,const void *StartAddr, x_size_t DataSize, int32 timeout);
x_err_t PopDataqueue(DataQueueType *queue, const void **StartAddr, x_size_t *size, int32 timeout);
x_err_t DataqueuePeak(DataQueueType *queue, const void **StartAddr, x_size_t *size);
void DeInitDataqueue(DataQueueType *p_queue);
typedef struct
{
x_err_t (*InitDataqueue)(DataQueueType *p_queue, uint16 NodeNumber);
x_err_t (*PushDataqueue)(DataQueueType *queue,
const void *StartAddr,
x_size_t DataSize,
int32 timeout);
x_err_t (*PopDataqueue)(DataQueueType *queue,
const void **StartAddr,
x_size_t *size,
int32 timeout);
x_err_t (*DataqueuePeak)(DataQueueType *queue,
const void **StartAddr,
x_size_t *size);
void (*DeInitDataqueue)(DataQueueType *p_queue);
} DataQueueDoneType;
#endif

45
kernel/include/xs_delay.h Normal file
View File

@@ -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.
*/
/**
* @file: xs_delay.h
* @brief: function declaration and structure defintion of delay
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/11
*
*/
#ifndef XS_DELAY_H
#define XS_DELAY_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#define TASK_DELAY_INACTIVE 0
#define TASK_DELAY_ACTIVE 1
struct Delay {
struct TaskDescriptor *task;
x_ticks_t ticks;
uint8 status;
DoubleLinklistType link;
};
typedef struct Delay *delay_t;
x_err_t KTaskSetDelay(struct TaskDescriptor *task, x_ticks_t ticks);
x_err_t KTaskUnSetDelay(struct TaskDescriptor *task);
void CheckTaskDelay(void);
#endif

66
kernel/include/xs_event.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* 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: xs_event.h
* @brief: function declaration and structure defintion of event
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_EVENT_H
#define XS_EVENT_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#include <xs_id.h>
#ifdef KERNEL_EVENT
#define EVENT_EVENTS_MASK 0x1FFFFFFF
#define EVENT_OPTIONS_MASK 0x7
#define EVENT_AND (1 << 0)
#define EVENT_OR (1 << 1)
#define EVENT_AUTOCLEAN (1 << 2)
typedef int32 EventIdType;
struct Event
{
struct IdNode id;
uint32 options : 3;
uint32 events : 29;
DoubleLinklistType pend_list;
DoubleLinklistType link;
};
typedef struct
{
int32 (*EventCreate)(uint32 options);
void (*EventDelete)(struct Event *event);
int32 (*EventTrigger)(struct Event *event, uint32 events);
int32 (*EventProcess)(struct Event *event, uint32 events, uint32 options, int32 msec, uint32 *processed);
} EventDoneType;
int32 KEventCreate(uint32 options);
void KEventDelete(int32 id);
int32 KEventTrigger(int32 id, uint32 events);
int32 KEventProcess(int32 id, uint32 events, uint32 options, int32 msec, uint32 *processed);
#endif
#endif

103
kernel/include/xs_hook.h Normal file
View 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: xs_hook.h
* @brief: function declaration and structure defintion of hook
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_HOOK_H
#define XS_HOOK_H
#include <xs_base.h>
#include <xs_ktask.h>
#include <xs_kdbg.h>
#include <xs_memory.h>
#ifdef KERNEL_HOOK
#define HOOK(function, argv) \
do { if ((function) != NONE) function argv; } while (0)
#else
#define HOOK(function, argv)
#endif
#define REGISTER_HOOK(hook, function) \
{ if ((function) != NONE) hook = function ; }
#define UNREGISTER_HOOK(hook) \
{ hook = NONE ; }
struct AssignHook
{
void (*hook_Assign)(KTaskDescriptorType from, KTaskDescriptorType to);
};
struct TaskHook
{
void (*hook_TaskCreate) (KTaskDescriptorType task);
void (*hook_TaskSuspend)(KTaskDescriptorType task);
void (*hook_TaskResume) (KTaskDescriptorType task);
};
struct MemHook
{
void (*hook_Malloc)(void *ptr, x_size_t size);
void (*hook_Free)(void *ptr);
#ifdef KERNEL_MEMBLOCK
void (*hook_GmAlloc)(struct MemGather *gm, void *date_ptr);
void (*hook_GmFree)(struct MemGather *gm, void *date_ptr);
#endif
};
struct TimerHook
{
void (*hook_TimerEnter)(struct Timer *timer);
void (*hook_TimerExit)(struct Timer *timer);
};
struct IsrHook
{
void (*hook_IsrEnter)(void);
void (*hook_IsrLeave)(void);
};
struct IdleHook
{
void (*hook_Idle)(void);
};
struct TestHook
{
void (*hook_test)(const char *buf);
};
struct KernelHook
{
struct AssignHook assign;
struct TaskHook task;
struct MemHook mem;
struct TimerHook timer;
struct IsrHook isr;
struct IdleHook idle;
struct TestHook test;
};
extern struct KernelHook hook;
int hook_init(void);
#endif

66
kernel/include/xs_id.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* 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: xs_id.h
* @brief: function declaration and structure defintion of id manager
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_ID_H
#define XS_ID_H
#include <xs_klist.h>
#ifdef __cplusplus
extern "C" {
#endif
struct IdNode
{
uint16 id;
DoubleLinklistType link;
};
struct IdManager
{
uint16 id_max;
uint16 hoffset;
uint8 *id_map;
DoubleLinklistType *htable;
};
#define DECLARE_ID_MANAGER(_name, _id_max) \
uint8 __id_map_##_name[((_id_max) + 7) / 8]; \
DoubleLinklistType __htable_##_name[(_id_max) < ID_HTABLE_SIZE ? (_id_max) : ID_HTABLE_SIZE]; \
struct IdManager _name = { \
.id_max = _id_max, \
.hoffset = (_id_max) < ID_HTABLE_SIZE ? (_id_max) : ID_HTABLE_SIZE, \
.id_map = __id_map_##_name, \
.htable = __htable_##_name \
};
int IdInsertObj(struct IdManager *manager, struct IdNode *idnode);
struct IdNode *IdGetObj(struct IdManager *manager, uint16 id);
void IdRemoveObj(struct IdManager *manager, uint16 id);
#ifdef __cplusplus
}
#endif
#endif

53
kernel/include/xs_init.h Normal file
View File

@@ -0,0 +1,53 @@
/*
* 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: xs_init.h
* @brief: init function declaration of components
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_INIT_H
#define XS_INIT_H
typedef int (*InitFnType)(void);
struct InitSequenceDesc
{
const char* fn_name;
const InitFnType fn;
};
#ifdef KERNEL_COMPONENTS_INIT
void InitCmpts(void);
#endif
extern int VfsInit(void);
extern int WorkSysWorkQueueInit(void);
extern int FlashW25qxxSpiDeviceInit(void);
extern int sal_mbedtls_proto_init(void);
extern int FatfsInit(void);
extern int Ch376fsInit(void);
extern int LibcSystemInit(void);
extern int sal_init(void);
extern int RtcNtpSyncInit(void);
extern int MountSDCard(void);
extern int dfs_mount_table(void);
extern int userShellInit(void);
extern int stm32_sdcard_mount(void);
extern int STM32USBHostRegister(void);
extern int WorkSysWorkQueueInit(void);
#endif

View File

@@ -0,0 +1,63 @@
/**
* 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: xs_isolation.h
* @brief: The macro and callback functions definitions for memory protect
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/14
*
*/
#ifndef MEMORY_PROTECT_H
#define MEMORY_PROTECT_H
#include <xsconfig.h>
#ifdef TASK_ISOLATION
#include <xiuos.h>
#include <board.h>
#if defined(ARCH_ARM) && defined(SURPORT_MPU)
#include <mpu.h>
extern struct Mpu *isolation ;
#define MOMERY_PROTECT_ENABLE
#endif
#if defined(ARCH_RISCV) && defined(SURPORT_PMP)
#include <pmp.h>
extern struct Pmp *isolation ;
#define MOMERY_PROTECT_ENABLE
#endif
#define REGION_TYPE_CODE (1)
#define REGION_TYPE_DATA (2)
#define REGION_TYPE_BSS (3)
#define REGION_TYPE_HEAP (4)
struct MemoryAccessLimit {
void (* Enable)( uint32_t option);
void (* Disable)(void);
x_err_t (* Init)(void **mem_access);
x_err_t (* InitIsolation)(void **mem_access, x_ubase stack_start , size_t stack_size);
x_err_t (* AddRegion)(void *mem_access, x_ubase start , size_t size , uint8_t region_type );
x_err_t (* ClearRegion)(void *mem_access, x_ubase addr);
void (* Load)(void *mem_access);
void (* Free)(void *mem_access);
x_bool (* FaultHandle)(void *mem_access, x_ubase addr);
};
extern struct MemoryAccessLimit mem_access ;
#endif
#endif

98
kernel/include/xs_isr.h Normal file
View File

@@ -0,0 +1,98 @@
/*
* 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: xs_isr.h
* @brief: function declaration and structure defintion of isr
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_ISR_H
#define XS_ISR_H
#include <xs_base.h>
#include <arch_interrupt.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DECLARE_HW_IRQ(_irq_num, _handler, _arg) \
const uint32 __irq_desc_idx_##_handler SECTION(".isrtbl.idx") = _irq_num + ARCH_IRQ_NUM_OFFSET ; \
const struct IrqDesc __irq_desc_##_handler SECTION(".isrtbl") = { \
.handler = _handler, \
.param = _arg, \
}
typedef void (*IsrHandlerType)(int vector, void *param);
struct IrqDesc
{
IsrHandlerType handler;
void *param;
#ifdef CONFIG_INTERRUPT_INFO
char name[NAME_NUM_MAX];
uint32 counter;
#endif
};
struct IsrDone
{
x_bool (*isInIsr)();
int32 (*registerIrq)(uint32 irq_num, IsrHandlerType handler, void *arg);
int32 (*freeIrq)(uint32 irq_num);
int32 (*enableIrq)(uint32 irq_num);
int32 (*disableIrq)(uint32 irq_num);
void (*handleIrq)(uint32 irq_num);
uint16 (*getCounter)() ;
void (*incCounter)();
void (*decCounter)();
uint8 (*getSwitchTrigerFlag)();
void (*setSwitchTrigerFlag)();
void (*clearSwitchTrigerFlag)();
};
struct InterruptServiceRoutines {
#ifdef ARCH_SMP
volatile uint16 isr_count[CPU_NUMBERS];
volatile uint8 isr_switch_trigger_flag[CPU_NUMBERS];
#else
volatile uint16 isr_count ;
volatile uint8 isr_switch_trigger_flag;
#endif
struct IrqDesc irq_table[ARCH_MAX_IRQ_NUM];
struct IsrDone *done;
};
extern struct InterruptServiceRoutines isrManager ;
x_base DisableLocalInterrupt();
void EnableLocalInterrupt(x_base level);
#define DISABLE_INTERRUPT DisableLocalInterrupt
#define ENABLE_INTERRUPT EnableLocalInterrupt
void SysInitIsrManager();
void InitHwinterrupt(void);
#ifdef __cplusplus
}
#endif
#endif

162
kernel/include/xs_kdbg.h Normal file
View File

@@ -0,0 +1,162 @@
/*
* 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: xs_kdbg.h
* @brief: function declaration and structure defintion of kernel debug
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_KDBG_H
#define XS_KDBG_H
#include <xsconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef KERNEL_DEBUG
/*Kernel Section Debug Define*/
#define KDBG_MEM 0
#define KDBG_MEMHEAP 0
#define KDBG_SCHED 0
#define KDBG_KTASK 0
#define KDBG_SOFTTIMER 0
#define KDBG_IRQ 0
#define KDBG_IPC 0
#define KDBG_HOOK 0
#define SYS_KDEBUG_LOG(section, information) \
do \
{ \
if(section) { \
KPrintf information; \
} \
}while (0)
#define KDYN_NONE 0
#define KDYN_DBG 1
#define KDYN_ERROR 2
#define KDYN_WARNING 3
#ifdef KDYN_LOG_DBG
#define DBG(args, ...) KDYNAMIC_LOG(KDYN_DBG, args, ##__VA_ARGS__)
#define SYS_ERR(args, ...) KDYNAMIC_LOG(KDYN_ERROR, args, ##__VA_ARGS__)
#define SYS_WARN(args, ...) KDYNAMIC_LOG(KDYN_WARNING, args, ##__VA_ARGS__)
#else
#define DBG(args, ...) KDYNAMIC_LOG(KDYN_NONE, args, ##__VA_ARGS__)
#define SYS_ERR(args, ...) KDYNAMIC_LOG(KDYN_ERROR, args, ##__VA_ARGS__)
#define SYS_WARN(args, ...) KDYNAMIC_LOG(KDYN_WARNING, args, ##__VA_ARGS__)
#endif
#define KDYNAMIC_LOG(level, args, ...) \
do \
{ \
switch(level) \
{ \
case KDYN_NONE: \
break; \
case KDYN_DBG: \
KPrintf("[DBG]"); \
KPrintf(args, ##__VA_ARGS__); \
break; \
case KDYN_ERROR: \
KPrintf("[ERR]"); \
KPrintf(args, ##__VA_ARGS__); \
break; \
case KDYN_WARNING: \
KPrintf("[WARN]"); \
KPrintf(args, ##__VA_ARGS__); \
break; \
default: \
break; \
} \
}while (0)
#define NULL_PARAM_CHECK(param) \
do \
{ \
if(param == NONE) { \
KPrintf("PARAM CHECK FAILED ...%s %d %s is NULL.\n",__FUNCTION__,__LINE__,#param); \
while(RET_TRUE); \
} \
}while (0)
#define CHECK(TRUE_CONDITION) \
do \
{ \
if(!(TRUE_CONDITION)) { \
KPrintf("%s CHECK condition is false at line[%d] of [%s] func.\n",#TRUE_CONDITION,__LINE__,__FUNCTION__);\
while(RET_TRUE); \
} \
} while(0)
#define KDEBUG_NOT_IN_INTERRUPT \
do \
{ \
x_base level; \
level = DISABLE_INTERRUPT(); \
if (isrManager.done->getCounter() != 0) \
{ \
KPrintf("Function[%s] is not supported in ISR\n", __FUNCTION__); \
CHECK(0); \
} \
ENABLE_INTERRUPT(level); \
} while (0)
#define KDEBUG_IN_KTASK_CONTEXT \
do \
{ \
x_base level; \
level = DISABLE_INTERRUPT(); \
if (GetKTaskDescriptor() == NONE) \
{ \
KPrintf("Function[%s] is not supported before task assign\n", __FUNCTION__); \
CHECK(0); \
} \
KDEBUG_NOT_IN_INTERRUPT; \
ENABLE_INTERRUPT(level); \
} while (0)
#define NOT_IN_CRITICAL_AREA \
do { \
if(GetOsAssignLockLevel() != 0){ \
KPrintf("Function[%s] is not supported switch in critical area.\n", __FUNCTION__); \
CHECK(0); \
} \
} while (0)
#else
#define SYS_KDEBUG_LOG(section, information)
#define DBG(args, ...)
#define SYS_ERR(args, ...)
#define SYS_WARN(args, ...)
#define NULL_PARAM_CHECK(param)
#define CHECK(TRUE_CONDITION)
#define KDEBUG_NOT_IN_INTERRUPT
#define KDEBUG_IN_KTASK_CONTEXT
#define NOT_IN_CRITICAL_AREA
#endif
#ifdef __cplusplus
}
#endif
#endif

119
kernel/include/xs_kdevice.h Normal file
View File

@@ -0,0 +1,119 @@
/*
* 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: xs_kdevice.h
* @brief: macor and structure defintion of kdevice
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_KDEVICE_H
#define XS_KDEVICE_H
/* import board special configuration */
#include <xsconfig.h>
#include <xs_klist.h>
#ifdef TOOL_SHELL
#include "shell.h"
#else
#define SHELL_EXPORT_CMD(_attr, _name, _func, _desc)
#endif
#ifdef __cplusplus
extern "C" {
#endif
enum dev
{
Dev_TYPE_Block,
Dev_TYPE_Char ,
Dev_TYPE_CAN ,
Dev_TYPE_Graphic,
Dev_TYPE_I2CBUS,
Dev_TYPE_Miscellaneous,
Dev_TYPE_NetIf ,
Dev_TYPE_RTC ,
Dev_TYPE_SPIBUS,
Dev_TYPE_SPIDevice,
Dev_TYPE_Timer,
Dev_TYPE_Touch,
Dev_TYPE_USBDevice,
Dev_TYPE_USBHost,
Dev_TYPE_Unknown
};
#define OSIGN_OPER_CLOSE (0U << 0)
#define OSIGN_OPER_RDONLY (1U << 0)
#define OSIGN_OPER_WRONLY (1U << 1)
#define OSIGN_OPER_RDWR (OSIGN_OPER_WRONLY| OSIGN_OPER_RDONLY )
#define OSIGN_OPER_OPEN (1U << 3)
#define OSIGN_OPER_MASK 0xf0f
#define SIGN_OPER_DEACTIVATE (0U << 0)
#define SIGN_OPER_RDONLY (1U << 0)
#define SIGN_OPER_WRONLY (1U << 1)
#define SIGN_OPER_RDWR (SIGN_OPER_RDONLY|SIGN_OPER_WRONLY)
#define SIGN_OPER_REMOVABLE (1U << 2)
#define SIGN_OPER_STANDALONE (1U << 3)
#define SIGN_OPER_ACTIVATED (1U << 4)
#define SIGN_OPER_SUSPENDED (1U << 5)
#define SIGN_OPER_STREAM (1U << 6)
#define SIGN_OPER_INT_RX (1U << 8)
#define SIGN_OPER_DMA_RX (1U << 9)
#define SIGN_OPER_INT_TX (1U << 10)
#define SIGN_OPER_DMA_TX (1U << 11)
enum SIGN_OPER
{
OPER_RESUME = 0x01,
OPER_SUSPEND = 0x02,
OPER_CONFIG = 0x03,
OPER_SET_INT = 0x10,
OPER_CLR_INT = 0x11,
OPER_GET_INT = 0x12,
OPER_CHAR_STREAM = 0x10,
OPER_BLK_GETGEOME = 0x10,
OPER_BLK_SYNC = 0x11,
OPER_BLK_ERASE = 0x12,
OPER_BLK_AUTOREFRESH = 0x13,
OPER_NETIF_GETMAC = 0x10,
OPER_MTD_FORMAT = 0x10,
OPER_RTC_GET_TIME = 0x10,
OPER_RTC_SET_TIME = 0x11,
OPER_RTC_GET_ALARM = 0x12,
OPER_RTC_SET_ALARM = 0x13,
};
struct DeviceBlockArrange
{
uint32 bank_num;
uint32 size_perbank;
uint32 block_size;
uint16 bank_start;
uint16 bank_end;
};
struct DeviceBlockAddr
{
uint32_t start;
uint32_t end;
};
#ifdef __cplusplus
}
#endif
#endif

129
kernel/include/xs_klist.h Normal file
View File

@@ -0,0 +1,129 @@
/*
* 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: xs_klist.h
* @brief: function declaration and structure defintion of linklist
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef XS_KLIST_H
#define XS_KLIST_H
#include <xs_base.h>
#include "libc.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LINKLIST_FLAG_FIFO 0x00
#define LINKLIST_FLAG_PRIO 0x01
typedef struct SysDoubleLinklistNode
{
struct SysDoubleLinklistNode *node_next;
struct SysDoubleLinklistNode *node_prev;
} DoubleLinklistType;
// Single List
typedef struct SingleLinklistNode
{
struct SingleLinklistNode *node_next;
} SysSingleLinklistType;
struct CommonMember
{
char name[NAME_NUM_MAX];
uint8 type;
uint8 flag;
DoubleLinklistType list;
};
#define CONTAINER_OF(item, type, member) \
((type *)((char *)(item) - (unsigned long)(&((type *)0)->member)))
#define DOUBLE_LINKLIST_OBJ_INIT(obj) { &(obj), &(obj) }
void InitDoubleLinkList(DoubleLinklistType *linklist_head);
void DoubleLinkListInsertNodeAfter(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node);
void DoubleLinkListInsertNodeBefore(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node);
void DoubleLinkListRmNode(DoubleLinklistType *linklist_node);
int IsDoubleLinkListEmpty(const DoubleLinklistType *linklist);
struct SysDoubleLinklistNode *DoubleLinkListGetHead(const DoubleLinklistType *linklist);
struct SysDoubleLinklistNode *DoubleLinkListGetNext(const DoubleLinklistType *linklist,
const struct SysDoubleLinklistNode *linklist_node);
unsigned int DoubleLinkListLenGet(const DoubleLinklistType *linklist);
#define SYS_DOUBLE_LINKLIST_ENTRY(item, type, member) \
CONTAINER_OF(item, type, member)
#define DOUBLE_LINKLIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != (head); item = item->node_next)
#define DOUBLE_LINKLIST_FOR_EACH_SAFE(item, node_next, head) \
for (item = (head)->node_next, node_next = item->node_next; item != (head); \
item = node_next, node_next = item->node_next)
#define DOUBLE_LINKLIST_FOR_EACH_ENTRY(item, head, member) \
for (item = SYS_DOUBLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (head); \
item = SYS_DOUBLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member))
#define DOUBLE_LINKLIST_FOR_EACH_ENTRY_SAFE(item, node_next, head, member) \
for (item = SYS_DOUBLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member), \
node_next = SYS_DOUBLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member); \
&item->member != (head); \
item = node_next, node_next = SYS_DOUBLE_LINKLIST_ENTRY(node_next->member.node_next, typeof(*node_next), member))
#define DOUBLE_LINKLIST_FIRST_ENTRY(ptr, type, member) \
SYS_DOUBLE_LINKLIST_ENTRY((ptr)->node_next, type, member)
#define SYS_SINGLE_LINKLIST_OBJ_INIT(obj) { NONE }
void InitSingleLinkList(SysSingleLinklistType *linklist);
void AppendSingleLinkList(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
void SingleLinkListNodeInsert(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
unsigned int SingleLinkListGetLen(const SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListRmNode(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
SysSingleLinklistType *SingleLinkListGetFirstNode(SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListGetTailNode(SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListGetNextNode(SysSingleLinklistType *linklist_node);
int IsSingleLinkListEmpty(SysSingleLinklistType *linklist);
#define SYS_SINGLE_LINKLIST_ENTRY(node, type, member) \
CONTAINER_OF(node, type, member)
#define SINGLE_LINKLIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != NONE; item = item->node_next)
#define SINGLE_LINKLIST_FOR_EACH_ENTRY(item, head, member) \
for (item = SYS_SINGLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (NONE); \
item = SYS_SINGLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member))
#define SINGLE_LINKLIST_FIRST_ENTRY(ptr, type, member) \
SYS_SINGLE_LINKLIST_ENTRY((ptr)->node_next, type, member)
#define SINGLE_LINKLIST_TAIL_ENTRY(ptr, type, member) \
SYS_SINGLE_LINKLIST_ENTRY(SingleLinkListGetTailNode(ptr), type, member)
#ifdef __cplusplus
}
#endif
#endif

222
kernel/include/xs_ktask.h Normal file
View File

@@ -0,0 +1,222 @@
/*
* 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: xs_ktask.h
* @brief: function declaration and structure defintion of kernel task
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_KTASK_H
#define XS_KTASK_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#include <xs_timer.h>
#include <xs_delay.h>
#ifdef __cplusplus
extern "C" {
#endif
#define KTASK_LOWEST_PRIORITY 0
#define KTASK_INIT 0x00
#define KTASK_READY 0x01
#define KTASK_SUSPEND 0x02
#define KTASK_RUNNING 0x03
#define KTASK_CLOSE 0x04
#define KTASK_STAT_MASK 0x07
#define KTASK_MAX_ADVANCE_PROCESS_TIME 0x1 ///< task max advance process times
#define UNCOMBINE_CPU_CORE CPU_NUMBERS
#ifdef ARCH_SMP
#define CPU_MASK ((1 << CPU_NUMBERS) - 1) /**< All CPUs mask bit. */
#ifndef ASSIGN_IPI
#define ASSIGN_IPI 0
#endif
#endif
struct TaskBaseInfo {
char name[NAME_NUM_MAX]; ///< task name
void *func_entry; ///< task function entry
void *func_param; ///< task parameter
uint8 origin_prio; ///< task init priority
uint32 stack_depth; ///< task stack size
void *stack_start; ///< task stack start address
};
typedef struct TaskBaseInfo TaskBaseInfoType;
struct TaskDyncSchedMember {
uint8 stat; ///< task stat
uint8 advance_cnt; ///< total time slice advance process count
uint8 cur_prio; ///< task current priority
x_ubase origin_timeslice; ///< task init timeslice
x_ubase rest_timeslice; ///< task remaining timeslice
#ifdef SEPARATE_COMPILE
uint8 isolation_flag; ///< task isolation flag
void *isolation; ///< task isolation pointer
uint8 isolation_status;
#if defined(ARCH_ARM)
uint32_t svc_return;
uint32_t exc_return;
#endif
#endif
DoubleLinklistType sched_link; ///< task sched list
#if KTASK_PRIORITY_MAX > 32
uint8 bitmap_offset;
uint8 bitmap_row;
#endif
uint32 bitmap_column;
delay_t delay;
};
typedef struct TaskDyncSchedMember TaskDyncSchedMembeType;
#ifdef ARCH_SMP
struct TaskSmpInfo {
uint8 combined_coreid; ///< task bind core id
uint8 runing_coreid; ///< task running core id
uint16 critical_lock_cnt; ///< critical lock count
};
typedef struct TaskSmpInfo TaskSmpInfoType;
#endif
struct TaskDescriptor
{
void *stack_point; ///< stack point
TaskDyncSchedMembeType task_dync_sched_member; ///< task dynamic sched member
TaskBaseInfoType task_base_info; ///< task base information
#ifdef ARCH_SMP
TaskSmpInfoType task_smp_info; ///< dual core information
#endif
#if defined(KERNEL_EVENT)
uint32 event_id_trigger : 29 ; ///< event ops (event trigger )
uint32 event_mode : 3; ///< event mode (AND/OR/AUTOCLEAN)
#endif
x_err_t exstatus; ///< exception status
DoubleLinklistType link; ///< manage list
struct IdNode id; ///< task id
struct KTaskDone *Done;
};
typedef struct TaskDescriptor *KTaskDescriptorType;
struct OsAssignReadyVector {
DoubleLinklistType priority_ready_vector[KTASK_PRIORITY_MAX];
uint32 priority_ready_group;
#if KTASK_PRIORITY_MAX > 32
/* Maximum priority level, 256 */
uint8 ready_vector[32];
#endif
x_ubase highest_prio;
};
struct KTaskDone
{
int32 (*init)(KTaskDescriptorType task,
const char *name,
void (*entry)(void *parameter),
void *parameter,
uint32 stack_size,
uint8 priority);
x_err_t (*start)(KTaskDescriptorType task);
x_err_t (*Delete)(KTaskDescriptorType task);
x_err_t (*delay)(KTaskDescriptorType task, x_ticks_t ticks);
x_err_t (*mdelay)(KTaskDescriptorType task,uint32 ms);
x_err_t (*prioset)(KTaskDescriptorType task, uint8 prio);
#ifdef ARCH_SMP
x_err_t (*combine)(KTaskDescriptorType task, uint8 coreid);
x_err_t (*uncombine)(KTaskDescriptorType task);
#endif
x_err_t (*suspend)(KTaskDescriptorType task);
x_err_t (*wake)(KTaskDescriptorType task);
};
int32 KTaskCreate(const char *name,
void (*entry)(void *parameter),
void *parameter,
uint32 stack_size,
uint8 priority);
void KTaskQuit(void);
#ifdef SEPARATE_COMPILE
int32 UTaskCreate(const char *name,
void (*entry)(void *parameter),
void *parameter,
uint32 stack_size,
uint8 priority);
#endif
void KUpdateExstatus(x_err_t no);
int *KObtainExstatus(void);
#if !defined(LIB_NEWLIB) && !defined(_WIN32)
#ifndef errno
#define errno *KObtainExstatus()
#endif
#endif
KTaskDescriptorType GetKTaskDescriptor(void);
KTaskDescriptorType KTaskSearch(char *name);
x_err_t StartupKTask(int32 id);
x_err_t KTaskDelete(int32 id);
x_err_t YieldOsAssign(void);
x_err_t DelayKTask(x_ticks_t tick);
x_err_t MdelayKTask(uint32 ms);
x_err_t KTaskPrioSet(int32 id, uint8 prio);
x_err_t KTaskCoreCombine(int32 id, uint8 coreid);
x_err_t KTaskCoreUnCombine(int32 id);
x_err_t SuspendKTask(int32 id);
x_err_t KTaskWakeup(int32 id);
void KTaskTimeout(void *parameter);
void InitIdleKTask(void);
void IdleKTaskExec(void);
KTaskDescriptorType GetIdleKTaskDescripter(void);
void KTaskOsAssign(void);
void KTaskOsAssignRemoveKTask(struct TaskDescriptor *task);
#if defined (SCHED_POLICY_FIFO)
void FifoTaskTimesliceInit(struct TaskDescriptor *task);
void FifoReadyVectorInsert(struct TaskDescriptor *task, struct OsAssignReadyVector* ready_table);
void FifoTaskTimesliceUpdate();
#elif defined (SCHED_POLICY_RR)
void RoundRobinTaskTimesliceInit(struct TaskDescriptor *task);
void RoundRobinReadyVectorInsert(struct TaskDescriptor *task, struct OsAssignReadyVector* ready_table);
void RoundRobinTaskTimesliceUpdate(struct TaskDescriptor *task);
#elif defined (SCHED_POLICY_RR_REMAINSLICE)
void RoundRobinRemainTaskTimesliceInit(struct TaskDescriptor *task);
void RoundRobinRemainReadyVectorInsert(struct TaskDescriptor *task, struct OsAssignReadyVector* ready_table);
void RoundRobinRemainTaskTimesliceUpdate(struct TaskDescriptor *task);
#endif
x_err_t LinklistSuspend(DoubleLinklistType *list,struct TaskDescriptor *task,uint8 flag);
x_err_t LinklistResume(DoubleLinklistType *list);
x_err_t LinklistResumeAll(DoubleLinklistType *list);
void HwSendIpi(int ipi_vector, unsigned int cpu_mask);
void KTaskIdDelete(int32 id);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -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.
*/
/**
* @file: xs_ktask_stat.h
* @brief: function declaration of task stat
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_KTASK_STAT_H
#define XS_KTASK_STAT_H
#include <xs_base.h>
#include<xs_ktask.h>
#include <stdbool.h>
void KTaskStateSet(KTaskDescriptorType task, uint8 stat);
void KTaskStatSetAsInit(KTaskDescriptorType task);
void KTaskStatSetAsReady(KTaskDescriptorType task);
void KTaskStatSetAsSuspend(KTaskDescriptorType task);
void KTaskStatSetAsRunning(KTaskDescriptorType task);
void KTaskStatSetAsClose(KTaskDescriptorType task);
uint8 KTaskStatGet(KTaskDescriptorType task);
bool JudgeKTaskStatIsInit(KTaskDescriptorType task);
bool JudgeKTaskStatIsReady(KTaskDescriptorType task);
bool JudgeKTaskStatIsSuspend(KTaskDescriptorType task);
bool JudgeKTaskStatIsRunning(KTaskDescriptorType task);
bool JudgeKTaskStatIsClose(KTaskDescriptorType task);
#endif

32
kernel/include/xs_ktick.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* 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: xs_ktick.h
* @brief: function declaration of kernel tick
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef XS_KTICK_H
#define XS_KTICK_H
#include <xs_base.h>
x_ticks_t CurrentTicksGain(void);
void TickAndTaskTimesliceUpdate(void);
x_ticks_t CalculteTickFromTimeMs(uint32 ms);
uint32 CalculteTimeMsFromTick(x_ticks_t ticks);
#endif

107
kernel/include/xs_memory.h Normal file
View File

@@ -0,0 +1,107 @@
/*
* 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: xs_memory.h
* @brief: function declaration and structure defintion of memory
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef XS_MEMORY_H
#define XS_MEMORY_H
#include <xsconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MM_PAGE_SIZE
#define MM_PAGE_SIZE 4096
#endif
#define MM_PAGE_MASK (MM_PAGE_SIZE - 1)
#define MM_PAGE_BITS 12
/* Set static memory block */
#ifndef SMALL_NUMBER_32B
#define SMALL_NUMBER_32B (0) /* Calculate the numbers of SIZEOF_32B blocks*/
#endif
#ifndef SMALL_NUMBER_64B
#define SMALL_NUMBER_64B (0) /* Calculate the numbers of SIZEOF_64B blocks*/
#endif
#ifndef KERNEL_MALLOC
#define KERNEL_MALLOC(sz) x_malloc(sz)
#endif
#ifndef KERNEL_FREE
#define KERNEL_FREE(ptr) x_free(ptr)
#endif
#ifndef KERNEL_REALLOC
#define KERNEL_REALLOC(ptr, size) x_realloc(ptr, size)
#endif
#ifdef KERNEL_MEMBLOCK
struct MemGather
{
char m_name[NAME_NUM_MAX];
uint8 m_kind;
uint8 m_sign;
DoubleLinklistType m_link;
void *m_start_address;
x_size_t m_size;
x_size_t one_block_size;
uint8 *m_block_link;
x_size_t block_total_number;
x_size_t block_free_number;
DoubleLinklistType wait_task;
};
typedef struct MemGather *GatherMemType;
x_err_t InitMemGather(struct MemGather *gm_handler, const char *gm_name, void *begin_address, x_size_t gm_size, x_size_t one_block_size);
x_err_t RemoveMemGather(struct MemGather *gm_handler);
GatherMemType CreateMemGather(const char *gm_name, x_size_t block_number, x_size_t one_block_size);
x_err_t DeleteMemGather(GatherMemType gm_handler);
void *AllocBlockMemGather(GatherMemType gm_handler, int32 wait_time);
void FreeBlockMemGather(void *data_block);
#endif
void InitBoardMemory(void *begin_addr, void *end_addr);
void *x_malloc(x_size_t nbytes);
void x_free(void *ptr);
void *x_realloc(void *ptr, x_size_t nbytes);
void *x_calloc(x_size_t count, x_size_t size);
#ifdef USER_APPLICATION
void UserInitBoardMemory(void *begin_addr, void *end_addr);
void *x_umalloc(x_size_t nbytes);
void x_ufree(void *ptr);
void *x_urealloc(void *ptr, x_size_t nbytes);
void *x_ucalloc(x_size_t count, x_size_t size);
#endif
void MemoryInfo(uint32 *total, uint32 *used, uint32 *max_used);
#ifdef __cplusplus
}
#endif
#endif

67
kernel/include/xs_msg.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* 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: xs_msg.h
* @brief: function declaration and structure defintion of message queue
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef XS_MSG_H
#define XS_MSG_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#ifdef KERNEL_MESSAGEQUEUE
struct MsgQueue
{
struct IdNode id;
void *msg_buf;
uint16 index;
uint16 num_msgs;
uint16 each_len;
uint16 max_msgs;
DoubleLinklistType send_pend_list;
DoubleLinklistType recv_pend_list;
DoubleLinklistType link;
struct MsgQueueDone *Done;
};
typedef struct MsgQueue *MsgQueueType;
struct MsgQueueDone
{
x_err_t (*init)(struct MsgQueue *mq, x_size_t msg_size, x_size_t max_msgs );
x_err_t (*urgensend)(struct MsgQueue *mq, const void *buffer, x_size_t size);
x_err_t (*send)(struct MsgQueue *mq, const void *buffer, x_size_t size,int32 timeout);
x_err_t (*recv)(struct MsgQueue *mq, void *buffer, x_size_t size, int32 timeout);
x_err_t (*reinit)(struct MsgQueue *mq);
x_err_t (*Delete)(struct MsgQueue *mq);
};
int32 KCreateMsgQueue( x_size_t msg_size, x_size_t max_msgs );
x_err_t KMsgQueueSendwait(int32 id, const void *buffer, x_size_t size, int32 timeout);
x_err_t KMsgQueueUrgentSend(int32 id, const void *buffer, x_size_t size);
x_err_t KMsgQueueSend(int32 id, const void *buffer, x_size_t size);
x_err_t KMsgQueueRecv(int32 id, void *buffer, x_size_t size, int32 timeout);
x_err_t KMsgQueueReinit(int32 id);
x_err_t KDeleteMsgQueue(int32 id);
#endif
#endif

56
kernel/include/xs_mutex.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* 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: xs_mutex.h
* @brief: function declaration and structure defintion of mutex
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_MUTEX_H
#define XS_MUTEX_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#include <xs_id.h>
#ifdef KERNEL_MUTEX
struct Mutex {
struct IdNode id;
uint16 val;
uint8 recursive_cnt;
uint8 origin_prio;
struct TaskDescriptor *holder;
DoubleLinklistType pend_list;
DoubleLinklistType link;
};
typedef struct {
int32 (*MutexCreate)();
void (*MutexDelete)(struct Mutex *mutex);
int32 (*MutexObtain)(struct Mutex *mutex, int32 wait_time);
int32 (*MutexAbandon)(struct Mutex *mutex);
} MutexDoneType;
int32 KMutexCreate();
void KMutexDelete(int32 id);
int32 KMutexObtain(int32 id, int32 wait_time);
int32 KMutexAbandon(int32 id);
#endif
#endif

59
kernel/include/xs_poll.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* 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: xs_pool.h
* @brief: function declaration and structure defintion of poll
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_POLL_H
#define XS_POLL_H
#include <xs_base.h>
#include <xs_waitqueue.h>
#include <sys/time.h>
#if !defined(POLLIN) && !defined(POLLOUT)
#define POLLIN 0x001
#define POLLOUT 0x002
#define POLLERR 0x004
#define POLLHUP 0x008
#define POLLNVAL 0x010
#define POLLMASK_DEFAULT (POLLIN | POLLOUT )
typedef unsigned long NfdsType;
struct pollfd
{
int fd;
short events;
short revents;
};
#endif
struct Pollreq;
typedef void (*poll_queue_proc)(WaitQueueType *, struct Pollreq *);
typedef struct Pollreq
{
poll_queue_proc _proc;
short _key;
} pollreqType;
void PollAdd(WaitQueueType *wq, pollreqType *req);
int poll(struct pollfd *fds, NfdsType nfds, int timeout);
#endif

View File

@@ -0,0 +1,47 @@
/*
* 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: xs_queue_manager.h
* @brief: function declaration and structure defintion of queue manager
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_QUEUE_MANAGER_H
#define XS_QUEUE_MANAGER_H
#include <xsconfig.h>
#ifndef QUEUE_MAX
#define QUEUE_MAX 16
#endif
typedef struct
{
void *property;
void *done;
} queue;
enum QUEUE_TYPE
{
DATA_QUEUE = 1,
WORK_QUEUE,
WAIT_QUEUE,
};
extern void *g_queue_done[];
extern void queuemanager_done_register();
#endif

57
kernel/include/xs_sem.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* 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: xs_sem.h
* @brief: function declaration and structure defintion of sem
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/12
*
*/
#ifndef XS_SEM_H
#define XS_SEM_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#include <xs_id.h>
#ifdef KERNEL_SEMAPHORE
struct Semaphore
{
struct IdNode id;
uint16 value;
DoubleLinklistType pend_list;
DoubleLinklistType link;
};
typedef struct {
int32 (*SemaphoreCreate)(uint16 val);
void (*SemaphoreDelete)(struct Semaphore *sem);
int32 (*SemaphoreObtain)(struct Semaphore *sem, int32 wait_time);
int32 (*SemaphoreAbandon)(struct Semaphore *sem);
int32 (*SemaphoreSetValue)(struct Semaphore *sem, uint16 val);
} SemaphoreDoneType;
int32 KSemaphoreCreate(uint16 val);
void KSemaphoreDelete(int32 id);
int32 KSemaphoreObtain(int32 id, int32 wait_time);
int32 KSemaphoreAbandon(int32 id);
int32 KSemaphoreSetValue(int32 id, uint16 val);
#endif
#endif

115
kernel/include/xs_service.h Normal file
View File

@@ -0,0 +1,115 @@
/*
* 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: xs_service.h
* @brief: maroc and switch table definition of kernel switch
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_SERVICE_H
#define XS_SERVICE_H
#include <stdint.h>
#include "xs_base.h"
#ifdef SEPARATE_COMPILE
// #include <board.h>
enum KernelService
{
KS_USER_PRINT_INFO = 0,
KS_USER_TASK_CREATE ,
KS_USER_TASK_STARTUP ,
KS_USER_TASK_DELETE,
KS_USER_TASK_EXECEXIT,
KS_USER_TASK_CORE_COMBINE,
KS_USER_TASK_CORE_UNCOMBINE,
KS_USER_TASK_DELAY,
KS_USER_GET_TASK_NAME,
KS_USER_GET_TASK_ID,
KS_USER_GET_TASK_STAT,
KS_USER_GET_TASK_COMBINEED_CORE,
KS_USER_GET_TASK_RUNNING_CORE,
KS_USER_GET_TASK_ERROR_STATUS,
KS_USER_GET_TASK_PRIORITY,
KS_USER_MALLOC,
KS_USER_FREE,
KS_USER_MUTEX_CREATE,
KS_USER_MUTEX_DELETE,
KS_USER_MUTEX_OBTAIN,
KS_USER_MUTEX_ABANDON,
KS_USER_SEMAPHORE_CREATE,
KS_USER_SEMAPHORE_DELETE,
KS_USER_SEMAPHORE_OBTAIN,
KS_USER_SEMAPHORE_ABANDON,
KS_USER_SEMAPHORE_SETVALUE,
KS_USER_EVENT_CREATE,
KS_USER_EVENT_DELETE,
KS_USER_EVENT_TRIGGER,
KS_USER_EVENT_PROCESS,
KS_USER_MSGQUEUE_CREATE,
KS_USER_MSGQUEUE_DELETE,
KS_USER_MSGQUEUE_SENDWAIT,
KS_USER_MSGQUEUE_SEND,
KS_USER_MSGQUEUE_URGENTSEND,
KS_USER_MSGQUEUE_RECV,
KS_USER_MSGQUEUE_REINIT,
KS_USER_OPEN,
KS_USER_READ,
KS_USER_WRITE,
KS_USER_CLOSE,
KS_USER_IOCTL,
KS_USER_LSEEK,
KS_USER_RENAME,
KS_USER_UNLINK,
KS_USER_STAT,
KS_USER_FS_STAT,
KS_USER_FS_SYNC,
KS_USER_FTRUNCATE,
KS_USER_MKDIR,
KS_USER_OPENDIR,
KS_USER_CLOSEDIR,
KS_USER_READDIR,
KS_USER_RMDIR,
KS_USER_CHDIR,
KS_USER_GETCWD,
KS_USER_TELLDIR,
KS_USER_SEEKDIR,
KS_USER_REWIND_DIR,
KS_USER_STAT_FS,
KS_USER_END
};
#define SERVICETABLE ((struct Kernel_Service*)SERVICE_TABLE_ADDRESS)
#endif
typedef uintptr_t (*kservice)(uint32_t knum,uintptr_t *param,uint8_t param_num);
struct Kernel_Service
{
const kservice fun;
const uint8_t param_num;
};
extern struct Kernel_Service g_service_table[] ;
#endif

View File

@@ -0,0 +1,107 @@
/*
* 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: xs_service.h
* @brief: maroc and switch table definition of kernel switch
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef XS_SPINLOCK_H
#define XS_SPINLOCK_H
#include <xs_isr.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ARCH_SMP
typedef union
{
unsigned long slock;
struct __arch_tickets
{
unsigned short owner;
unsigned short next;
} tickets;
} HwSpinlock;
struct SpinLock
{
HwSpinlock lock;
};
struct Spin_Lockfileops
{ //定义自旋锁
struct SpinLock node_lock; //原有的自旋锁结构体
void (*SPinLock)(struct Spin_Lockfileops *spinlock);
void (*UnlockSpinLock)(struct Spin_Lockfileops *spinlock);
void (*UnlockSpinLockIrqRestore)(struct Spin_Lockfileops *spinlock, x_base level);
x_base (*SpinLockIrqSave)(struct Spin_Lockfileops *spinlock);
};
extern struct Spin_Lockfileops spinlock;
extern HwSpinlock _CriticalLock;
void InitHwSpinlock(HwSpinlock *lock);
void HwLockSpinlock(HwSpinlock *lock);
void HwUnlockSpinlock(HwSpinlock *lock);
int GetCpuId(void);
#define HW_SPIN_LOCK_INITIALIZER(lockname) {0}
#define HW_SPIN_LOCK_UNLOCKED(lockname) (HwSpinlock) HW_SPIN_LOCK_INITIALIZER(lockname)
#define DEFINE_SPINLOCK(x) HwSpinlock x = HW_SPIN_LOCK_UNLOCKED(x)
#define DECLARE_SPINLOCK(x)
void StartupSecondaryCpu(void);
void ExecSecondaryCpuIdleKtask(void);
#else
#define HwLockSpinlock(lock) *(lock) = DISABLE_INTERRUPT()
#define HwUnlockSpinlock(lock) ENABLE_INTERRUPT(*(lock))
#endif
#ifdef ARCH_SMP
struct SpinLock;
void InitSpinLock(struct Spin_Lockfileops * spinlock);
void _SpinLock(struct Spin_Lockfileops * spinlock);
void _UnlockSpinLock(struct Spin_Lockfileops * spinlock);
x_base _SpinLockIrqSave(struct Spin_Lockfileops * spinlock);
void _UnlockSpinLockIrqRestore(struct Spin_Lockfileops * spinlock, x_base level);
#else
#define InitSpinLock(lock) /* nothing */
#define SpinLock(lock) CriticalAreaLock()
#define UnlockSpinLock(lock) CriticalAreaUnLock()
#define SpinLockIrqSave(lock) DISABLE_INTERRUPT()
#define UnlockSpinLockIrqRestore(lock, level) ENABLE_INTERRUPT(level)
#endif
#ifdef __cplusplus
}
#endif
#endif

87
kernel/include/xs_timer.h Normal file
View File

@@ -0,0 +1,87 @@
/*
* 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: xs_timer.h
* @brief: function declaration and structure defintion of timer
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/10
*
*/
#ifndef XS_TIMER_H
#define XS_TIMER_H
#include <xsconfig.h>
#include <xs_kdbg.h>
#include <xs_base.h>
#include <xs_klist.h>
#include <xs_id.h>
#define TIMER_TRIGGER_ONCE (1 << 0)
#define TIMER_TRIGGER_PERIODIC (1 << 1)
#define TIMER_ACTIVE_FALSE (1 << 0)
#define TIMER_ACTIVE_TRUE (1 << 1)
struct Timer
{
struct IdNode id_node;
char name[NAME_NUM_MAX];
uint8 active_status;
uint8 trigger_mode;
void (*func_callback)(void *param);
void *param;
x_ticks_t origin_timeslice;
x_ticks_t deadline_timeslice;
DoubleLinklistType link;
DoubleLinklistType sortlist;
uint8 prio;
struct Work * t_work;
struct TimerDone* done;
};
typedef struct Timer *TimerType;
struct TimerDone
{
void (*Init)(struct Timer *timer,
const char *name,
void (*timeout)(void *parameter),
void *parameter,
x_ticks_t time,
uint8 trigger_mode);
x_err_t (*Delete)(TimerType timer);
x_err_t (*StartRun)(TimerType timer);
x_err_t (*QuitRun)(TimerType timer);
x_err_t (*Modify)(TimerType timer, x_ticks_t ticks);
};
int32 KCreateTimer(const char *name,
void (*timeout)(void *parameter),
void *parameter,
x_ticks_t time,
uint8 trigger_mode);
x_err_t KDeleteTimer(int32 timer_id);
x_err_t KTimerStartRun(int32 timer_id);
x_err_t KTimerQuitRun(int32 timer_id);
x_err_t KTimerModify(int32 timer_id, x_ticks_t ticks);
x_err_t KTimerAssignMemberRun(int32 timer_id, x_ticks_t ticks);
TimerType KGetTimer(int32 id);
int32 KGetTimerID(TimerType timer);
x_ticks_t TimerNextTimeoutTick(void);
void CheckTimerList(void);
#endif

View File

@@ -0,0 +1,78 @@
/*
* 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: xs_waitqueue.h
* @brief: function declaration and structure defintion of waitqueue
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_WAITQUEUE_H
#define XS_WAITQUEUE_H
#include <xs_ktask.h>
#include <xs_timer.h>
#include <xs_queue_manager.h>
#define WQ_FLAG_CLEAN 0x00
#define WQ_FLAG_WAKEUP 0x01
struct WaitQueue
{
DoubleLinklistType block_threads_list;
};
typedef struct WaitQueue WaitQueueType;
struct WaitqueueNode;
typedef int (*wqueue_func_t)(struct WaitqueueNode *wait, void *key);
struct WaitqueueNode
{
KTaskDescriptorType polling_task;
DoubleLinklistType list;
wqueue_func_t cb;
x_ticks_t deadline_tick;
uint32 key;
};
typedef struct WaitqueueNode WaitqueueNodeType;
int __WqueueDefaultWake(struct WaitqueueNode *wait, void *key);
void InitWqueue(WaitQueueType *queue);
void WqueueAdd(WaitQueueType *queue, struct WaitqueueNode *node);
void WqueueRemove(struct WaitqueueNode *node);
int WqueueWait(WaitQueueType *queue, x_ticks_t tick);
void WakeupWqueue(WaitQueueType *queue, void *key);
#define DEFINE_WAIT_FUNC(name, function) \
struct WaitqueueNode name = { \
os_running_task, \
DOUBLE_LINKLIST_OBJ_INIT(((name).list)), \
\
function, \
0 \
}
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, __WqueueDefaultWake)
typedef struct
{
void (*InitWqueue)(WaitQueueType *queue);
void (*WqueueAdd)(WaitQueueType *queue, WaitqueueNodeType *node);
void (*WqueueRemove)(WaitqueueNodeType *node);
int (*WqueueWait)(WaitQueueType *queue, x_ticks_t tick);
void (*WakeupWqueue)(WaitQueueType *queue, void *key);
} WaitQueueDoneType;
#endif

View File

@@ -0,0 +1,66 @@
/*
* 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: xs_workqueue.h
* @brief: function declaration and structure defintion of workqueue
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/4/20
*
*/
#ifndef XS_WORKQUEUE_H
#define XS_WORKQUEUE_H
#include <xs_ktask.h>
#include <xs_timer.h>
#include <xs_queue_manager.h>
#define MAX_WORK_QUEUE 32
struct Work
{
void (*cb_func)(struct Work *work, void *work_data);
void *cb_param;
};
typedef struct
{
int front;
int rear;
struct Work* base;
int32 task;
}WorkqueueType;
typedef struct
{
WorkqueueType* p_queue;
struct Work* p_work;
int32 p_timer;
}WorkTimerParamType;
WorkqueueType *CreateWorkQueue(const char *name, uint16 stack_size, uint8 priority);
void WorkInit(struct Work *work, void (*work_func)(struct Work *work,void *work_data), void *work_data);
x_err_t WorkSubmit(WorkqueueType* sys_workq, struct Work *work, x_ticks_t time);
x_err_t WorkSubmit_immediate(WorkqueueType* sys_workq, struct Work *work);
int WorkSysWorkQueueInit(void);
typedef struct
{
WorkqueueType *(*CreateWorkQueue)(const char *name, uint16 stack_size, uint8 priority);
void (*WorkInit)(struct Work *work, void (*work_func)(struct Work *work, void *work_data), void *work_data);
x_err_t (*WorkSubmit)(WorkqueueType *sys_workq, struct Work *work, x_ticks_t time);
x_err_t (*WorkSubmit_immediate)(WorkqueueType *sys_workq, struct Work *work);
} WorkQueueDoneType;
#endif