μc/OS micro-kernel analysis

Source: Internet
Author: User

The source code for the μc/OS embedded RTOs can be divided into three parts: hardware-independent kernel code, processor-related porting code, and user profiles.


The kernel code is located in the source directory and provides 4 tiny cores. They are located in Source\source1 (including set up tasks and delay functions), source \source2 (Add Delete task function), source\source3 (increase semaphore file) and Source\source4 (Increase deletion semaphore function). Their functions are enhanced in turn, and the code increases in turn.




Μc/os-ⅱ is the task control block to manage tasks. Task control block is a linked list-based data structure, the task control block is mainly used to record the task's stack top pointer, pointer to the next task control block, the delay time of the task wait, the task's current status flag and task priority level and other tasks related to the management of the properties.
When the task's CPU usage is stripped, Μc/os-ⅱ uses the task control block to save the task's state, ensuring that the task is executed from the breakpoint at the time of the CPU's regain access.

μc/Os must be initialized after the function osinit () to be used, calling only Os_initmisc (), Os_initrdylist (), Os_inittcblist (), and Os_inittaskidle () 4 functions.

ostaskcreate () calls the Ostaskstkinit () task stack initialization function and the Os_tcbinit () function to obtain and initialize a OS_TCB.

Task Scheduling Summary:

Reentrant code refers to a piece of code that can be called simultaneously by multiple tasks without worrying about data corruption. That is, the reentrant function can be interrupted at any time, and can continue to run for a period of time, while the corresponding data is not lost. Reentrant functions or only local variables, which are stored in the CPU registers or stacks. If global variables are used, the global variables are protected. This shows that the re-entry of code is the basis to ensure the completion of multi-tasking.

Μc/os-ⅱ in order to handle the critical section code need to prohibit interrupts, processing and then allow the interrupt, which allows Μc/os-ⅱ to avoid other tasks or interrupt service into the critical segment code, two macros os_enter_critical () and os_exit_critical () To prohibit interrupts and allow interrupts.

μc/OS is collectively referred to as "events" for semaphores, mutexes, message mailboxes, and message queues, and then manages events through a data structure called the event control block (ECB), which means that the task and interrupt service programs can send signals to another task path through the ECB. A task can also wait for another task or interrupt the service program to send it a signal.

Before using the event control block, you need to link all the event control blocks into an idle event control block list. Whenever a semaphore, mutex, message mailbox, Message queue is established, an idle event control block is removed from the linked list and initialized. When the semaphore, mutex, message mailbox, message queue are deleted, the corresponding event control block also needs to be put back into the list of idle event control blocks.

The μc/OS supports 3 operations on semaphores: Create Semaphore ossemcreate (), send Semaphore ossempost (), and wait for Semaphore ossempend ().






































μc/OS micro-kernel analysis

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.