📄 kernel.h
字号:
//Kernel Head File:
//Copyright (c) 2008 www.evvei.com, All Rights Reserved.
//_____________________________________________________________________________________
//File name: kernel.h
//Abstract: Head file for C/C++ language programing of the e-kernel.
//
//C declarations in C++.
#ifdef __cplusplus
extern "C" {
#endif
//_____________________________________________________________________________________
//Constant Definitions:
#define NESTED_INTERRUPT 0
#define reg register
#define NA 0xfaaaaaaa
#define NULL 0
#define TRUE 1
#define FALSE 0
//Kernel Object ID:
#define KID_THREAD 0x01
#define KID_TIMER 0x02
#define KID_APPTIMER 0x03
#define KID_POOL 0x05
#define KID_MUTEX 0x06
#define KID_SEMAPHORE 0x07
#define KID_MAILBOX 0x08
#define KID_QUEUE 0x09
#define KID_PIPE 0x0a
#define KID_EVENT 0x0b
//Option Flags for Kernel Object Initialization:
#define OPT_DEFAULT 0x00000000
#define OPT_FIXED 0x80000000
#define OPT_EXISTING 0x40000000
#define OPT_PRIOR_WAITING 0x08000000
#define OPT_FIFO_WAITING 0x00000000
#define OPT_READY 0x00000001
#define OPT_PREEMPTION 0x00000002
#define OPT_ACTIVING 0x00000080
#define OPT_REPEAT 0x00000040
#define OPT_EVENT_AND 0x00000100
#define OPT_EVENT_OR 0x00000000
#define OPT_EVENT_CLEAR 0x00000200
//Return Status of Kernel Interface Function:
#define RS_FAILING 0
#define RS_SUCCESSFUL 1
#define RS_MUTEX_DESTROYED -1
#define RS_SEMAPHORE_DESTROYED -1
#define RS_EVENT_DESTROYED -1
#define RS_MAILBOX_DESTROYED -1
#define RS_QUEUE_DESTROYED -1
#define RS_PIPE_DESTROYED -1
#define RS_POOL_DESTROYED -1
#define RS_SEMAPHORE_RESETED 10
#define RS_MAILBOX_RESETED 10
#define RS_QUEUE_RESETED 10
#define RS_PIPE_RESETED 10
//Thread Status:
#define TS_INITIAL 0
#define TS_READY 1
#define TS_WAITING 4
#define TS_SLEEPING 5
#define TS_SUSPENDED 6
#define TS_LATENCY 10
#define TS_TERMINATED 15
//thread critical priorities:
#define PRI_CRITICAL7 63
#define PRI_CRITICAL6 62
#define PRI_CRITICAL5 61
#define PRI_CRITICAL4 60
#define PRI_CRITICAL3 59
#define PRI_CRITICAL2 58
#define PRI_CRITICAL1 57
#define PRI_CRITICAL0 56
//thread realtime priorities:
#define PRI_REALTIME23 55
#define PRI_REALTIME22 54
#define PRI_REALTIME21 53
#define PRI_REALTIME20 52
#define PRI_REALTIME19 51
#define PRI_REALTIME18 50
#define PRI_REALTIME17 49
#define PRI_REALTIME16 48
#define PRI_REALTIME15 47
#define PRI_REALTIME14 46
#define PRI_REALTIME13 45
#define PRI_REALTIME12 44
#define PRI_REALTIME11 43
#define PRI_REALTIME10 42
#define PRI_REALTIME9 41
#define PRI_REALTIME8 40
#define PRI_REALTIME7 39
#define PRI_REALTIME6 38
#define PRI_REALTIME5 37
#define PRI_REALTIME4 36
#define PRI_REALTIME3 35
#define PRI_REALTIME2 34
#define PRI_REALTIME1 33
#define PRI_REALTIME0 32
//thread normal priorities:
#define PRI_NORMAL31 31
#define PRI_NORMAL30 30
#define PRI_NORMAL29 29
#define PRI_NORMAL28 28
#define PRI_NORMAL27 27
#define PRI_NORMAL26 26
#define PRI_NORMAL25 25
#define PRI_NORMAL24 24
#define PRI_NORMAL23 23
#define PRI_NORMAL22 22
#define PRI_NORMAL21 21
#define PRI_NORMAL20 20
#define PRI_NORMAL19 19
#define PRI_NORMAL18 18
#define PRI_NORMAL17 17
#define PRI_NORMAL16 16
#define PRI_NORMAL15 15
#define PRI_NORMAL14 14
#define PRI_NORMAL13 13
#define PRI_NORMAL12 12
#define PRI_NORMAL11 11
#define PRI_NORMAL10 10
#define PRI_NORMAL9 9
#define PRI_NORMAL8 8
#define PRI_NORMAL7 7
#define PRI_NORMAL6 6
#define PRI_NORMAL5 5
#define PRI_NORMAL4 4
#define PRI_NORMAL3 3
#define PRI_NORMAL2 2
#define PRI_NORMAL1 1
#define PRI_NORMAL0 0
//Define kernel object size:
#define KLOCK_SIZE 12
#define KTHREAD_SIZE 256
#define KTIMER_SIZE 88
#define KMUTEX_SIZE 56
#define KSEMAPHORE_SIZE 52
#define KEVENT_SIZE 52
#define KMAILBOX_SIZE 68
#define KQUEUE_SIZE 80
#define KPIPE_SIZE 76
#define KPOOL_SIZE 80
//_____________________________________________________________________________________
//Kernel Data Type Difenitions:
//
//Basic data types:
typedef char CHAR;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned long QWORD;
typedef unsigned int BOOL;
typedef char INT8;
typedef short INT16;
typedef int INT32;
typedef long INT64;
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef unsigned long UINT64;
typedef unsigned int HANDLE;
typedef void * POINTER;
typedef void VOID;
typedef INT32 STATUS;
typedef UINT32 OPTION;
//Lock access control data structure.
typedef struct _KLOCK
{
BYTE Data[KLOCK_SIZE];
} KLOCK;
//thread control data structure.
typedef struct _KTHREAD
{
BYTE Data[KTHREAD_SIZE];
} KTHREAD;
//Mutex control data structure.
typedef struct _KMUTEX
{
BYTE Data[KMUTEX_SIZE];
} KMUTEX;
//Semaphore control data structure.
typedef struct _KSEMAPHORE
{
BYTE Data[KSEMAPHORE_SIZE];
} KSEMAPHORE;
//Mailbox control data structure.
typedef struct _KMAILBOX
{
BYTE Data[KMAILBOX_SIZE];
} KMAILBOX;
//Queue control data structure.
typedef struct _KQUEUE
{
BYTE Data[KQUEUE_SIZE];
} KQUEUE;
//Piple control data structure.
typedef struct _KPIPE
{
BYTE Data[KPIPE_SIZE];
} KPIPE;
//Event control data structure.
typedef struct _KEVENT
{
BYTE Data[KEVENT_SIZE];
} KEVENT;
//Timer control data structure.
typedef struct _KTIMER
{
BYTE Data[KTIMER_SIZE];
} KTIMER;
//Memory pool control data structure.
typedef struct _KPOOL
{
BYTE Data[KPOOL_SIZE];
} KPOOL;
//Kernel startup information structrue.
typedef struct _KSTARTUP
{
DWORD KernelCode; //0x656b3031,the ASCII code "ek01"
DWORD ProcessorCode; //Code number for supported proccessor.
DWORD UserCode; //Code number for target user.
DWORD LicenceCode; //Licence code to target user.
BOOL VectorConfig; //Vector configuration flag.
BOOL MemoryMode; //Virtual or actual memory mode.
VOID *kernelStack; //Kernel stack address.
UINT32 KernelStackSize; //Fixed to 20KBytes.
VOID *physicalMemoryStart; //Physical memory start address.
VOID *physicalMemoryEnd; //Physical memory end address.
VOID *textSection; //Kernel code and constant section.(.text)
UINT32 TextSize;
VOID *dataSection; //Kernel static data section.(.data)
UINT32 DataSize;
VOID *dynamicStoreSection; //Kernel dynamic store section.(.dss)
UINT32 DynamicStoreSize;
UINT32 HardClockFrequency; //Processor main clock frequency(MHz)
UINT32 SoftClockFrequency; //Kernel tick timer clock frequency(Hz)
UINT32 DefaultTimeslice; //The default timeslice value for thread.
DWORD Reserved[42];
} KSTARTUP;
//_____________________________________________________________________________________
//Kernel Interface Function Definitions:
//
//Common functions:
#define KeCheckStack KiCheckStack
#define KeGetKernelTime KiGetKernelTime
#define KeSetKernelTime KiSetKernelTime
UINT32 KiCheckStack(VOID);
UINT32 KeCheckStack(VOID);
UINT32 KiGetKernelTime();
VOID KiSetKernelTime(UINT32 Time);
UINT32 KeGetKernelTime();
VOID KeSetKernelTime(UINT32 Time);
VOID KernelStartup(KSTARTUP *);
VOID ApplicationInitialize(VOID *dssAddress, UINT32 dssSize);
//Interrupt management functions:
#define KeMaskInterrupt KiMaskInterrupt
#define KeUnmaskInterrupt KiUnmaskInterrupt
#define KeConnectIsr KiConnectIsr
#define KeDisconnectIsr KiDisconnectIsr
VOID KiLockInterrupt();
VOID KiUnlockInterrupt();
VOID KiMaskInterrupt(UINT32 Vector);
VOID KiUnmaskInterrupt(UINT32 Vector);
VOID* KiConnectIsr(UINT32 Vector, VOID (* isr)(UINT32));
VOID* KiDisconnectIsr(UINT32 Vector);
VOID KeLockInterrupt();
VOID KeUnlockInterrupt();
VOID KeMaskInterrupt(UINT32 Vector);
VOID KeUnmaskInterrupt(UINT32 Vector);
VOID* KeConnectIsr(UINT32 Vector, VOID (* isr)(UINT32));
VOID* KeDisconnectIsr(UINT32 Vector);
//Lock access control functions:
VOID KeInitializeLock(KLOCK *lock);
VOID KeLock(KLOCK *lock);
VOID KeUnlock(KLOCK *lock);
//Thread control functions:
STATUS KeInitializeThread(
KTHREAD *thread,
UINT32 Priority,
STATUS (* routine)(UINT32, VOID *),
UINT32 argc,
VOID *argv,
VOID *stackAddress,
UINT32 StackSize,
OPTION InitSet
);
VOID KiActivateThread(KTHREAD *thread,UINT32 argc,VOID *argv);
STATUS KeResumeThread(KTHREAD *thread);
STATUS KeSuspendThread(KTHREAD *thread);
STATUS KeTerminateThread(KTHREAD *thread);
STATUS KeResetThread(KTHREAD *thread,UINT32 Argc,VOID *Argv);
BOOL KeSetThreadPremption(KTHREAD *thread, BOOL Preempt);
UINT32 KeSetThreadPriority(KTHREAD *thread,UINT32 Priority);
UINT32 KeSetThreadTimeslice(KTHREAD *thread,UINT32 Timeslice);
VOID KeSleepThread(UINT32 Time);
VOID KeBreakThread();
VOID KeExitThread();
//Timer management functions:
#define KeInitializeTimer KeInitializeAppTimer
#define KeDestroyTimer KeDestroyAppTimer
#define KeStartTimer KeStartAppTimer
#define KeStopTimer KeStopAppTimer
STATUS KeInitializeTimer(
KTIMER *timer,
UINT32 Time,
VOID (* routine)(UINT32, VOID *),
UINT32 arg1,
VOID *arg2,
OPTION InitSet
);
STATUS KeDestroyTimer(KTIMER *timer);
STATUS KeStartTimer(KTIMER *timer);
STATUS KeStopTimer(KTIMER *timer);
//Mutex management functions:
STATUS KeInitializeMutex(KMUTEX *mutex, OPTION InitSet);
STATUS KeDestroyMutex(KMUTEX *mutex);
STATUS KeEnterMutex(KMUTEX *mutex, UINT32 Timeout);
STATUS KeLeaveMutex(KMUTEX *mutex);
//Semaphore management functions:
STATUS KeInitializeSemaphore(KSEMAPHORE *semaphore, UINT32 ResCount, OPTION InitSet);
STATUS KeDestroySemaphore(KSEMAPHORE *semaphore);
STATUS KeResetSemaphore(KSEMAPHORE *semaphore, UINT32 ResCount);
STATUS KeObtainSemaphore(KSEMAPHORE *semaphore, UINT32 Timeout);
STATUS KeReleaseSemaphore(KSEMAPHORE *semaphore);
//Event group management functions:
STATUS KeInitializeEvent(KEVENT *event, OPTION InitSet);
STATUS KeDestroyEvent(KEVENT *event);
STATUS KeSetEvent(KEVENT *event, DWORD Flags, OPTION OpType);
STATUS KeCheckEvent(KEVENT *event, DWORD Flags, OPTION OpType, UINT32 Timeout);
//Mailbox management functions:
STATUS KeInitializeMailbox(KMAILBOX *mailbox, OPTION InitSet);
STATUS KeDestroyMailbox(KMAILBOX *mailbox);
STATUS KeResetMailbox(KMAILBOX *mailbox);
STATUS KeSendMailbox(KMAILBOX *mailbox, VOID *message, UINT32 Timeout);
STATUS KeBroadcastMailbox(KMAILBOX *mailbox, VOID *message, UINT32 Timeout);
STATUS KeReceiveMailbox(KMAILBOX *mailbox, VOID *message, UINT32 Timeout);
//Queue management functions:
STATUS KeInitializeQueue(
KQUEUE *queue,
VOID *buffer,
UINT32 QueueSize,
UINT32 MessageSize,
OPTION InitSet
);
STATUS KeDestroyQueue(KQUEUE *queue);
STATUS KeResetQueue(KQUEUE *queue);
STATUS KeSendQueue(KQUEUE *queue, VOID *message, UINT32 Timeout);
STATUS KeSendQueueFront(KQUEUE *queue, VOID *message, UINT32 Timeout);
STATUS KeBroadcastQueue(KQUEUE *queue, VOID *message, UINT32 Timeout);
STATUS KeReceiveQueue(KQUEUE *queue, VOID *message, UINT32 Timeout);
//Pipe management functions:
STATUS KeInitializePipe(
KPIPE *pipe,
VOID *buffer,
UINT32 PipeSize,
OPTION InitSet
);
STATUS KeDestroyPipe(KPIPE *pipe);
STATUS KeResetPipe(KPIPE *pipe);
STATUS KeSendPipe(KPIPE *pipe, VOID *data, UINT32 Size, UINT32 Timeout);
STATUS KeSendPipeFront(KPIPE *pipe, VOID *data, UINT32 Size, UINT32 Timeout);
STATUS KeBroadcastPipe(KPIPE *pipe, VOID *data, UINT32 Size, UINT32 Timeout);
UINT32 KeReceivePipe(KPIPE *pipe, VOID *data,UINT32 Size, UINT32 Timeout);
//Memory pool management functions:
STATUS KeInitializePool(
KPOOL *pool,
VOID *address,
UINT32 TotalSize,
UINT32 BlockSize,
OPTION InitSet
);
STATUS KeInitializePoolEx(
KPOOL *pool,
VOID *mapArea,
UINT32 MapSize,
VOID *allocArea,
UINT32 AllocSize,
UINT32 BlockSize,
OPTION InitSet
);
VOID* KeAllocateMemory(KPOOL *pool,UINT32 Size,UINT32 Timeout);
STATUS KeFreeMemory(KPOOL *pool,VOID *address);
//End of C declarations.
#ifdef __cplusplus
}
#endif
//_____________________________________________________________________________________
//End of the file.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -