⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel.h

📁 很好的一个微型操作系统源码
💻 H
字号:
#include "types.h"
#include "platform.h"
#include "stdio.h"

void keEntryMain(uint32 param);

void keTimerIsr();
uint32 keGetTickCount();
void keDelay(uint32 ticks);

struct heapmem
{
	struct header *p_base;  //头指针
	struct header *p_free;  //当前指针
	uint32 heapsize;
	char heapbuf[0];
};

void keHeapInit(struct heapmem * heap, int size);
void *keHeapAlloc(struct heapmem * heap,  uint32 nbytes);
void keHeapFree(struct heapmem * heap,  void *pointer);
void keHeapDump(struct heapmem * heap);

void* keMalloc(uint32 nbytes);
void keFree(void *pointer);
void keKernelHeapInit();
void keKernelHeapDump();

void keKeyboardIsr();
uint8 keGetChar();

struct taskblock
{
	uint32 *esp;
	char taskname[32];
	uint32 priority;
	uint32 taskid;
	uint32 status;
	struct taskblock *next;
	struct taskblock ** queue;
	char stacks[0];
};

typedef void(*TASK_ENTRY)(uint32 param);

#define TASK_ACTIVE 0
#define TASK_PEND 1

extern uint32 currentTaskId;
extern struct taskblock *tasks[1024];

void keInitTaskSystem();
struct taskblock* keNewTask(char *name, TASK_ENTRY entry, uint32 param, uint32 priority, uint32 stacksize);
void keDoSched();
void keKillTask(uint32 taskid);
void keShowTasks();

void keTaskEnqueue(struct taskblock ** header, struct taskblock *data);
struct taskblock * keTaskDequeue(struct taskblock ** header);
struct taskblock * keTaskRemove(struct taskblock *data);
struct taskblock * keActiveTask(struct taskblock *task);
struct taskblock * kePendTask(struct taskblock ** pendlist, struct taskblock *task);

_inline keDoSchedNormal()
{
	_int17();
}

struct semaphore
{
	uint32 value;
	struct taskblock * pendingtasks;
};

void initsemaphore(struct semaphore * sem, uint32 initial);
void wait(struct semaphore * sem);
void release(struct semaphore * sem);

_inline void Assert(int exp, char* str)
{
	if(!exp)
	{
		puts(str);
		keKillTask(currentTaskId);
		while(1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -