[Topics] uC/OS-II kernel Architecture Analysis (7)-uC/OS-II Application Development

Source: Internet
Author: User
1. application development steps

(1) The total header file containing the uC/OS-II, Des. h;

(2) define the task stack size and task stack;

(3) assigning task priorities;

(4) implement the task function;

(5) Call the osinit () function to initialize the data structure of uC/OS-II;

(6) create user task, start uC/OS-II;

2. Compile task Functions

The user's task function must be an infinite loop, and the program execution flow is changed by the OS kernel. After executing the user code, it is best to call the system service and take the initiative to give the CPU right to the desired task.

Mode 1:

Void yourtask (void * pdata)

{

For (;;)

{

/* User code */

Call the uC/OS II service;

Osmboxpend ();

Osqpend ();

Ossempend ();

Ostimedlyhmsm ();

/* User code */

}

}

 

Mode 2 (self-deletion task)

Void yourtask (void * pdata)

{

/* User code */

Ostaskdel (OS _prio_self );

} // The task is deleted after it is run.

3. Stack design Extension

Method: Separate the interrupt stack and task stack.

Cause: uC/OS-II occupies Ram mainly for task TCB, task stack and other aspects, the task stack is large because the hardware design does not interrupt stack and Task Stack separated, this results in computing the number of Partial Variables and nested function layers in the task, as well as the maximum number of interrupted nested layers, resulting in a large amount of Ram waste. You can separate the interrupt Stack from the task stack. In this way, you do not need to compute the memory usage in the interrupt processing (including interrupt nesting) into the task stack when calculating the task stack, you only need to calculate the memory size required by each task.

4. Some references

(1) When writing interrupt programs, try to use the assembly language if conditions are met. This can avoid some compiler operations and reduce the number of pointer adjustments.

(2) When writing ISR in C, you sometimes need to call the assembler function. Some of the PCs that press the stack may destroy the stack structure. Therefore, you need to adjust the stack to ensure the correct format.

(3) because the uC/OS-II Interrupt Processing in the original design may not adjust the SP, you need to call osintexit () to return, determine whether the program is in the nested state of interruption. 

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.