VOS_VOID CpuView_Start(VOS_UINT32 ulMode)
{
    VOS_INT32         lLockValue;

    if (CPU_VIEW_NO == g_ulCpuViewInitFlag)
    {
        /* 按照默认值初始化 */
        CpuView_Init(CPU_VIEW_MEMORY_MODE_DYNAMIC, 0);
    }

    if (CPU_VIEW_YES == g_ulCpuViewStartFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView is already started!\r\n");
        return;
    }

    g_ulCpuViewMode = ulMode;

    CpuView_OpenPointWatch();
    CpuView_OpenTaskWatch();
    CpuView_OpenFuncWatch();

    lLockValue = VOS_SplIMP();
    g_ulCpuViewCnt          = 0;
    g_ulCpuViewOC           = CPU_VIEW_RECORD_OVERTURN_NO;
    g_ulCpuViewStartFlag    = CPU_VIEW_YES;
    VOS_Splx(lLockValue);

    CPU_VIEW_LOG_PRINT("CpuView Start......\r\n");

    return;
} /* CpuView_Start */
/******************************************************************************
 Prototype      : CpuView_CloseTaskWatch
 Description    : 关闭任务跟踪
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

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

    if (CPU_VIEW_NO == g_ulTaskWatch)
    {
        return;
    }

    lLockValue       = VOS_SplIMP();

    g_ulTaskWatch   = CPU_VIEW_NO;

    /* 关闭中断切换跟踪 */
    mdrv_int_unregister_enterhook();
    mdrv_int_unregister_exithook();

    /* 关闭任务切换跟踪 */
    if ( VOS_OK != CPU_VIEW_DEL_TASK_SWITCH_HOOK( (FUNCPTR)CpuView_TaskSwitchHook ) )
    {
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("CpuView_CloseTaskWatch CPU_VIEW_DEL_TASK_SWITCH_HOOK fail!\r\n");
        return;
    }

    VOS_Splx(lLockValue);

    return;
} /* CpuView_CloseTaskWatch */
VOS_VOID CpuView_CloseTaskWatch(VOS_VOID)
{
    VOS_INT32     lLockValue;

    if (CPU_VIEW_NO == g_ulTaskWatch)
    {
        return;
    }

    lLockValue       = VOS_SplIMP();

    g_ulTaskWatch   = CPU_VIEW_NO;

    /* 关闭中断切换跟踪 */
    DRV_VICINT_LVLCHG_HOOK_DEL();
    DRV_VICINT_EXIT_HOOK_DEL();

    /* 关闭任务切换跟踪 */
    if ( VOS_OK != CPU_VIEW_DEL_TASK_SWITCH_HOOK( (FUNCPTR)CpuView_TaskSwitchHook ) )
    {
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("CpuView_CloseTaskWatch CPU_VIEW_DEL_TASK_SWITCH_HOOK fail!\r\n");
        return;
    }

    VOS_Splx(lLockValue);

    return;
} /* CpuView_CloseTaskWatch */
/******************************************************************************
 Prototype      : CpuView_OpenTaskWatch
 Description    : 开启任务跟踪
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

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

    if (CPU_VIEW_NO == g_ulCpuViewInitFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView_OpenTaskWatch, CpuView is not initialized!\r\n");
        return;
    }

    if (CPU_VIEW_YES == g_ulTaskWatch)
    {
        CPU_VIEW_LOG_PRINT("WatchTask is already opened!\r\n");
        return;
    }

    CpuView_GetTaskName();

    lLockValue = VOS_SplIMP();

    if ( VOS_OK != CPU_VIEW_ADD_TASK_SWITCH_HOOK( (FUNCPTR)CpuView_TaskSwitchHook ) )
    {
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("CpuView_OpenTaskWatch CPU_VIEW_ADD_TASK_SWITCH_HOOK fail!\r\n");
        return;
    }

    mdrv_int_register_enterhook((FUNCPTR_1)CpuView_IntLevChgInHook);
    mdrv_int_register_exithook((FUNCPTR_1)CpuView_IntLevChgOutHook);

    g_ulTaskWatch   = CPU_VIEW_YES;
    VOS_Splx(lLockValue);

    CPU_VIEW_LOG_PRINT("WatchTask open successfully!\r\n");

    return;
} /* CpuView_OpenTaskWatch */
/******************************************************************************
 Prototype      : CpuView_OpenFuncWatch
 Description    : 开启函数跟踪
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

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

    if (CPU_VIEW_NO == g_ulCpuViewInitFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView_OpenFuncWatch, CpuView is not initialized!\r\n");
        return;
    }

    if (CPU_VIEW_YES == g_ulFuncWatch)
    {
        CPU_VIEW_LOG_PRINT("CpuView_OpenFuncWatch is already opened!\r\n");
        return;
    }

    lLockValue = VOS_SplIMP();
    g_ulFuncWatch   = CPU_VIEW_YES;
    VOS_Splx(lLockValue);

    CPU_VIEW_LOG_PRINT("FuncWatch open successfully!\r\n");

    return;
} /* CpuView_OpenFuncWatch */
VOS_VOID CpuView_End(VOS_VOID)
{
    if (CPU_VIEW_NO == g_ulCpuViewStartFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView is not started!\r\n");
        return;
    }

    CpuView_ClosePointWatch();
    CpuView_CloseTaskWatch();
    CpuView_CloseFuncWatch();

    g_ulCpuViewStartFlag = CPU_VIEW_NO;

    return;
} /* CpuView_End */
/******************************************************************************
 Prototype      : CpuView_BaseAddrPrint
 Description    : 打印CPU_VIEW所使用的地址
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_InfoPrint(VOS_VOID)
{
    if ((CPU_VIEW_NO == g_ulCpuViewInitFlag) || (VOS_NULL == g_pstCpuViewCtrl))
    {
        CPU_VIEW_LOG_PRINT("CpuView is not initialized!\r\n");
        return;
    }

    CPU_VIEW_LOG_PRINT1("CpuViewCtrl Base Addr:0x%x\r\n", (VOS_INT)g_pstCpuViewCtrl);
    CPU_VIEW_LOG_PRINT1("CpuView Base Addr:0x%x\r\n", (VOS_INT)g_pstCpuViewCtrl->pstCpuView);

    CPU_VIEW_LOG_PRINT1("CpuView Mode:%d\r\n", (VOS_INT)g_pstCpuViewCtrl->ulCpuViewMode);
    CPU_VIEW_LOG_PRINT1("CpuView TraceCnt:%d\r\n", (VOS_INT)g_pstCpuViewCtrl->ulCpuViewTraceCnt);
    CPU_VIEW_LOG_PRINT1("CpuView Cnt:%d\r\n", (VOS_INT)g_pstCpuViewCtrl->ulCpuViewCnt);
    CPU_VIEW_LOG_PRINT1("CpuView OC:%d\r\n", (VOS_INT)g_pstCpuViewCtrl->ulCpuViewOC);
    CPU_VIEW_LOG_PRINT1("CpuView TaskNumber:%d\r\n", (VOS_INT)g_pstCpuViewCtrl->ulTaskNumber);

    return;
}
VOS_VOID CpuView_StopTimer(VOS_VOID)
{
    VOS_INT32         lValue;

    if (CPU_VIEW_NO == g_ulCpuViewTimerFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView_StartTimer Timer is already Stopped!\r\n");
        return;
    }

    /* disenable CPU_VIEW timer,时钟频率为19.2MHz */
    lValue = mdrv_timer_stop(CPU_VIEW_CLK_ID);
    if (0 > lValue)
    {
        CPU_VIEW_LOG_PRINT1("CpuView_StopTimer Stop Timer Fail:%d\r\n", lValue);
        return;
    }

    g_ulCpuViewTimerFlag = CPU_VIEW_NO;

    return;
}
VOS_VOID CpuView_StartTimer(VOS_VOID)
{
    VOS_INT32         lValue;

    if (CPU_VIEW_YES == g_ulCpuViewTimerFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView_StartTimer Timer is already Started!\r\n");
        return;
    }

    /* enable CPU_VIEW timer,时钟频率为19.2MHz */
    lValue = mdrv_timer_start(CPU_VIEW_CLK_ID, VOS_NULL, 0, TIMER_MAX_VALUE, TIMER_PERIOD_COUNT, TIMER_UNIT_NONE);
    if (0 > lValue)
    {
        CPU_VIEW_LOG_PRINT1("CpuView_StartTimer Start Timer Fail:%d\r\n", lValue);
        return;
    }

    g_ulCpuViewTimerFlag = CPU_VIEW_YES;

    return;
}
/******************************************************************************
 Prototype      : CpuView_Restart
 Description    : 重启监测
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

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

    if (CPU_VIEW_NO == g_ulCpuViewStartFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView is not started,please start first!\r\n");
        return;
    }

    lLockValue = VOS_SplIMP();

    g_ulPointWatch      = CPU_VIEW_YES;
    g_ulTaskWatch       = CPU_VIEW_YES;
    g_ulFuncWatch       = CPU_VIEW_YES;

    g_ulCpuViewOC       = CPU_VIEW_RECORD_OVERTURN_NO;
    g_ulCpuViewCnt      = 0;

    VOS_Splx(lLockValue);

    return;
} /* CpuView_Restart */
/******************************************************************************
 Prototype      : CpuView_Dump
 Description    : 输出结果到主机文件上
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_Dump(VOS_UINT32 ulDumpMode)
{
    FILE                               *fp;
    VOS_CHAR                            acDumpFileName[500];
    static VOS_UINT8                    s_ucDumpFileNO = 0;
    VOS_INT                             iRet;
    VOS_INT32                           lLockValue;

    /* cpu_View未初始化,则按照默认值进行初始化 */
    if (CPU_VIEW_NO == g_ulCpuViewInitFlag)
    {
        /* 按照默认值初始化 */
        CpuView_Init(CPU_VIEW_MEMORY_MODE_DYNAMIC, 0);

        /* 非循环模式 */
        CpuView_Start(CPU_VIEW_RECORD_MODE_CYCLE_NO);

        /* 等待10s */
        CPU_VIEW_TASK_DELAY(1000);
    }

    /* cpu_View未开始,则按照默认值开始 */
    if (CPU_VIEW_NO == g_ulCpuViewStartFlag)
    {
        /* 非循环模式 */
        CpuView_Start(CPU_VIEW_RECORD_MODE_CYCLE_NO);

        /* 等待10s */
        CPU_VIEW_TASK_DELAY(1000);
    }

    if ( (VOS_NULL == g_pstCpuView)
        || ((0 == g_ulCpuViewCnt) && (CPU_VIEW_RECORD_OVERTURN_NO == g_ulCpuViewOC)) )
    {
        CPU_VIEW_LOG_PRINT("CpuView_DumpTrace, No Trace need dump!\r\n");
        return;
    }

    CpuView_End();

    CPU_VIEW_LOG_PRINT("CpuView Dump Begin ............\r\n");

    lLockValue = VOS_SplIMP();

    if (CPU_VIEW_DUMP_GEN_MODE_FLASH == ulDumpMode)    /* 输出到FLASH */
    {
#if (FEATURE_ON == FEATURE_MULTI_FS_PARTITION) /* SFT board*/
        sprintf(acDumpFileName, "/data/hisi_logs/cp_log/coredump/CpuView%d.dump", s_ucDumpFileNO);
#else
        sprintf(acDumpFileName, "/yaffs0/CpuView%d.dump", s_ucDumpFileNO);
#endif

        fp  = mdrv_file_open(acDumpFileName, "wb");
    }
    /* 暂不支持输出到网卡 */
#if 0
    else if (CPU_VIEW_DUMP_GEN_MODE_NETCARD == ulDumpMode)   /* 输出到网卡 */
    {
        CPU_VIEW_LOG_PRINT("Dump to Host!\r\n");
        fp  = DRV_FILE_OPEN("host:CpuView.dump", "wb");
    }
#endif
    else
    {
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("Not support Dump file mode,Please check again!\r\n");

        return;
    }

    if (VOS_NULL == fp)
    {
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("Open File Fail!\r\n");

        return;
    }

    iRet = mdrv_file_write(g_pstCpuViewCtrl, sizeof(CPU_VIEW_CTRL_STRU), 1, fp);
    if (-1 ==  iRet)
    {
        mdrv_file_close(fp);
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("Write Control Info Fail!\r\n");

        return;
    }

    iRet = mdrv_file_write(g_pstCpuView, sizeof(CPU_VIEW_STRU), g_ulCpuViewTraceCnt, fp);
    if (-1 ==  iRet)
    {
        mdrv_file_close(fp);
        VOS_Splx(lLockValue);
        CPU_VIEW_LOG_PRINT("Write Cpu View Fail!\r\n");

        return;
    }

    mdrv_file_close(fp);

    VOS_Splx(lLockValue);

    CPU_VIEW_LOG_PRINT("CpuView Dump End ............\r\n");
    CPU_VIEW_LOG_PRINT1("Dump File Name:%s......\r\n", (VOS_INT)acDumpFileName);

    s_ucDumpFileNO++;

    return;
} /* CpuView_Dump */
/******************************************************************************
 Prototype      : CpuView_Init
 Description    : CPU_VIEW初始化
 Input          :
 Output         :
 Return Value   :
 Calls          :
 Called By      :

 History        : ---
  1.Date        : 2007-1-24
    Author      : g45205
    Modification: Created function
******************************************************************************/
VOS_VOID CpuView_Init(VOS_UINT32 ulRecordMode, VOS_UINT32 ulRecordCnt)
{
    /* ulRecordMode 记录CpuView的内存模式,
       0:动态模式;
       1:静态模式,暂不支持。
    */
    VOS_UINT32  ulCpuViewTraceCnt;
#if 0
    VOS_UINT32  ulCpuViewStaticBufferLenth;
#endif

    if (CPU_VIEW_YES == g_ulCpuViewInitFlag)
    {
        CPU_VIEW_LOG_PRINT("CpuView is already initialized!\r\n");
        return;
    }

    if (0 == ulRecordCnt)
    {
        ulCpuViewTraceCnt   = CPU_VIEW_RECORD_DEFAULT_NUM;
    }
    else if (CPU_VIEW_RECORD_MAX_NUM < ulRecordCnt)
    {
        ulCpuViewTraceCnt   = CPU_VIEW_RECORD_MAX_NUM;
    }
    else
    {
        ulCpuViewTraceCnt   = ulRecordCnt;
    }

    if (CPU_VIEW_MEMORY_MODE_DYNAMIC == ulRecordMode)
    {
        g_pstCpuViewCtrl    = (CPU_VIEW_CTRL_STRU *)VOS_CacheMemAlloc(sizeof(CPU_VIEW_CTRL_STRU) + (sizeof(CPU_VIEW_STRU) * ulCpuViewTraceCnt));
        if (VOS_NULL == g_pstCpuViewCtrl)
        {
            g_ulCpuViewInitFlag = CPU_VIEW_NO;
            CPU_VIEW_LOG_PRINT("CpuView initialize failed!\r\n");

            return;
        }

        memset((void *)g_pstCpuViewCtrl, 0, sizeof(CPU_VIEW_CTRL_STRU));
        g_pstCpuViewCtrl->ulCpuViewTraceCnt = ulCpuViewTraceCnt;
        g_pstCpuViewCtrl->pstCpuView        = (CPU_VIEW_STRU *)(g_pstCpuViewCtrl + 1);
    }
    /* 暂不支持静态内存方式 */
#if 0
    else if (CPU_VIEW_MEMORY_MODE_STATIC == ulRecordMode)
    {
        /*lint -e527 -e774*/
        ulCpuViewStaticBufferLenth = CPU_VIEW_STATIC_MEM_ADDRESS_END - CPU_VIEW_STATIC_MEM_ADDRESS_START;
        if (sizeof(CPU_VIEW_CTRL_STRU) > ulCpuViewStaticBufferLenth)
        {
            CPU_VIEW_LOG_PRINT("CpuView_Init fail, no enough static buffer!\r\n");
            return;
        }
        /*lint +e527 +e774*/

        g_pstCpuViewCtrl    = (CPU_VIEW_CTRL_STRU *)CPU_VIEW_STATIC_MEM_ADDRESS_START;

        memset((void *)g_pstCpuViewCtrl, 0, sizeof(CPU_VIEW_CTRL_STRU));

        g_pstCpuViewCtrl->ulCpuViewTraceCnt = (ulCpuViewStaticBufferLenth - sizeof(CPU_VIEW_CTRL_STRU))/(sizeof(CPU_VIEW_STRU));
        g_pstCpuViewCtrl->pstCpuView        = (CPU_VIEW_STRU *)(g_pstCpuViewCtrl + 1);
    }
#endif
    else
    {
        /* 目前仅支持动态内存申请模式,直接返回 */
        CPU_VIEW_LOG_PRINT("CpuView_Init Fail!Only Dynamic malloc is available!\r\n");
        return;
    }

    CPU_VIEW_LOG_PRINT("CpuView initialize successfully!\r\n");

    g_ulCpuViewInitFlag = CPU_VIEW_YES;

    return;
} /* CpuView_Init */