μc/OS Experiment: Basic management of experimental task

Source: Internet
Author: User
Tags printf
About μc/OS's learning materials poke here.
Experiment Generic Code Description:
Experiment Code Template (MDK4.70)Note: The app here is the code for the last experiment, as described below to copy it in OK. You can also start with the last one. The μc/OS system functions involved are: ...
Reference and companion code: UCOS-II Experimental Instruction Book
Ucos_demo
Note: It is a reference to this data yes, but several experiments (almost every ⊙﹏⊙ B sweat) of the concept or code problems, I mostly point out (maybe I have some of the wrong), not clear can be down to compare. recommended assignment code to the project, side debugging change, different boards can also, simulator Usart can see the output of serial data.
Experiment Code: APP.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
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 suspended!\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 suspended!\r\n");
printf ("Task_1 is running..............................\r\n");
printf ("***********************************************\r\n");
ostimedly (1000);
Err=ostaskresume (Task0_task_prio); /* Resume Task0 */
}
}


App.h
1
GLOBAL int32u Count;

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 Task1_task_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 a 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 the experimental task */
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 another task
Ostaskdel (os_prio_self);
}

Experimental results:
Note: Systick_configuration that provide heart beats must be called after osstart (preferably in the task Taskstart that initiates the task-good habits), otherwise the consequences are unknown because you opened the interrupt before the system started, and the system did not know what to do.

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.