⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app_main.c

📁 UCOSII在mcs12dg128上的移植
💻 C
字号:
//==================================================================================================
//| 文件名称 | APP_MAIN.c
//|--------- |--------------------------------------------------------------------------------------
//| 文件描述 | 系统
//|--------- |--------------------------------------------------------------------------------------
//| 运行环境 | 所有C/++语言编译器,包括单片机编译器
//|--------- |--------------------------------------------------------------------------------------
//| 版权声明 | Copyright2008
//|----------|--------------------------------------------------------------------------------------
//|  版本    |  时间       |  作者     | 描述
//|--------- |-------------|-----------|------------------------------------------------------------
//|  V1.0    | 2008.08.18 | chen       | 初版
//==================================================================================================


#define  APP_MAIN_GLOBALS
#include "..\sources\application\Include.h"

void main (void)
{
	DDRB_BIT0=1;
	DDRT_DDRT4=1; 
	DDRP_DDRP3=1;
    TASK_LED_BLUE=OFF;
   	TASK_LED_RED=OFF;
    TASK_LED_YELLOW=OFF;
	PLLINIT(24,5);		//25M总线频率
    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);  
    OSStart();
}
/*$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   : pdata   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'pdata' 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()'.
*********************************************************************************************************
*/

static void  AppStartTask (void *pdata)
{
    pdata = pdata;
    AppTickInit();                          /* Initialize the ticker                                   */
    OSStatInit();  	//Initialize the stat task.
    TrafficSemRed=OSSemCreate(1); //creat a semphore
    TrafficSemBlue=OSSemCreate(0); 
    TrafficSemYellow=OSSemCreate(0);
    OSTaskCreateExt(AppTaskRedLed,
    			    (void *)0,
    			    (OS_STK *)&AppTaskRedLedStk[TASK_STK_SIZE-1],
    			    TASK_REDLED_PRIO,
    			    TASK_REDLED_PRIO,
    			    (OS_STK *)&AppTaskRedLedStk[0],
    			    TASK_STK_SIZE,
    			    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); 
    OSTaskCreateExt(AppTaskBlueLed,
    			    (void *)0,
    			    (OS_STK *)&AppTaskBlueLedStk[TASK_STK_SIZE-1],
    			    TASK_BLUELED_PRIO,
    			    TASK_BLUELED_PRIO,
    			    (OS_STK *)&AppTaskBlueLedStk[0],
    			    TASK_STK_SIZE,
    			    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  
    OSTaskCreateExt(AppTaskYellowLed,
    			    (void *)0,
    			    (OS_STK *)&AppTaskYellowLedStk[TASK_STK_SIZE-1],
    			    TASK_YELLOWLED_PRIO,
    			    TASK_YELLOWLED_PRIO,
    			    (OS_STK *)&AppTaskYellowLedStk[0],
    			    TASK_STK_SIZE,
    			    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);                                    
    while (TRUE) 
    {                          /* Task body, always written as an infinite loop.          */
   		TASK_LED_BLUE=OFF;
   		TASK_LED_RED=OFF;
    	TASK_LED_YELLOW=OFF;
		OSTaskSuspend(TASK_START_PRIO);
    }
}
/*
*********************************************************************************************************
*                                          AppTaskRedLed
*
* Description : This is a task to control red led which use a synchronize samphore. 
* Arguments   : pdata   is the argument passed to 'AppTaskRedLed()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'pdata' 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()'.
*********************************************************************************************************
*/

static void  AppTaskRedLed (void *pdata)
{
    pdata = pdata;
    while (TRUE) 
    {                          /* Task body, always written as an infinite loop.          */
    	OSSemPend(TrafficSemRed,0,err);
    	TASK_LED_RED=ON;
    	TASK_LED_BLUE=OFF;
    	TASK_LED_YELLOW=OFF;     	
    	OSTimeDlyHMSM(0, 0, 5, 0);
    	OSSemPost(TrafficSemBlue); 
    }
} 

/*
*********************************************************************************************************
*                                          AppTaskBlueLed
*
* Description : This is a task to control blue led which use a synchronize samphore. 
* Arguments   : pdata   is the argument passed to 'AppTaskRedLed()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'pdata' 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()'.
*********************************************************************************************************
*/

static void  AppTaskBlueLed (void *pdata)
{
    pdata = pdata;
    while (TRUE) 
    {                          /* Task body, always written as an infinite loop.          */
    	OSSemPend(TrafficSemBlue,0,err);
    	TASK_LED_RED=OFF;
    	TASK_LED_BLUE=ON;
    	TASK_LED_YELLOW=OFF;
    	OSTimeDlyHMSM(0, 0, 4, 0);
    	OSSemPost(TrafficSemYellow);
    }
}  

/*
*********************************************************************************************************
*                                          AppTaskYellowLed
*
* Description : This is a task to control red led which use a synchronize samphore. 
* Arguments   : pdata   is the argument passed to 'AppTaskRedLed()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'pdata' 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()'.
*********************************************************************************************************
*/

static void  AppTaskYellowLed (void *pdata)
{
	int i;
    pdata = pdata;
    while (TRUE) 
    {                          /* Task body, always written as an infinite loop.          */
		OSSemPend(TrafficSemYellow,0,err);
    	TASK_LED_RED=OFF;
    	TASK_LED_BLUE=OFF;
    	for(i=0;i<5;i++) 
    	{
    		TASK_LED_YELLOW=ON;
    		OSTimeDlyHMSM(0, 0, 0, 100);
    		TASK_LED_YELLOW=OFF;
    		OSTimeDlyHMSM(0, 0, 0, 100);	
    	}    
		OSSemPost(TrafficSemRed);
    }
}  
 
/*$PAGE*/
/*
*********************************************************************************************************
*                                      TICKER INITIALIZATION
*
* Description : This function is used to initialize one of the eight output compares to generate an
*               interrupt at the desired tick rate.  You must decide which output compare you will be
*               using by setting the configuration variable OS_TICK_OC (see OS_CFG.H and also OS_CPU_A.S) 
*               to 0..7 depending on which output compare to use.
*                   OS_TICK_OC set to 0 chooses output compare #0 as the ticker source
*                   OS_TICK_OC set to 1 chooses output compare #1 as the ticker source
*                   OS_TICK_OC set to 2 chooses output compare #2 as the ticker source
*                   OS_TICK_OC set to 3 chooses output compare #3 as the ticker source
*                   OS_TICK_OC set to 4 chooses output compare #4 as the ticker source
*                   OS_TICK_OC set to 5 chooses output compare #5 as the ticker source
*                   OS_TICK_OC set to 6 chooses output compare #6 as the ticker source
*                   OS_TICK_OC set to 7 chooses output compare #7 as the ticker source
* Arguments   : none
* Notes       : 1) It is assumed that you have set the prescaler rate of the free running timer within
*                  the first 64 E clock cycles of the 68HC12.
*               2) CPU registers are define in 6812dp256.h (see Metrowerks codewarrior compiler)
*********************************************************************************************************
*/

static void AppTickInit (void)
{
    TSCR2|=3; //预分频器输出时钟频率为P时钟的1/8,定时器溢出时间为21.97ms 
   	TSCR1   = 0x80;                         /* Enable timer*/
        
#if OS_TICK_OC == 0
    TIOS  |= 0x01;                          /* Make channel an output compare                          */
    TC0    = TCNT + OS_TICK_OC_CNTS;        /* Set TC0 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x01;	              			/* set timer control reg */
    TIE |= 0x01;                          /* Enable OC0 interrupt.                                   */
#endif

#if OS_TICK_OC == 1 
    TIOS  |= 0x02;                          /* Make channel an output compare                          */
    TC1    = TCNT + OS_TICK_OC_CNTS;        /* Set TC1 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x02;	              			/* set timer control reg */
    TIE |= 0x02;                          /* Enable OC1 interrupt.                                   */
#endif

#if OS_TICK_OC == 2
    TIOS  |= 0x04;                          /* Make channel an output compare                          */
    TC2    = TCNT + OS_TICK_OC_CNTS;        /* Set TC2 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x04;	              			/* set timer control reg */
    TIE |= 0x04;                          /* Enable OC2 interrupt.                                   */
#endif

#if OS_TICK_OC == 3
    TIOS  |= 0x08;                          /* Make channel an output compare                          */
    TC3    = TCNT + OS_TICK_OC_CNTS;        /* Set TC3 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x08;	              			/* set timer control reg */
    TIE |= 0x08;                          /* Enable OC3 interrupt.                                   */
#endif

#if OS_TICK_OC == 4
    TIOS  |= 0x10;                          /* Make channel an output compare                          */
    TC4    = TCNT + OS_TICK_OC_CNTS;        /* Set TC4 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x10;	              			/* set timer control reg */
    TIE |= 0x10;                          /* Enable OC4 interrupt.                                   */
#endif

#if OS_TICK_OC == 5
    TIOS  |= 0x20;                          /* Make channel an output compare                          */
    TC5    = TCNT + OS_TICK_OC_CNTS;        /* Set TC5 to present time + OS_TICK_OC_CNTS               */
    TCTL1  |= 0x20;	              			/* set timer control reg */
    TIE |= 0x20;                          /* Enable OC5 interrupt.                                   */
#endif

#if OS_TICK_OC == 6
    TIOS  |= 0x40;                          /* Make channel an output compare                          */
    TC6    = TCNT + OS_TICK_OC_CNTS;        /* Set TC6 to present time + OS_TICK_OC_CNTS */
    TCTL1  |= 0x40;	              			/* set timer control reg */
    TIE |= 0x40;                          /* Enable OC6 interrupt.                                   */
#endif

#if OS_TICK_OC == 7
    TIOS  |= 0x80;                          /* Make channel an output compare                          */
    TC7    = TCNT + OS_TICK_OC_CNTS;
    TCTL1  |= 0x80;							/* set timer control reg */
    TIE |= 0x80;                          /* Enable OC7 interrupt. */
   								                             
#endif
}

/******************************************************************
*函数名:PLLINIT
*入口参数

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -