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.