开源EMOS-简单嵌入式操作系统

开源EMOS-简单嵌入式操作系统
[**### 开源软件EMOS简介[开源软件EMOS**]http://sourceforge.net/projects/emos/摘要EMOS 是基于 uCOS-ii v2.0 改写的开源嵌入式操作系统采用商业化代码风格提供 MinGW 仿真平台环境支持 32 位和 64 位 Windows 系统。系统包含任务调度、信号量、内存管理、消息队列等核心模块并新增了类似 VxWorks 的 MsgQ 功能。本文详细介绍了 EMOS 的系统架构、核心函数、编译运行方法以及测试验证过程适合嵌入式系统学习者参考使用。开源软件EMOS条款26 开源软件EMOS嵌入式操作系统D.1 EMOS嵌入式操作系统简介EMOS 嵌入式操作系统继承于uCOS-ii v2.0 的改写。基于uCOS-ii 的核心思想和核心代码进行了如下改写1 所有核心代码基于商业代码常用风格进行重写。结合笔者多年嵌入式软件开发经验总结进行重写和归纳。2 提供MinGW仿真平台环境无需基于Borland C或者实物CPU平台进行仿真。uCOS-ii提供了大量平台的移植件这些移植件基于简单的修改即可提供给EMOS使用。MinGW仿真平台移植代码基于uCOS-ii 之Visual C 6.0 仿真平台代码修改获得。3 新增加VxWorks类似MsgQ操作模块从源代码可概览嵌入式系统MsgQ详细工作机理。4 新增加适量的测试Case测试Functions等。5 较大量的源代码细节改动等后续新功能不断更新和升级如tcl debug等。6 请使用UltraEdit/Notepad或者SourceInsight阅读代码并且配置为如下字体才能获取正确清晰的代码风格。EMOS源代码下载地址如下http://sourceforge.net/projects/emos/点击Download EMOS 获取源代码包裹当时最新版本为EMOS 1.0.0; 目前本文档附件部分会升级为最新的EMOS 1.0.1版本。所有源文件简单解释如下README32.txtREADME64.txtMakefilecmnd.batemos_inc.hemos_core.hemos_core.cemos_cfg.hemos_task.cemos_sem.cemos_mem.cemos_mbox.cemos_msgq.cemos_cpu.cemos_cpu.hemos_test.cstart_cmd.batstart_cmdd.bat 说明文件MinGW(32bit)用UltraEdit打开说明文件MinGW64(64bit)用UltraEdit打开Makefile文件建立MinGW编译工具路径bat文件参考笔者《MinGW指南》常用标准数据类型定义头文件核心数据结构定义核心函数声明文件核心功能实现EMOS模块功能选择性配置头文件学习取默认即可EMOS的任务实现文件EMOS的信号量实现文件EMOS的简单memory管理文件EMOS的MBox实现文件EMOS的MsgQ实现文件EMOS的CPU相关实现文件当前提供MinGW的仿真环境EMOS的CPU相关头文件EMOS的主要测试代码以及main()函数入口启动EMOS的案例等笔者的cmd环境给MinGW(32bit)使用主要找到编译环境路径。笔者的cmd环境专为MinGW64(64bit)配置主要用于定位编译环境路径。EMOS嵌入式操作系统MinGW仿真uCOS-ii提供不同CPU的Porting时有四个最核心的函数且代码基于不同CPU的汇编实现如下为这四个函数PUBLIC _OSTickISRPUBLIC _OSStartHighRdyPUBLIC _OSCtxSwPUBLIC _OSIntCtxSw具体的细节可参考uCOS-ii的实现。本章节内容主要讨论基于MinGW仿真时的实现在源代码文件emos_cpu.c中如下为核心porting函数void emosCtxSw(void); /implement in cpu.asm of context switch/ void emosIntCtxSw(void); /implement in cpu.asm of interrupt context switch/ void emosStartHighRdy(void); /implement in cpu.asm of task switch/ void emosTickISR(void); /implement in cpu.asm of tick interrupt/ void* emosTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, uint16 opt);核心思想为 1 EMOS的每个任务绑定于MinGW中每个windows的线程 2 EMOS的任务上下文切换中断和EMOS的Tick中断在仿真中均基于windows中最高优先级线程仿真实现。部分代码可参考如下EMOS任务上下文切换中断基于windows最高优先级线程仿真启动代码EMOS中Tick中断基于windows最高优先级线程仿真启动代码说明基于MinGW的仿真Porting可参考emos_cpu.c具体代码详细实现这里不作详细叙述EMOS嵌入式操作系统组件基础 EMOS的主要基本模块简要介绍如下EMOS核心的任务调度切换等由emos_core.c文件实现核心的模块函数为void emosTimeDly(uint16 ticks); void emosTimeSet(uint32 ticks); void emosTimeTick(void); uint8 emosTimeDlyHMSM(uint8 hours, uint8 minutes, uint8 seconds, uint16 milli); uint8 emosTimeDlyResume(uint8 prio); uint32 emosTimeGet(void);void emosInit(void); void emosInitStart(void); void emosStart(void); void emosStatInit(void); void emosIntEnter(void); void emosIntExit(void); void emosSchedLock(void); void emosSchedUnlock(void); uint16 emosVersion(void); char* emosVersionString(void);/*************************************************************************** I NTERNAL FUNCTION PROTOTYPES (Your application MUST NOT call these functions)***************************************************************************/ uint8 emosTCBInit(uint8 prio, EMOS_STK *ptos, EMOS_STK *pbos, uint16 id, uint16 stk_size, void *pext, uint16 opt); void emosSched(void); void emosTaskIdle(void *data);#if EMOS_MBOX_EN || EMOS_Q_EN || EMOS_SEM_EN void emosEventTaskRdy(EMOS_EVENT_T *pevent, void *msg, uint8 msk); void emosEventTaskWait(EMOS_EVENT_T *pevent); void emosEventTo(EMOS_EVENT_T *pevent); void emosEventWaitListInit(EMOS_EVENT_T *pevent);#endifEMOS的任务操作模块函数有 uint8 emosTaskCreate(void (*task)(void *pd), void *pdata, EMOS_STK *ptos, uint8 prio); uint8 emosTaskQuery(uint8 prio, EMOS_TCB_T *pdata);#if EMOS_TASK_CHANGE_PRIO_EN uint8 emosTaskChangePrio(uint8 oldprio, uint8 newprio);#endif#if EMOS_TASK_CREATE_EXT_EN uint8 emosTaskCreateExt(void (*task)(void *pd),void *pdata,EMOS_STK *ptos,uint8 prio,uint16 id,EMOS_STK *pbos,uint32 stk_size,void *pext,uint16 opt);#endif#if EMOS_TASK_CREATE_EXT_EN uint8 emosTaskStkChk(uint8 prio, EMOS_STK_DATA_T *pdata); /*uint8 emosTaskStkChk (uint8 prio, EMOS_STK_DATA_Tpdata);/#endif#if EMOS_TASK_DEL_EN uint8 emosTaskDel(uint8 prio); uint8 emosTaskDelReq(uint8 prio);#endif#if EMOS_TASK_SUSPEND_EN uint8 emosTaskResume(uint8 prio); uint8 emosTaskSuspend(uint8 prio);#endifEMOS的信号量操作模块函数有 EMOS_EVENT_T* emosSemCreate(uint16 value); uint16 emosSemAccept(EMOS_EVENT_T *pevent); void emosSemPend(EMOS_EVENT_T *pevent, uint16 timeout, uint8 *err); uint8 emosSemPost(EMOS_EVENT_T *pevent); uint8 emosSemQuery(EMOS_EVENT_T *pevent, EMOS_SEM_DATA_T *pdata);EMOS的MBox操作模块函数有 EMOS_EVENT_T* emosMboxCreate(voidmsg); voidemosMboxAccept(EMOS_EVENT_Tpevent); voidemosMboxPend(EMOS_EVENT_T *pevent, uint16 timeout, uint8 *err); uint8 emosMboxPost(EMOS_EVENT_T *pevent, void *msg); uint8 emosMboxQuery(EMOS_EVENT_T *pevent, EMOS_MBOX_DATA_T *pdata);EMOS的MsgQ操作模块函数有 原uCOS-ii实现的MsgQ的改写功能模块 EMOS_EVENT_T* emosQCreate(void *start, uint16 size); voidemosQAccept(EMOS_EVENT_Tpevent); voidemosQPend(EMOS_EVENT_T *pevent, uint16 timeout, uint8 *err); uint8 emosQFlush(EMOS_EVENT_T *pevent); uint8 emosQPost(EMOS_EVENT_T*pevent, void *msg); uint8 emosQPostFront(EMOS_EVENT_T *pevent, void *msg); uint8 emosQQuery(EMOS_EVENT_T *pevent, EMOS_Q_DATA_T *pdata);笔者新增加的类VxWorks之MsgQ实现 struct EMOS_MSGQ_t; typedef struct EMOS_MSGQ_t* EMOS_MSGQ_ID; void emosMsgQInit(); EMOS_MSGQ_ID emosMsgQCreate(uint16 msgNum, uint16 msgLen); EMOS_MSGQ_ID emosMsgQDelete(EMOS_MSGQ_ID ID ); int emosMsgQRecv(EMOS_MSGQ_ID ID, char* buf, uint16 size, int timeout); int emosMsgQSend(EMOS_MSGQ_ID ID, char* buf, uint16 size);D.1 EMOS嵌入式操作系统测试CASE 笔者编写了内核核心调试信息函数emos_core.c文件中void emosDbgShow()输出的格式信息如下红色部分为笔者文档说明内容--------------- EMOS Debug Information by zenf_zhao Jan2008-------------- TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrptaskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0000081 004019d0 004019ee 00000305 EMOS核心的全局重要数据变量信息 RDY TBLAll:8个gEmosRdyTbl的内容可监控所有运行任务的优先级 Rdy[0]01 Rdy[1]00 Rdy[2]00Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTbl TBL All:64个TCB的内存地址信息 004080b0 00408080 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0040805000408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 0040808000408050 004080b0 00409a2b 010 65535 001 01 00 02 01 00408050 0040802000408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 0040805000408248 000 000 062 06 07 40 80 所有活动任务的TCB内存地址信息和链接关系以及各任务的状态信息--------------- Debug Information end --------------其余的测试函数和EMOS启动案例函数在emos_test.c文件中, 笔者运行测试时的某输出结果案例如下D:\core\srcmake gcc -Wall -Werror -I. -g -o emos.o emos_core.cemos_task.c emos_mem.c emos_cpu.c emos_sem. c emos_msgq.c emos_mbox.cemos_test.c -lwinmm -mconsole emos.o emos_msgq.c 526 Initsucessfully,sizeof40Trace:emosTaskTst1404df4Trace:emosTaskTst2404e19 EMOS Test Task B Running--------------- EMOS Debug Information by zenf_zhao Jan2008-------------- TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrptaskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0000081 004019d0 004019ee 00000001 RDY TBL All: Rdy[0]03 Rdy[1]00Rdy[2]00 Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTblTBL All: 004080b0 00408080 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0040805000408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 0040808000408050 004080b0 00409a2b 000 000 001 01 00 02 01 00408050 0040802000408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 0040805000408248 000 000 062 06 07 40 80--------------- Debug Information end --------------emos_test.c 111 MsgQ null EMOS Test Task A Running Task Stat Runningcnt0 max0 cpu%00 Task Stat Running cnt767014 max863000 cpu%12Task Stat Running cnt780170 max868400 cpu%11 EMOS Test Task BRunning--------------- EMOS Debug Information by zenf_zhao Jan2008-------------- TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrptaskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0000081 004019d0 004019ee 00000305 RDY TBL All: Rdy[0]01 Rdy[1]00Rdy[2]00 Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTblTBL All: 004080b0 00408080 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0040805000408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 0040808000408050 004080b0 00409a2b 010 65535 001 01 00 02 01 00408050 0040802000408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 0040805000408248 000 000 062 06 07 40 80--------------- Debug Information end --------------emos_test.c 106 MsgQSendID numMsg1 emos_test.c 82 MsgQRecv ok HelloWorld002 numMsg0 Task Stat Running cnt783010 max871500 cpu%11Task Stat Running cnt778001 max874800 cpu%122021年更新内容 MinGW(32bit)编译和运行过程MinGW(32bit)笔者安装在C盘MinGW下C:\MinGW\emos100make gcc -Wall -I. -g -o emos.o emos_core.cemos_task.c emos_mem.c emos_cpu.c emos_sem.c emos_msgq.c emos_mbox.cemos_test.c -lwinmm -mconsole emos_cpu.c: In function ‘emosCtxSw’:emos_cpu.c:385:11: warning: variable ‘n’ set but not used[-Wunused-but-set-variable]DWORD n 0;^ emos_cpu.c: In function ‘emosIntCtxSw’: emos_cpu.c:404:11: warning: variable ‘n’ set but not used[-Wunused-but-set-variable]DWORD n 0;^ emos.o emos_msgq.c 526 Init sucessfully,sizeof40Trace:emosTaskTst14050deTrace:emosTaskTst2405103---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 00000000 000000 0000000 0040c0d0000081 00401c2f 00401c5b 00000000 RDY TBL All: Rdy[0]03 Rdy[1]00Rdy[2]00 Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTblTBL All: 0040c0d0 0040c0a0 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0040c0700040c040 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY0040c0d0 0040c0a0 00000000 0040db1b 000 000 000 00 00 01 01 0040c0a00040c070 0040c0d0 0040d91b 000 000 001 01 00 02 01 0040c070 0040c0400040c0a0 0040ca68 000 000 061 05 07 20 80 0040c040 00000000 0040c0700040c268 000 000 062 06 07 40 80------------------------------ Debug Information end ------------------------------ Main Entrance Is Running… cnt0 EMOS Test Task B Running emos_test.c 113 MsgQ null---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000001 0040c0a0 000001 0000001 0040c0d0000081 EMOS Test Task A Running 00401c2f 00401c5b 00000002 Task StatRunning cnt0 max0 cpu%00RDY TBL All: Rdy[0]00 Rdy[1]00 Rdy[2]00 Rdy[3]00 Rdy[4]00Rdy[5]00 Rdy[6]00 Rdy[7]40 TcbPrioTbl TBL All: 0040c0d0 0040c0a000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 0040c070 0040c040 Tcb_Addr Tcb_nextTcb_prev stk_Ptr Sta Dly Pri tX tY bX bY 0040c0d0 0040c0a0 000000000040db1b 000 290 000 00 00 01 01 0040c0a0 0040c070 0040c0d0 0040d91b010 65535 001 01 00 02 01 0040c070 0040c040 0040c0a0 0040ca68 000 089061 05 07 20 80 0040c040 00000000 0040c070 0040c268 000 000 062 06 0740 80------------------------------ Debug Information end ------------------------------Task Stat Running cnt380419 max461600 cpu%18 Task Stat Runningcnt416092 max461600 cpu%10 EMOS Test Task B Running emos_test.c 108MsgQSendID numMsg1 emos_test.c 84 MsgQRecv ok Hello World002numMsg0 Task Stat Running cnt414028 max462500 cpu%11 Task StatRunning cnt417007 max462500 cpu%10 EMOS Test Task A Running TaskStat Running cnt416507 max462600 cpu%10 EMOS Test Task B Runningemos_test.c 108 MsgQSendID numMsg1 emos_test.c 84 MsgQRecv ok HelloWorld003 numMsg0 Task Stat Running cnt415617 max462600 cpu%11Task Stat Running cnt416317 max462600 cpu%11 EMOS Test Task ARunning Task Stat Running cnt416581 max464000 cpu%11 EMOS Test TaskB Running emos_test.c 108 MsgQSendID numMsg1 emos_test.c 84 MsgQRecvok Hello World004 numMsg0 Task Stat Running cnt415575 max464000cpu%11 Task Stat Running cnt416255 max465400 cpu%11 EMOS Test TaskA Running Task Stat Running cnt416027 max465400 cpu%11 EMOS TestTask B Running emos_test.c 108 MsgQSendID numMsg1 emos_test.c 84MsgQRecv ok Hello World005 numMsg0 Task Stat Running cnt406374max465400 cpu%13 Task Stat Running cnt246692 max465400 cpu%47EMOS Test Task A Running Task Stat Running cnt241631 max465400cpu%49 EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg1emos_test.c 84 MsgQRecv ok Hello World006 numMsg0 Task StatRunning cnt238255 max465400 cpu%49 Task Stat Running cnt238475max465400 cpu%49 EMOS Test Task A Running Task Stat Runningcnt235845 max465400 cpu%50 EMOS Test Task B Running emos_test.c 108MsgQSendID numMsg1 emos_test.c 84 MsgQRecv ok Hello World007numMsg0 Task Stat Running cnt235164 max465400 cpu%50 Task StatRunning cnt248406 max465400 cpu%47 EMOS Test Task A Running TaskStat Running cnt415252 max465400 cpu%11 Main Returning, Ending …MinGW64(64bit)编译和运行过程MinGW64(64bit)笔者安装在D盘MinGW下D:\MinGW64\emos100make gcc -Wall -I. -g -o emos.o emos_core.cemos_task.c emos_mem.c emos_cpu.c emos_sem.c emos_msgq.c emos_mbox.cemos_test.c -lwinmm -mconsole emos_core.c: In function ‘emosDbgShow’:emos_core.c:1158:18: warning: cast from pointer to integer ofdifferent size [-Wpointer-to-int-cast] printf(“%08x“,(int)gEmosTCBHighRdy);^ emos_core.c:1161:18: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] printf(”%08x“,(int)gEmosTCBList );^ emos_core.c:1163:18: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] printf(”%08x“,(int)emosTaskIdle);^ emos_core.c:1165:18: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] printf(”%08x“,(int)emosTaskStat);^ emos_core.c:1182:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)gEmosTCBPrioTbl[i]);^ emos_core.c:1193:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)p);^ emos_core.c:1194:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)p-osTCBNext);^ emos_core.c:1195:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)p-osTCBPrev);^ emos_core.c:1196:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)p-osTCBStkPtr);^ emos_mem.c: In function ‘emos_mem_view’: emos_mem.c:206:19: warning: cast from pointer to integer of differentsize [-Wpointer-to-int-cast]printf(”%08x “,(int)mem);^ emos_mem.c:207:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)mem-osMemAddr);^ emos_mem.c:208:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)mem-osMemFreeList);^ emos_mem.c: In function ‘emos_mem_test’: emos_mem.c:231:20: warning: cast from pointer to integer of differentsize [-Wpointer-to-int-cast]printf(”%08x “,(int)emosMemTbl[i]);^ emos_mem.c:240:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(”%08x “,(int)emosMemTbl[i]);^ emos_mem.c:251:55: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]printf(“the mem id created error! memid%x\r\n”, (int)memId);^ emos_mem.c:255:53: warning: cast from pointer to integer of differentsize [-Wpointer-to-int-cast]printf(“the mem id created OK! memid%x\r\n”, (int)memId);^ emos_cpu.c: In function ‘emosCtxSw’: emos_cpu.c:385:11: warning: variable ‘n’ set butnot used [-Wunused-but-set-variable]DWORD n 0;^ emos_cpu.c: In function ‘emosIntCtxSw’: emos_cpu.c:404:11: warning: variable ‘n’ set but not used[-Wunused-but-set-variable]DWORD n 0;^ emos_msgq.c: In function ‘emosMsgQInit’: emos_msgq.c:526:46: warning: format ‘%d’ expects argument of type‘int’, but argument 4 has type ‘long long unsigned int’ [-Wformat]EMOS_Print(”%s %d Initsucessfully,sizeof%d\r\n”,FILE,LINE,sizeof(EMOS_MSGQ_T));~^ ~~~~~~~~~~~~~~~~~~~%I64d emos_msgq.c:526:46: warning: format ‘%d’ expects argument of type ‘int’, but argument 4has type ‘long long unsigned int’ [-Wformat] EMOS_Print(“%s %dInitsucessfully,sizeof%d\r\n”,FILE,LINE,sizeof(EMOS_MSGQ_T));~^ ~~~~~~~~~~~~~~~~~~~%I64d In file included from emos_test.c:15: emos_test.c: In function ‘main’:emos_core.h:523:58: warning: cast from pointer to integer of differentsize [-Wpointer-to-int-cast] #define EMOS_DBGSTR_VAL(a)printf(“Trace:“#a”%x\r\n,(int)a)^ emos_test.c:215:3: note: in expansion of macro ‘EMOS_DBGSTR_VAL’EMOS_DBGSTR_VAL(emosTaskTst1); ^~~~~~~~~~~~~~~ emos_core.h:523:58:warning: cast from pointer to integer of different size[-Wpointer-to-int-cast] #define EMOS_DBGSTR_VAL(a)printf(Trace:”#a%x\r\n,(int)a)^ emos_test.c:216:3: note: in expansion of macro ‘EMOS_DBGSTR_VAL’EMOS_DBGSTR_VAL(emosTaskTst2); ^~~~~~~~~~~~~~~ emos.o emos_msgq.c526 Init sucessfully,sizeof56Trace:emosTaskTst1405e80Trace:emosTaskTst2405ea9---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 00000000 000000 0000000 0040c150000081 00401fdf 00402021 00000000 RDY TBL All: Rdy[0]03 Rdy[1]00Rdy[2]00 Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTblTBL All: 0040c150 0040c100 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0040c0b00040c060 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY0040c150 0040c100 00000000 0040e5cb 000 000 000 00 00 01 01 0040c1000040c0b0 0040c150 0040e7cb 000 000 001 01 00 02 01 0040c0b0 0040c0600040c100 0040cbf8 000 000 061 05 07 20 80 0040c060 00000000 0040c0b00040c3f8 000 000 062 06 07 40 80------------------------------ Debug Information end ------------------------------ Main Entrance Is Running… cnt0---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 0040c150 000000 0000000 0040c150000081 00401fdf 00402021 00000002 RDY TBL All: Rdy[0]03 Rdy[1]00Rdy[2]00 Rdy[3]00 Rdy[4]00 Rdy[5]00 Rdy[6]00 Rdy[7]60 TcbPrioTblTBL All: 0040c150 0040c100 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 EMOS Test Task B Runningemos_test.c 113 MsgQ null00000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 EMOS Test Task A Running 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 0040c0b0 0040c060 Tcb_AddrTcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY 0040c150 0040c10000000000 0040e5cb 000 297 000 00 00 01 01 0040c100 0040c0b0 0040c1500040e7cb 010 65535 001 01 00 02 01 0040c0b0 0040c060 0040c100 0040cbf8000 000 061 05 07 20 80 0040c060 00000000 0040c0b0 0040c3f8 000 000062 06 07 40 80------------------------------ Debug Information end ------------------------------Task Stat Running cnt0 max0 cpu%00 Task Stat Running cnt310798max468300 cpu%34 Task Stat Running cnt275681 max468300 cpu%42EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg0emos_test.c 84 MsgQRecv ok Hello World002 numMsg0 Task StatRunning cnt271481 max468300 cpu%43 Task Stat Running cnt277236max468300 cpu%41 EMOS Test Task A Running Task Stat Runningcnt268686 max468300 cpu%43 EMOS Test Task B Running emos_test.c 108MsgQSendID numMsg0 emos_test.c 84 MsgQRecv ok Hello World003numMsg0 Task Stat Running cnt270492 max468300 cpu%43 Task StatRunning cnt273449 max468300 cpu%42 EMOS Test Task A Running TaskStat Running cnt278765 max468300 cpu%41 EMOS Test Task B Runningemos_test.c 108 MsgQSendID numMsg0 emos_test.c 84 MsgQRecv ok HelloWorld004 numMsg0 Task Stat Running cnt267265 max468300 cpu%43Task Stat Running cnt270206 max468300 cpu%43 EMOS Test Task ARunning Task Stat Running cnt264414 max468300 cpu%44 EMOS Test TaskB Running emos_test.c 108 MsgQSendID numMsg0 emos_test.c 84 MsgQRecvok Hello World005 numMsg0 Task Stat Running cnt272259 max468300cpu%42 Task Stat Running cnt270017 max468300 cpu%43 EMOS Test TaskA Running Task Stat Running cnt270783 max468300 cpu%43 EMOS TestTask B Running emos_test.c 108 MsgQSendID numMsg0 emos_test.c 84MsgQRecv ok Hello World006 numMsg0 Task Stat Running cnt399518max522300 cpu%24 Task Stat Running cnt483428 max536900 cpu%10EMOS Test Task A Running Task Stat Running cnt482724 max537600cpu%11 EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg0emos_test.c 84 MsgQRecv ok Hello World007 numMsg0 Task StatRunning cnt482214 max537600 cpu%11 Task Stat Running cnt483381max537600 cpu%11 EMOS Test Task A Running Main Returning, Ending …D:\MinGW64\emos100 敲入任意键结束使用make clean去清楚编译 再敲入make可以重新编译建议仔细阅读Makefile笔者已经默认编译结果为emos.o实际为.exe的编译结果同时能够自动运行。总结EMOS基于uCOS-ii v2.0的商业化代码风格改写并增加了相对适当的新功能当前版本emos-1.0.1提供在MinGW(32bit)和MinGW64(64bit)环境下的仿真测试。EMOS可作为学习嵌入式操作系统工作原理的入门参考利器一个月的时间足可以掌握可为后续深入学习实用和实践中的嵌入式软件开发工作打好坚实基础。