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

📄 diotest_183.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* dioTest_183.c - Sample code to use DIO channels.  *//************************************************************************** * *   Copyright (c) 2005 Curtiss-Wright Controls, Inc. All rights *   reserved.  This Source Code is the Property of Curtiss-Wright *   Controls, Inc. and can only be used in accordance with Source *   Code License Agreement(s) of Curtiss-Wright Controls, Inc. or any *   of its subsidiaries. * **************************************************************************//*Modification History--------------------01a, 23nov05, tis created based on dioTest.c 01e v9*/ /*DESCRIPTIONThis libray contains the following routines, see function headers for further detailsdioTest()dioDirectionSetTestdioReadTest()dioWriteTest()dioIntEnableTest()dioIntDisableTest()testAll()testAllN()testSelectN()INCLUDE file: dio.h*//* includes */#include <vxWorks.h>#include <stdio.h>#include <string.h>#include <ioLib.h>#include "sioLib.h"#include "taskLib.h"#include "config.h"#include "logLib.h"#include "tyLib.h"#include "iosLib.h"#include "intLib.h"#include "sysLib.h"#include "h/drv/dio/dio_dy4.h"#include "config.h" /* also includes dy418x.h and sysFpgaInt.h */#include "fpga183.h"IMPORT UINT32 dioCpuConfig;IMPORT  UINT16 sysInWordNoSwap (UINT32);IMPORT  void sysOutWordNoSwap (UINT32,UINT32);extern int sysProcId;/* Forward Declarations */void 	dioTest();UINT32	dioDirectionTest ();UINT32	dioIntEnableTest ();UINT32	dioIntDisableTest ();UINT32	dioReadTest ();UINT32 	dioWriteTest ();UINT32	dioEdgeSetTest();UINT32	dioIntTest();UINT32  dioIntTest183();void dioIntIsr1();void dioIntIsr2();void dioIntIsr3();void dioIntIsr4();void dioIntIsr5();void dioIntIsr6();void dioIntIsr7();void dioIntIsr8();/* 0 - 5, 12 */#define LOWER_BITS_TST      0x103F/* 6 - 11, 13 */#define UPPER_BITS_TST      0x2FC0#define DIO_BITS_TST        0x3FFFUINT32	connector = 0;char dioIntBuf[32];static char *isr_base_addr = (char *)0x3000000;/************************* Function Header *****************************	dioTest - main menu for test suite**	This function is a menu driven test suite to test the various*	functionality of the DIO driver:*	- test dioDirectionSet function*	- test dioRead()*	- test dioWrite()*	- test dioIntEnable()*	- test dioIntDisable()*	- test interupts with loopback connector installed************************ End Function Header **************************//*void dioTest(void)*/void dioTest(BOOL connectorIn){/*   UINT32 	len;   UINT32	input = 0;   UINT32	c;*/   UINT32	status = 0;	/* status returned from selected test */	   dioCpuConfig = (UINT32)DIO_BITS_TST; /* test all DIOs */   printf ("This test SW validates the Digital I/O functionality on "            "any of the VME-182/3 SBC products.\n\n");   printf ("The test works with or without the P0 loopback connector.\n");   if(connectorIn==TRUE) {       connector = 1;   }   else {        connector = 0;   }			   printf ("Function               Pass/Fail\n");   printf ("================================\n");   status = dioDirectionTest();   if (status == ERROR)      printf ("dioDirection           **FAILED**\n");   else      printf ("dioDirection           **PASSED**\n");   status = dioReadTest();   if (status == ERROR)      printf ("dioRead                **FAILED**\n");   else      printf ("dioRead                **PASSED**\n");   status = dioWriteTest();   if (status == ERROR)      printf ("dioWrite               **FAILED**\n");   else      printf ("dioWrite               **PASSED**\n");   status = dioIntEnableTest();   if (status == ERROR)      printf ("dioIntEnable           **FAILED**\n");   else      printf ("dioIntEnable           **PASSED**\n");   status = dioIntDisableTest();   if (status == ERROR)      printf ("dioIntDisable          **FAILED**\n");   else      printf ("dioIntDisable          **PASSED**\n");   status = dioEdgeSetTest();   if (status == ERROR)      printf ("dioEdgeSet             **FAILED**\n");   else      printf ("dioEdgeSet             **PASSED**\n");   if (connector)   {   status = dioIntTest();   if (status == ERROR)         printf ("dioIntTest             **FAILED**\n");   else         printf ("dioIntTest             **PASSED**\n");   }}/************************ Function Header *****************************	dioDirectionTest - tests the dioDirectionSet() of the DIO driver** 	This function is used to test the direction bits.  It will use a *	"walking" 1 (OUTPUT) for each DIO line then use a walking 0 to test *	the	INPUT direction.**	RETURNS: OK on success, ERROR on failure**************************** End Header *******************************/UINT32	dioDirectionTest()	{	UINT32 	testValue;	/* value passed into DirectionSet function */	UINT32 	testMask;	/* holds the walking 1 value */	UINT16 	readPdint;	/* read in value in DIR reg to compare with */	UINT16	count;		/* I'll let you guess what this does... */		/* Set all the bits in the Direction Register to 0's */	testValue = UPPER_MASK;	/* initial value of all zero's */	testMask = 0x0001;	/* initial value of mask will be 0x0000 */    /* Disable Interrupts on the tested DIO lines*/    dioIntDisable(testValue);	for (count = 0; count < DIO_LINES; count++)		{		/* set all of the lines to 0's i.e. INPUT's */		dioDirectionSet (testValue, INPUT);					dioDirectionSet (testMask, OUTPUT); /* set current bit to 1 */		readPdint = sysInWordNoSwap ((UINT32)FPGA_DIO_MODE);						if (testMask != (readPdint & UPPER_MASK) )			{			printf ("ERROR: dioDirectionTest-test mask = %x, readPdint - %x\n", testMask, readPdint);			return (ERROR);			}		testMask <<= 1; 	/* shift the mask over 1 bit placement */		}/* for loop end */	testMask = 0x0001;	for (count = 0; count < DIO_LINES; count++)		{		/* set all of the lines to 1's i.e. OUTPUT's */		dioDirectionSet (testValue, OUTPUT);			dioDirectionSet (testMask, INPUT);	/* set the current bit to 0 */			readPdint = sysInWordNoSwap ((UINT32)FPGA_DIO_MODE);		if ((~testMask & UPPER_MASK) != (readPdint & UPPER_MASK))			{			printf ("ERROR: dioDirectionTestvalue of readPdint = %x, value of testMask = %x\n",			         readPdint, testMask);			return (ERROR);			}		testMask <<= 1; 	/* shift the mask over 1 bit placement */		} /* for loop end */	return(OK);	}/************************ Function Header *****************************	dioReadTest - tests the dioReadTest() of the DIO driver**	This test will write a walking 1 then read it back.  *	Interrupts are NOT tested in this function.**	RETURNS: OK on success, ERROR on failure************************* End Function Header *************************/UINT32 dioReadTest()	{		UINT32 regVal;			/* value to be manipulate register value */		UINT32 readVal;		/* value read from data lines */	UINT32 testVal;			/* value holding walking 1 or walking zero */        UINT32 expVal;	UINT32 status;			/* return status */	UINT32 out;	UINT16 loop;	UINT16 i = 0;			/* for loop counter */		readVal = 0x0000;	testVal = 0x0001;	if (connector)	{	   out = LOWER_BITS_TST;           expVal = 0x0041;	   loop = DIO_LINES / 2;	}	else	{	   out = UPPER_MASK;           expVal = 0x0001;	   loop = DIO_LINES;	}	        dioDirectionSet (out, OUTPUT);	if (connector)           dioDirectionSet (UPPER_BITS_TST, INPUT);	/* clear the register */	status = dioWrite (out, (UINT32)0x0000); 	regVal = dioRead (&readVal);	if ((regVal & UPPER_MASK) != 0)		{		printf ("Failure on first read of Read/Write test function ***!!\n\n");		return (ERROR);		}	for(i = 0; i < loop; i++)		{		if (connector && (i == 6))		{		   testVal = 0x1000;		   expVal = 0x3000;		}		status = dioWrite (out, testVal);		status = dioRead (&readVal);		if ((readVal & UPPER_MASK) != expVal)			{			printf ("Fail values: readVal = %x, expVal = %x\n", 			         readVal, expVal);			return (ERROR);			}		testVal <<= 1;		/* shift the walking 1 once */		expVal <<= 1;		readVal = 0x0000;	/* clear read variable */		/* clear the data register */		status = dioWrite (out, (UINT32)0x0000); 			} /* end for loop */	return (OK);	}/************************ Function Header *****************************	dioWriteTest - tests the dioWriteTest() of the DIO driver**	This test will write a walking 1 then read it back in order to test*	the masking ability of the Write function.  It will then test a *	walking zero as well.*  *	Interrupts are NOT tested in this function.**	RETURNS: OK on success, ERROR on failure************************* End Function Header *************************/UINT32 dioWriteTest()	{			UINT32 mask;		/* mask of write value */	UINT32 writeVal;	/* value written to register */		UINT32 readVal;		/* value read from Data reg */        UINT32 expVal;	UINT32 out;	UINT32 status;		/* status returned from various function calls */	UINT16 loop;	UINT16 i;			/* loop counter var. */		mask = (UINT32)UPPER_MASK;	writeVal = (UINT32)0x0000;	if (connector)	{	   out = LOWER_BITS_TST;           expVal = 0x0041;	   loop = DIO_LINES / 2;	}	else	{	   out = UPPER_MASK;           expVal = 0x0001;	   loop = DIO_LINES;	}        status = dioDirectionSet (out, OUTPUT);	if (connector)           dioDirectionSet (UPPER_BITS_TST, INPUT);	status = dioWrite (mask, writeVal);	status = dioRead (&readVal);	if ((readVal & UPPER_MASK) != 0)		{		printf ("ERROR: dioWriteTest-error on first write/read\n\n");		return (ERROR);		}	mask = (UINT32)0x0001;	/* for walking one test - always write FFFF's mask is what changes */	writeVal = 0xFFFF;  			for(i = 0; i < loop; i++)		{		if (connector && (i == 6))		{		   mask = (UINT32)0x1000;		   expVal = 0x3000;		}		dioWrite (mask, writeVal);			dioRead (&readVal);		if ((readVal & UPPER_MASK) != expVal)			{                        printf ("Fail values: readVal = %x, expVal = %x\n",                                 readVal, expVal);			return (ERROR);			}			readVal = 0x0000; 	/* clear read value */		dioWrite (out, (UINT32) 0x0000); /* clear the register */		mask = mask << 1;                expVal <<= 1;		} /* end for loop */	/* test a walking 0 now */	mask = (UINT32)0x0001;  /* start zero in LSBit */	writeVal = 0x0000;	/* always write zero's */	if (connector)           expVal = 0x0041;	else           expVal = 0x0001;	/* Initialize to all 1's */	status = dioWrite (out, (UINT32)0xFFFF);		status = dioRead(&readVal);	for (i = 0; i < loop; i++)		{		if (connector && (i == 6))		{		   mask = (UINT32)0x1000;		   expVal = 0x3000;		}		status = dioWrite (mask, writeVal);  		status = dioRead (&readVal);		if ((readVal & UPPER_MASK) != (~expVal & UPPER_MASK))			{                        printf ("Fail values: readVal = %x, ~expVal = %x\n",                                 readVal & UPPER_MASK, ~expVal & UPPER_MASK);			return (ERROR);			}		/* reset the data register to all F's */		status = dioWrite (out, (UINT32)0xFFFF);		mask = mask << 1;	/* shift the bugger */                expVal <<= 1;		}	/* end for loop */			return (status);	}

⌨️ 快捷键说明

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