📄 arm_00_os_core.bak
字号:
/**********************************************************************************************
本程序只供学习使用,不得用于其它任何用途,否则后果自负。
ARM_00_OS_Core.H file
作者:Computer-lov
建立日期:2006-5-1
修改日期:2006-5-12
版本:V1.0
版权所有,盗版必究。
任何技术问题可到我的博客上留言: http://computer00.21ic.org
Copyright(C) Computer-lov 2006-2016
All rights reserved
**********************************************************************************************/
#ifndef __ARM_00_OS_CORE_H__
#define __ARM_00_OS_CORE_H__
//消息结构体
//用来保存一则消息
typedef struct OSMsg
{
volatile uint32 MsgType; //消息的类型
volatile uint32 Length; //本则消息的长度
struct OSpcb * Sender; //消息的发送者
volatile uint32 * volatile pMsg; //指向消息内容的指针
}OSMsg;
//OSpcb结构体——进程控制块
typedef struct OSpcb
{
struct OSpcb * Prior; //指向前一个pcb
struct OSpcb * Next; //指向后一个pcb
volatile uint32 PID; //程序ID号。用的是申请到的内存块的首地址
volatile uint32 Delay; //延迟时钟节拍数
volatile uint32 Priority; //任务的优先级。该值越小,优先级越高。操作系统保留0号及0xFFFFFFFF号优先级
volatile uint32 TaskSP; //任务切换时,保存堆栈指针使用。
volatile uint32 StackLength; //任务创建时,申请的堆栈长度。单位为字节。
volatile uint32 Status; //任务所处的状态。有OSInRunning、StatusOSInDelayStatus、OSInSuspendingStatus
volatile uint64 TotalRunTime; //该任务总运行时间。时间单位由定时器0计数1的值决定。
volatile uint32 RunTimeInThisRefreshPeriod; //该任务在一个刷新周期内,运行的时间,运行的时间。时间单位由定时器0计数1的值决定。
volatile uint32 WaitFor; //任务等待的资源
struct OSMsg * Msg; //消息指针
volatile uint8 Title[16]; //任务的标题
}OSpcb;
//OSSortPcb结构体。该结构体用来做一些pcb列表的底部,由于底部一些变量是无用的,因此建一个短表,可以节省RAM
//所有成员的意义同OSpcb结构体。
typedef struct OSShortPcb
{
struct OSpcb * Prior;
struct OSpcb * Next;
volatile uint32 PID;
volatile uint32 Delay;
volatile uint32 Priority;
}OSShortPcb;
extern OSpcb * OSReadyList; //就绪态任务表表头
extern OSpcb * OSSuspendList; //挂起态任务表表头
extern OSpcb * OSDelayList; //延时态任务表表头
extern OSpcb * OSCurrentPcb; //当前运行的任务
extern OSpcb OSSystemIdlePcb; //系统空闲任务
#define OSReadyListBottom OSSystemIdlePcb //就绪态列表的底部为系统空闲表
extern OSShortPcb OSSuspendListBottom; //挂起态列表表底
extern OSShortPcb OSDelayListBottom; //延时态列表表底
//设备
typedef struct OSdevice
{
struct OSdevice * Next;
volatile OSpcb * User;
volatile uint32 RequestCount;
volatile uint32 DeviceID;
}OSdevice;
extern OSdevice * OSDeviceList;
void OSInit(void); //操作系统初始化
void OSTickInit(void); //时钟节拍初始化
#define OS_I_Bit 0x00000080 /*IRQ中断控制位*/
#define OS_F_Bit 0x00000040 /*FIQ中断控制位*/
#define OS_ARM_MODE 0x00000000 /*选择任务为ARM代码*/
#define OS_THUMB_MODE 0x00000020 /*选择任务为THUMB代码*/
#define MaxOfTimer0 (163200/100-1) /*定时器0计数的最大值。定时器0由最大开始减小,到0时,发生中断,产生时钟节拍。时钟节拍被设置为100Hz*/
#define RefreshPeriod 200 /*任务管理器的刷新周期。设置为200,表示200个时钟周期刷新一次,即2S刷新一次*/
#define TotalTime ((MaxOfTimer0+1)*RefreshPeriod) /*任务管理器运行一次的总时间数*/
#define OSInReadyStatus 0x00000001 /*就绪状态*/
#define OSInDelayStatus 0x00000002 /*延时状态*/
#define OSInSuspendStatus 0x00000004 /*挂起状态*/
extern volatile uint32 CopyOfIRQEN; //用来备份IRQEN的状态
extern volatile uint32 CopyOfFIQEN; //用来备份FIQEN的状态
extern volatile uint32 OSEnCrCount; //用来统计进入临界代码段次数
extern volatile uint32 TimeOfTaskStart; //用来保存一个任务刚被切换到运行态的时刻
void OSTaskDelay(uint32 NumOfTick); //延任务时NumOfTick个时钟节拍
uint32 OSTaskSuspend(OSpcb * pcb); //将一个任务挂起
#define NO_SUCH_A_TASK 1 /*错误代号:该任务不存在*/
#define CAN_NOT_BE_SUSPENDED 2 /*错误代号:该任务不能被挂起*/
void OSSystemIdle(void); //系统空闲任务
void OSTaskManager(void); //任务管理器
void OSEnterCritical(void); /*进入临界段*/
void OSExitCritical(void); /*退出临界段*/
#define OSSizeOfMemoryPool (7*1024) //缓冲池为7K字节
#define OSSizePerBlock (4*4) //每块大小为16字节
#define MEMORY_INIT 0
#define MEMORY_ALLOCATION 1 /*操作代码0,分配内存*/
#define MEMORY_FREE 2 /*操作代码1,释放内存*/
#define MEMORY_STATISTIC 4 /*操作代码2,统计内存*/
#define GET_MEMORY_POOL_SIZE 8 /*操作代码4,获取内存缓冲池大小*/
#define MEMORY_TEST 16 /*操作代码8,内存检测*/
uint32 OSMemoryManage(uint32 Operation,uint32 StartAddr,uint32 Length); /*内存管理函数*/
#define OSMalloc(Length) OSMemoryManage(MEMORY_ALLOCATION,0,(Length)) /*申请一块长度为Length字节的内存块*/
#define OSFree(StartAddr,Length) OSMemoryManage(MEMORY_FREE,StartAddr,Length) /*释放地址为StartAddr,长度为Length的一块内存*/
#define OSMemoryStatistic() OSMemoryManage(MEMORY_STATISTIC,0,0) /*统计内存使用量*/
#define OSGetMemoryPoolSize() OSMemoryManage(GET_MEMORY_POOL_SIZE,0,0) /*获取内存缓冲池的大小*/
#define OSMemoryTest() OSMemoryManage(MEMORY_TEST,0,0) /*内存检测*/
#define OSMemoryInit() OSMemoryManage(MEMORY_INIT,0,0) /*内存初始化*/
extern volatile uint32 TaskAmount; //用来统计共有多少个任务
uint64 OSTaskCreat(uint32 TaskEntryAddr,uint32 StackLength,uint32 Priority,uint32 Mode,uint8 *TaskName); /*创建一个任务*/
//定义各种消息类型
#define SYSTEM_MSG 1 /*系统消息*/
#define KEYBOARD_MSG 2 /*键盘消息*/
#define UART_MSG 3 /*串口消息*/
uint32 OSSendMsg(OSpcb * pcb,OSMsg * pMsg); //发送消息函数
uint32 OSTaskKill(OSpcb * pcb); //杀死一个任务
#define OSTaskSelfKill() OSTaskKill(OSCurrentPcb) /*任务自杀*/
#define OS_PRINTER_DEVICE_ID 1 /*打印机设备的ID号*/
#define NO_SUCH_A_DEVICE 1 /*设备错误代号*/
uint32 OSAddDevice(uint32 DeviceID); //添加一个设备
uint32 OSDeleteDevice(uint32 DeviceID); //删除指定的任务
uint32 OSGetDeviceAddr(uint32 DeviceID); //根据设备ID号,获取设备结构体的指针地址
uint32 OSRequestDevice(uint32 DeviceAddr,uint32 DelayTicks); //申请设备
void OSFreeDevice(uint32 DeviceAddr); //设备使用完毕,释放设备
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -