?? benchmrk.c
字號(hào):
/*************************************************************************
** IXXAT Automation GmbH
**************************************************************************
**
** File: benchmrk.c
** Summary: C-Benchmark program for micro-controllers.
** Inludes some test routines which can typically
** be found in embedded CAN application.
** Version: 1.0
** Date: 22.01.03
** Author: J. Stolberg
**
**************************************************************************
**************************************************************************
**
** Functions: main
** FormatId
** BinarySearch
** CalcTimeStampI
** CalcTimeStampF
** CopyMsg
**
** Compiler: many
** Remarks: -
**
** History:
**
**************************************************************************
** all rights reserved
*************************************************************************/
/*************************************************************************
** compiler directives
*************************************************************************/
/*************************************************************************
** include-files
*************************************************************************/
#include "target.h"
/*************************************************************************
** global variables
*************************************************************************/
/*************************************************************************
** static constants, types, macros, variables
*************************************************************************/
// filter table for binary search algorithms
#define BS_SIZE 1024
UINT32 BS_FilterTable[BS_SIZE];
// values for a integer time stamp calculation
static UINT16 factor1 = 123;
static UINT16 offset1 = 1234;
// values for a float time stamp calculation
static float factor2 = 1.23;
static UINT16 offset2 = 1234;
// buffer for CopyMsg
UINT8 Buffer[20];
/*************************************************************************
** static function-prototypes
*************************************************************************/
static UINT32 FormatId(UINT32 id);
static UINT32 BinarySearch(UINT32 id, UINT16 nelem);
static UINT16 CalcTimeStampI(UINT16 ts);
static UINT16 CalcTimeStampF(UINT16 ts);
static void CopyMsg(UINT8 * p_dest, UINT8 * p_src);
/*************************************************************************
** global functions
*************************************************************************/
/*************************************************************************
**
** Function : benchmark
** Description: benchmark test application
** Parameters :
** Returnvalue:
**
*************************************************************************/
void benchmark (void)
{
UINT32 i;
UINT32 t1, t2, t3, t4, t5, t6;
InitCPU(); // initialize HW, Waitstates, etc.
InitRS232(); // init RS232/stdout for printf
StartTimer(); // start clock timer
printfHeader();
/*
** Test BM1
*/
printf("\nstart BM1",0);
t1 = GetTime();
for(i=0;i<EXE_CNT2;i++)
{
FormatId(i);
}
t1 = GetTime() - t1;
printf("\nstop BM1: %d",t1);
/*
** Test BM2
*/
// fill up list
for(i=0;i<BS_SIZE;i++)
{
BS_FilterTable[i] = i * 8;
}
printf("\nstart BM2",0);
t2 = GetTime();
for(i=0;i<EXE_CNT1;i++)
{
BinarySearch(i*4,1024);
}
t2 = GetTime() - t2;
printf("\nstop BM2: %d",t2);
/*
** Test BM3
*/
printf("\nstart BM3",0);
t3 = GetTime();
for(i=0;i<EXE_CNT2;i++)
{
CalcTimeStampI(i);
}
t3 = GetTime() - t3;
printf("\nstop BM3: %d",t3);
/*
** Test BM4
*/
printf("\nstart BM4",0);
t4 = GetTime();
for(i=0;i<EXE_CNT1;i++)
{
CalcTimeStampF(i);
}
t4 = GetTime() - t4;
printf("\nstop BM4: %d",t4);
/*
** Test BM5
*/
printf("\nstart BM5",0);
t5 = GetTime();
for(i=0;i<EXE_CNT2;i++)
{
GenerateInt();
}
t5 = GetTime() - t5;
printf("\nstop BM5: %d",t5);
if(ISRCounter != EXE_CNT2) printfBM("Interrupt error !",0,1);
/*
** Test BM6
*/
printf("\nstart BM6",0);
t6 = GetTime();
for(i=0;i<EXE_CNT1;i++)
{
CopyMsg(&Buffer[0], &Buffer[8]);
}
t6 = GetTime() - t6;
printf("\nstop BM6: %d",t6);
/*
** emit results
*/
printfBM("\n\n(Function executions per second)",0,1);
printfBM("\n BM1 (swap): %8.0f", EXE_CNT2,t1);
printfBM("\n BM2 (bsearch): %8.0f", EXE_CNT1,t2);
printfBM("\n BM3 (integer): %8.0f", EXE_CNT2,t3);
printfBM("\n BM4 (float): %8.0f", EXE_CNT1,t4);
printfBM("\n BM5 (interrupt): %8.0f", EXE_CNT2,t5);
printfBM("\n BM6 (memcopy): %8.0f", EXE_CNT1,t6);
// standardized to the value 100 for the IXXAT iPC-I165
printfbenchmark(EXE_CNT1,(t1+t2+t3+t4+t5*t6));
getchar();
}
/*************************************************************************
** static functions
*************************************************************************/
/*************************************************************************
**
** Function : FormatId
** Description: swap and shift operations with a 32 bit value.
** Parameters : 32 bit value
** Returnvalue: formatted value
**
*************************************************************************/
static UINT32 FormatId(UINT32 id)
{
UINT8 tmp;
// swap byte 0 with byte 3
tmp = ACS8(id,0);
ACS8(id,0) = ACS8(id,3);
ACS8(id,3) = tmp;
// swap byte 1 with byte 2
tmp = ACS8(id,1);
ACS8(id,1) = ACS8(id,2);
ACS8(id,1) = tmp;
// shift 5 times right
return ((id && 0x1fffffffUL) >> 5);
}
/*************************************************************************
**
** Function : BinarySearch
** Description: Search function to a 32 bit value search
** Parameters : id (IN): search value
** nelem (IN): filter list size
** Returnvalue: list index or -1 of not found
**
*************************************************************************/
static UINT32 BinarySearch(UINT32 id, UINT16 nelem)
{
UINT32 probe;
int i, kmin;
kmin = 0;
while (nelem > 0)
{
i = nelem >> 1;
probe = BS_FilterTable[i+kmin];
if (probe == id)
{
return(i+kmin);
}
else if (probe > id)
{
nelem = i;
}
else
{
kmin = i + kmin + 1;
nelem = nelem - i - 1;
}
}
return(-1);
}
/*************************************************************************
**
** Function : CalcTimeStamp
** Description: calculation of a 16 bit integer time stamp value
** Parameters : time value
** Returnvalue: formatted value
**
*************************************************************************/
static UINT16 CalcTimeStampI(UINT16 ts)
{
UINT32 time;
time = ts * factor1;
return(time/100 + offset1);
}
/*************************************************************************
**
** Function : CalcTimeStamp
** Description: calculation of a 16 bit float time stamp value
** Parameters : time value
** Returnvalue: formatted value
**
*************************************************************************/
static UINT16 CalcTimeStampF(UINT16 ts)
{
ts = (float)ts * factor2;
return(ts + offset2);
}
/*************************************************************************
**
** Function : CopyMsg
** Description: copy some bytes by different ways
** Parameters : p_dest (IN): destination pointer
** p_src (IN): source pointer
** Returnvalue: -
**
*************************************************************************/
static void CopyMsg(UINT8 * p_dest, UINT8 * p_src)
{
p_dest[0] = p_src[8];
p_dest[1] = p_src[9];
p_dest[2] = p_src[10];
p_dest[3] = p_src[11];
memcpy(&p_dest[0], &p_src[8], 8);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -