The learning material for the μC/OS-II is poked here. General tutorial Code Description:
Experiment Code Template (mdk4.70)Note: The app here is the code of the last experiment. It is okay to copy the code as described below. You can also start from the last one. Involved μC/OS-II system function :... Reference materials and supporting code: uCOS-II experiment guide ucos_demo
Note: It is correct to refer to this document, but there are some problems with the concept or code of several experiments (almost every ⊙ B Khan, I have pointed it out later (maybe some of my points are also wrong). If you don't know it, you can make a comparison.
It is recommended that you assign values to the project, and debug and modify the codes. You can also view the serial port data output in the usart of the simulator.Experiment code: App. c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
|
Void task0 (void * pdata)
{
Int8u err;
While (1)
{
Printf ("application tasks switched % d times! \ R \ n ", ++ count );
Printf ("task_0 is running ............................. \ r \ n ");
Printf ("task_1 is suincluded! \ R \ n ");
Printf ("************************************* * ********* \ r \ n ");
Err = ostasksuspend (OS _prio_self); // suspend itself
}
}
Void task1 (void * pdata)
{
Int8u err;
While (1)
{
Ostimedly (1000 );
Printf ("application tasks switched % d times! \ R \ n ", ++ count );
Printf ("task_0 is suincluded! \ R \ n ");
Printf ("task_1 is running .............................. \ r \ n ");
Printf ("************************************* * ********* \ r \ n ");
Ostimedly (1000 );
Err = ostaskresume (task0_task_prio);/* resume task0 */
}
} |
App. h
App_cfg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
|
# Define task0_stk_size 64
# Define task1_stk_size 64
# Define task0_task_prio 4
# Define taskdetailtask_prio 5
# Ifdef global_stask_define
# Define global
# Else
# Define global extern
# Endif
Global OS _stk task_task0_stk [task0_stk_size];
Global OS _stk task_task1_stk [task1_stk_size];
Void task0 (void * pdata );
Void task1 (void * pdata ); |
Main. c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
|
// Start the task
Static void taskstart (void * pdata)
{
Pdata = pdata;
// App Initialization
// The system clock must be called after osstart ()
Systick_configuration ();
# If (OS _task_stat_en> 0)
Osstatinit ();
# Endif
/* Basic management of Experiment 1 */
Ostaskcreate (task0, (void *) & taskdata [0], (OS _stk *) & task_task0_stk [TASK0_STK_SIZE-1], task0_task_prio );
Ostaskcreate (task1, (void *) & taskdata [1], (OS _stk *) & task_task1_stk [TASK1_STK_SIZE-1], task1_task_prio );
// Delete yourself after creating other tasks
Ostaskdel (OS _prio_self );
} |
Experiment results: Note: The heartbeat ick_configuration must be called after osstart (preferably in the taskstart task of the startup task-good habits). Otherwise, the consequences are unknown, because you have opened the interrupt before the system is started, and the system does not know what to do.