12月份的主要工作是研究一下操作系统。uCossii比较简单,可以先从它下手。由于没有相应的嵌入式平台,就只好在电脑上模拟了。在电脑上porting的工作已经有人做了,拿过来直接用了。项目的位置如下:
http://www.it.fht-esslingen.de/~zimmerma/software/uCOS-II_WIN32.htm#Internals
因为在电脑上安装了cygwin,所以我的工作都是在cygwin下进行的,全部的src code可以从以下地址下载。
svn checkout http://desktopcalendar.googlecode.com/svn/trunk/ desktopcalendar-read-only
这里主要讲下uCosii信号量集的使用中的一个注意事项。以下是我修改的程序:
/* ********************************************************************************************************* * uC/OS-II * The Real-Time Kernel * * (c) Copyright 2004-... [email protected] * (Similar to Example 1 of the 80x86 Real Mode port by Jean J. Labrosse) * All Rights Reserved * * Application Template ********************************************************************************************************* */ #include "includes.h" /* ********************************************************************************************************* * CONSTANTS ********************************************************************************************************* */ #define TASK_STK_SIZE 512 /* Size of start task's stacks */ #define TASK_START_PRIO 0 /* Priority of your startup task */ #define TASK_IOMONITOR_PRIO 10 /* Priority of your startup task */ /* ********************************************************************************************************* * VARIABLES ********************************************************************************************************* */ OS_STK TaskStartStk[TASK_STK_SIZE]; /* Start task's stack */ OS_STK TaskIOMonitorStk[TASK_STK_SIZE]; /* Start task's stack */ OS_FLAG_GRP* flag_grp; OS_FLAGS flag; INT8U err; /* ********************************************************************************************************* * FUNCTION PROTOTYPES ********************************************************************************************************* */ void TaskStart(void *data); /* Function prototypes of Startup task */ void Thread_IOMonitor(void *data); /* Function prototypes of Startup task */ /* ********************************************************************************************************* * MAIN ********************************************************************************************************* */ int main (void) { #ifdef __WIN32__ printf("##### uCOS-II V%4.2f Port V%4.2f for WIN32 #####\n", ((FP32)OSVersion())/100, ((FP32)OSPortVersion())/100); printf("##### (C) by Werner.Zimmermann@hs-esslingen - Startup task\n"); #endif #ifdef __LINUX__ printf("##### uCOS-II V%4.2f Port V%4.2f for LINUX #####\n", ((FP32)OSVersion())/100, ((FP32)OSPortVersion())/100); printf("##### (C) by Werner.Zimmermann@hs-esslingen - Startup task\n"); #endif OSInit(); /* Initialize uC/OS-II */ /* ToDo: Create semaphores, mailboxes etc. here */ OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], TASK_START_PRIO); /* Create the startup task*/ OSTaskCreate(Thread_IOMonitor, (void *)0, &TaskIOMonitorStk[TASK_STK_SIZE - 1], TASK_IOMONITOR_PRIO); /* Create the startup task*/ OSStart(); /* Start multitasking */ return 0; } /* ********************************************************************************************************* * STARTUP TASK ********************************************************************************************************* */ void TaskStart (void *pdata) { INT16S key; pdata = pdata; /* Prevent compiler warning */ #if OS_TASK_STAT_EN > 0 OSStatInit(); /* Initialize uC/OS-II's statistics */ #endif /* Create all other application tasks here */ flag_grp = OSFlagCreate(0x00,&err); //OS_FlagInit(); //用户不可以调用,只在uCosii内部使用;此句导致工作不正常; while (1) /* Startup task's infinite loop */ { /* ToDo: Place additional code for your startup task, which you want to run once or periodically here */ printf("Now running for %6u ticks - press ESC to stop\n", OSTime); if (PC_GetKey(&key) == TRUE) /* See if key has been pressed */ { if (key == 0x1B) /* Yes, see if it's the ESCAPE key */ { exit(0); /* End program */ } } /* ToDo: Don't forget to call the uCOS scheduler with OSTimeDly etc., to give other tasks a chance to run */ OSTimeDly(100); /* Wait 100 ticks */ if(OSTime > 500) { OSFlagPost(flag_grp,0x01,OS_FLAG_SET,&err); //printf("OS Flag set in functioin:%s\n",__FUNCTION__); } } } /* ********************************************************************************************************* * STARTUP TASK ********************************************************************************************************* */ void Thread_IOMonitor (void *pdata) { INT16S key; pdata = pdata; /* Prevent compiler warning */ #if OS_TASK_STAT_EN > 0 OSStatInit(); /* Initialize uC/OS-II's statistics */ #endif /* Create all other application tasks here */ while (1) /* Startup task's infinite loop */ { //printf("Thread_IOMonitor \n"); /* ToDo: Place additional code for your startup task, which you want to run once or periodically here */ if(OSFlagPend(flag_grp,0x01,OS_FLAG_WAIT_SET_ALL,10,&err)) { printf("How long it will exec %6u ticks \n", OSTime); } /* ToDo: Don't forget to call the uCOS scheduler with OSTimeDly etc., to give other tasks a chance to run */ OSTimeDly(100); /* Wait 100 ticks */ } }程序的主要工作是开始两个任务,其中一个任务的执行打印工作需要等待另外一个任务的信号量。刚开始怎么也不工作。后来查看到一个函数有用法有误,没有仔细看文档及函数说明,想当然了。mark后工作正常;