The uC/OS kernel can be basically divided into three parts: task scheduling, task synchronization and memory management:
Task scheduling
uC/OSII assigns a different priority to each task to ensure real-time performance. When a task switch occurs, it always switches to the highest priority task that is ready. There are two situations in which task switching occurs.
1. The task waits for resources to be ready or self-delays;
2. Exit interrupts;
Situation 1 can be understood as the task actively giving up the right to use the CPU. Situation 2 can be understood as after the interrupt, some resources may be ready and task switching is required.
It should be noted that the SysTick interrupt is the "heartbeat" of the OS and must be present. This allows the CPU to periodically switch tasks. Since uC/OSII does not support time slice round-robin scheduling, the only work that must be done in this interrupt is OS time management. That is, calling OSTimeTick()
Task synchronization
Task synchronization is similar to the practices of most operating systems. If you have studied operating systems or have multi-threaded programming experience, it should be easy to understand. It is nothing more than that task A gives up the right to use the CPU because a certain resource is not ready, and waits for task B or interrupt to make the resource ready. When the task is switched again, if task A has the highest priority, task A continues to execute. For specific implementation, please refer to the book recommended above.
Memory management
ucosii's memory management should have been mentioned before.
Ucosii code composition
os_core.c is the core of ucosii, which includes kernel initialization, task switching, event block management, etc., among which the event block is the basis of each synchronization quantity (here I call mutex, semaphore, mailbox, queue as synchronization quantity, which is not very scientific, but for convenience. The event flag group is not based on the event block, but the principle is similar).
os_task.c
os_flag.c
os_mbox.c
os_mutex.c
os_q.c
os_sem.c
os_mem.c
os_time.c
os_tmr.c
Timer management code, this part of the code is only available from version V2.81. Mr. Shao's book talks about the code of version V2.55, which does not have this part. If you understand the previous code, this part of the code is not difficult to understand. A timer is generally composed of 3 parts: timing time, callback function and attributes. When the timing time is reached, the callback function is processed once. The timer attribute indicates whether the timer is periodic timing or only one-time timing. If the user enables OS_TMR_EN, ucosii will create a timer task internally to handle each timer. This task should generally be activated by calling OSTmrSignal() in the interrupt function of the hardware timer. So in essence, the timer in os_tmr.c is differentiated from a hardware timer.
By default, the timer task is activated by OSTimeTickHook() in the SysTick interrupt.
Transplantation related files
os_cpu.h:
os_cpu_c.c:
os_cpu_a.asm:
os_dbg.c:
introduction of ucosii kernel ends here.
2.
after decompressing the stm32f10x_stdperiph_lib.zip library file downloaded from the ST official website, there are six files, as shown below: Libraries contains the source code of the library, Project contains examples of using various stm32 peripherals and a project template, Utilitiess is an example of using the st company evaluation board, _htmresc are two icons stm32f10x_stdperiph_lib_um.chm teaches us how to use the standard peripheral library. We are mainly concerned about the Libraries and Project folders, from which we will copy the required information later. 1) Establish the project folder structure: It should be a large project to use a 32-bit microcontroller, so the project directory should also be planned. Here is a recommended directory structure. Ø Suppose a folder named stm32-ucosII-demo is created, and there are 6 folders App, Bsp, Libraries, OS-uCOSII, Project, and Readme under this directory. App is used to store application files, Bsp is used to store version-level driver files, Libraries is used to store STM32 standard peripheral library files, OS-uCOSII is used to store uCOS files, Project is used to store project files, and Readme is used to store the self-description or description files of this project in TXT format. Ø Create two subfolders Output and List under Project. Ø Create two subfolders core and port under OS-uCOSII. 2) Organize the library code: Since many codes in the CMSIS folder under Libraries are related to the compiler and chip, there are many folders and the depth is large, which is not conducive to project maintenance. In fact, a project often uses a fixed compiler and chip, so it is necessary to organize the library. a) Copy the STM32F10x_StdPeriph_Lib_V3.5.0Libraries folder under the newly unzipped STM32F10x_StdPeriph_Driver to the new folder Stm32-ucosII-demoLibraries. b)
core_cm3.c, core_cm3.h under STM32F10x_StdPeriph_Lib_V3.5.0LibrariesCMSISCM3CoreSupport and
stm3210x.h, system_stm32f10x.c, system_stm32f100x.h under STM32F10x_StdPeriph_Lib_V3.5.0LibrariesCMSISCM3DeviceSupportSTSTM32F10x to the new LibrariesCM3 folder, and remove the read-only attribute of these three files.
c)
d)
e)
Previous article:Transplantation of ucosII to STM32F103ZE (Part 3)
Next article:Porting ucosII to STM32F103ZE (Part 1)
Recommended ReadingLatest update time:2024-11-16 15:37
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