一、準備工作
1. 開發環境: Keil C集成開發環境
3. 文件分析:
1)UCOSII文件中與處理器無關的文件:
OS_CORE.C
OS_FLAG.C
OS_MBOX.C
OS_MEM.C
OS_MUTEX.C
OS_Q.C
OS_SEM.C
OS_TASK.C
OS_TIME.C
UCOS_II.C
UCOS_II.H
以上這些文件在c51移植過程中只需給函數加上可重入性即可,即在每個函數后面添加關鍵字:reentrant
2)與應用相關的文件:
INCLUDES.H——其中包含51單片機頭文件和相關應用頭文件
OS_CFG.H——這個文件對于要應用系統中的相關工具,如郵箱,信號等,都要在這個頭文件中把相關宏設置為1
3)與處理器相關的文件:
OS_CPU.H——相關的數據類型、關中斷、任務堆棧方向、任務切換宏定義等
OS_CPU_A.ASM——一堆的匯編和偽指令,我表示沒去深究,但是是整個移植的關鍵所在
OS_CPU_C.C——OSTaskStkInit()函數和系統中斷定時器的編寫。
還有一個重要的思想就是c51堆棧的設計,我對于這個有點頭大,不清楚。
二、開始修改和編寫代碼移植。
我沒有經歷過移植的過程,所以我沒有發言權,我只參考51單片機牛人的代碼,學著應用就行
由于在CSDN上忘記移植者是誰了,我在這將重要文件中的代碼貼出參考參考,只做交流使用。
includes.h
#ifndef __INCLUDES__
#define __INCLUDES__
#include “uCosii\os_cpu.h”
#include “uCosii\os_cfg.h”
#include “uCosii\ucos_ii.h”
#include“reg51.h”
#endif
OS_CFG.H
#ifndef __OS_CFG_H
#define __OS_CFG_H
#define MaxStkSize 64 /*根據修改,每個任務使用同樣大小的堆棧,這就是每個堆棧的大小*/
#define OS_MAX_EVENTS 1 /* Max. number of event control blocks in your application 。.. */
/* 。.. MUST be 》 0 */
#define OS_MAX_FLAGS 1 /* Max. number of Event Flag Groups in your application 。.. */
/* 。.. MUST be 》 0 */
#define OS_MAX_MEM_PART 1 /* Max. number of memory partitions 。.. */
/* 。.. MUST be 》 0 */
#define OS_MAX_QS 1 /* Max. number of queue control blocks in your application 。.. */
/* 。.. MUST be 》 0 */
#define OS_MAX_TASKS 3 /* Max. number of tasks in your application 。.. */
/* 。.. MUST be 》= 2 */
#define OS_LOWEST_PRIO 4 /* Defines the lowest priority that can be assigned 。.. */
/* 。.. MUST NEVER be higher than 63! */
#define OS_TASK_IDLE_STK_SIZE MaxStkSize /* Idle task stack size (# of OS_STK wide entries),使用相同的棧大小*/
#define OS_TASK_STAT_EN 0 /* Enable (1) or Disable(0) the statistics task */
#define OS_TASK_STAT_STK_SIZE MaxStkSize /* Statistics task stack size (# of OS_STK wide entries),使用相同的棧大小*/
#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 */
/* ----------------------- EVENT FLAGS ------------------------ */
#define OS_FLAG_EN 0 /* Enable (1) or Disable (0) code generation for EVENT FLAGS */
#define OS_FLAG_WAIT_CLR_EN 0 /* Include code for Wait on Clear EVENT FLAGS */
#define OS_FLAG_ACCEPT_EN 0 /* Include code for OSFlagAccept() */
#define OS_FLAG_DEL_EN 0 /* Include code for OSFlagDel() */
#define OS_FLAG_QUERY_EN 0 /* Include code for OSFlagQuery() */
/* -------------------- MESSAGE MAILBOXES --------------------- */
#define OS_MBOX_EN 1 /* Enable (1) or Disable (0) code generation for MAILBOXES */
#define OS_MBOX_ACCEPT_EN 0 /* Include code for OSMboxAccept() */
#define OS_MBOX_DEL_EN 0 /* Include code for OSMboxDel() */
#define OS_MBOX_POST_EN 1 /* Include code for OSMboxPost() */
#define OS_MBOX_POST_OPT_EN 0 /* Include code for OSMboxPostOpt() */
#define OS_MBOX_QUERY_EN 0 /* Include code for OSMboxQuery() */
/* --------------------- MEMORY MANAGEMENT -------------------- */
#define OS_MEM_EN 0 /* Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_QUERY_EN 0 /* Include code for OSMemQuery() */
評論