PageRenderTime 364ms CodeModel.GetById 124ms app.highlight 6ms RepoModel.GetById 155ms app.codeStats 0ms

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

http://ftk.googlecode.com/
C | 135 lines | 62 code | 21 blank | 52 comment | 1 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
 17#include <includes.h>

 18
 19/*
 20*********************************************************************************************************
 21*                                                CONSTANTS
 22*********************************************************************************************************
 23*/
 24
 25#define  TASK_STK_SIZE    1024

 26#define  APP_TASK_PRIO    5

 27
 28/*
 29*********************************************************************************************************
 30*                                                VARIABLES
 31*********************************************************************************************************
 32*/
 33
 34static OS_STK AppTaskStk[TASK_STK_SIZE];
 35
 36/*
 37*********************************************************************************************************
 38*                                            FUNCTION PROTOTYPES
 39*********************************************************************************************************
 40*/
 41
 42static void  AppTask(void *p_arg);
 43
 44#if OS_VIEW_MODULE > 0

 45static  void  AppTerminalRx(INT8U rx_data);
 46#endif

 47
 48#define _log(msg)	do{   \

 49	OS_ENTER_CRITICAL();	\
 50	printf("%s",msg);		\
 51	OS_EXIT_CRITICAL();	\
 52}while(0)
 53
 54/*
 55*********************************************************************************************************
 56*                                                _tmain()
 57*
 58* Description : This is the standard entry point for C++ WIN32 code.  
 59* Arguments   : none
 60*********************************************************************************************************
 61*/
 62
 63void C_AppMain(void)
 64{
 65	INT8U  err;
 66
 67#if 0
 68    BSP_IntDisAll();                       /* For an embedded target, disable all interrupts until we are ready to accept them */
 69#endif
 70    OSInit();                              /* Initialize "uC/OS-II, The Real-Time Kernel"                                      */
 71
 72	OSTaskCreate(AppTask,
 73		(void *)0,
 74		(OS_STK *)&AppTaskStk[TASK_STK_SIZE-1],
 75		APP_TASK_PRIO);
 76
 77#if OS_TASK_NAME_SIZE > 11

 78    OSTaskNameSet(APP_TASK_START_PRIO, (INT8U *)"Start Task", &err);
 79#endif

 80
 81#if OS_TASK_NAME_SIZE > 14

 82    OSTaskNameSet(OS_IDLE_PRIO, (INT8U *)"uC/OS-II Idle", &err);
 83#endif

 84
 85#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)

 86    OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat", &err);
 87#endif

 88
 89    OSStart();                             /* Start multitasking (i.e. give control to uC/OS-II)                               */
 90}
 91/*$PAGE*/
 92/*
 93*********************************************************************************************************
 94*                                          STARTUP TASK
 95*
 96* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
 97*               initialize the ticker only once multitasking has started.
 98* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
 99* Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
100*                  used.  The compiler should not generate any code for this statement.
101*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
102*                  set to 0 by 'OSTaskCreate()'.
103*********************************************************************************************************
104*/
105static int argc = 1;
106static char* argv[] = {"ftk", NULL};
107extern int ftk_main(int argc, char* argv[]);
108extern HANDLE ucoshandle;
109
110static void AppTask (void *p_arg)
111{
112    p_arg = p_arg;
113#if 0
114    BSP_Init();                                  /* For embedded targets, initialize BSP functions                             */
115#endif
116
117#if OS_TASK_STAT_EN > 0

118    OSStatInit();                                /* Determine CPU capacity                                                     */
119#endif

120	OSTimeDly(10);
121
122	ftk_main(argc, argv); /* Task never return,so ftk_deinit() will be not called*/
123	_log("ftk end\n");
124#ifdef UCOS_SIM

125	ReleaseSemaphore(ucoshandle, 1, NULL); // increase count by one
126	OSTaskDel(OS_PRIO_SELF);
127#else

128	while(1)
129	{
130		_log(".");
131		OSTimeDly(200);
132	}
133#endif

134}
135