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

📄 ucosppcc.c

📁 ppc860平台上移植uc OS的实例
💻 C
字号:
/* file: ucosppcc.c */
/************************************************************
*                      UCOSPPCC.C
*               PowerPC Specific Code
************************************************************/

/************************************************************
*                     INCLUDE FILES
************************************************************/
#include "INCLUDES.H"
#ifdef TM_MPC860
#include <trsocket.h>
#include <trmpc860.h>
#endif /* TM_MPC860 */

/*
************************************************************
*                    Defines
************************************************************
*/

/*
 * MPC860 Specific Code
 */
#ifdef TM_MPC860
void OSSetUpTimer(void);
void OSTickISR(void);
void OSInstallSuiIsr(void *funcPtr, unsigned long offSet);
void OSCpicInterrupt(void);
void OSNoInterrupt(void);
void OSSIUInterrupt(void);
#define TM_MAX_VECTORS       16
#define TM_MAX_CPIC_VECTORS  30 

/*
 * Typedef for the SIU
 */
typedef struct {
    void (*vectFuncPtr)(void);
} ttVector;

typedef void (*ttVectPtr)();

/*
 * The SIU Vector Table
 */
ttVector tvVectorTable[TM_MAX_VECTORS];

/*
 * The CPIC Vector Table
 */
ttVector tvCpicVectorTable[TM_MAX_CPIC_VECTORS];
#endif /* TM_MPC860 */



#define NUMBER_REGISTERS 30
#define INITIAL_SR       0x8000
extern unsigned long _SDA_BASE_;
extern unsigned long _SDA2_BASE_;

/***********************************************************
*                    CREATE A TASK
************************************************************/
UBYTE OSTaskCreate(void (*task)(void *dptr), void  *data, void  *pstk, UBYTE  p)
{
    long  *stk;
    int   regCount;
    UBYTE err;


/* get tasks stack pointer (LONG WORD ALIGNED) */
     stk              = (long *)((long) pstk &
                        (long) 0xfffffffcL);  

/* Avoid creating task if already exist */
    if (OSTCBPrioTbl[p] == (OS_TCB *)0) 
	{
/* save the status register */
        *--stk = INITIAL_SR;    /* MSR */  	
        *--stk = 0L;            /* r31 */
        *--stk = 0L;            /* r30 */
        *--stk = 0L;            /* r29 */
        *--stk = 0L;            /* r28 */
        *--stk = 0L;            /* r27 */
        *--stk = 0L;            /* r26 */
        *--stk = 0L;            /* r25 */
        *--stk = 0L;            /* r24 */
        *--stk = 0L;            /* r23 */
        *--stk = 0L;            /* r22 */
        *--stk = 0L;            /* r21 */
        *--stk = 0L;            /* r20 */
        *--stk = 0L;            /* r19 */
        *--stk = 0L;            /* r18 */
        *--stk = 0L;            /* r17 */
        *--stk = 0L;            /* r16 */
        *--stk = 0L;            /* r15 */
        *--stk = 0L;            /* r14 */
        --stk;                  /* r13  Processor Initialized */
        *--stk = 0L;            /* r12 */
        *--stk = 0L;            /* r11 */
        *--stk = 0L;            /* r10 */
        *--stk = 0L;            /* r09 */
        *--stk = 0L;            /* r08 */
        *--stk = 0L;            /* r07 */
        *--stk = 0L;            /* r06 */
        *--stk = 0L;            /* r05 */
        *--stk = 0L;            /* r04 */
        *--stk = (long)data;    /* r03 */
        --stk;                  /* r02  Processor Initialized */
        --stk;                  /* BLANK */
        *--stk = (long)task;    /* LR */
        --stk;                  /* CR */
        --stk;                  /* XCR */
        --stk;                  /* CTR */
        *--stk = INITIAL_SR;    /* SRR1 */  	
        *--stk = (long)task;    /* SRR0 */
        --stk;                  /* R0 */
        --stk;                  /* BLANK */
        *--stk = (long)pstk;    /* Stack Ptr */

/* Get and initialize a TCB */
        err = OSTCBInit(p, (void *)stk); 
        if (err == OS_NO_ERR) 
        {
            if (OSRunning) 
            {
/* Find highest priority task if multitasking has started */
                OSSched();
            }
        }
        return (err);
    } 
    else 
    {
        OS_EXIT_CRITICAL();
        return (OS_PRIO_EXIST);
    }
}

#ifdef TM_MPC860
volatile static ttMpc860 *tl860Ptr;
unsigned long tlIsrCount;

int __init_main()
{
	__init();
    __tfInit860(TM_MPC860_IMMR_LOC);
    main();
}

/*
 * Initialize the SUI (System Integration Unit)
 * We need this to setup the timer
 * After it is setup, go ahead and setup timer
 */
