单片机教程网

电脑版
提示:原网页已由神马搜索转码, 内容由www.51hei.com提供.
查看:2563|回复:0
打印上一主题下一主题

uCOS-II+VS2012源程序

[复制链接]
跳转到指定楼层
楼主
ID:752665发表于 2020-6-16 19:42|只看该作者|只看大图回帖奖励
利用提供的uc-os工程,实现两个任务之间的通信。要求自行建立两个任务TaskA和TaskB,利用进程间通信工具mailbox进行实现,任务A定期发送(post)给任务B你的学号,和一个计数码,计数码每次发送自增1;任务B挂起(pend)在相同的mailbox上,接收到任务A从mailbox发送的数据后,打印出来你的名字+从任务A接收到的数据。

要求:
提供任务A和任务B输出的结果,任务A要打印出你的学号和序列号和一串A,任务b要打印出你的名字、学号和序列号以及一串B。


例如:
任务A打印:
“ 学号:012345678:序列号 20—AAAAAAAAAAA”
任务B打印:
“张某甲:学号02345678:序列号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. }
复制代码

所有资料51hei提供下载:
uCOS-II+VS2012_完美仿真.7z(4.42 MB, 下载次数: 20)

评分

黑币 +50
收起理由
+ 50
共享资料的黑币奖励!

查看全部评分

手机版|小黑屋|51黑电子论坛|51黑电子论坛6群QQ管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网