RT-Thread Programming Guide points excerpt (seven)

——…——

8 interrupt management

Interrupt handling is closely related to CPU architecture.

8.1 Cortex-M CPU Architecture Foundation

- Temporarily slightly -

8.2 RT-Thread interrupt mechanism

Interrupt processing

RT-Thread interrupt management, the interrupt handler is divided into interrupt leading program, the user interrupt service routine, interrupt the follow-up program of three parts.

Interrupt program leading
main tasks:

  1. Save CPU interrupt field
    for cortex-M, the current context of the processor hardware will automatically register operation portion is pressed into the interrupt stack
  2. Inform the kernel to enter an interrupt state

The user's ISR
divided into two cases:

  1. Thread switching is not required in the interrupt processing

In this case the user interrupts and interrupt service routine follow-up program after exiting the interrupt mode operation, return to the interrupted thread.

  1. In the interrupt processing thread switching is required

This situation calls rt_hw_context_switch_interrupt () function to context switch, the function associated with the CPU architecture, there are differences in implementations of different CPU architectures.

ISR is a need to pay special attention to the operating environment, it is run in a non-threaded execution environment, you can not use current thread suspends operations in this operating environment, because the current thread does not exist.

Interrupt the follow-up program
main tasks:

  1. Inform the kernel interrupt leaving state
  2. CPU before the interrupt context restore

If the thread switching is not performed in the interrupt processing, the CPU context of recovery from the thread, if the thread switch interrupt, then restore the CPU context to thread.

Interrupt stack

Interrupt stack can be saved in break thread's stack, when to exit from the interrupt, return the appropriate thread to continue.
Interrupt stack can be completely separated from the stack to the thread, that is, each interrupt entry, after you finish saving the interrupted thread context switching to a new interrupt stack independently.

RT-Thread mode is used to provide separate interrupt stack .

Using separate interrupt stack is relatively easier to implement, and so it will not interrupt stack space occupied by a thread, thereby improving the utilization of memory space, and with the increase of the thread, which reduce the memory footprint of the more obvious effects.

The bottom half interrupt handling

Users need to ensure that all of the interrupt service routine is completed in the shortest possible time.

When an interrupt occurs, the interrupt service routine needs to obtain the appropriate state or hardware data. For some complex interrupt, in order to improve responsiveness and concurrency capability of the system typically require the Interrupt divided into two, i.e., upper half (Top Half) and bottom half (Bottom Half).

After the upper half, obtaining hardware status and data, open the masked interrupts, sends a notification to the relevant thread (which may be the amount of signal RT-Thread provided, an event, a mailbox or queue, etc.), and then ends the interrupt service program ;
and the next, the associated thread after receiving the notification, then the state of the data or for further processing, this process is called the bottom-half process .

The lower portion is called by the operating system at the right time. As a result greatly reduces the time required for interrupt handling.

8.3 RT-Thread interrupt management interface

RT-Thread interrupt and exception to encapsulate a set of abstract interfaces, so that the abnormal operation of the system and the system underlying hardware interrupt isolate.

Interrupt Service Routine hook : interrupt number associated with the user's system interrupt service routine (handler) and designated them.

Interrupt Source Management : usually ready in ISR (Interrupt Service Routines, the interrupt service routine) before processing an interrupt signal, we need to mask the interrupt source masked before after ISR state or processed data, timely open interrupt sources .

Maskable interrupt source can be guaranteed in the next processing hardware state or the data will not be disturbed.

Global interrupt switch : The main problem with using break a lock that closed during the interrupt system will no longer respond to any interruption, it can not respond to external events, the impact of real-time interrupt lock system is enormous.
Interrupt notification : When the entire system is interrupted interrupted, into the interrupt handler, you need to tell the kernel has entered the current interrupt status.

8.4 interrupt and polling

Polling law concept is: issue a query timed by the CPU, in turn asking whether each peripheral device needs its services, ie to the service, ask the service after the end of a peripheral, and then continue again and again.

It may occur in real-time system polling mode very big problem: When a program sustained implementation of the
(polling), it will always run in thread, than it is a low-priority thread does not get run. )
So usually more real-time system uses the interrupt mode to drive peripherals.

Interrupt disadvantages : the device for high-speed, data less than 100% bandwidth utilization, so that insufficient data throughput overhead consumed in the thread switch.

The smaller the amount of transmission data, the faster the transmission speed, it will affect the data throughput greater. In the final analysis, how to interrupt the frequency depends on the system generated.

Released seven original articles · won praise 0 · Views 71

Guess you like

Origin blog.csdn.net/weixin_45263626/article/details/104615898