📄 msg2.c
字号:
/********************************************************************** * * Copyright (c) 2004, Dy 4 Systems All rights reserved. * This Source Code is the Property of Dy 4 Systems Inc. and * can only be used in accordance with Source Code License * Agreement of Dy 4 Systems Inc. dba (doing business as) * CURTISS-WRIGHT CONTROLS EMBEDDED COMPUTING, "CWCEC". * **********************************************************************//********************************************************************************* Filename: demo/msg2.c ** Copyright 2003 by DY4 Systems. All Rights Reserved.** Project Name: 182 BSP ** Target: 182 ** Description: On-board CPU communication library** Usage: ** Log: * 2003-10-06-JCS Initial revision ********************************************************************************//*modification history--------------------01a,29nov04,tis -add nsupport for CCA-145*/#include "vxWorks.h"#include "taskLib.h"#include "sysLib.h"#include "tickLib.h"#include "logLib.h"#include "errnoLib.h"#include "h/drv/dy4/boardName.h"#ifdef VME_182#include "dy4182.h"#include "intCtrl182_dy4.h"#endif#ifdef CCA_145#include "cca145.h"#include "intCtrl145.h"#endif#include "h/drv/mms/dy4mmsMP.h"#include "h/drv/dy4Debug/dy4Debug.h"#define MAX_LOOPS 1000#define LOOP_MOD 1000#define NUM_MSGS 1024#if 0 #define TEST_TIMEOUT (sysClkRateGet() * 2)#else #define TEST_TIMEOUT WAIT_FOREVER#endif#define PERFint tst2 ( void ) { void *sendMsg[NUM_MSGS]; void *recvMsg[NUM_MSGS]; int size, loop; int i; ULONG startTime, stopTime; float time;#ifndef PERF int j;#endif dy4mmsClearStats(); /* * CPU0 * - Malloc memory for a message * - for( MAX_LOOPS ) * - Fill the message with 0x5a5a5a5a * - Send the message to CPU1 * - Wait for CPU1 to send a message back * - Test the message with 0xa5a5a5a5 * - Free the memory * CPU1 * - for( MAX_LOOPS ) * - Wait for CPU0 message * - Compare the message content with 0x5a5a5a5a * - Fill the message with 0xa5a5a5a5 * - Send the message to CPU0 */ if (sysProcId == CPU_ID_0) { /* * allocate 100 bytes message */ DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMalloc\n")); for( i = 0; i < NUM_MSGS; i++ ) { if (dy4mmsMalloc(&sendMsg[i], 100) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMalloc error 0x%08x\n",errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } else { DEBUGIP(("dy4mmsTest: dy4mmsMalloc returns 0x%08X\n", (int)sendMsg[i])); } } DEBUGMP(("This test sends 1000 msgs one way, then recvs 1000 in return, and does this %d times\n", MAX_LOOPS)); DEBUGMP(("The loop time calculated is for 1 send and 1 recv\n\n")); taskDelay( 1 ); /* sync to fence post */ startTime = tickGet(); for( loop = 0; loop < MAX_LOOPS; loop++ ) {#ifndef PERF if(( loop % LOOP_MOD) == 0 ) { DEBUGMP(("Loop %d\n", loop )); }#endif for( i = 0; i < NUM_MSGS; i++ ) {#ifndef PERF /* * fill message with pattern */ for (j = 0; j < 100/4; j++) { *((int *)(sendMsg[i]) + j) = 0x5a5a5a5a; } CACHE_FLUSH(DATA_CACHE, sendMsg, 100 );#endif /* * send the message to CPU 1 */ DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgSend\n")); if (dy4mmsMsgSend(0, sendMsg[i], 100, TEST_TIMEOUT, DY4MMS_LOW_PRIORITY) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } /* * get the response back from CPU 1 */ for( i = 0; i < NUM_MSGS; i++ ) { DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgRecv\n")); if (dy4mmsMsgRecv(0, &recvMsg[i], &size, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } else { DEBUGIP(("dy4mmsTest: dy4mmsMsgRecv returns 0x%08X %d\n", (int)recvMsg[i], size)); }#ifndef PERF /* * test the receive message */ CACHE_INVALIDATE(DATA_CACHE, sendMsg, 100 ); for (j = 0; j < size/4; j++) { if (*((int *)(recvMsg[i]) + j) != 0xa5a5a5a5) { DEBUGEP(("dy4mmsTest: Error in receive message %d 0x%08X\n", j, *((int *)(recvMsg[i]) + j))); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } }#endif } } stopTime = tickGet(); time = ((((float)stopTime) - ((float)startTime)) / ((float)(sysClkRateGet()))); DEBUGMP(("MsgSend/Recv:Time %0.3fs, loopcount %d\n", time, NUM_MSGS * MAX_LOOPS)); DEBUGMP(("MsgSend/Recv:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(NUM_MSGS * MAX_LOOPS)), ((float)(NUM_MSGS * MAX_LOOPS)) / time)); DEBUGMP(("MsgSend/Recv:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(2 * NUM_MSGS * MAX_LOOPS)), ((float)(2 * NUM_MSGS * MAX_LOOPS)) / time)); for( i = 0; i < NUM_MSGS; i++ ) { DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsFree\n")); if (dy4mmsFree(recvMsg[i]) == ERROR) { DEBUGEP(("dy4mmsTest: recvMsg dy4mmsFree error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } } else /* sysProcId == CPU_ID_1 */ { DEBUGMP(("This test sends 1000 msgs one way, then recvs 1000 in return, and does this %d times\n", MAX_LOOPS)); DEBUGMP(("The loop time calculated is for 1 send and 1 recv\n\n")); taskDelay( 1 ); /* sync to fence post */ startTime = tickGet(); for( loop = 0; loop < MAX_LOOPS; loop++ ) {#ifndef PERF if(( loop % LOOP_MOD) == 0 ) { DEBUGMP(("Loop %d\n", loop )); }#endif for( i = 0; i < NUM_MSGS; i++ ) { DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgRecv\n")); if (dy4mmsMsgRecv(0, &recvMsg[i], &size, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } else { DEBUGIP(("dy4mmsTest: dy4mmsMsgRecv returns 0x%08X %d\n", (int)recvMsg[i], size)); }#ifndef PERF /* * test the receive message */ CACHE_INVALIDATE(DATA_CACHE, recvMsg, 100 ); for (j = 0; j < size/4; j++) { if (*((int *)(recvMsg[i]) + j) != 0x5a5a5a5a) { DEBUGEP(("dy4mmsTest: Error in receive message %d 0x%08X\n", j, *((int *)(recvMsg[i]) + j))); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } } for( i = 0; i < NUM_MSGS; i++ ) { /* * fill message with pattern */ for (j = 0; j < 100/4; j++) { *((int *)(recvMsg[i]) + j) = 0xa5a5a5a5; } CACHE_FLUSH(DATA_CACHE, recvMsg, 100 );#endif DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgSend\n")); if (dy4mmsMsgSend(0, recvMsg[i], 100, TEST_TIMEOUT, DY4MMS_LOW_PRIORITY ) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } } stopTime = tickGet(); time = ((((float)stopTime) - ((float)startTime)) / ((float)(sysClkRateGet()))); DEBUGMP(("MsgSend/Recv:Time %0.3fs, loopcount %d\n", time, NUM_MSGS * MAX_LOOPS)); DEBUGMP(("MsgSend/Recv:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(NUM_MSGS * MAX_LOOPS)), ((float)(NUM_MSGS * MAX_LOOPS)) / time)); DEBUGMP(("MsgSend/Recv:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(2 * NUM_MSGS * MAX_LOOPS)), ((float)(2 * NUM_MSGS * MAX_LOOPS)) / time)); } dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( OK ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -