📄 semb.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/semB.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 10000000#define LOOP_MOD 1000#if 0 #define TEST_TIMEOUT (sysClkRateGet() * 2)#else #define TEST_TIMEOUT WAIT_FOREVER#endif#define PERFint tst3 ( void ) { void *buff; int tmp, size, loop; ULONG startTime, stopTime; float time; dy4mmsClearStats(); /* * CPU0 * - Malloc shared memory * - send a pointer to the buuf to the other CPU * - create a binary ssem * - for number of loops * - sem take * - write cpu 0 signature to buff * - task delay * - read back and verify cpu 0 signature * - sem give * - Free the memory * CPU1 * - receive the buff pointer * - create a binary ssem * - for number of loops * - sem take * - write cpu 1 signature to buff * - task delay * - read back and verify cpu 1 signature * - sem give * - Free the memory */ if (sysProcId == CPU_ID_0) { DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMalloc\n")); if (dy4mmsMalloc(&buff, 32) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMalloc error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgSend\n")); if (dy4mmsMsgSend(0, buff, 32, TEST_TIMEOUT, DY4MMS_LOW_PRIORITY) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } DEBUGMP(("This test does a take and give of a binary sem %d times\n", MAX_LOOPS)); DEBUGMP(("Each loop consists of a dy4mmsSemTake and a dy4mmsSemGive\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 if (dy4mmsSemTake(DY4MMS_USER_SEM_0, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemTake error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); }#ifndef PERF *((unsigned long *)(buff)) = 0xAAAA5555; CACHE_FLUSH(DATA_CACHE, buff, 32 ); taskDelay( 1 ); CACHE_INVALIDATE(DATA_CACHE, buff, 32 ); if( *((unsigned int*)(buff)) != 0xAAAA5555 ) { DEBUGEP(("ERROR Sem broken\n")); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); }#endif if (dy4mmsSemGive(DY4MMS_USER_SEM_0) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemGive error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } stopTime = tickGet(); time = ((((float)stopTime) - ((float)startTime)) / ((float)(sysClkRateGet()))); DEBUGMP(("SemTake/Give:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS)); DEBUGMP(("SemTake/Give:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time)); DEBUGMP(("SemTake/Give:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(2 * MAX_LOOPS)), ((float)(2 * MAX_LOOPS)) / time)); /* * Allow other side to complete before we delete the sem * since it could still be trying to use it */ DEBUGIP(("Syncing with CPU 1\n")); if (dy4mmsMsgSend(0, (void*)tmp, 0, TEST_TIMEOUT, DY4MMS_LOW_PRIORITY) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } if (dy4mmsMsgRecv(0, (void*)&tmp, &size, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsFree\n")); if (dy4mmsFree(buff) == ERROR) { DEBUGEP(("dy4mmsTest: recvMsg dy4mmsFree error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } else /* sysProcId == CPU_ID_1 */ { DEBUGIP(("\n")); DEBUGIP(("Calling dy4mmsMsgRecv\n")); if (dy4mmsMsgRecv(0, &buff, &size, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } DEBUGMP(("This test does a take and give of a binary sem %d times\n", MAX_LOOPS)); DEBUGMP(("Each loop consists of a dy4mmsSemTake and a dy4mmsSemGive\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 if (dy4mmsSemTake(DY4MMS_USER_SEM_0, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemTake error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); }#ifndef PERF *((unsigned long *)(buff)) = 0x5555AAAA; CACHE_FLUSH(DATA_CACHE, buff, 32 ); taskDelay( 1 ); CACHE_INVALIDATE(DATA_CACHE, buff, 32 ); if( *((unsigned int*)(buff)) != 0x5555AAAA ) { DEBUGEP(("ERROR Sem broken\n")); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); }#endif if (dy4mmsSemGive(DY4MMS_USER_SEM_0) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemGive error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } stopTime = tickGet(); time = ((((float)stopTime) - ((float)startTime)) / ((float)(sysClkRateGet()))); DEBUGMP(("SemTake/Give:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS)); DEBUGMP(("SemTake/Give:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time)); DEBUGMP(("SemTake/Give:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(2 * MAX_LOOPS)), ((float)(2 * MAX_LOOPS)) / time)); /* * Allow other side to complete before we delete the sem * since it could still be trying to use it */ DEBUGIP(("Syncing with CPU 0\n")); if (dy4mmsMsgRecv(0, (void*)&tmp, &size, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } if (dy4mmsMsgSend(0, (void*)tmp, 0, TEST_TIMEOUT, DY4MMS_LOW_PRIORITY) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( OK ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -