/******************************************************************************
 Prototype      : CpuView_TaskSwitchHook
 Description    : 任务切换钩子函数
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_TaskSwitchHook(CPUVIEW_TCB *pOldTcb, CPUVIEW_TCB *pNewTcb)
{
    VOS_INT32           lLockValue;
    VOS_UINT32          ulCurrentSlice;

    if (CPU_VIEW_NO == g_ulTaskWatch)
    {
        return;
    }

    lLockValue      = VOS_SplIMP();

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return;
    }

    /* get current time */
    mdrv_timer_get_rest_time(CPU_VIEW_CLK_ID, TIMER_UNIT_NONE, (unsigned int *)&ulCurrentSlice);

    g_pstCpuView[g_ulCpuViewCnt].ulId       = (VOS_UINT32)pOldTcb;
    g_pstCpuView[g_ulCpuViewCnt].ucType     = CPU_VIEW_TYPE_TASK;
    g_pstCpuView[g_ulCpuViewCnt].ucLev      = CPU_VIEW_LEV_EXIT;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice    = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick     = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC       = (VOS_UINT32)CPU_VIEW_GET_TASK_PC(pOldTcb);
    g_pstCpuView[g_ulCpuViewCnt].ulPara1    = 0;
    g_ulCpuViewCnt++;

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return;
    }

    g_pstCpuView[g_ulCpuViewCnt].ulId       = (VOS_UINT32)pNewTcb;
    g_pstCpuView[g_ulCpuViewCnt].ucType     = CPU_VIEW_TYPE_TASK;
    g_pstCpuView[g_ulCpuViewCnt].ucLev      = CPU_VIEW_LEV_ENTRY;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice    = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick     = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC       = (VOS_UINT32)CPU_VIEW_GET_TASK_PC(pNewTcb);
    g_pstCpuView[g_ulCpuViewCnt].ulPara1    = 0;
    g_ulCpuViewCnt++;

    VOS_Splx(lLockValue);

    return;
} /* CpuView_TaskSwitchHook */
/******************************************************************************
 Prototype      : CpuView_SetPoint
 Description    : 在代码中设置观察点的函数
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_SetPoint(VOS_UINT32 ulId, VOS_UINT8 ucLev, VOS_UINT32 ulPara0, VOS_UINT32 ulPara1)
{
    VOS_INT32   lLockValue;
    VOS_UINT32  ulCurrentSlice;

    if (CPU_VIEW_NO == g_ulPointWatch)
    {
        return;
    }

    lLockValue = VOS_SplIMP();

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return;
    }

    /* get current time */
    mdrv_timer_get_rest_time(CPU_VIEW_CLK_ID, TIMER_UNIT_NONE, (unsigned int *)&ulCurrentSlice);

    g_pstCpuView[g_ulCpuViewCnt].ulId       = ulId;
    g_pstCpuView[g_ulCpuViewCnt].ucType     = CPU_VIEW_TYPE_POINT;
    g_pstCpuView[g_ulCpuViewCnt].ucLev      = ucLev;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice    = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick     = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC       = ulPara0;
    g_pstCpuView[g_ulCpuViewCnt].ulPara1    = ulPara1;
    g_ulCpuViewCnt++;

    VOS_Splx(lLockValue);

    return;
} /* CpuView_SetPoint */
/******************************************************************************
 Prototype      : __cyg_profile_func_exit
 Description    : 函数退出钩子函数
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID __cyg_profile_func_exit(VOS_VOID *this_fn, VOS_VOID *call_site)
{
    VOS_INT32       lLockValue;
    VOS_UINT32      ulCurrentSlice;

    if (CPU_VIEW_NO == g_ulFuncWatch)
    {
        return;
    }

    lLockValue = VOS_SplIMP();

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return;
    }

    /* get current time */
    mdrv_timer_get_rest_time(CPU_VIEW_CLK_ID, TIMER_UNIT_NONE, (unsigned int *)&ulCurrentSlice);

    g_pstCpuView[g_ulCpuViewCnt].ulId       = (VOS_UINT32)this_fn;
    g_pstCpuView[g_ulCpuViewCnt].ucType     = CPU_VIEW_TYPE_FUNC;
    g_pstCpuView[g_ulCpuViewCnt].ucLev      = CPU_VIEW_LEV_EXIT;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice    = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick     = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC       = (VOS_UINT32)call_site;
    g_pstCpuView[g_ulCpuViewCnt].ulPara1    = 0;
    g_ulCpuViewCnt++;

    VOS_Splx(lLockValue);

    return;
} /* __cyg_profile_func_exit */
/******************************************************************************
 Prototype      : CpuView_IntLevChgOutHook
 Description    : 中断切换钩子函数
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_IntLevChgOutHook(VOS_UINT32 ulOldLev)
{
    VOS_INT32           lLockValue;
    VOS_UINT32          ulCurrentSlice;

    if (CPU_VIEW_NO == g_ulTaskWatch)
    {
        return;
    }

    lLockValue = VOS_SplIMP();

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return;
    }

    /* get current time */
    mdrv_timer_get_rest_time(CPU_VIEW_CLK_ID, TIMER_UNIT_NONE, (unsigned int *)&ulCurrentSlice);

    g_pstCpuView[g_ulCpuViewCnt].ulId           = ulOldLev;
    g_pstCpuView[g_ulCpuViewCnt].ucType         = CPU_VIEW_TYPE_INT;
    g_pstCpuView[g_ulCpuViewCnt].ucLev          = CPU_VIEW_LEV_EXIT;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice        = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick         = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC           = 0xFFFFFFFF;
    g_pstCpuView[g_ulCpuViewCnt].ulPara1        = 0;
    g_ulCpuViewCnt++;

    VOS_Splx(lLockValue);

    return;
} /* CpuView_IntLevChgOutHook */
int CpuView_IntLevChgInHook(VOS_UINT32 ulNewLev)
{
    VOS_INT32           lLockValue;
    VOS_UINT32          ulCurrentSlice;

    if (CPU_VIEW_NO == g_ulTaskWatch)
    {
        return VOS_ERR;
    }

    lLockValue = VOS_SplIMP();

    if (CPU_VIEW_YES == CpuView_IsOverturn())
    {
        VOS_Splx(lLockValue);
        return VOS_ERR;
    }

    /* get current time */
    DRV_TIMER_GET_REST_TIME(CPU_VIEW_CLK_ID, TIMER_UNIT_NONE, (unsigned int *)&ulCurrentSlice);

    g_pstCpuView[g_ulCpuViewCnt].ulId           = ulNewLev;
    g_pstCpuView[g_ulCpuViewCnt].ucType         = CPU_VIEW_TYPE_INT;
    g_pstCpuView[g_ulCpuViewCnt].ucLev          = CPU_VIEW_LEV_ENTRY;
    g_pstCpuView[g_ulCpuViewCnt].ulSlice        = ulCurrentSlice;
    g_pstCpuView[g_ulCpuViewCnt].ulTick         = CPU_VIEW_GET_TICK();
    g_pstCpuView[g_ulCpuViewCnt].ulPC           = 0xFFFFFFFF;
    g_pstCpuView[g_ulCpuViewCnt].ulPara1        = 0;
    g_ulCpuViewCnt++;

    VOS_Splx(lLockValue);

    return VOS_OK;
} /* CpuView_IntLevChgInHook */