摘 要:介紹μC/OS-Ⅱ操作系統的特點、內核結構和工作原理,并通過對NXP公司LPC2378及ARM7TDMI-S內核體系結構及內部寄存器工作原理的分析,討論了μC/OS-Ⅱ移植過程中的重難點問題及解決方法,重點闡述移植代碼中堆棧初始化、任務切換、時鐘中斷服務程序的編寫過程,并對調試中出現的程序跑飛和堆棧空間不夠的問題進行了解決和修改,最后通過設計多任務應用程序證明了該移植是成功的。
關鍵詞: μC/OS-Ⅱ; LPC2378; 實時操作系統; 移植
中圖分類號:TP316.2 文獻標識碼:B
文章編號:1004-373X(2010)12-0033-04
Transplant and Application of the Embedded Real-time OS μC/OS-Ⅱ on LPC2378
SUN Ji-ru, GUO Min, ZHANG Yu-xiang, WANG Ming-li
(Physics and Engineering Department, Zhengzhou University, Zhengzhou 450001, China)
Abstract:The characteristics, kernel structure and the operating principle of the real-time embedded operating system μC/OS-Ⅱ are introduced. Besides, the key problem and the resolution appeared in the μC/OS-Ⅱ transplant are discussed through analyzing the ARM7TDMI-S and the kernel of LPC2378 produced by NXP Company. The process of preparing of Stack initialization, task switch and the clock interrupt service routine are expatiated. The problems of running fly and less of stack space during the debugging program are resolved, the success of transplant is proved by designing the multi-task application on the LPC2378.
Keywords: μC/OS-Ⅱ; LPC2378; real-time operating system; transplant
0 引 言
目前,市場以及院校科研用嵌入式系統產品,如Vxworks,Linux和Windows CE等都已經相當成熟,提供了有力的開發和調試工具,但有些開發成本昂貴,周期較長,而μC/OS-Ⅱ是一種多任務實時源代碼的公開操作系統,內核精簡,移植性較強,非常適合用于一些小型控制和實驗系統的開發。
1 操作系統及CPU介紹
μC/OS-Ⅱ是基于優先級的占先式實時多任務操作系統,包含有任務管理、時間管理、任務間同步通信(信號量,郵箱,消息隊列)和內存管理等功能。絕大部分代碼用C語言寫成,極少部分與處理器密切相關的代碼用匯編語言編寫,便于移植。作為一個源代碼公開的實時操作系統,最多可以管理64個任務,并支持信號量、郵箱、消息隊列等多種進程間的通信機制,同時用戶可以根據需求對內核中的功能模塊進行裁剪[1-3] 。
LPC2378是一款基于ARM7TDMI-S內核的嵌入式精簡指令集微控制器,包含了1個支持仿真的ARM7TDMI-S CPU,適用于為了各種目的而需要進行串行通信的應用。該體系機構支持用戶、軟中斷、中斷、管理、中止、未定義、系統等7種處理器模式,ARM7 TDMI-S處理器內部有31個通用32位寄存器,6個狀態寄存器。……