@[**### 开源软件EMOS简介

@[开源软件EMOS**]
http://sourceforge.net/projects/emos/
摘要:EMOS 是基于 uCOS-ii v2.0 改写的开源嵌入式操作系统,采用商业化代码风格,提供 MinGW 仿真平台环境,支持 32 位和 64 位 Windows 系统。系统包含任务调度、信号量、内存管理、消息队列等核心模块,并新增了类似 VxWorks 的 MsgQ 功能。本文详细介绍了 EMOS 的系统架构、核心函数、编译运行方法以及测试验证过程,适合嵌入式系统学习者参考使用。

开源软件EMOS
条款26 开源软件EMOS嵌入式操作系统
注:笔者在2008年在sourceforge中的开源,现(2021)简单修改后最新基于MinGW(32bit)和MinGW64(64bit)都能正常运行。
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阅读代码,并且配置为如下字体才能获取正确清晰的代码风格。
在这里插入图片描述

说明:MinGW的使用请参考笔者撰写的《BBS MinGW的使用指南.pdf》和《BBS MinGW嵌入式软件调试平台.pdf》,从google或者baidu搜索获取。

EMOS源代码可从笔者建立的开源EMOS项目目录获取,下载地址如下:
http://sourceforge.net/projects/emos/

点击Download EMOS 获取源代码包裹,当时最新版本为EMOS 1.0.0; 目前本文档附件部分会升级为最新的EMOS 1.0.1版本。

所有源文件简单解释如下:
README32.txt
README64.txt
Makefile
cmnd.bat
emos_inc.h
emos_core.h
emos_core.c
emos_cfg.h
emos_task.c
emos_sem.c
emos_mem.c
emos_mbox.c
emos_msgq.c
emos_cpu.c
emos_cpu.h
emos_test.c
start_cmd.bat
start_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 _OSTickISR
PUBLIC _OSStartHighRdy
PUBLIC _OSCtxSw
PUBLIC _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);
#endif

EMOS的任务操作模块函数有: 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_T pdata);/
#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);
#endif

