📄 semc.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/semC.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 tst4 ( void ) { int loop, tmp, size; ULONG startTime, stopTime; float time; dy4mmsClearStats(); /* * CPU0 * - create a counting ssem * - for number of loops * - give counting SSEM * CPU1 * - create a counting ssem * - for number of loops * - take counting SSEM * take counting sem with timeout * verify timeout */ if (sysProcId == CPU_ID_0) { DEBUGMP(("This test gives a counting sem %d times\n", MAX_LOOPS)); DEBUGMP(("There is 1 dy4mmsSemGive per loop\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 (dy4mmsSemGive(DY4MMS_USER_SEM_1) == 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(("SemGive:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS)); DEBUGMP(("SemGive:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time)); DEBUGMP(("SemGive:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(MAX_LOOPS)), ((float)(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 ); } } else /* sysProcId == CPU_ID_1 */ { DEBUGMP(("This test takes a counting sem %d times\n", MAX_LOOPS)); DEBUGMP(("There is 1 dy4mmsSemTake per loop\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_1, TEST_TIMEOUT) == ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemTake error 0x%08x\n", errnoGet())); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } } stopTime = tickGet(); time = ((((float)stopTime) - ((float)startTime)) / ((float)(sysClkRateGet()))); DEBUGMP(("SemTake:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS)); DEBUGMP(("SemTake:time/loop %0.9fs, loops/sec %0.2f \n", time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time)); DEBUGMP(("SemTake:time/call %0.9fs, calls/sec %0.2f \n\n", time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time)); DEBUGMP(("Calling semTake one more time with timeout\n")); if (dy4mmsSemTake(DY4MMS_USER_SEM_1, 2) != ERROR) { DEBUGEP(("dy4mmsTest: dy4mmsSemTake did not time out\n\n")); dy4mmsShow(); taskDelay( 10 * sysClkRateGet() ); return( ERROR ); } else { DEBUGMP(("dy4mmsTest: dy4mmsSemTake timed out as expected, error 0x%08x\n\n", errnoGet())); } DEBUGIP(("Syncing with CPU 0\n")); /* * Allow other side to complete before we delete the sem * since it could still be trying to use it */ 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 + -