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

📄 os_cpu_c.c

📁 ucos内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
void OSInitHookBegin (void)
{
    if (g_pOsInitHookBeginRoutine != NULL)
    {
        (*g_pOsInitHookBeginRoutine)();
    }
}
#endif

/*
*********************************************************************************************************
*                                       OS INITIALIZATION HOOK
*                                               (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookEnd (void)
{
    if (g_pOsInitHookEndRoutine != NULL)
    {
        (*g_pOsInitHookEndRoutine)();
    }
}
#endif


/*
*********************************************************************************************************
*                                          TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskCreateHook (OS_TCB *ptcb)
{
    #if OS_VIEW_MODULE > 0
    OSView_TaskCreateHook(ptcb);
    #endif
    
    if (g_pOsTaskCreateHookRoutine != NULL)
    {
        (*g_pOsTaskCreateHookRoutine)(ptcb);
    }
}

/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
#if OS_TASK_DEL_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
    if (g_pOsTaskDelHookRoutine != NULL)
    {
        (*g_pOsTaskDelHookRoutine)(ptcb);
    }
}
#endif

/*
*********************************************************************************************************
*                                           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_TASK_SW_HOOK_EN > 0
void OSTaskSwHook (void)
{
    #if OS_VIEW_MODULE > 0
    OSView_TaskSwHook();
    #else
    #if OS_TASK_PROFILE_EN > 0
    OSTCBCur->OSTCBCyclesTot      += OSTime - OSTCBCur->OSTCBCyclesStart;// This task is done
    OSTCBHighRdy->OSTCBCyclesStart = OSTime;                             // Save absolute #cycles at task activation
    #endif
    #endif
    
    if (g_pOsTaskSwHookRoutine != NULL)
    {
        (*g_pOsTaskSwHookRoutine)();
    }
}
#endif

/*
*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your
*              application to add functionality to the statistics task.
*
* Arguments  : none
*********************************************************************************************************
*/
#if OS_TASK_STAT_EN > 0
void OSTaskStatHook (void)
{
    if (g_pOsTaskStatHookRoutine != NULL)
    {
        (*g_pOsTaskStatHookRoutine)();
    }
}
#endif

/*
*********************************************************************************************************
*                                           OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() 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_VERSION >= 204
void OSTCBInitHook (OS_TCB *ptcb)
{
    if (g_pOsTcbInitHookRoutine != NULL)
    {
        (*g_pOsTcbInitHookRoutine)(ptcb);
    }
}
#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_TIME_TICK_HOOK_EN > 0
void OSTimeTickHook (void)
{
    #if OS_VIEW_MODULE > 0
    OSView_TickHook();
    #endif
    
    #if OS_CLK_EN > 0
    ClkSignalClk();
    #endif
    
    if (g_pOsTimeTickHookRoutine != NULL)
    {
        g_pOsTimeTickHookRoutine();
    }
}
#endif

/*
*********************************************************************************************************
*                                             IDLE TASK HOOK
*
* Description: This function is called by the idle task.  This hook has been added to allow you to do  
*              such things as STOP the CPU to conserve power.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 251
void OSTaskIdleHook (void)
{
    if (g_pOsTaskIdleHookRoutine != NULL)
    {
        g_pOsTaskIdleHookRoutine();
    }
}
#endif

#endif

//------------------------------------------------------------------------------
// 函数描述:初始化定时器的中断处理程序
void Timer0Isr(void)
{	
    //OS_ENTER_CRITICAL();
	
    T0IR = 0x01;    
    VICVectAddr = 0;//interrupt close 通知中断控制器中断结束
    
    OSTimeTick();   
    
    //OS_EXIT_CRITICAL();   
    
     
}

//------------------------------------------------------------------------------
// 函数描述:初始化定时器0
void Timer0Init(void)
{
    IntConnect(INT_NUM_TIMER0, Timer0Isr);
    
    T0IR = 0xffffffff;
    T0TC = 0;

    SET_BITS(T0TCR, T0TCR_T0_EN_MASK);
    SET_BITS(T0MCR, (T0MCR_INTMR0_MASK | T0MCR_RSTMR0_MASK));
    
    T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
    
    IntEnable(INT_NUM_TIMER0);
 }

//------------------------------------------------------------------------------
// 函数描述:开始uC/OS II的系统节拍
void OSTickStart(void)
{
    OS_ENTER_CRITICAL();
    
    Timer0Init();
    
    OS_EXIT_CRITICAL();
}

/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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