μc/osII is powerful and supports 56 user tasks. Its kernel is preemptive and supports a variety of commonly used inter-process communication mechanisms such as semaphores, mailboxes, and message queues. It has been successfully applied to many commercial embedded systems and is a mature and stable real-time kernel. Unlike most commercial RTOS, μc/osII discloses all source code. 90% of the code is written in the standard ANSI C language, and the program is highly readable and portable. At the same time, it is available for free, and even commercial applications only charge a small license fee. Therefore, it is of great significance to study, research, develop, and apply the μc/osII real-time operating system. The Infineon C164CI-8EM processor is a very excellent 16-bit microcontroller. The CPU system chip integrates the following components: 64KB OTP memory, 2KB on-chip RAM, 16-bit 3/6-channel PWM, 8-channel 10-bit A/D, timer unit, and compare/capture unit. It can achieve seamless connection with commonly used peripheral devices and is powerful. It is currently widely used in the automotive field.
μc/osII real-time operating system structure
Figure 1 illustrates the hardware and software architecture of μc/osII. The application is at the top level of the entire system. Each task can think that it has exclusive CPU, so it can be designed as an infinite loop. μc/osII processor-independent code provides μc/osII system services. Applications can use these API functions for memory management, inter-task communication, and task creation and deletion.
Most of the μc/osII code is written in ANSI C, so μc/osII has good portability. However, some processor-related code still needs to be written in C and assembly language. The porting of μc/osII needs to meet the following requirements:
① The C compiler of the processor can generate reusable code.
② C calls can be used to enter and exit the critical section code.
③ The processor must support hardware interrupts and requires a timer interrupt source.
④ The processor needs a hardware stack that can accommodate a certain amount of data.
⑤ The processor needs instructions that can exchange data between CPU registers and memory and stack.
The Infineon C164CI-8EM processor fully meets the above requirements.
Transplantation of real-time kernel μc/osII on Infineon C164CI-8EM processor
We use KEIL compiler. Transplantation of μc/osII mainly includes the following steps:
(1) Set the processor and compiler related codes in OS_CPU.H Compiler related
data types
typedef unsigned char BOOLEAN; / * Boolean value */
typedef unsigned char INT8U; / * 8-bit unsigned number */
typedef signed char INT8S; / * 8-bit signed number */
typedef unsigned short INT16U; / * 16-bit unsigned number */
typedef signed short INT16S; / * 16-bit signed number */
typedef unsigned long INT32U; / * 32-bit unsigned number */
typedef signed long INT32S; / * 32-bit signed number */
typedef unsigned int OS_STK; / * Stack entry width 16 bits */
Code related to C164 processor
#define OS_EXIT_CRITICAL() (IEN= 1) /* Enable interrupt and exit critical section*/
#define OS_ENTER_CRITICAL() (IEN= 0) /* Enable interrupt and exit critical section*/
#define OS_STK_GROWTH 1 /* The stack grows from high address to low address*/
(2) Write 6 operating system related functions in C language
(OS_CPU_C.C)
OS_STK *OSTaskStkInit (void (*task)
(void *pd), void *pdata, OS_STK *ptos,
INT16Uopt)
{
INT16U*stk;
INT32Uusr;
INT16Upage;
INT16Uoffset;
INT16Udata_pag;
INT16Udata_pof;
opt = opt;
data_pag = (INT16U)_pag(pdata);
data_pof = (INT16U)_pof(pdata);
stk = (INT16U*)ptos;
*stk-- = data_pag;
*stk-- = data_pof; *stk-- = (INT16U) _seg
(task); )- 10) | 0x4000); *stk-- = offset; page = (INT16U)(usr >> 0x000E); *stk-- = page; *stk-- =(INT16U)0x0800; *stk-- = (INT16U) _sof (task); OSTaskBuildStk(page, offset, data_pag, data_pof); return ((OS_STK *)stk); } The last five functions are hook functions, and no code is required: OSTaskCreateHook (OS_TCB *ptcb);
OSTaskDelHook (OS_TCB *ptcb);
OSTaskSwHook (void);
OSTaskStatHook (void);
OSTimeTickHook (void);
(3) Write 4 processor-related functions (O S_ CPU. A SM) in assembly language. Functions called in the multi-task startup function:
OSStartHighRdy(), which is called by the OSStar() function and runs the ready task with the highest priority. Task switching function: OSCtxSw(), which implements task switching at the task level. Interrupt task switching function: OSIntCtxSw(), which implements interrupt-level task switching. Clock tick service function: OSTickISR(), which provides a clock resource to implement time delay and expiration functions.
After completing the above work, μc/osII can run on C164CI.
Test, write drivers and applications
After completing the above work, you need to test whether the transplantation is correct. Testing a μc/osII real-time kernel is not complicated. It is to make this real-time kernel run on your target board. At the beginning, you can run some simple tasks and clock beat interrupt tasks. If the debugging is successful, you can add applications on it.
After the μc/osII transplantation is completed, you need to write interface drivers on this real-time kernel. Because the embedded operating system is smaller in size, more powerful, fast, stable, and more targeted, it does not need to drive, manage, schedule, and monitor all interface devices of the system like other operating systems. Because embedded products are designed for special purposes and have strong specificity. Therefore, when writing drivers, the content is more concise, more stable, and the driver module is smaller.
The following basic functions should be completed when writing drivers;
① Initialize and release the device;
② Transfer data from the kernel to the hardware and read data from the hardware;
③ Read the data sent by the application to the device file and send back the data requested by the application;
④ Detect and handle errors in the device. After realizing the above functions, an embedded operating system is basically formed. After
completing the porting of μc/osII and the writing of the driver
, use the API functions provided by the operating system to write applications and call the system services related to the application in μc/osII. After debugging, solidify it on the target board, and the embedded application software is completed.
Conclusion
This article completes the porting of μc/osII on the C164CI 16-bit microcontroller. After debugging, the system runs stably, which builds a good development platform for the user's application project.
Previous article:Using CPLD to create a microcontroller with a flexible instruction set
Next article:Implementation of TCP/IP protocol stack on MSP430 microcontroller
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
- Radar microwave division table
- Today's Live: Creating an Electrified Future with Sitara AM263x MCUs
- RFID multi-card identification antenna design
- Why is the output impedance of the common emitter amplifier circuit Rc itself?
- [Erha Image Recognition Artificial Intelligence Vision Sensor] 1. Unboxing and Review
- STM32MP157A-DK1 Review
- TouchGFX Design + Make a Rubik's Cube (3)
- Detailed analysis of static in C language
- Using MicroPython on Lego EV3
- 【Showing goods】The third wave