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

📄 ucos2xxc.c

📁 This code ports the uC/OS operating system by Jean LaBrosse to the TI TMS320C2xx family of DSP s.
💻 C
字号:
/*******************************************************************************
* Module    :   ucosc2xx.c
*
* Purpose   :   TMS320C2xx uC/OS Real Time Operating System.
*				'C' source for machine dependent code of uC/OS, the real-time
*				kernel - create a task, set a default stack.
*
* Language  :
*
* Written   :   Kirby W. Cartwright, The Vanner Power Group, 06/22/98
*
* Modified  :
*
* Project   :   Vanner Power Group Modular Controller Project PX-02.
*
* Copyright :   (C) copyright 1998 by Vanner, Inc.  All Rights Reserved.
*
* Notes     :   Somewhat based on TI's Application Brief "Designing an Embedded
*               Operating System with the TMS320 Familiy of DSPs" and source
*				posted to http://ucos-ii.com by for the 'C31a DSP.
*				The context switch code uses TI's I$$REST 'C' interrupt restore
*				state code block and I$$SAVE save state routine from
*				"rts.src" dated 4/4/95 5:37 pm.
*
*	Software Stack Organization ('C2x, 'C2xx, and 'C5x):
* 	----------------------------------------------------* 		ST0, ST1, ACC, P, T, AR0, AR2, AR3, AR4, AR5, AR6, AR7, h/w stack (8).
*
* Unit Tested:	7/28/98, KWC.
*
*******************************************************************************/
#include	"INCLUDES.H"

/*******************************************************************************
*
* Routine	:   UBYTE OSTaskCreate(void (OS_FAR * task)(void *pd), void *pdata, void *pstk, UBYTE p)
*
* Purpose   : 	"CREATE A TASK."
*
* Inputs    :   pointer to a routine, pointer to context, pointer to stack,
*				and priority.
*
* Globals	:	uC/OS internals.
*
* Outputs (Returns):
*				if OK, OS_NO_ERR, else OS_NO_MORE_TCB or OS_PRIO_EXIST.
*
* Note(s)	:
*
*******************************************************************************/
UBYTE OSTaskCreate(void (OS_FAR * task)(void *pd), void *pdata, void *pstk, UBYTE p)
	{
    UWORD          *stk;
    UBYTE           err;

    OS_ENTER_CRITICAL();
    /*
     * Make sure task doesn't already exist at this priority
     */
    if (OSTCBPrioTbl[p] == (OS_TCB *) 0)
    	{
        OS_EXIT_CRITICAL();
        stk    = (UWORD *) pstk;   	/* Load stack pointer          			*/
        *stk++ = (UWORD) pdata;   	/* arg 0 								*/
        stk++;						/* next word for use.  Task assembly code
        							   will pop return address to here.		*/
		*stk++ = (UWORD) 0x2000;	/* ST1 = ARB = AR1.						*/
        *stk++ = (UWORD) 0x2200;	/* ST0 = AR1 is current Aux. Reg,  		*/
        							/* Interrupts are Enabled, DP is zero. 	*/
        *stk++ = (UWORD) 0x0000;	/* Accumulator high is 0.				*/
        *stk++ = (UWORD) 0x0000;	/* Accumulator low is 0.				*/
		*stk++ = (UWORD) 0x0000;	/* Product High is 0.    				*/
		*stk++ = (UWORD) 0x0000;	/* T is 0.								*/
		*stk++ = (UWORD) 0x0000;	/* Product Low is 0.   					*/
		pstk=stk;
        *stk++ = (UWORD) 0x0000;	/* AR0 = 0.  b.p. = ? 					*/
        *stk++ = (UWORD) 0x0000;	/* AR2 = 0 								*/
        *stk++ = (UWORD) 0x0000;	/* AR3 = 0 								*/
        *stk++ = (UWORD) 0x0000;	/* AR4 = 0 								*/
        *stk++ = (UWORD) 0x0000;	/* AR5 = 0 								*/
        *stk++ = (UWORD) 0x0000;	/* AR6 = 0 								*/
        *stk++ = (UWORD) 0x0000;	/* AR7 = 0 								*/
        *stk++ = (UWORD) task;  	/* Interrupt return address = start of task */
        *stk++ = (UWORD) c_int0;
        *stk++ = (UWORD) c_int0;
        *stk++ = (UWORD) c_int0;
        *stk++ = (UWORD) c_int0;  	/* Initialize the h/w stack.			*/
        *stk++ = (UWORD) c_int0;
        *stk++ = (UWORD) c_int0;	/* reset if an unbalanced return.		*/


        * (UWORD *)pstk=(UWORD)stk;	/* now set frame pointer.				*/
        /*
         * Get and initialize a TCB
         */
        if ((err = OSTCBInit(p, (void OS_FAR *)stk)) == OS_NO_ERR) {
            /*
             * Find highest priority task if multitasking has started
             */
            if (OSRunning)
                OSSched();
        }
        return err;
    }
    OS_EXIT_CRITICAL();
    return OS_PRIO_EXIST;
	}

⌨️ 快捷键说明

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