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

📄 tstclock.c

📁 pnx1500 clock test demo
💻 C
字号:
/*
 * Copyright (C) 2003 Koninklijke Philips Electronics N.V.,
 * All Rights Reserved.
 *
 * This source code and any compilation or derivative thereof is the
 * proprietary information of Koninklijke Philips Electronics N.V.
 * and is confidential in nature.
 * Under no circumstances is this software to be exposed to or placed
 * under an Open Source License of any type without the expressed
 * written permission of Koninklijke Philips Electronics N.V.
 *
 *----------------------------------------------------------*/
/*!
 *      \file           tstClock.c
 *
 *      Verifies os 1 second == processor 1 second
 *
 */
/*-----------------------------------------------------------
 *
 *      %version:       9 %
 *      instance:       DS_4
 *      %date_created:  Mon Jun 09 18:11:08 2003 %
 *
 */
 //-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Standard include files:
//-----------------------------------------------------------------------------
//
#include <stdio.h>
#include <unistd.h>

//-----------------------------------------------------------------------------
// Project include files:
//-----------------------------------------------------------------------------
//
#include <tmStdLib.h>
#include <tmNxTypes.h>
#include <tmDbg.h>
#include <tmosal.h>
#include <tmMain.h>
#include <tmbslCore.h>
#include <ops/custom_ops.h>

//-----------------------------------------------------------------------------
// Types and defines:
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Global data:
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// Internal Prototypes:
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// Main Entry Point
//-----------------------------------------------------------------------------
//
tmMain()  // expands to right framework for all OS with init.  See tmMain.h
{
    ptmbslCoreSystemInfo_t pSystemInfo;
    UInt32 cpu_frequency ;
    UInt32 cpu_frequency_5_percent ;
    UInt32 cpu_frequency_plus_5_percent ;
    UInt32 cpu_frequency_minus_5_percent ;
    UInt32 onesec_start ;
    UInt32 onesec_end ;
    UInt32 os_frequency ;
    UInt32 usleep_frequency ;
    UInt err;
    int index;
    int errors ;

    printf("\n") ;
    printf("tstClock start\n") ;
    printf("\n") ;

    err = tmbslCoreGetSystemInfo (&pSystemInfo);
    if (err) {
        printf("tmbslCoreGetSystemInfo error %08x\n", err) ;
        tmMain_EXIT (1);
    }
    index = pSystemInfo->cpuId;
    cpu_frequency = pSystemInfo->pCpuInfo[index].cpuClockFreq ;
    cpu_frequency_5_percent = (cpu_frequency * 5) / 100 ;
    cpu_frequency_plus_5_percent  = cpu_frequency + cpu_frequency_5_percent ;
    cpu_frequency_minus_5_percent = cpu_frequency - cpu_frequency_5_percent ;

    printf("testing tmosalTaskSleep\n") ;
    onesec_start = cycles() ;
    tmosalTaskSleep(1000) ;
    onesec_end = cycles() ;
    os_frequency = onesec_end - onesec_start ;

    printf("testing microsleep\n") ;
    onesec_start = cycles() ;
    microsleep(1000000) ;
    onesec_end = cycles() ;
    usleep_frequency = onesec_end - onesec_start ;

    printf("cpu  frequency:             %10d\n", cpu_frequency) ;
    printf("tmosalTaskSleep frequency:  %10d\n", os_frequency) ;
    printf("microsleep frequency:       %10d\n", usleep_frequency) ;
    printf("\n") ;

    errors = 0 ;
    if ((os_frequency < cpu_frequency_minus_5_percent) ||
        (os_frequency > cpu_frequency_plus_5_percent)) {
        printf("tmosalTaskSleep frequency is not +-5%% of cpu frequency\n") ;
        errors++ ;
    }
    if ((usleep_frequency < cpu_frequency_minus_5_percent) ||
        (usleep_frequency > cpu_frequency_plus_5_percent)) {
        printf("microsleep frequency is not +-5%% of cpu frequency\n") ;
        errors++ ;
    }

    if (errors != 0) {
        printf("FAIL\n") ;
        tmMain_EXIT (2);
    }
    else {
        printf("PASS\n") ;
        tmMain_EXIT (0);
    }
}

⌨️ 快捷键说明

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