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

📄 os_cpu_c.c

📁 uCosII是一个小型的多任务调度内核
💻 C
📖 第 1 页 / 共 2 页
字号:
        *(--stk) = (INT32U)ARM_SVC_MODE_ARM;                            /* CPSR  (Enable IRQ interrupts, ARM-mode)     */
    }

    return (stk);
}

/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
*                 task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TASK_SW_HOOK_EN > 0)
void  OSTaskSwHook (void)
{
#if OS_CPU_FPU_EN > 0
    void  *pblk;
#endif

#if OS_CPU_FPU_EN > 0                                      /* Save VFP context of preempted task       */
    if (OSRunning == OS_TRUE) {                            /* Don't save on OSStart()!                 */
        if (OSTCBCur->OSTCBOpt & OS_TASK_OPT_SAVE_FP) {    /* See if task used FP                      */
            pblk = OSTCBCur->OSTCBExtPtr;                  /* Yes, Get pointer to FP storage area      */
            if (pblk != (void *)0) {                       /*      Make sure we have storage           */
                OS_CPU_FP_Save(pblk);                      /*      Save the VFP registers in block     */
            }
        }
    }
                                                           /* Restore VFP context of new task          */
    if (OSTCBHighRdy->OSTCBOpt & OS_TASK_OPT_SAVE_FP) {    /* See if new task uses FP                  */
        pblk = OSTCBHighRdy->OSTCBExtPtr;                  /* Yes, Get pointer to FP storage area      */
        if (pblk != (void *)0) {                           /*      Make sure we have storage           */
            OS_CPU_FP_Restore(pblk);                       /*      Get contents of VFP registers       */
        }
    }
#endif

#if OS_VIEW_MODULE > 0
    OSView_TaskSwHook();
#endif
}
#endif

/*
*********************************************************************************************************
*                                           OS_TCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
*
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSTCBInitHook (OS_TCB *ptcb)
{
    (void)ptcb;                                                         /* Prevent Compiler warning                                 */
}
#endif


/*
*********************************************************************************************************
*                                               TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TIME_TICK_HOOK_EN > 0)
void  OSTimeTickHook (void)
{
#if OS_VIEW_MODULE > 0
    OSView_TickHook();
#endif

#if OS_TMR_EN > 0
    OSTmrCtr++;
    if (OSTmrCtr >= (OS_TICKS_PER_SEC / OS_TMR_CFG_TICKS_PER_SEC)) {
        OSTmrCtr = 0;
        OSTmrSignal();
    }
#endif

#if OS_CPU_ARM_DCC_EN > 0
    OSDCC_Handler();
#endif
}
#endif


/*
*********************************************************************************************************
*                             INTERRUPT DISABLE TIME MEASUREMENT, START
*********************************************************************************************************
*/

#if OS_CPU_INT_DIS_MEAS_EN > 0
void  OS_CPU_IntDisMeasInit (void)
{
    OS_CPU_IntDisMeasNestingCtr = 0;
    OS_CPU_IntDisMeasCntsEnter  = 0;
    OS_CPU_IntDisMeasCntsExit   = 0;
    OS_CPU_IntDisMeasCntsMax    = 0;
    OS_CPU_IntDisMeasCntsDelta  = 0;
    OS_CPU_IntDisMeasCntsOvrhd  = 0;
    OS_CPU_IntDisMeasStart();                                           /* Measure the overhead of the functions                    */
    OS_CPU_IntDisMeasStop();
    OS_CPU_IntDisMeasCntsOvrhd  = OS_CPU_IntDisMeasCntsDelta;
}


void  OS_CPU_IntDisMeasStart (void)
{
    OS_CPU_IntDisMeasNestingCtr++;
    if (OS_CPU_IntDisMeasNestingCtr == 1) {                             /* Only measure at the first nested level                   */
        OS_CPU_IntDisMeasCntsEnter = OS_CPU_IntDisMeasTmrRd();
    }
}


void  OS_CPU_IntDisMeasStop (void)
{
    OS_CPU_IntDisMeasNestingCtr--;                                      /* Decrement nesting ctr                                    */
    if (OS_CPU_IntDisMeasNestingCtr == 0) {
        OS_CPU_IntDisMeasCntsExit  = OS_CPU_IntDisMeasTmrRd();
        OS_CPU_IntDisMeasCntsDelta = OS_CPU_IntDisMeasCntsExit - OS_CPU_IntDisMeasCntsEnter;
        if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsOvrhd) {  /* Ensure overhead < delta                                  */
            OS_CPU_IntDisMeasCntsDelta -= OS_CPU_IntDisMeasCntsOvrhd;
        } else {
            OS_CPU_IntDisMeasCntsDelta  = OS_CPU_IntDisMeasCntsOvrhd;
        }
        if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsMax) {    /* Track MAXIMUM                                            */
            OS_CPU_IntDisMeasCntsMax = OS_CPU_IntDisMeasCntsDelta;
        }
    }
}
#endif


/*
*********************************************************************************************************
*                                     INITIALIZE EXCEPTION VECTORS
*
* Description : This function initialize exception vectors to the default handlers.
*
* Arguments   : None.
*********************************************************************************************************
*/

