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

📄 ucos2test.c

📁 UCOS II源码 内含SOURCE 解压后使用
💻 C
字号:
/*
*************************************************************************
*************************************************************************
**                                                                     **
**  FILE	    : TEST.C                                           **
**                                                                     **
**  DESCRIPTION     : TriCore-specific C code for the uC/OS-II kernel  **
**                                                                     **
**  AUTHOR          : Jean J. Labrosse                                 **
**                                                                     **
**  MODIFIED BY     : Andre Gompel for Infineon TriCore implementation ** 
**                    of UCOS-II Andre.Gompel@Infineon.com             **   
**                    agompel@bigfoot.com.                             **
**                                                                     **
**                    Connect TriBord DB9 connector to a "dumb"        ** 
**                    terminal set at 9600 bps, no parity, 8bits,      ** 
**                    no H/W flow control.                             **
**                                                                     **
**  REVISION HISTORY:                                                  **
**                                                                     **
**                                                                     **
**  Copyright (c) 2000 Micrium Inc.                                    **
**                All Rights Reserved                                  **
**                                                                     **
**  Copyright (c) 2000 Infineon Technologies Corproration              **
**                All Rights Reserved                                  **
**                                                                     **
**  THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR           **
**  IMPLIED WARRANTY. BOTH INFINEON TECHNOLOGIES CORPORATION AND       **
**  MICRIUM INC. DISCLAIMS ALL REPRESENTATIONS AND WARRANTIES WITH     **
**  REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF       **
**  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT  **
**  SHALL INFINEON TECHNOLOGIES CORPORATION OR MICRIUM INC. BE LIABLE  **
**  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES  **
**  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN **
**  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACT OR         **
**  OMISSION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR          **
**  PERFORMANCE OF THIS SOFTWARE.                                      **
**                                                                     **
*************************************************************************
*************************************************************************
*/

#include "INCLUDES.H"
#include "uCOS2test.h"
#include "rename_f.h"

OS_STK  AppStartTaskStk[256]; 	// Word aligned, implicit
OS_STK  AppTask1Stk[256];
OS_STK  AppTask2Stk[256];
OS_EVENT *RxSem;						// Receive Semaphore
extern OS_EVENT *pSem;


static void  AppStartTask(void *pdata);
static void  AppTask1(void *pdata);
static void  AppTask2(void *pdata);
static void  AppTickInit(void);


INT8U MyDbg;

os_tsk_ext_t  		tsk_ext;
p_os_tsk_ext_t  	p_tsk_ext = &tsk_ext;

void main (void)
{
	char message[] = " Test of the transmit routine";
	char *p_msg = (char*) &message;

														// Initialize Context globals,
	OSInitTriCore();								// Initialize Tricore registers,
														// Initialize Tricore timers.


   OSInit();         /* Init defaults, create "OSTaskIdle", may create "OSSTASKStatStk" */

	RxSem = OSSemCreate(0); // Create receive Semaphore, itialized to 0.
									// The first "P" primitive or OSSemPend() 
									// will put task in the task waiting list.
									// REF: J.L's book page 306.


/*
		We may want to create the task, only if the context and stack
		requirements have been fullfilled.
		Need more work for dynamic task creation.

		In fact OsTakCreateExt is a macro which first initialize the CSA list for the task,
		then call "normal" OsTaskCreateExt.
		It was implemented that way to keep the processor independent code
		untouched.
*/

    OSTaskCreateExt(AppStartTask,		  									// p_task code
							(void *)0,												// pdata not used here
							&TaskStartStk[TASK_STK_SIZE-1],   				// p_tos	 (top of stk)
							TASK_1_PRIO,														// Task priority Zero=Highest
                   	TASK_1_PRIO,														// Task ID
							&TaskStartStk[0],										// p_bos
							TASK_STK_SIZE,											// n of stack words
							(void *)p_tsk_ext, 									// p_Context info 
                   	OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);	// Task options

    /*---- Create any other task you want before we start multitasking --------------------------------*/

    OSStart();                              /* Start multitasking (i.e. give control to uC/OS-II)      */
}

/*********************************************************************************************************
*                                          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()'.
**********************************************************************************************************/


