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

📄 semr.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 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/semR.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 PERFstatic void userHandler( SEM_ID sem )    {    semGive( sem );    }int tst5    (    void    )    {    void        *buff;    int         size, loop;    SEM_ID      sem;    ULONG       startTime, stopTime;    float       time;#ifndef PERF    int         i;#endif    dy4mmsClearStats();    size = 100;    /*      * CPU0     *      - Malloc memory for a message     *      - send the address to CPU 1     *      - create a binary sem     *      - create a RAW ssem     *      - attach the ISR     *      - Fill the message with 0x5a5a5a5a     *      - for( MAX_LOOPS )     *      -    wait for the doorbell     *      -    Compare the message content with 0x5a5a5a5a     *      -    Fill the message with 0x5a5a5a5a     *      -    hit the doorbell     *      - Free the memory     * CPU1     *      - recv the address from CPU 0     *      - create a binary sem     *      - create a RAW ssem     *      - attach the ISR     *      - hit the doorbell     *      - for( MAX_LOOPS )     *      -    wait for the doorbell     *      -    Compare the message content with 0x5a5a5a5a     *      -    Fill the message with 0xa5a5a5a5      *      -    hit the doorbell     */    if (sysProcId == CPU_ID_0)        {	/*          * allocate buff         */	DEBUGIP(("\n"));	DEBUGIP(("Calling dy4mmsMalloc\n"));	if (dy4mmsMalloc(&buff, size) == ERROR)	    {	    DEBUGEP(("dy4mmsTest: dy4mmsMalloc error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	else            {	    DEBUGIP(("dy4mmsTest: dy4mmsMalloc returns 0x%08X\n", (int)buff));            }        /*         * Create the binary sem         */	if((sem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY)) == (SEM_ID)ERROR)	    {	    DEBUGEP(("dy4mmsTest: semBCreate error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	/* 	 * send the message to CPU 1	 */	DEBUGIP(("\n"));	DEBUGIP(("Calling dy4mmsMsgSend\n"));	if (dy4mmsMsgSend(0, buff, 			  size, 			  TEST_TIMEOUT, 			  DY4MMS_LOW_PRIORITY) 	    == ERROR)	    {	    DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	/* 	 * wait for a response back, so that we know that they         * have created the sem. 	 */	if (dy4mmsMsgRecv(0, &buff, &size, TEST_TIMEOUT) == ERROR)	    {	    DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }        /*         * connect the handler         */	if( dy4mmsDoorbellIntConnect( DY4MMS_USER_SEM_2, 				      userHandler, 				      (int)sem ) 	    == ERROR )	    {	    DEBUGEP(("dy4mmsTest:Error, failed to int Connect\n"));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	/*	 * now we can enable the int	 */	if( dy4mmsDoorbellIntEnable(DY4MMS_USER_SEM_2) == ERROR )	    {	    DEBUGEP(("dy4mmsTest:Error, failed to int enable\n"));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }#ifndef PERF	/* 	 * fill message with pattern	 */	for (i = 0; i < size/4; i++)	    {	    *((int *)buff + i) = 0xa5a5a5a5;	    }        CACHE_FLUSH(DATA_CACHE, buff, size );#endif        DEBUGMP(("This test toggles ownership of a buffer, using a doorbell %d times\n",                  MAX_LOOPS));        DEBUGMP(("There is one semTake and one doorbellRing 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( semTake( sem , TEST_TIMEOUT ) == ERROR )		{		DEBUGEP(("dy4mmsTest:Error, failed to take doorbellSem\n"));		dy4mmsShow();		taskDelay( 10 * sysClkRateGet() );		return( ERROR );		}#ifndef PERF	    /* 	     * test the message 	     */	    CACHE_INVALIDATE(DATA_CACHE, buff, size );	    for (i = 0; i < size/4; i++)		{		if (*((int *)buff + i) != 0xa5a5a5a5)		    {		    DEBUGEP(("dy4mmsTest: Error in receive message %d 0x%08X\n",		       i, *((int *)buff + i)));		    dy4mmsShow();		    taskDelay( 10 * sysClkRateGet() );		    return( ERROR );		    }		}	    /* 	     * fill message with pattern	     */	    for (i = 0; i < size/4; i++)		{		*((int *)buff + i) = 0x5a5a5a5a;		}	    CACHE_FLUSH(DATA_CACHE, buff, size );#endif            dy4mmsDoorbellRing( CPU_ID_1, DY4MMS_USER_SEM_2 );	    }        stopTime   = tickGet();        time       =  ((((float)stopTime) -                       ((float)startTime)) / ((float)(sysClkRateGet())));        DEBUGMP(("DBTake/Give:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS));        DEBUGMP(("DBTake/Give:time/loop %0.9fs, loops/sec %0.2f \n",                time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time));        DEBUGMP(("DBTake/Give:time/call %0.9fs, calls/sec %0.2f \n\n",                time / ((float)(2 * MAX_LOOPS)),                 ((float)(2 * MAX_LOOPS)) / time));	DEBUGIP(("\n"));	DEBUGIP(("Calling dy4mmsFree\n"));	if (dy4mmsFree(buff) == ERROR)            {	    DEBUGEP(("dy4mmsTest: buff dy4mmsFree error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );            }        }    else /* sysProcId == CPU_ID_1 */        {        /*         * Create the binary sem         */	if((sem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY)) == (SEM_ID)ERROR)	    {	    DEBUGEP(("dy4mmsTest: semBCreate error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }        /*         * recv the buff ptr and size form CPU 0         */	if (dy4mmsMsgRecv(0, &buff, &size, TEST_TIMEOUT) == ERROR)	    {	    DEBUGEP(("dy4mmsTest: dy4mmsMsgRecv error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	/* 	 * send a response back, so that they know that we         * have created the sem. 	 */	DEBUGIP(("\n"));	DEBUGIP(("Calling dy4mmsMsgSend\n"));	if (dy4mmsMsgSend(0, buff, 			  size, 			  TEST_TIMEOUT, 			  DY4MMS_LOW_PRIORITY) 	    == ERROR)	    {	    DEBUGEP(("dy4mmsTest: dy4mmsMsgSend error 0x%08x\n", errnoGet()));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }        /*         * connect the handler         */	if( dy4mmsDoorbellIntConnect( DY4MMS_USER_SEM_2, 				      userHandler, 				      (int)sem ) 	    == ERROR )	    {	    DEBUGEP(("dy4mmsTest:Error, failed to int Connect\n"));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }	/*	 * now we can enable the int	 */	if( dy4mmsDoorbellIntEnable(DY4MMS_USER_SEM_2) == ERROR )	    {	    DEBUGEP(("dy4mmsTest:Error, failed to int enable\n"));	    dy4mmsShow();	    taskDelay( 10 * sysClkRateGet() );	    return( ERROR );	    }        DEBUGMP(("This test toggles ownership of a buffer, using a doorbell %d times\n",                  MAX_LOOPS));        DEBUGMP(("There is one semTake and one doorbellRing per loop\n\n"));        taskDelay( 1 ); /* sync to fence post */        startTime = tickGet();	dy4mmsDoorbellRing( CPU_ID_0, DY4MMS_USER_SEM_2 );        for( loop = 0; loop < MAX_LOOPS; loop++ )            {#ifndef PERF            if(( loop % LOOP_MOD) == 0 )                {                DEBUGMP(("Loop %d\n", loop ));                }#endif            if( semTake( sem , TEST_TIMEOUT ) == ERROR )		{		DEBUGEP(("dy4mmsTest:Error, failed to take doorbellSem\n"));		dy4mmsShow();		taskDelay( 10 * sysClkRateGet() );		return( ERROR );		}#ifndef PERF	    /* 	     * test the receive message 	     */	    CACHE_INVALIDATE(DATA_CACHE, buff, size );	    for (i = 0; i < size/4; i++)		{		if (*((int *)buff + i) != 0x5a5a5a5a)		    {		    DEBUGEP(("dy4mmsTest: Error in receive message %d 0x%08X\n",		       i, *((int *)buff + i)));		    dy4mmsShow();		    taskDelay( 10 * sysClkRateGet() );		    return( ERROR );		    }		}	    /* 	     * fill message with pattern	     */	    for (i = 0; i < size/4; i++)		{		*((int *)buff + i) = 0xa5a5a5a5;		}	    CACHE_FLUSH(DATA_CACHE, buff, size );#endif            dy4mmsDoorbellRing( CPU_ID_0, DY4MMS_USER_SEM_2 );	    }        stopTime   = tickGet();        time       =  ((((float)stopTime) -                       ((float)startTime)) / ((float)(sysClkRateGet())));        DEBUGMP(("DBTake/Give:Time %0.3fs, loopcount %d\n", time, MAX_LOOPS));        DEBUGMP(("DBTake/Give:time/loop %0.9fs, loops/sec %0.2f \n",                time / ((float)(MAX_LOOPS)), ((float)(MAX_LOOPS)) / time));        DEBUGMP(("DBTake/Give:time/call %0.9fs, calls/sec %0.2f \n\n",                time / ((float)(2 * MAX_LOOPS)),                 ((float)(2 * MAX_LOOPS)) / time));	}    dy4mmsShow();    taskDelay( 10 * sysClkRateGet() );    return( OK );    }    

⌨️ 快捷键说明

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