找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2877|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

uCOS-II+VS2012源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
利用提供的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”


源程序如下:
  1. /*
  2. *********************************************************************************************************
  3. *                                               uC/OS-II
  4. *                                         The Real-Time Kernel
  5. *
  6. *                             (c) Copyright 1998-2004, Micrium, Weston, FL
  7. *                                          All Rights Reserved
  8. *
  9. *
  10. *                                            WIN32 Sample Code
  11. *
  12. * File : APP.C
  13. * By   : Eric Shufro
  14. *********************************************************************************************************
  15. */

  16. #include <includes.h>

  17. /*
  18. *********************************************************************************************************
  19. *                                                CONSTANTS
  20. *********************************************************************************************************
  21. */

  22. #define  TASK_STK_SIZE    128
  23. #define  TASK_START_PRIO    5

  24. /*
  25. *********************************************************************************************************
  26. *                                                VARIABLES
  27. *********************************************************************************************************
  28. */

  29. OS_STK        AppStartTaskStk[TASK_STK_SIZE];

  30. /*
  31. *********************************************************************************************************
  32. *                                            FUNCTION PROTOTYPES
  33. *********************************************************************************************************
  34. */

  35. static  void  AppStartTask(void *p_arg);

  36. #if OS_VIEW_MODULE > 0
  37. static  void  AppTerminalRx(INT8U rx_data);
  38. #endif

  39. /*
  40. *********************************************************************************************************
  41. *                                                _tmain()
  42. *
  43. * Description : This is the standard entry point for C++ WIN32 code.  
  44. * Arguments   : none
  45. *********************************************************************************************************
  46. */

  47. void main(int argc, char *argv[])
  48. {
  49.         INT8U  err;


  50. #if 0
  51.     BSP_IntDisAll();                       /* For an embedded target, disable all interrupts until we are ready to accept them */
  52. #endif

  53.     OSInit();                              /* Initialize "uC/OS-II, The Real-Time Kernel"                                      */

  54.     OSTaskCreateExt(AppStartTask,
  55.                     (void *)0,
  56.                     (OS_STK *)&AppStartTaskStk[TASK_STK_SIZE-1],
  57.                     TASK_START_PRIO,
  58.                     TASK_START_PRIO,
  59.                     (OS_STK *)&AppStartTaskStk[0],
  60.                     TASK_STK_SIZE,
  61.                     (void *)0,
  62.                     OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

  63. #if OS_TASK_NAME_SIZE > 11
  64.     OSTaskNameSet(APP_TASK_START_PRIO, (INT8U *)"Start Task", &err);
  65. #endif

  66. #if OS_TASK_NAME_SIZE > 14
  67.     OSTaskNameSet(OS_IDLE_PRIO, (INT8U *)"uC/OS-II Idle", &err);
  68. #endif

  69. #if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
  70.     OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat", &err);
  71. #endif

  72.     OSStart();                             /* Start multitasking (i.e. give control to uC/OS-II)                               */
  73. }
  74. /*$PAGE*/
  75. /*
  76. *********************************************************************************************************
  77. *                                          STARTUP TASK
  78. *
  79. * Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
  80. *               initialize the ticker only once multitasking has started.
  81. * Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
  82. * Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
  83. *                  used.  The compiler should not generate any code for this statement.
  84. *               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
  85. *                  set to 0 by 'OSTaskCreate()'.
  86. *********************************************************************************************************
  87. */

  88. void  AppStartTask (void *p_arg)
  89. {
  90.     p_arg = p_arg;

  91. #if 0
  92.     BSP_Init();                                  /* For embedded targets, initialize BSP functions                             */
  93. #endif


  94. #if OS_TASK_STAT_EN > 0
  95.     OSStatInit();                                /* Determine CPU capacity                                                     */
  96. #endif
  97.    
  98.     while (TRUE)                                 /* Task body, always written as an infinite loop.                             */
  99.         {                       
  100.                 OS_Printf("Delay 1 second and print\n");  /* your code here. Create more tasks, etc.                                    */
  101.         OSTimeDlyHMSM(0, 0, 1, 0);      
  102.     }
  103. }
復(fù)制代碼

所有資料51hei提供下載:
uCOS-II+VS2012_完美仿真.7z (4.42 MB, 下載次數(shù): 20)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表