/*
**
**	Andre's note: the tasks priorities are higher when their number is lower,
** also some priorities are reserved by the RTOS: see JL book, page 77, 3.01 Tasks.
** 
** In order to create a task, the call to os_ctx_alloc must return a non null
** value thru the global variable g_tsk_ctx0.
** OSTaskCreate first will call for context allocation.
** 
** 
*/

static void  AppStartTask (void *pdata)
{
	 INT8U first_time=TRUE;

	 OSprintf("\x1b[2J \n\r=== Starting MicroC/OS-II, The Real-Time Kernel, Infineon TriCore version ===");
	 OSprintf("\n\r RTOS by Jean Labrosse, TriCore port by Andre Gompel,   (Size 15 Kbytes)\n\r");

OSprintf
	("\n\r In this application, a main task creates two tasks, then start them");

OSprintf
	("\n\r Task 1 execute once, then yield time, the Task 2 execute and wait its semaphore \
(initialized to 0) to be released by a \"Post\" or \"V\" primitive when\
 a character is received by the on chip UART (ASC0)\
	\n\n\r A task couter is incremented each time the task \"task1\" is waken up\
	\n\r __________   Now Running  __________");
	 

	 OSStatInit();

    OSTaskCreateExt(AppTask1,		  											// p_task code
							(void *)0,												// pdata not used here
							&TaskStartStk[TASK_STK_SIZE-1],   				// p_tos	 (top of stk)
							TASK_2_PRIO,														// Task priority
                   	TASK_2_PRIO,														// Task ID
							&TaskStartStk[0],										// p_bos
							sizeof(AppTask1Stk)/sizeof(OS_STK),				// n of stack words
							(void *)p_tsk_ext, 									// p_Context info 
                   	0);														// Task options


    OSTaskCreateExt(AppTask2,		  											// p_task code
							(void *)0,												// pdata not used here
							&TaskStartStk[TASK_STK_SIZE-1],   				// p_tos	 (top of stk)
							TASK_3_PRIO,														// Task priority
                   	TASK_3_PRIO,														// Task ID
							&TaskStartStk[0],										// p_bos
							sizeof(AppTask1Stk)/sizeof(OS_STK),				// n of stack words
							(void *)p_tsk_ext, 									// p_Context info 
                   	0);														// Task options

	 OSprintf ("\n\r Starting AppStartTask infinite loop" );
    while (TRUE) {                          /* Task body, always written as an infinite loop.          */
		if (first_time)
		{
			first_time=FALSE;
		}
		/*---- Task code goes HERE! -------------------------------------------------------------------*/
        OSTimeDly(1);                       /* Delay task execution for one clock tick                 */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                            TASK #1
*
* Description : This is an example of a task.  
* Arguments   : pdata   is the argument passed to 'AppTask1()' 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  AppTask1 (void *pdata)
{
	 INT32U Task1Ctr=0;
	 static char	q[5];
    														// Task initialization code goes HERE!
	 q[0]='-'; q[1]='\\'; q[2]='|'; q[3]='/';
	 OSprintf ("\n\r Task 1, TaskCtr = %d ", Task1Ctr);
    while (TRUE)                           	// Task body, always written as an infinite loop.
    {    		  										// Task code goes HERE!
        Task1Ctr++;
		  OSprintf ("\r Task1 pass %d    %c", Task1Ctr, q[Task1Ctr&3]);
		  OSTimeDlyHMSM(0, 0, 2,0);				// Delay task execution for 1 second.
		  P0_OUT ^= 0x80;
    }
}

static void  AppTask2 (void *pdata)
{
	 INT32U Task2Ctr=0;
	 INT8U	error;
    														// Task initialization code goes HERE!
	 OSprintf
	("\n\r Task 2 now waiting for an ASC0 interrupt to release the semaphore. \
Pass # %d\n\r",Task2Ctr);
    while (TRUE)                           	// Task body, always written as an infinite loop.
    {    		  										// Task code goes HERE!

		  Task2Ctr++;
			
		  OSSemPend(RxSem, 10000, &error);			// Do a "P" primitive on the semaphore.

		  OSprintf ("\n\r Task 2 waken (pass # %d) up by a receive interrupt or semaphore timed out \n\r",Task2Ctr);

		  OSTimeDly(1);                      	//	Delay task execution for one clock tick
    }
}

⌨️ 快捷键说明

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