利用提供的uc-os工程,實(shí)現(xiàn)兩個(gè)任務(wù)之間的通信。要求自行建立兩個(gè)任務(wù)TaskA和TaskB,利用進(jìn)程間通信工具mailbox進(jìn)行實(shí)現(xiàn),任務(wù)A定期發(fā)送(post)給任務(wù)B你的學(xué)號(hào),和一個(gè)計(jì)數(shù)碼,計(jì)數(shù)碼每次發(fā)送自增1;任務(wù)B掛起(pend)在相同的mailbox上,接收到任務(wù)A從mailbox發(fā)送的數(shù)據(jù)后,打印出來你的名字+從任務(wù)A接收到的數(shù)據(jù)。
要求: 提供任務(wù)A和任務(wù)B輸出的結(jié)果,任務(wù)A要打印出你的學(xué)號(hào)和序列號(hào)和一串A,任務(wù)b要打印出你的名字、學(xué)號(hào)和序列號(hào)以及一串B。
例如: 任務(wù)A打。 “ 學(xué)號(hào):012345678:序列號(hào) 20—AAAAAAAAAAA” 任務(wù)B打。 “張某甲:學(xué)號(hào)02345678:序列號(hào)20----BBBBBBBBBBBBB”
51hei.png (8.27 KB, 下載次數(shù): 58)
下載附件
2020-6-17 23:13 上傳
源程序如下:
- /*
- *********************************************************************************************************
- * uC/OS-II
- * The Real-Time Kernel
- *
- * (c) Copyright 1998-2004, Micrium, Weston, FL
- * All Rights Reserved
- *
- *
- * WIN32 Sample Code
- *
- * File : APP.C
- * By : Eric Shufro
- *********************************************************************************************************
- */
- #include <includes.h>
- /*
- *********************************************************************************************************
- * CONSTANTS
- *********************************************************************************************************
- */
- #define TASK_STK_SIZE 128
- #define TASK_START_PRIO 5
- /*
- *********************************************************************************************************
- * VARIABLES
- *********************************************************************************************************
- */
- OS_STK AppStartTaskStk[TASK_STK_SIZE];
- /*
- *********************************************************************************************************
- * FUNCTION PROTOTYPES
- *********************************************************************************************************
- */
- static void AppStartTask(void *p_arg);
- #if OS_VIEW_MODULE > 0
- static void AppTerminalRx(INT8U rx_data);
- #endif
- /*
- *********************************************************************************************************
- * _tmain()
- *
- * Description : This is the standard entry point for C++ WIN32 code.
- * Arguments : none
- *********************************************************************************************************
- */
- void main(int argc, char *argv[])
- {
- INT8U err;
- #if 0
- BSP_IntDisAll(); /* For an embedded target, disable all interrupts until we are ready to accept them */
- #endif
- OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
- OSTaskCreateExt(AppStartTask,
- (void *)0,
- (OS_STK *)&AppStartTaskStk[TASK_STK_SIZE-1],
- TASK_START_PRIO,
- TASK_START_PRIO,
- (OS_STK *)&AppStartTaskStk[0],
- TASK_STK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- #if OS_TASK_NAME_SIZE > 11
- OSTaskNameSet(APP_TASK_START_PRIO, (INT8U *)"Start Task", &err);
- #endif
- #if OS_TASK_NAME_SIZE > 14
- OSTaskNameSet(OS_IDLE_PRIO, (INT8U *)"uC/OS-II Idle", &err);
- #endif
- #if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
- OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat", &err);
- #endif
- OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
- }
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * STARTUP TASK
- *
- * Description : This is an example of a startup task. As mentioned in the book's text, you MUST
- * initialize the ticker only once multitasking has started.
- * Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
- * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
- * used. The compiler should not generate any code for this statement.
- * 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
- * set to 0 by 'OSTaskCreate()'.
- *********************************************************************************************************
- */
- void AppStartTask (void *p_arg)
- {
- p_arg = p_arg;
- #if 0
- BSP_Init(); /* For embedded targets, initialize BSP functions */
- #endif
- #if OS_TASK_STAT_EN > 0
- OSStatInit(); /* Determine CPU capacity */
- #endif
-
- while (TRUE) /* Task body, always written as an infinite loop. */
- {
- OS_Printf("Delay 1 second and print\n"); /* your code here. Create more tasks, etc. */
- OSTimeDlyHMSM(0, 0, 1, 0);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
uCOS-II+VS2012_完美仿真.7z
(4.42 MB, 下載次數(shù): 20)
2020-6-17 23:14 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|