📄 eg1.c
字号:
/*
* File: example1.c
*
* uC/OS Real-time multitasking kernel for the ARM processor.
*
* Simple example of using multiple tasks and mailboxes.
*
* Created by Marco Graziano (marcog@crl.com).
*
*/
#include "includes.h" /* uC/OS interface */
//#include "Sems.h"
/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE (64+SEMIHOSTED_STACK_NEEDS)
#else
#define STACKSIZE 256
#endif
OS_STK Stack1[STACKSIZE]= {0, };
OS_STK Stack2[STACKSIZE]= {0, };
OS_STK Stack3[STACKSIZE]= {0, };
OS_EVENT *UART_sem;
/* mailbox event control blocks */
OS_EVENT *Mbox1;
OS_EVENT *Mbox2;
OS_EVENT *Mbox3;
char PassMsg[] = "Example 1";
/*
* Task running at the lowest priority.
* Wait for a message in the first mailbox and post
* a messages to the third mailbox.
*/
void Task1(void *Id)
{
char *Msg;
INT8U err;
OSSemPend(UART_sem, 0, &err);
uHALr_printf("Task1() called\r\n");
for (;;)
{
/* wait for a message from the input mailbox */
Msg = (char *)OSMboxPend(Mbox1, 0, &err);
/* print task's id */
uHALr_printf("%c", *(char *)Id);
/* post the input message to the output mailbox */
OSMboxPost(Mbox2, Msg);
}
}
void
Task2(void *Id)
{
char *Msg;
INT8U err;
uHALr_printf("Task2() called\r\n");
for (;;)
{
/* wait for a message from the input mailbox */
Msg = (char *)OSMboxPend(Mbox2, 0, &err);
/* print task's id */
uHALr_printf("%c", *(char *)Id);
/* post the input message to the output mailbox */
OSMboxPost(Mbox3, Msg);
}
}
void
Task3(void *Id)
{
char *Msg;
INT8U err;
uHALr_printf("Task3() called\r\n");
for (;;)
{
/* wait for a message from the input mailbox */
Msg = (char *)OSMboxPend(Mbox3, 0, &err);
/* print task's id */
uHALr_printf("%c", *(char *)Id);
/* post the input message to the output mailbox */
OSMboxPost(Mbox1, Msg);
}
}
/*
* Main function.
*/
int
Main(int argc, char **argv)
{
char Id1 = '1';
char Id2 = '2';
char Id3 = '3';
/* do target (uHAL based ARM system) initialisation */
ARMTargetInit();
/* needed by uC/OS */
OSInit();
uHALr_ResetMMU();
/*
* create the first mailbox in the pipeline with a message
* in it to get the first task started.
*/
Mbox1 = OSMboxCreate(PassMsg);
/* create the remaining mailboxes empty */
Mbox2 = OSMboxCreate((void *)0);
Mbox3 = OSMboxCreate((void *)0);
/*
* create the tasks in uC/OS and assign increasing
* priorities to them so that Task3 at the end of
* the pipeline has the highest priority.
*/
OSTaskCreate(Task1, (void *)&Id1, (OS_STK *)&Stack1[STACKSIZE - 1], 3);
OSTaskCreate(Task2, (void *)&Id2, (OS_STK *)&Stack2[STACKSIZE - 1], 2);
OSTaskCreate(Task3, (void *)&Id3, (OS_STK *)&Stack3[STACKSIZE - 1], 1);
/* Start the (uHAL based ARM system) system running */
ARMTargetStart();
/* start the game */
OSStart();
/* never reached */
return 0;
} /* main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -