Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deep and simple processor (middle) _ interrupt

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Topic 1-Deep and simple processors 2. Processor (middle) _ interrupt 2.1 concept and meaning of interrupt:

A mechanism by which a processor communicates with a peripheral during an interrupt to inform the processor that an "important event" has occurred outside the processor, and generally the interrupt needs to be responded to by the processor.

2.2 interrupt Service Program (ISR)

1. Read the value of the interrupt register from the peripheral to understand the type of interrupt

two。 Design the processing logic according to the interrupt type

3. Clear the interrupt flag bit in the peripheral status register

4. Clean up interrupt identification bits in the processor

The entire processor process is as follows:

Interrupt service programs in the eyes of software engineers:

-No return value, no parameter passing

-must be short and efficient to avoid floating-point operations

Example of error:

_ _ interrupt double compute_area (double radius)

{

Double area = PI radius radius

Printf ("\ narea =% f", area)

Return area

}

2.3 meaning of interrupts:-the meaning of interrupts is that the application does not have to care about the occurrence and handling of interrupts-the interrupt service program does not have to be related to the execution state of the application-interrupts are the dividing line between "upper application" and "underlying code".

2.4 types of interrupts

-hard interrupts: interrupts generated by processor interrupt signal lines

CPU and external devices are independent hardware execution units. CPU manages and schedules all devices. If CPU wants to know the running status of external devices, either CPU regularly checks the specific registers of external devices, or let external devices "interrupt" CPU when they need CPU interference processing, and let it handle external device requests. There is no doubt that the second way is more reasonable. You can let CPU "concentrate" to work, where the "interrupt" operation is called interrupt request, according to the emergency of the request, interrupt request is divided into general interrupt and fast interrupt, fast interrupt has the highest interrupt priority and minimum interrupt delay, usually used to deal with high-speed data transmission and medium data recovery processing of the channel, such as DMA, most peripherals use general interrupt request.

-soft interrupts: interrupts (or exceptions) initiated by illegal or special instructions

The exception is generated when the application is called by itself, and is used when the user program applies to access the hardware resources, such as the printf () print function, to print the user data to the display, the user program must apply to use the display to print, and the user program does not have the right to use the peripheral hardware, so it can only use the software interrupt instruction to switch to the kernel state and access the peripheral hardware through the kernel code of the operating system. The kernel mode works in privileged mode, and the operating system prints user data to the display in privileged mode. The purpose of doing this is nothing more than to protect the security of the operating system and the rational use of hardware resources, and the exception is handled in management mode.

2.5 interrupt priority

When multiple interrupts occur at the same time, the processor will first respond to high-priority interrupts, and the low-priority interrupt ISR can be interrupted by high-priority interrupts.

Think about it: how does CPU make fiq faster than irq? There are two reasons:

First, the fiq mode has a dedicated r8~r12, so you can use r8-r12 directly in the isr of fiq without saving, which saves time

Second, fiq is the last entry of exception vector in the anomaly vector scale. Therefore, the isr of fiq does not need to jump, it can be written directly in place, so it will jump less than other exceptions and save some time.

2.6 interrupted application _ program breakpoint

a. Breakpoints refer to the location of instructions used by the debugging tool to pause code execution,

b. The implementation of breakpoints supports interrupts for processors.

Software breakpoint: using illegal instruction exception to generate interrupt (soft interrupt)

Hardware interrupts: using interrupt registers to specifically generate interrupts

The principle of breakpoint program:

1. Get the code address corresponding to the development line of the source program

two。 Replace the instruction in the code address with the interrupt trigger instruction

3. Give control to the debugger in the interrupt service program

4. The debugger reads the source program context information

5. The debugger restores instructions in the code

6. The source program continues to execute downward from the breakpoint

The above process is exactly the same as the interrupt handling process, which is illustrated as follows:

2.7 Engineering application of interrupt debugging

Background: the real-time requirement of embedded products is very high, each task has strict time requirements, breakpoint debugging is not available, can only rely on print debugging (log debugging), but print debugging, print data distributed in every corner of the product, difficult to analyze and locate, while the print operation is designed to IO operation, will affect product efficiency

Solution: combined with the advantages of log debugging and breakpoint debugging, real-time system debugging can arbitrarily view the context information of the code line; and do not increase the print statement, do not suspend execution.

Final plan:

1. Get the code address corresponding to the original program development line

two。 Replace the instruction in the code address with the interrupt trigger instruction

3. Grab global information and stack information in interrupt service program

4. The message captured will be parsed and output by the debugger.

I would like to thank you for referring to this article from the Ditai course.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report