|
功能:简单的任务间收发信息
目的:熟悉任务间的简单通讯
测试代码:
#include "includes.h"
#define TASK_STK_SIZE 512
OS_STK DispCharMStk[TASK_STK_SIZE]; /* Tasks stacks */
OS_STK DispCharYStk[TASK_STK_SIZE];
INT16S key;
INT8U y1 = 0;
INT8U y2 = 0;
char *ss;
char* s = "original data";
void DispCharM(void *data);
void DispCharY(void *data);
BOOLEAN ac_key = FALSE;
INT8U time = 0;
void main (void)
{
PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);
OSInit();
PC_DOSSaveReturn();
PC_VectSet(uCOS, OSCtxSw);
OSTaskCreate(DispCharM, (void *)0, &DispCharMStk[TASK_STK_SIZE - 1], 0);
OSStart();
}
void DispCharM (void *pdata)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
char* s = "DispCharM Received the Message! "; /*收到资源提示*/
char* NoMessage = "DispCharM have lost the Message! "; /*资源被剥夺提示*/
pdata = pdata;
OS_ENTER_CRITICAL();
PC_VectSet(0x08, OSTickISR);
PC_SetTickRate(OS_TICKS_PER_SEC);
OS_EXIT_CRITICAL();
OSStatInit();
OSTaskCreate(DispCharY,(void *)0, &DispCharYStk[TASK_STK_SIZE - 1], 2);
for (;;)
{
if( ac_key == FALSE )
{
PC_DispStr( 5, 10, NoMessage, DISP_BGND_BLACK + DISP_FGND_WHITE);
}else{
PC_DispStr( 5, 10, s, DISP_BGND_BLACK + DISP_FGND_WHITE);
}
if( PC_GetKey(&key) == TRUE )
{
if( key == 0x1B )
{
PC_DOSReturn();
}
}
OSTimeDly( 8 );
}
}
void DispCharY(void *pdata)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
char* s2 = "DispChary recycled the Message "; /*强行回收资源提示*/
char* s = "DispCharY Send the Message to DispCharM "; /*发送资源提示*/
pdata = pdata;
for (;;)
{
time += 1;
if( time == 10 && ac_key == FALSE )
{
PC_DispStr( 28, 15, s, DISP_BGND_BLACK + DISP_FGND_WHITE);
ac_key = TRUE;
}
if( time == 20 )
{
ac_key = FALSE;
time = 0;
PC_DispStr( 28, 15, s2, DISP_BGND_BLACK + DISP_FGND_WHITE);
}
if( PC_GetKey(&key) == TRUE )
{
if( key == 0x1B )
{
PC_DOSReturn();
}
}
OSTimeDly( 100 );
}
} |
|