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

📄 os.h

📁 mcu 单片机环境的多任务操作系统的例子
💻 H
字号:
#ifndef __OS_NEW_THUNDER_HEADER__
#define __OS_NEW_THUNDER_HEADER__

/* next define: in case of Hi-Tech C compiler:
 * which bank should the OS use for its own variables? */
#ifdef _MPC_
 #define _OSBANK					bank3
#else
 #define _OSBANK
#endif

/* <true> and <false> defined only in C++ */
#ifndef true
 #define true						1
#endif
#ifndef false
 #define false						0
#endif

/* maximal number of tasks in the system 5 bytes per task*/
#define OS_TASKS					11

/* maximal number of messages in the system */
#define OS_EVENTS					6

/* processes priorities limits */
#define OS_MAX_PRIORITY					0
#define OS_MIN_PRIORITY					15

typedef struct {
	unsigned state					: 3;
	unsigned priority				: 4;
	unsigned counterOverflow			: 1;
	void (*task)();
	union {
		unsigned int delayTicks;
		unsigned char msgWaiting;
	} data;
} osTaskType, *osTaskTypePtr;

typedef struct {
	unsigned type					: 4;
	unsigned state					: 4;
	void* data;
} osMessageType, *osMessageTypePtr;

extern _OSBANK unsigned int osTicksCounter;
extern _OSBANK unsigned char osCurrentTask;

#define osTimer()	osTicksCounter++;

/* states of tasks */
#define OS_TASK_STATE_UNDEFINED				0
#define OS_TASK_STATE_DESTROYED				1
#define OS_TASK_STATE_STOPPED				2
#define OS_TASK_STATE_DELAYED				3
#define OS_TASK_STATE_WAITING				4
#define OS_TASK_STATE_WAITING_TO			5
#define OS_TASK_STATE_ELIGIBLE				6
#define OS_TASK_STATE_RUNNING				7

/* states of events */
#define OS_MESSAGE_STATE_UNDEFINED			0
#define OS_MESSAGE_STATE_WAITING			1
#define OS_MESSAGE_STATE_ANSWERED			2
#define OS_MESSAGE_STATE_DESTROYED			3

/* errors */
typedef enum {
	OS_ERROR_NO_ERROR
	, OS_ERROR_TASK_INVALID_STATE
	, OS_ERROR_QUEUE_FULL
	, OS_ERROR_INVALID_TASK
} osErrorType;

extern void osSched();
extern void osInit();
extern unsigned char osCreateTask(void *taskPtr, unsigned char prio);
extern osErrorType osStopTask(unsigned char id);
extern osErrorType osStartTask(unsigned char id);
extern osErrorType osDelayTask(unsigned char id, unsigned int ticks);
extern osErrorType osDestroyTask(unsigned char id);
extern osErrorType osSendMessage(unsigned char type, void * data);
extern osErrorType osWaitMessage(unsigned char id, unsigned char type);
extern void * osReadMessage(unsigned char type);
extern unsigned char osCheckMessage(unsigned char type);

/* macro functions */
#define osDelayCurrentTask(ticks)		osDelayTask(osCurrentTask, ticks)
#define osStopCurrentTask()			osStopTask(osCurrentTask)
#define osDestroyCurrentTask()			osDestroyTask(osCurrentTask)
#define osCurrentWaitMessage(type)		osWaitMessage(osCurrentTask, type)
#define osCurrentTaskID()			osCurrentTask

#define osProfilerEnterOsFunction()
#define osProfilerExitOsFunction()

#define osRand()				osTicksCounter

#endif//__OS_NEW_THUNDER_HEADER__

⌨️ 快捷键说明

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