/src/compiler/ucos-vs2008/UCOS_SIM/src/app/app.c

http://ftk.googlecode.com/ · C · 135 lines · 62 code · 21 blank · 52 comment · 2 complexity · ceb9dd582a6640f5a0dd200ed8c5de46 MD5 · raw file

  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 1024
  23. #define APP_TASK_PRIO 5
  24. /*
  25. *********************************************************************************************************
  26. * VARIABLES
  27. *********************************************************************************************************
  28. */
  29. static OS_STK AppTaskStk[TASK_STK_SIZE];
  30. /*
  31. *********************************************************************************************************
  32. * FUNCTION PROTOTYPES
  33. *********************************************************************************************************
  34. */
  35. static void AppTask(void *p_arg);
  36. #if OS_VIEW_MODULE > 0
  37. static void AppTerminalRx(INT8U rx_data);
  38. #endif
  39. #define _log(msg) do{ \
  40. OS_ENTER_CRITICAL(); \
  41. printf("%s",msg); \
  42. OS_EXIT_CRITICAL(); \
  43. }while(0)
  44. /*
  45. *********************************************************************************************************
  46. * _tmain()
  47. *
  48. * Description : This is the standard entry point for C++ WIN32 code.
  49. * Arguments : none
  50. *********************************************************************************************************
  51. */
  52. void C_AppMain(void)
  53. {
  54. INT8U err;
  55. #if 0
  56. BSP_IntDisAll(); /* For an embedded target, disable all interrupts until we are ready to accept them */
  57. #endif
  58. OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
  59. OSTaskCreate(AppTask,
  60. (void *)0,
  61. (OS_STK *)&AppTaskStk[TASK_STK_SIZE-1],
  62. APP_TASK_PRIO);
  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. static int argc = 1;
  89. static char* argv[] = {"ftk", NULL};
  90. extern int ftk_main(int argc, char* argv[]);
  91. extern HANDLE ucoshandle;
  92. static void AppTask (void *p_arg)
  93. {
  94. p_arg = p_arg;
  95. #if 0
  96. BSP_Init(); /* For embedded targets, initialize BSP functions */
  97. #endif
  98. #if OS_TASK_STAT_EN > 0
  99. OSStatInit(); /* Determine CPU capacity */
  100. #endif
  101. OSTimeDly(10);
  102. ftk_main(argc, argv); /* Task never return,so ftk_deinit() will be not called*/
  103. _log("ftk end\n");
  104. #ifdef UCOS_SIM
  105. ReleaseSemaphore(ucoshandle, 1, NULL); // increase count by one
  106. OSTaskDel(OS_PRIO_SELF);
  107. #else
  108. while(1)
  109. {
  110. _log(".");
  111. OSTimeDly(200);
  112. }
  113. #endif
  114. }