ucosii_win -- 在windows环境的建立
此是在别人已经做好的环境上修改的,其目的在与为了能在此环境上调试的代码顺利移植到ARM单板
编者--张永辉 2012年11月14日
----------------------------------------------------------------------------------------------------
1 网络下载源文件AN-1032-V2.86.zip 解压到D:\uc 有如下目录
D:\UC\MICRIUM
├─AppNotes
│ └─AN1xxx-RTOS
│ └─AN1032-uCOS-II-Windows XP
└─Software
├─EvalBoards
│ └─Microsoft
│ └─Windows
│ └─Visual Studio 2008
│ └─Ex1-OS
│ └─Debug
├─uC-CPU
│ └─Win32
│ └─Microsoft
└─uCOS-II
├─Doc
├─Ports
│ └─WIN32
└─Source
2 使用VS2008编译
打开 D:\uc\Micrium\Software\EvalBoards\Microsoft\Windows\Visual Studio 2008\Ex1-OS\Ex1_OS.sln
按下F5编译 即能编译通过。
3 修改配置为最小配置
打开 os_cfg.h 按如下配置:
/********************************************************************************************************
* uC/OS-II
********************************************************************************************************/
#ifndef OS_CFG_H
#define OS_CFG_H
/* ---------------------- MISCELLANEOUS ----------------------- */
#define OS_APP_HOOKS_EN 0 /* Application-defined hooks are called from the uC/OS-II hooks */
#define OS_ARG_CHK_EN 0 /* Enable (1) or Disable (0) argument checking */
#define OS_CPU_HOOKS_EN 1 /* uC/OS-II hooks are found in the processor port files */
#define OS_DEBUG_EN 1 /* Enable(1) debug variables */
#define OS_EVENT_MULTI_EN 0 /* Include code for OSEventPendMulti() */
#define OS_EVENT_NAME_SIZE 32 /* Determine the size of the name of a Sem, Mutex, Mbox or Q */
#define OS_LOWEST_PRIO 63 /* Defines the lowest priority that can be assigned ... */
/* ... MUST NEVER be higher than 254! */
#define OS_MAX_EVENTS 50 /*若用了邮箱\消息队列\信号量,则OS_MAX_EVENTS最小=2,此是总数 */
#define OS_MAX_FLAGS 5 /* Max. number of Event Flag Groups in your application */
#define OS_MAX_MEM_PART 5 /*最大内存块数 若使用最少=2, OS_MEM_EN也要同时置1*/
#define OS_MAX_QS 4 /*最大消息队列数 若使用消息队列最小=2,OS_Q_EN也要同时置1*/
#define OS_MAX_TASKS 10 /*最大任务数,最少=2。 设置太大会浪费内存。 (8位中最大62) */
#define OS_SCHED_LOCK_EN 1 /* Include code for OSSchedLock() and OSSchedUnlock() */
#define OS_TICK_STEP_EN 1 /* Enable tick stepping feature for uC/OS-View */
#define OS_TICKS_PER_SEC 500 /* number of ticks in one second 标识调用OSTimeTick()函数的频率 */
/* --------------------- TASK STACK SIZE ---------------------- */
#define OS_TASK_TMR_STK_SIZE 128 /* Timer task stack size (# of OS_STK wide entries) */
#define OS_TASK_STAT_STK_SIZE 128 /* Statistics task stack size (# of OS_STK wide entries) */
#define OS_TASK_IDLE_STK_SIZE 128 /* Idle 其堆栈用得少,单要防止中断嵌套会用的多些 */
/* --------------------- TASK MANAGEMENT ---------------------- */
#define OS_TASK_CHANGE_PRIO_EN 0 /* Include code for OSTaskChangePrio() */
#define OS_TASK_CREATE_EN 1 /* Include code for OSTaskCreate() */
#define OS_TASK_CREATE_EXT_EN 0 /* OSTaskCreateExt() 如果要使用堆栈检查函数OSTaskStkChk() */
#define OS_TASK_DEL_EN 1 /* Include code for OSTaskDel() */
#define OS_TASK_NAME_SIZE 32 /* Determine the size of a task name */
#define OS_TASK_PROFILE_EN 1 /* Include variables in OS_TCB for profiling */
#define OS_TASK_QUERY_EN 1 /* Include code for OSTaskQuery() */
#define OS_TASK_STAT_EN 0 /* Enable (1) or Disable(0) the statistics task 统计任务使能 */
#define OS_TASK_STAT_STK_CHK_EN 0 /* Check task stacks from statistic task */
#define OS_TASK_SUSPEND_EN 1 /* Include code for OSTaskSuspend() and OSTaskResume() */
#define OS_TASK_SW_HOOK_EN 1 /* Include code for OSTaskSwHook() */
/* ----------------------- EVENT FLAGS ------------------------ */
#define OS_FLAG_EN 0 /* Enable (1) or Disable (0) code generation for EVENT FLAGS */
#define OS_FLAG_ACCEPT_EN 1 /* Include code for OSFlagAccept() */
#define OS_FLAG_DEL_EN 1 /* Include code for OSFlagDel() */
#define OS_FLAG_NAME_SIZE 32 /* Determine the size of the name of an event flag group */
#define OS_FLAG_QUERY_EN 1 /* Include code for OSFlagQuery() */
#define OS_FLAG_WAIT_CLR_EN 1 /* Include code for Wait on Clear EVENT FLAGS */
#define OS_FLAGS_NBITS 16 /* Size in #bits of OS_FLAGS data type (8, 16 or 32) */
/* -------------------- MESSAGE MAILBOXES --------------------- */
#define OS_MBOX_EN 0 /* Enable (1) or Disable (0) code generation for MAILBOXES */
#define OS_MBOX_ACCEPT_EN 1 /* Include code for OSMboxAccept() */
#define OS_MBOX_DEL_EN 1 /* Include code for OSMboxDel() */
#define OS_MBOX_PEND_ABORT_EN 1 /* Include code for OSMboxPendAbort() */
#define OS_MBOX_POST_EN 1 /* Include code for OSMboxPost() */
#define OS_MBOX_POST_OPT_EN 1 /* Include code for OSMboxPostOpt() */
#define OS_MBOX_QUERY_EN 1 /* Include code for OSMboxQuery() */
/* --------------------- MEMORY MANAGEMENT -------------------- */
#define OS_MEM_EN 0 /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_NAME_SIZE 32 /* Determine the size of a memory partition name */
#define OS_MEM_QUERY_EN 0 /* Include code for OSMemQuery() */
/* ---------------- MUTUAL EXCLUSION SEMAPHORES --------------- */
#define OS_MUTEX_EN 0 /* Enable (1) or Disable (0) code generation for MUTEX */
#define OS_MUTEX_ACCEPT_EN 1 /* Include code for OSMutexAccept() */
#define OS_MUTEX_DEL_EN 1 /* Include code for OSMutexDel() */
#define OS_MUTEX_QUERY_EN 1 /* Include code for OSMutexQuery() */
/* ---------------------- MESSAGE QUEUES ---------------------- */
#define OS_Q_EN 0 /* Enable (1) or Disable (0) code generation for QUEUES */
#define OS_Q_ACCEPT_EN 1 /* Include code for OSQAccept() */
#define OS_Q_DEL_EN 1 /* Include code for OSQDel() */
#define OS_Q_FLUSH_EN 1 /* Include code for OSQFlush() */
#define OS_Q_PEND_ABORT_EN 1 /* Include code for OSQPendAbort() */
#define OS_Q_POST_EN 1 /* Include code for OSQPost() */
#define OS_Q_POST_FRONT_EN 1 /* Include code for OSQPostFront() */
#define OS_Q_POST_OPT_EN 1 /* Include code for OSQPostOpt() */
#define OS_Q_QUERY_EN 0 /* Include code for OSQQuery() */
/* ------------------------ SEMAPHORES ------------------------ */
#define OS_SEM_EN 0 /* Enable (1) or Disable (0) code generation for SEMAPHORES */
#define OS_SEM_ACCEPT_EN 1 /* Include code for OSSemAccept() */
#define OS_SEM_DEL_EN 1 /* Include code for OSSemDel() */
#define OS_SEM_PEND_ABORT_EN 1 /* Include code for OSSemPendAbort() */
#define OS_SEM_QUERY_EN 1 /* Include code for OSSemQuery() */
#define OS_SEM_SET_EN 1 /* Include code for OSSemSet() */
/* --------------------- TIME MANAGEMENT ---------------------- */
#define OS_TIME_DLY_HMSM_EN 1 /* Include code for OSTimeDlyHMSM() */
#define OS_TIME_DLY_RESUME_EN 0 /* Include code for OSTimeDlyResume() */
#define OS_TIME_GET_SET_EN 1 /* Include code for OSTimeGet() and OSTimeSet() */
#define OS_TIME_TICK_HOOK_EN 1 /* Include code for OSTimeTickHook() */
/* --------------------- TIMER MANAGEMENT --------------------- */
#define OS_TMR_EN 0 /* Enable (1) or Disable (0) code generation for TIMERS */
#define OS_TMR_CFG_MAX 16 /* Maximum number of timers */
#define OS_TMR_CFG_NAME_SIZE 16 /* Determine the size of a timer name */
#define OS_TMR_CFG_WHEEL_SIZE 8 /* Size of timer wheel (#Spokes) */
#define OS_TMR_CFG_TICKS_PER_SEC 10 /* Rate at which timer management task runs (Hz) */
#endif
4 创建最简单的任务 在App.c
/********************************************************************************************************
* INCLUDE FILES
********************************************************************************************************/
#include <includes.h>
OS_STK AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE];
static void App_TaskStart (void);
/********************************************************************************************************
* INCLUDE FILES
********************************************************************************************************/
int main (void)
{
INT8U err;
OSInit();
OSTaskCreate((void (*)(void *)) App_TaskStart,
(void * ) 0,
(OS_STK * )&AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE-1],
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
#if (OS_TASK_NAME_SIZE >= 5) //Give a name to tasks
OSTaskNameSet(OS_TASK_IDLE_PRIO,"Idle",&err); //默认的Idle任务
#endif
OSStart(); // Start OS
}
/********************************************************************************************************
* App_TaskStart()
********************************************************************************************************/
void App_TaskStart (void)
{
#if OS_TASK_STAT_EN > 0
OSStatInit(); // Determine CPU capacity
#endif
while (1)
{
printf("Delay 1 second and print\n");
OSTimeDlyHMSM(0, 0, 1, 0);
}
}
5 编译并运行任务
注意观察任务的堆栈情况。内存使用情况。