Interruption management of the μC/OS-ⅲ System

Source: Internet
Author: User

I. Analysis of Typical μC/OS-ⅲ interrupt service programs

In the μC/OS-ⅲ system, a typical example of a kernel involved in the interrupt service program is as follows:

Myisr: (1)

Disable all interrupts; (2)

Save the CPU registers; (3)

Osintnestingctr ++; (4)

If (osintnestingctr = 1) {(5)

Ostcbcurptr-> stkptr = current task's CPU Stack pointer register value;

}

Clear interrupting device; (6)

Re-enable interrupts (optional); (7)

Call User ISR; (8)

Osintexit (); (9)

Restore the CPU registers; (10)

Return from interrupt; (10)

(1) The interrupt service program must be compiled in assembly language. Replace myisr with the custom interrupt service program name.

(2) Close all interruptions before handling other interruptions, to prevent other interruptions from interrupting on-site protection procedures. If the CPU performs hardware processing on this function, no software is required.

(3) On-site protection. In the μC/OS-ⅲ system, all general registers and special registers that require on-site protection must be stored in the task stack.

(4) Increment osintnestingctr variable, which indicates the number of nested layers of interruption.

(5) If osintnestingctr is set to 1, a task is interrupted. During on-site protection, the interrupted task pointer must be saved to OS _tcb.

(6) After the on-site protection is completed, the interruption should be cleared to prevent repeated execution interruption after the interrupt processing function is exited.

(7) If you need to implement interrupt nesting, you can enable the interrupt again here. (Optional)

(8) Call the user-compiled interrupt handler user ISR. This program should be streamlined as much as possible.

(9) after the interrupt service program ends, osintexit () program is called to notify the system kernel of the interruption. Osintnestingctr is decreased in osintexit (). When osintnestingctr is found to be 0, that is, a task-level program has been returned, the task is scheduled. If a program with a higher priority needs to be executed, it is executed directly, no interruption is returned. If no task has a higher priority, an interruption is returned.

(10) If the operation can be resumed, the on-site recovery will be performed. And return the interrupted task.

 

The following is an example of a typical non-kernel interrupt service program in the μC/OS-ⅲ system:

Myinitisr: (1)

Save enough registers as needed by the ISR; (2)

Clear inter rupting device; (3)

Do not re-enable interrupts; (4)

Call User ISR; (5)

Restore the saved CPU registers; (6)

Return from interrupt; (6)

(1) Same as above, this name must be replaced with the custom interrupt service function name.

(2) Here, only registers used to interrupt the service program are saved.

(3) Clear the interruption to avoid the interruption of the response after the service program exits.

(4) do not re-open the interrupt here, because after the re-open interrupt, the high-priority interrupt may interrupt the interrupted execution. If the high-priority interrupt calls to the system kernel, it will lead to a longer interruption time.

(5) Call the interrupt processing function.

(6) The interrupt processing is completed, the CPU register is restored, and the original task is returned.

Q: The response operation is not interrupted in this Code. Why?

Ii. Method of interrupting message publishing to a task

(1) Direct release

Direct Publishing means that after a response is interrupted, the interrupt processing function processes the requests required for the interrupt and then calls the system kernel to check whether a high-priority task is ready for task scheduling. In this mode, the Guanzhong disconnection mode is used to protect the critical segment code.

(2) delayed release

Delayed publishing means that after a response is interrupted, the interrupt processing function initially processes the interrupt request, then sends the interrupt to the interrupt queue, waits for further processing, and then returns the result from the interrupt. In this mode, the lock scheduler is used to protect the critical segment code.

Iii. system cycle interruption

Systems based on μC/OS-ⅲ usually require the underlying platform to provide a periodic timing signal, called a clock cycle or a system cycle. The clock signal cycle is generally 10 ~ 1000Hz.

The clock cycle interrupt is basically the same as other interrupts, but the ostimetick () function must be called. This interrupt is only used to notify the System of the arrival of the clock cycle.

The clock cycle can be used for system functions such as latency and timeout.

Interruption management of the μC/OS-ⅲ System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.