一、準(zhǔn)備工作
1. 開發(fā)環(huán)境: Keil C集成開發(fā)環(huán)境
2. 源代碼:UCOSII的源代碼,網(wǎng)上可以自己下載
3. 文件分析:
1)UCOSII文件中與處理器無關(guān)的文件:
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移植過程中只需給函數(shù)加上可重入性即可,即在每個(gè)函數(shù)后面添加關(guān)鍵字:reentrant
2)與應(yīng)用相關(guān)的文件:
INCLUDES.H——其中包含51單片機(jī)頭文件和相關(guān)應(yīng)用頭文件
OS_CFG.H——這個(gè)文件對于要應(yīng)用系統(tǒng)中的相關(guān)工具,如郵箱,信號等,都要在這個(gè)頭文件中把相關(guān)宏設(shè)置為1
3)與處理器相關(guān)的文件:
OS_CPU.H——相關(guān)的數(shù)據(jù)類型、關(guān)中斷、任務(wù)堆棧方向、任務(wù)切換宏定義等
OS_CPU_A.ASM——一堆的匯編和偽指令,我表示沒去深究,但是是整個(gè)移植的關(guān)鍵所在
OS_CPU_C.C——OSTaskStkInit()函數(shù)和系統(tǒng)中斷定時(shí)器的編寫。
還有一個(gè)重要的思想就是c51堆棧的設(shè)計(jì),我對于這個(gè)有點(diǎn)頭大,不清楚。
二、開始修改和編寫代碼移植。
我沒有經(jīng)歷過移植的過程,所以我沒有發(fā)言權(quán),我只參考51單片機(jī)牛人的代碼,學(xué)著應(yīng)用就行
由于在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 /*根據(jù)修改,每個(gè)任務(wù)使用同樣大小的堆棧,這就是每個(gè)堆棧的大小*/
#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() */
評論