Application of uCOS II Embedded System on C8051F060

Publisher:SereneDreamerLatest update time:2011-02-28 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
With the rapid development of integrated circuits and the continuous improvement of CMOS process level, system-on-chip SOC has begun to become the mainstream of design. The C8051F060 microcontroller is designed and manufactured by Cygnal Corporation of the United States. It is a fully integrated mixed-signal system-on-chip SOC with a microcontroller that has the same core and instruction set as the MCS51. In traditional microcontroller development work, programs often run away or fall into an infinite loop, especially when complex calculations are involved, which only takes a lot of time to analyze slowly. If the uCOS II real-time operating system is embedded in the system, it will make debugging programs simple and greatly enhance the stability and reliability of the system.

1 Application of uCOS II system on C8051F060
To apply uCOS II system, the first thing to do is to transplant the system on C8051F060; secondly, develop on a system that runs stably and normally. In addition, a C compiler for C8051F060 is required as the system working environment. The author uses Keil uVision3 V8.09 from Keil Software Company, which supports mixed programming of C and assembly.

1.1 Porting uCOS II system on C8051F060
The main work of the porting is to use C8051F060 as the processor. Modify several files related to C8051F060
(1) Modify the INCLUDES.H file
For C8051F060, the header files added by the author in INCLUDES.H are placed at the end of the header file list:
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
(2) Modify the OS CPU.H file
To ensure that the C8051F060 system runs normally in the KEIL environment, a series of data structures, macros and constants related to C8051F060 and KEIL compiler are redefined in OS_CPU.H.

  1. In the redefined data structure, it is important to note that
    the stack in the C8051F060 microcontroller is operated on a byte basis, and the stack data type OS_STK is declared as 8 bits:
    typedef unsigned char OS_STK; /*Define the stack width as 8 bits*/
    typedef unsigned char OS_CPU_SR;
  2. In the C8051F060 microcontroller, the stack grows from low address to high address, so OS_STK_GROWTH = 0
  3. The setting of the critical section macro is implemented by using the interrupt enable and interrupt disable instructions of the C8051F060 microcontroller:
    #define OS_ENTER_CRITICAL() EA=0
    #define OS_EXIT CRITICAL() EA=1
  4. OS_TASK_SW() Function definition: #define Os_TASK_SW() OSCtxSw()

(3) Modify the OS_CPU_A.ASM file
The user needs to write the code for four functions: OSSTartHihgRdv(), OSCtxSw(), OSIntCtxSw(), and OSTickISR(). In addition, since C8051F060 lacks internal RAM, it is necessary to use the external program storage space as the task stack image. The function code implementation method is as follows:
① Write the OSSTartHihgRdy() function
Get the lowest address of the stack image of the ready task to be resumed, calculate the stack length, and then copy the data, stack pointer SP and stack image pointer ?C_XBP to the system stack, and finally use the interrupt to return.
② Write the OSCtxSw() function
First, get the current task stack length and stack image pointer from the TCB control block of the current task, then copy the contents of the system stack to the task stack image, and finally get the TCB of the ready task to be resumed. The program jumps to the entry of the OSSTartHihgRdy() function to implement task switching.
③ Write the OSIntCtxSw() function
Most of the OSIntCtxSw() function code is the same as OSCtxSw(), except that:

  1. There is no need to save the C8051F060 registers here;
  2. The stack pointer (SP=SP-4) needs to be adjusted to remove the redundant content pushed into the stack when calling OSIntExit() and OSIntCtxSw(), so that the stack contains only the task's running environment.

④ Write the OSTickISR() function
Use timer 0 as the interrupt source. Initialize timer 0 so that the system interrupts 100 times per second, and the tick rate Tick = 100 times/second.

(4) Modify the OS_CPU_C.C file.
Write the OSTaskStkInit() function to initialize the stack. It should be noted that in the KEIL compilation environment used by the author, task parameters are passed through registers R3, R2, and R1, rather than through the virtual stack. For example:
*stk++=(INT16U)dpdata&0xFF; //R1
*stk++=(INT16U)dpdata>>8; //R2
*stk++=0x03; //R3

1.2 System test
After the uCOS II system is transplanted, it is necessary to check whether the system can run normally. The author referred to the test method of the author of the uCOS II system and conducted a three-step test:

  1. Verify OSTaskStkInit() and OSStartHighRdy() functions;
  2. Verify the OSCtxSw() function;
  3. Verify the OSIntCtxSw() and OSTickISR() functions.

The test results show that the system runs normally on C8051F060.

1.3 Development of uCOS II system with C8051F060 microcontroller as application platform
After the uCOS II system runs stably and normally, it can be used as an application platform for project development.
The C8051F060 microcontroller with rich resources is a relatively new mixed-signal system-on-chip SOC. From its main characteristics, it can be seen that it can greatly simplify the circuit while meeting the requirements of larger peripheral circuit design. The hardware environment used by the author is the C8051F MCU teaching experiment system produced by Xinhualong Company. The system integrates various sensors, RS-485 and RS232 serial communication ports, stepper motor and DC motor controllers, and RJ-45 Ethernet measurement and control interface. The entire system is connected to the PC using a serial adapter.
In the software design, the main function starts with the OSInit() function and ends with the OSStart() function. The middle part is the system initialization function related to the hardware and the function of establishing the task. For the establishment of application tasks, you must follow the format of establishing tasks in the uCOS II system, determine the number of tasks according to your own needs, and set the priority according to the importance of the task and the frequency of being called. After creating the task, list each task function outside the main function. Each task function is an infinite loop program. In the infinite loop, call the application function that implements certain functions, and then set the suspension mode and suspension time according to the design requirements. The interrupt service subroutine is best written in assembly language and placed in the OS_CPU_A.ASM file. The application written in C language is placed in the OS_CPU_C.C file. These functions are called by the main function and tasks.
After the software is designed, it can be connected to the hardware for debugging.

2 Conclusion
The application of uCOS II real-time operating system is becoming more and more widespread. It is an inevitable trend to embed the processor into the operating system for development, which can fully demonstrate its superiority. The author has successfully transplanted the uCOS II system to the C8051F060 microcontroller and successfully applied it to the design of a multi-functional electronic perpetual calendar, making the perpetual calendar system more stable and reliable, and achieving the expected effect.

Reference address:Application of uCOS II Embedded System on C8051F060

Previous article:Software injection technology based on C8051F023 (2)
Next article:A brief discussion on the application of C8051 single chip microcomputer in variable air volume air conditioning control system

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号