void  OS_CPU_InitExceptVect (void)
{
/*
    (*(INT32U *)OS_CPU_ARM_EXCEPT_RESET_VECT_ADDR)             =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_RESET_HANDLER_ADDR)          = (INT32U)OS_CPU_ARM_ExceptResetHndlr;


    (*(INT32U *)OS_CPU_ARM_EXCEPT_UNDEF_INSTR_VECT_ADDR)       =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_UNDEF_INSTR_HANDLER_ADDR)    = (INT32U)OS_CPU_ARM_ExceptUndefInstrHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_SWI_VECT_ADDR)               =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_SWI_HANDLER_ADDR)            = (INT32U)OS_CPU_ARM_ExceptSwiHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_PREFETCH_ABORT_VECT_ADDR)    =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_PREFETCH_ABORT_HANDLER_ADDR) = (INT32U)OS_CPU_ARM_ExceptPrefetchAbortHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_DATA_ABORT_VECT_ADDR)        =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_DATA_ABORT_HANDLER_ADDR)     = (INT32U)OS_CPU_ARM_ExceptDataAbortHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_ADDR_ABORT_VECT_ADDR)        =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_ADDR_ABORT_HANDLER_ADDR)     = (INT32U)OS_CPU_ARM_ExceptAddrAbortHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_IRQ_VECT_ADDR)               =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_IRQ_HANDLER_ADDR)            = (INT32U)OS_CPU_ARM_ExceptIrqHndlr;

    (*(INT32U *)OS_CPU_ARM_EXCEPT_FIQ_VECT_ADDR)               =         OS_CPU_ARM_INSTR_JUMP_TO_HANDLER;
    (*(INT32U *)OS_CPU_ARM_EXCEPT_FIQ_HANDLER_ADDR)            = (INT32U)OS_CPU_ARM_ExceptFiqHndlr;
*/

}

/* added by wyf */
void       OS_CPU_ExceptHndlr(INT32U  except_type)
{
;

}

void OSMain(void);

void OS_CInitialize(void *memory)
{
	OSInit();
	OS_SysPoolInit(memory);
	OSMain();
	OSStart();
}

INT32U OS_Registered_LISRs[OS_MAX_VECTORS];
void (*OS_LISR_Pointers[OS_MAX_LISRS])(INT32U);


void  OS_Dispatch_LISR(int vector)
{

	INT32U index;                      /* Working index variable    */

    /* Determine if the specified vector has an LISR registered to it.  */
    index = OS_Registered_LISRs[vector];
    if (index)
    
        /* Yes, an LISR is associated with this vector.  Call the actual 
           registered LISR routine.  */
        (*(OS_LISR_Pointers[index])) (vector);
    else
    {
        /* System error, unhandled interrupt.  */
        while(1);
    }
}

INT8U OS_RegisterISR(INT32U vector, void(*isr)(INT32U))
{

	INT32U index;                      /* Working index variable    */
	INT8U status;                     /* Completion status         */
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr = 0;
#endif

    /* Determine if the vector is legal. */
    if ((vector >= OS_MAX_VECTORS)||(vector == OS_REVD_VECTOR))
        return OS_ERR_INVALID_VECTOR;

	if (isr == (void *)0) return OS_ERR_INVALID_ISRENTRY;

    /* Initialize the completion status to successful.  */
    status =  OS_NO_ERR;

    /* Protect against LISR registration list access.  */
    OS_ENTER_CRITICAL();

    
    /* Determine if the vector already has a registration.  */
    if (OS_Registered_LISRs[vector])
    {
    
        /* Yes, a registration exists.  */
        
        /* Pickup the index into the LISR pointer list.  */
        index = OS_Registered_LISRs[vector];
        
        /* Temporarily indicate that the LISR is not registered.  */
        OS_Registered_LISRs[vector] =  0;
        
        /* Place the new LISR into the list. */
        OS_LISR_Pointers[index] = isr;
        
        /* Indicate the LISR is registered again.  */
        OS_Registered_LISRs[vector] = index;
    }
    else
    {
    
        /* An empty slot needs to be found in the LISR pointers list.  */
        
        index =  1;
        while ((OS_LISR_Pointers[index] != (void *)0) && (index < OS_MAX_LISRS))
            index++;
            
        /* Determine if an empty slot was found.  */
        if (index < OS_MAX_LISRS)
        {
        
            /* Yes, an empty slot was found.  */
            
            /* Place the new LISR in the LISR pointers list.  */
            OS_LISR_Pointers[index] = isr;
            
            /* Associate the index into the pointers list to the actual
               vector.  */
            OS_Registered_LISRs[vector] = index;
            
        }
        else
        
            /* Return the completion status that indicates that there
               is no more room in the LISR pointers list.  */
            status =  OS_ERR_NOMORE_ISRS;    
    }
    
    /* Release protection on the LISR registration list.  */
    OS_EXIT_CRITICAL();

    /* Return the completion status.  */
    return(status);
}

void OS_ISRInit(void)
{
	INT32U i;

    for (i = 0; i < OS_MAX_VECTORS; i++)
        OS_Registered_LISRs[i] =  0;
        
    for (i = 0; i < OS_MAX_LISRS; i++)
        OS_LISR_Pointers[i] =  (void *)0;

}

⌨️ 快捷键说明

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