EMOS的信号量操作模块函数有: 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(void msg); void emosMboxAccept(EMOS_EVENT_T pevent); void emosMboxPend(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); void emosQAccept(EMOS_EVENT_T pevent); void emosQPend(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 RdyGrp
taskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0
000081 004019d0 004019ee 00000305 (EMOS核心的全局重要数据变量信息) RDY TBL
All:(8个gEmosRdyTbl的内容,可监控所有运行任务的优先级) Rdy[0]=01 Rdy[1]=00 Rdy[2]=00
Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl TBL All:
(64个TCB的内存地址信息) 004080b0 00408080 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00408050
00408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY
004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 00408080
00408050 004080b0 00409a2b 010 65535 001 01 00 02 01 00408050 00408020
00408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 00408050
00408248 000 000 062 06 07 40 80 (所有活动任务的TCB内存地址信息和链接关系,以及各任务的状态信息)
--------------- Debug Information end --------------

其余的测试函数和EMOS启动案例函数在emos_test.c文件中, 笔者运行测试时的某输出结果案例如下:

D:\core\src>make gcc -Wall -Werror -I. -g -o emos.o emos_core.c
emos_task.c emos_mem.c emos_cpu.c emos_sem. c emos_msgq.c emos_mbox.c
emos_test.c -lwinmm -mconsole emos.o emos_msgq.c 526 Init
sucessfully,sizeof=40
==>Trace:emosTaskTst1=404df4
==>Trace:emosTaskTst2=404e19 EMOS Test Task B Running

--------------- EMOS Debug Information by zenf_zhao Jan2008-------------- TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp
taskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0
000081 004019d0 004019ee 00000001 RDY TBL All: Rdy[0]=03 Rdy[1]=00
Rdy[2]=00 Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl
TBL All: 004080b0 00408080 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00408050
00408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY
004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 00408080
00408050 004080b0 00409a2b 000 000 001 01 00 02 01 00408050 00408020
00408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 00408050
00408248 000 000 062 06 07 40 80

--------------- Debug Information end --------------

emos_test.c 111 MsgQ null EMOS Test Task A Running Task Stat Running
cnt=0 max=0 cpu=%00 Task Stat Running cnt=767014 max=863000 cpu=%12
Task Stat Running cnt=780170 max=868400 cpu=%11 EMOS Test Task B
Running

--------------- EMOS Debug Information by zenf_zhao Jan2008-------------- TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp
taskIdle taskStat timeTick 00000000 004080b0 000000 0000000 004080b0
000081 004019d0 004019ee 00000305 RDY TBL All: Rdy[0]=01 Rdy[1]=00
Rdy[2]=00 Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl
TBL All: 004080b0 00408080 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00408050
00408020 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY
004080b0 00408080 00000000 00409c2b 000 000 000 00 00 01 01 00408080
00408050 004080b0 00409a2b 010 65535 001 01 00 02 01 00408050 00408020
00408080 00408a48 000 000 061 05 07 20 80 00408020 00000000 00408050
00408248 000 000 062 06 07 40 80

--------------- Debug Information end --------------

emos_test.c 106 MsgQSendID numMsg=1 emos_test.c 82 MsgQRecv ok = Hello
World=002 numMsg=0 Task Stat Running cnt=783010 max=871500 cpu=%11
Task Stat Running cnt=778001 max=874800 cpu=%12

2021年更新内容: MinGW(32bit)编译和运行过程,MinGW(32bit)笔者安装在C盘MinGW下:
C:\MinGW\emos100>make gcc -Wall -I. -g -o emos.o emos_core.c
emos_task.c emos_mem.c emos_cpu.c emos_sem.c emos_msgq.c emos_mbox.c
emos_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,sizeof=40
==>Trace:emosTaskTst1=4050de
==>Trace:emosTaskTst2=405103

---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 00000000 000000 0000000 0040c0d0
000081 00401c2f 00401c5b 00000000 RDY TBL All: Rdy[0]=03 Rdy[1]=00
Rdy[2]=00 Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl
TBL All: 0040c0d0 0040c0a0 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 0040c070
0040c040 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY
0040c0d0 0040c0a0 00000000 0040db1b 000 000 000 00 00 01 01 0040c0a0
0040c070 0040c0d0 0040d91b 000 000 001 01 00 02 01 0040c070 0040c040
0040c0a0 0040ca68 000 000 061 05 07 20 80 0040c040 00000000 0040c070
0040c268 000 000 062 06 07 40 80
------------------------------ Debug Information end ------------------------------

=========> Main Entrance Is Running… cnt=0 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 0040c0d0
000081 EMOS Test Task A Running 00401c2f 00401c5b 00000002 Task Stat
Running cnt=0 max=0 cpu=%00

RDY TBL All: Rdy[0]=00 Rdy[1]=00 Rdy[2]=00 Rdy[3]=00 Rdy[4]=00
Rdy[5]=00 Rdy[6]=00 Rdy[7]=40 TcbPrioTbl TBL All: 0040c0d0 0040c0a0
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 0040c070 0040c040 Tcb_Addr Tcb_next
Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY 0040c0d0 0040c0a0 00000000
0040db1b 000 290 000 00 00 01 01 0040c0a0 0040c070 0040c0d0 0040d91b
010 65535 001 01 00 02 01 0040c070 0040c040 0040c0a0 0040ca68 000 089
061 05 07 20 80 0040c040 00000000 0040c070 0040c268 000 000 062 06 07
40 80
------------------------------ Debug Information end ------------------------------

Task Stat Running cnt=380419 max=461600 cpu=%18 Task Stat Running
cnt=416092 max=461600 cpu=%10 EMOS Test Task B Running emos_test.c 108
MsgQSendID numMsg=1 emos_test.c 84 MsgQRecv ok = Hello World=002
numMsg=0 Task Stat Running cnt=414028 max=462500 cpu=%11 Task Stat
Running cnt=417007 max=462500 cpu=%10 EMOS Test Task A Running Task
Stat Running cnt=416507 max=462600 cpu=%10 EMOS Test Task B Running
emos_test.c 108 MsgQSendID numMsg=1 emos_test.c 84 MsgQRecv ok = Hello
World=003 numMsg=0 Task Stat Running cnt=415617 max=462600 cpu=%11
Task Stat Running cnt=416317 max=462600 cpu=%11 EMOS Test Task A
Running Task Stat Running cnt=416581 max=464000 cpu=%11 EMOS Test Task
B Running emos_test.c 108 MsgQSendID numMsg=1 emos_test.c 84 MsgQRecv
ok = Hello World=004 numMsg=0 Task Stat Running cnt=415575 max=464000
cpu=%11 Task Stat Running cnt=416255 max=465400 cpu=%11 EMOS Test Task
A Running Task Stat Running cnt=416027 max=465400 cpu=%11 EMOS Test
Task B Running emos_test.c 108 MsgQSendID numMsg=1 emos_test.c 84
MsgQRecv ok = Hello World=005 numMsg=0 Task Stat Running cnt=406374
max=465400 cpu=%13 Task Stat Running cnt=246692 max=465400 cpu=%47
EMOS Test Task A Running Task Stat Running cnt=241631 max=465400
cpu=%49 EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg=1
emos_test.c 84 MsgQRecv ok = Hello World=006 numMsg=0 Task Stat
Running cnt=238255 max=465400 cpu=%49 Task Stat Running cnt=238475
max=465400 cpu=%49 EMOS Test Task A Running Task Stat Running
cnt=235845 max=465400 cpu=%50 EMOS Test Task B Running emos_test.c 108
MsgQSendID numMsg=1 emos_test.c 84 MsgQRecv ok = Hello World=007
numMsg=0 Task Stat Running cnt=235164 max=465400 cpu=%50 Task Stat
Running cnt=248406 max=465400 cpu=%47 EMOS Test Task A Running Task
Stat Running cnt=415252 max=465400 cpu=%11
=========> Main Returning, Ending …

MinGW64(64bit)编译和运行过程,MinGW64(64bit)笔者安装在D盘MinGW下:
D:\MinGW64\emos100>make gcc -Wall -I. -g -o emos.o emos_core.c
emos_task.c emos_mem.c emos_cpu.c emos_sem.c emos_msgq.c emos_mbox.c
emos_test.c -lwinmm -mconsole emos_core.c: In function ‘emosDbgShow’:
emos_core.c:1158:18: warning: cast from pointer to integer of
different 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 different
size [-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 different
size [-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 different
size [-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 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_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 Init
sucessfully,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 4
has type ‘long long unsigned int’ [-Wformat=] EMOS_Print(“%s %d
Init
sucessfully,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 different
size [-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.c
526 Init sucessfully,sizeof=56
==>Trace:emosTaskTst1=405e80
==>Trace:emosTaskTst2=405ea9

---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 00000000 000000 0000000 0040c150
000081 00401fdf 00402021 00000000 RDY TBL All: Rdy[0]=03 Rdy[1]=00
Rdy[2]=00 Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl
TBL All: 0040c150 0040c100 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 0040c0b0
0040c060 Tcb_Addr Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY
0040c150 0040c100 00000000 0040e5cb 000 000 000 00 00 01 01 0040c100
0040c0b0 0040c150 0040e7cb 000 000 001 01 00 02 01 0040c0b0 0040c060
0040c100 0040cbf8 000 000 061 05 07 20 80 0040c060 00000000 0040c0b0
0040c3f8 000 000 062 06 07 40 80
------------------------------ Debug Information end ------------------------------

=========> Main Entrance Is Running… cnt=0

---------------------- EMOS Debug Information by zhfzhao Jan2008 ------------------ TCBCur TCBHRdy PriCur PriHRdy gTCBList RdyGrp taskIdle taskStat timeTick 00000000 0040c150 000000 0000000 0040c150
000081 00401fdf 00402021 00000002 RDY TBL All: Rdy[0]=03 Rdy[1]=00
Rdy[2]=00 Rdy[3]=00 Rdy[4]=00 Rdy[5]=00 Rdy[6]=00 Rdy[7]=60 TcbPrioTbl
TBL All: 0040c150 0040c100 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 EMOS Test Task B Running
emos_test.c 113 MsgQ null

00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 EMOS Test Task A Running 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 0040c0b0 0040c060 Tcb_Addr
Tcb_next Tcb_prev stk_Ptr Sta Dly Pri tX tY bX bY 0040c150 0040c100
00000000 0040e5cb 000 297 000 00 00 01 01 0040c100 0040c0b0 0040c150
0040e7cb 010 65535 001 01 00 02 01 0040c0b0 0040c060 0040c100 0040cbf8
000 000 061 05 07 20 80 0040c060 00000000 0040c0b0 0040c3f8 000 000
062 06 07 40 80
------------------------------ Debug Information end ------------------------------

Task Stat Running cnt=0 max=0 cpu=%00 Task Stat Running cnt=310798
max=468300 cpu=%34 Task Stat Running cnt=275681 max=468300 cpu=%42
EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg=0
emos_test.c 84 MsgQRecv ok = Hello World=002 numMsg=0 Task Stat
Running cnt=271481 max=468300 cpu=%43 Task Stat Running cnt=277236
max=468300 cpu=%41 EMOS Test Task A Running Task Stat Running
cnt=268686 max=468300 cpu=%43 EMOS Test Task B Running emos_test.c 108
MsgQSendID numMsg=0 emos_test.c 84 MsgQRecv ok = Hello World=003
numMsg=0 Task Stat Running cnt=270492 max=468300 cpu=%43 Task Stat
Running cnt=273449 max=468300 cpu=%42 EMOS Test Task A Running Task
Stat Running cnt=278765 max=468300 cpu=%41 EMOS Test Task B Running
emos_test.c 108 MsgQSendID numMsg=0 emos_test.c 84 MsgQRecv ok = Hello
World=004 numMsg=0 Task Stat Running cnt=267265 max=468300 cpu=%43
Task Stat Running cnt=270206 max=468300 cpu=%43 EMOS Test Task A
Running Task Stat Running cnt=264414 max=468300 cpu=%44 EMOS Test Task
B Running emos_test.c 108 MsgQSendID numMsg=0 emos_test.c 84 MsgQRecv
ok = Hello World=005 numMsg=0 Task Stat Running cnt=272259 max=468300
cpu=%42 Task Stat Running cnt=270017 max=468300 cpu=%43 EMOS Test Task
A Running Task Stat Running cnt=270783 max=468300 cpu=%43 EMOS Test
Task B Running emos_test.c 108 MsgQSendID numMsg=0 emos_test.c 84
MsgQRecv ok = Hello World=006 numMsg=0 Task Stat Running cnt=399518
max=522300 cpu=%24 Task Stat Running cnt=483428 max=536900 cpu=%10
EMOS Test Task A Running Task Stat Running cnt=482724 max=537600
cpu=%11 EMOS Test Task B Running emos_test.c 108 MsgQSendID numMsg=0
emos_test.c 84 MsgQRecv ok = Hello World=007 numMsg=0 Task Stat
Running cnt=482214 max=537600 cpu=%11 Task Stat Running cnt=483381
max=537600 cpu=%11 EMOS Test Task A Running
=========> Main Returning, Ending …

D:\MinGW64\emos100> 敲入任意键结束

使用make clean去清楚编译 再敲入make可以重新编译
建议仔细阅读Makefile,笔者已经默认编译结果为emos.o(实际为.exe的编译结果),同时能够自动运行。

#makefile MinGW compile EMOS TOP_DIR = … BCC_DIR = $(TOP_DIR)\bcc. BIN_DIR = $(TOP_DIR)\bin src_core_list =
emos_core.c emos_task.c emos_mem.c emos_cpu.c emos_sem.c emos_msgq.c
emos_mbox.c emos_test.c obj_core_list = emos.o

CP_FLAGS = -Wall -I. -g
#CP_FLAGS = -Wall -Werror -I. -g
#C++FLAGS = -Wno-deprecated -Wall -Werror -I.

CC = gcc RM = del

all: //注释:编译结果在这 $(CC) $(CP_FLAGS) -o emos.o $(src_core_list)
-lwinmm -mconsole

@echo “src core dir” $(SRC_CORE_DIR)

@echo “src core list” $(src_core_list)

@echo “src obj list” $(obj_core_list)

@echo “CP_FLAGS” $(CP_FLAGS) emos.o //注释:自动运行在这 $target_list:

$(CC) $(cp_flags) -c $(src_list) clean: //注释:make clean 在这 $(RM) *.exe *.asm *.o *.obj

总结
EMOS基于uCOS-ii v2.0的商业化代码风格改写,并增加了相对适当的新功能,当前版本emos-1.0.1提供在MinGW(32bit)和MinGW64(64bit)环境下的仿真测试。

EMOS可作为学习嵌入式操作系统工作原理的入门参考利器,一个月的时间足可以掌握,可为后续深入学习实用和实践中的嵌入式软件开发工作打好坚实基础。

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