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.
-
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; - In the C8051F060 microcontroller, the stack grows from low address to high address, so OS_STK_GROWTH = 0
-
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 - 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:
- There is no need to save the C8051F060 registers here;
- 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:
- Verify OSTaskStkInit() and OSStartHighRdy() functions;
- Verify the OSCtxSw() function;
- 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.
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Calculate the frequency of the sinusoidal signal collected by msp430
- I recently used a chip that is compatible with both RS232 and RS485, but I don't know which pins are A and B for RS485.
- [ATmega4809 Curiosity Nano Review] Configuring GPIO using MCC
- [Android Development Learning Road] 1-- Android Development Environment Construction
- Today at 10:30 AM Microchip Live | Manufacturing Logistics Challenges of Key Security Provisioning: Advantages of Discrete Secure Components
- Multisim circuit simulation does not oscillate?
- In order to solve network congestion, what black technologies does Wi-Fi 6 use?
- [Atria AT32WB415 Review] 1. Unboxing, installation and use of AT32 IDE development environment (especially error resolution)
- Please ask the experts about STM32, FSMC control LCD problem?
- Made a JLINK OB and shared the production process and experience