void OSSetUpTimer()
{
	int vectorIndex;
    unsigned long  mpc860Registers;
    unsigned char  timerVector;
    unsigned long  timerLocation;

    
    mpc860Registers=TM_MPC860_IMMR_LOC;
    tl860Ptr = (ttMpc860 *)(mpc860Registers&0xfffffffc);
/* Reset the CP on the 860 */
    tl860Ptr->cp_cr = 0x8001;
    while (tl860Ptr->cp_cr != 0)
    {
        ;
    }
/* Clear the SUI interrupt table */
	for ( vectorIndex = 0; vectorIndex < TM_MAX_VECTORS; vectorIndex++ )
		tvVectorTable[vectorIndex].vectFuncPtr = OSNoInterrupt;
/* Clear the CPIC interrupt table */
	for ( vectorIndex = 0; vectorIndex < TM_MAX_CPIC_VECTORS; vectorIndex++ )
		tvCpicVectorTable[vectorIndex].vectFuncPtr = OSNoInterrupt;
    
/* Install the master cpic vector */
    OSInstallSuiIsr((void *)OSCpicInterrupt,TM_MPC860_CPIC_SIVEC);
/* Unmask the SUI Level */
    tl860Ptr->siu_simask |= TM_MPC860_CPIC_MASK; 
    
    tl860Ptr->timer_tgcr=0x0000;
/* Install the Timer Cpic Vector */
    OSInstallISR((void *)OSTickISR,TM_MPC860_TMR1_INT);

    tl860Ptr->intr_cicr=TM_MPC860_CICR_DEFAULT;
    tl860Ptr->intr_cipr = 0xffffffffUL;
    tl860Ptr->intr_cisr |= TM_MPC860_TMR1_INT_MASK;
    tl860Ptr->intr_cimr = TM_MPC860_TMR1_INT_MASK;
/* 
 * The MPC860 Timer Clock is either 25mhz or 40mhz
 * for 25mhz:
 * We use a divide by value of 4 so that the clock appears to be
 * running at 6.25mhz.  We then wait for the clock to count down
 * from 62500 to 0 to get a 10ms resolution
 *
 * for 40Mhz:
 * We use a divide by value of 8 so that the clock appears to be
 * running at 5.00mhz.  We then wait for the clock to count down
 * from 50000 to 0 to get a 10ms resolution
 */

/* 
 * Set the Mode register to divide by x, Interrupt, Auto Restart (FRR)
 * and use the internal system clock
 * Note: The prescale value ranges 0 - 255 and represents the divide by
 * number of 1 - 256.  That is why there is a x-1 for the prescale 
 */
/*    tl860Ptr->timer_tmr1=0x031a; */
    tl860Ptr->timer_tmr1=0x071a; 
/* Clear the count */
    tl860Ptr->timer_tcn1=0x0000;
/* Set the reference value to 62500 */
/*    tl860Ptr->timer_trr1=0xF424; */
/* Set the reference value to 50000 */
    tl860Ptr->timer_trr1=0xC350; 
/* Clear the events */
    tl860Ptr->timer_ter1=0xFFFF;
/* Start the timer */
    tl860Ptr->timer_tgcr=0x0005;
}




/*
 * MPC 860 Main Interrupt Handler from the SIU
 * All MPC860 Interrupts are called through the SIU
 */
void OSSIUInterrupt()
{
	OSIntEnter();
	tlIsrCount++; 
/* Call the specific Interrupt Handler	*/
	(tvVectorTable[tl860Ptr->siu_sivec>>26].vectFuncPtr)();		
	OSIntExit();
}



/*
 * NULL Interrupt for ISR that are not processed
 */
void OSNoInterrupt(void)
{
}

/*
 * Install a SUI ISR
 */
void OSInstallSuiIsr(void *funcPtr, unsigned long offSet)
{
    tlIsrCount=0;
    tvVectorTable[offSet>>26].vectFuncPtr=(ttVectPtr)funcPtr;
}

/*
 * Install a CPIC ISR
 */
void OSInstallISR(void *funcPtr, unsigned long offSet)
{
    tvCpicVectorTable[offSet].vectFuncPtr=(ttVectPtr)funcPtr;
}
/*
 * Master CPIC Interrupt Handler
 */
void OSCpicInterrupt(void)
{
    tl860Ptr->intr_civr |= TM_MPC860_CIVR_IACK; 
	(tvCpicVectorTable[tl860Ptr->intr_civr>>11].vectFuncPtr)();		
}


/*
 * Timer ISR
 */
void OSTickISR(void)
{
	OSTimeTick();
    tl860Ptr->timer_ter1=0xFFFF;
    tl860Ptr->intr_cisr |= TM_MPC860_TMR1_INT_MASK;
}



/*
 * MPC860 ISR
 */
void tfMpc860Scc1Isr(void)
{
    tfMpc860Scc1HandlerIsr();
}
#endif /* TM_MPC860 */

⌨️ 快捷键说明

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