Most of the work of porting uC/OS-II is concentrated on the porting of the os_cpu_a.s file. The implementation of this file focuses on the architecture of the processor to be ported and the porting principle of uC/OS-II. In this file, the most difficult work is concentrated on the implementation of the two functions OSIntCtxSw and OSTickISR. This is because the implementation of these two functions is related to the porter's porting ideas and the settings of related hardware timers and interrupt registers. In actual porting work, these two places are also prone to errors.
The most important function of OSIntCtxSw is that it completes the task switching directly in the interrupt ISR, thereby improving the speed of real-time response. It happens when the ISR executes to OSIntExit. If a high-priority task is found to have obtained the execution condition because of the waiting time tick, it can be scheduled for execution immediately without returning to the interrupted task and then switching tasks, because that would not be real-time enough.
There are two ways to implement OSIntCtxSw: one is to adjust the sp stack pointer. According to the compiler's processing of function nesting, the sp position that needs to be adjusted is accurately calculated so that the work of saving the scene when entering the interrupt can be reused. The advantage of this method is that the task switch occurs directly inside the function nesting, so that the high-priority task can be scheduled and executed as quickly as possible. However, this method needs to be related to the specific compiler and the setting of the compilation parameters, and requires more skills. The other is to set the flag bit that needs to be switched. No switching occurs in OSIntCtxSw, but a flag that needs to be switched is set. After the function nesting exits from entering OsIntExit => OS_ENTER_CRITICAL() => OSIntCtxSw()=>OS_EXIT_CRITICAL() => OSIntExit, the flag bit is used to determine whether an interrupt-level task switch is required. The advantage of this method is that there is no need to consider compiler factors. There is no need to do calculations, but it is not the fastest in terms of real-time response. However, it is easier to understand and implement this method when you first learn it.
When switching tasks in the interrupt state, one issue that needs special explanation is how to obtain the lr_svc of the interrupted task. Because after entering the interrupt state, lr becomes lr_irq, and the lr_svc of the original task cannot be obtained in the interrupt state. In order to obtain l_svc, a CPU mode forced conversion must be performed in the interrupt ISR, that is, the CPSR is assigned to 0x000000d3. Only after returning to the SVC state can the lr of the original task be obtained. This is very important for task switching. Another issue that needs attention is that after forcing the CPSR to the SVC state, the SPSR will also become SPSR_irq accordingly. In this way, it is necessary to save the SPSR before the forced conversion, that is, the CPSR before the interrupt task is interrupted.
Previous article:ARM Linux Interrupt Analysis
Next article:High-efficiency embedded ARM program development
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Keep up with the latest news in 2018: fast charging and wireless charging, Bluetooth and smart home and GaN
- Application of LOTO oscilloscope with VI curve tester in circuit board maintenance
- Please help provide the entire PCB board production process and the SMD component mounting process animation. Thank you
- Summary of DSP's real clock system--Explained with TI's DSP TMS320F2812 as an example
- E840-DTU device unresponsive problem
- Is it better to first increase the voltage to 5V and then decrease it to 3.3V when using a 3.7V lithium battery? Or is it better to first decrease it to 3.3V and then increase it to 5V?
- Download the Pomona Connectors catalogue and win a Xiaomi Mosquito Repellent!
- Are smaller components better?
- Anyone have any ADS simulation tutorials to share?
- The Xiaomi IoT module wifi version only costs 9.99 yuan. What would you most like to use it for?