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

📄 diotest_183.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************ Function Header *****************************	dioIntEnableTest - tests the masking of interrupts**	This function will ensure that each interrupt line can be   *	individually set.  It will mask out all interrupt line except for *	one, test it, then perform the same test on the next one.*	Interrupts are NOT tested in this function.**	RETURNS: OK on success, ERROR on failure************************ End Function Header *************************/UINT32 dioIntEnableTest()	{	UINT32 status;		/* return status of this function */	UINT32 mask;		/* interrupt enable mask */	UINT32 intEnLine;	/* lines that are enabled in the PIEN register */	UINT16 i;			/* loop variable */        /* Disable DIo interrupts */	status = dioIntDisable (dioCpuConfig);        /* Clear all pending interrupts */        sysOutWordNoSwap((UINT32)FPGA_DIO_MSB_INTENBL, dioCpuConfig );        sysOutWordNoSwap((UINT32)FPGA_DIO_MSB_INTSTAT, dioCpuConfig );	/* Need to set the DIO lines Direction to input so we can enable the interrupts*/        dioDirectionSet ((UINT32)dioCpuConfig, INPUT);   if(0 == sysProcId)        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU0_DIO_MSB_INTMSK);   else        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU1_DIO_MSB_INTMSK); 	if((intEnLine & UPPER_MASK) != 0x0)		{		printf ("ERROR: dioIntEnableTest- value if int eable reg is %x\n", intEnLine);		return (ERROR);		}	mask = (UINT32)0x0001;		/* set up mask for initial value */		for (i = 0; i < DIO_LINES; i++)		{		dioIntEnable (mask);                if(0 == sysProcId)                     intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU0_DIO_MSB_INTMSK);                else                     intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU1_DIO_MSB_INTMSK);		if(intEnLine != mask)			{			printf ("ERROR: dioIntEnableTest- mask of different value than register in Int Enable "			         "test #%d\n\n", i);			return (ERROR);			}		status = dioIntDisable (mask);		mask = mask << 1;		}	return (OK);	}/************************ Function Header *****************************	dioIntDisableTest - tests the disabling and masking of interrupts**	This function will ensure that each interrupt line can be   *	individually cleared.  It will enable all interrupt lines and then* 	disable them one at a time until all have been tested.*	*	Interrupts are NOT tested in this function.**	RETURNS: OK on success, ERROR on failure************************ End Function Header *************************/UINT32 dioIntDisableTest()	{	UINT32 status;		/* return status of various function calls */	UINT32 mask;		/* used to clear a particular interrupt */	UINT32 intEnLine;	/* lines that are enabled in the PIEN register */	UINT16 i;			/* loop variable */    status = dioIntEnable (dioCpuConfig);		   if(0 == sysProcId)        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU0_DIO_MSB_INTMSK);   else        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU1_DIO_MSB_INTMSK); 	if((intEnLine & UPPER_MASK) != UPPER_MASK)		{		printf ("Cry Bloody Murder!! Foul in IntDisableTest() \n\n");		return (ERROR);		}	mask = (UINT32)0x03fe;		/* set up mask for initial value */	for (i = 0; i < DIO_LINES; i++)		{		dioIntDisable (mask);                   if(0 == sysProcId)                        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU0_DIO_MSB_INTMSK);                   else                        intEnLine = sysInWordNoSwap ((UINT32)FPGA_CPU1_DIO_MSB_INTMSK);		if((~intEnLine & UPPER_MASK) != mask)			{			printf ("mask of different value than register in Int Enable "			         "test #%d\n\n", i);			return (ERROR);			}				status = dioIntEnable (dioCpuConfig);		mask = ~mask;		mask = mask << 1;		mask = (~mask & UPPER_MASK);		}	return (OK);	}/************************ Function Header *****************************	dioEdgeSetTest() - tests the rising/falling edges of interrupts**	**	RETURNS: OK on success, ERROR on failure************************ End Function Header *************************/UINT32 dioEdgeSetTest()	{	UINT32 status;		/* return status of various function calls */	UINT32 mask;		/* mask to set the edge register */	UINT32 readReg;		/* value read back from Edge register */	UINT16 i;			/* loop variable */    mask = dioCpuConfig;    dioIntDisable (mask);	status = dioEdgeSet ((UINT32)mask, FALLING);	readReg = sysInWordNoSwap ((UINT32)FPGA_DIO_EDGE);	/* read back reg value */	mask = (UINT32)0x001;	for (i = 0; i < DIO_LINES; i++)		{		status = dioEdgeSet (mask, RISING);			readReg = sysInWordNoSwap ((UINT32)FPGA_DIO_EDGE);			/* compare - should be same as mask */		if ((readReg & UPPER_MASK) != mask)				{			printf ("dioEdgeSetTest() Failed - iteration #%d\n\n", i);			printf ("value on failure: readReg = %x, mask = %x\n", readReg, 			         mask);			return (ERROR);			}		/* set all edge bits to Falling */		status = dioEdgeSet (dioCpuConfig, FALLING);		mask = mask << 1;		}			status = dioEdgeSet (dioCpuConfig, RISING);	mask = (UINT32)0x0001;	for (i = 0; i < DIO_LINES; i++)		{		status = dioEdgeSet(mask, FALLING);		readReg = sysInWordNoSwap ((UINT32)FPGA_DIO_EDGE);		/* clearing the top byte of mask before compare */		if ((readReg & UPPER_MASK) != (~mask & UPPER_MASK))				{			printf ("dioEdgeSetTest Fail - Falling test #%d\n\n",i);			printf ("value on failure: readReg = %x, mask = %x\n", readReg, 			         mask);			return (ERROR);			}				mask = mask << 1;		status = dioEdgeSet (dioCpuConfig, RISING);		}	return (OK);	}/********************** Function Header ***********************       dioIntTest - This function tests interrupts on the 12 DIO*       lines.**		Description:  This test sets up the upper 6 bits as outputs*		and the lower (LSBits) to be inputs.  An individual ISR*		is attached to each dio line of the lower 6 bits.  Then a *		logical 1 is written to the upper six bits which should*		generate an interrupt for each of the corresponding input *		bits.  Each individual ISR writes to an area of memory a *		uniques value. (0x300000) is the default location and can *		modified by changing the #define ISR_BASE_ADRS in dio.h**       A terse algorithm is as follows**       Set up pins 0 through 5 to inputs*       Set up pins 6 through 11 for outputs*       Attach interrupt ISR to 0 through 5*       Enable the interrupts on lines 0 through 5*       Send data out - generating an interrupt*       Service and return - loop de loop for all********************** End Function Header ********************/UINT32 dioIntTest(){    UINT32 status;          /* return status from various function calls */    UINT32 mask;            /* mask used for various IO pins and functions */    UINT32  intPatt[8] = {                            0xdeadbeef,                            0x0defaced,                            0xbeaddeaf,                            0xdeadfeed,                            0x0effaced,                            0xdeafbead,			    0xdabadaba,                            0                         };    memset(dioIntBuf, 0, 32);    isr_base_addr = dioIntBuf;printf("\n-------------------\n");printf("DIO Interrupt Test\n");printf("-------------------\n"); printf("1.  Disabling interrupts...");    dioIntDisable (dioCpuConfig);printf("done.\n");printf("2.  Clear intStat regester...");    sysOutWordNoSwap ((UINT32)FPGA_DIO_MSB_INTENBL, dioCpuConfig);    sysOutWordNoSwap ((UINT32)FPGA_DIO_MSB_INTSTAT, dioCpuConfig);printf("done.\n");printf("3.  Attach ISR's...");    /* attach ISR to bit 0 */    status = dioConnect (0x0001, (FUNCPTR)dioIntIsr1, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to bit 1 */    status = dioConnect (0x0002, (FUNCPTR)dioIntIsr2, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to bit 2 */    status = dioConnect (0x0004, (FUNCPTR)dioIntIsr3, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to bit 3 */    status = dioConnect (0x0008, (FUNCPTR)dioIntIsr4, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to pin 4 */    status = dioConnect (0x0010, (FUNCPTR)dioIntIsr5, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to pin 5 */    status = dioConnect (0x0020, (FUNCPTR)dioIntIsr6, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }    /* attach ISR to pin 12 */    status = dioConnect (0x1000, (FUNCPTR)dioIntIsr7, 0);      if (status == ERROR)        {        printf ("Error returned from dioConnect()\n");        return (ERROR);        }printf("done.\n");    /*      * set the in-comming lines for rising edge.     */printf("4.  Set rising edge detection on INPUT lines...");    status = dioEdgeSet ((UINT32)LOWER_BITS_TST, RISING);    if (status == ERROR)        {        printf ("Error returned from dioEdgeSet()\n");        return (ERROR);        }printf("done.\n");printf("5.  Set direction of INPUT lines...");    /* set lines 0-5, 12-13 for inputs */    status = dioDirectionSet ((UINT32)LOWER_BITS_TST, INPUT);    if (status == ERROR)        {        printf ("Error returned from dioDirectionSet()\n");        return (ERROR);        }printf("done.\n");printf("5.  Set direction of OUTPUT lines...");    /* set lines 6-11, 14-15 for outputs */    status = dioDirectionSet ((UINT32)UPPER_BITS_TST, OUTPUT);     if (status == ERROR)        {        printf ("Error returned from dioDirectionSet()\n");        return (ERROR);        }printf("done.\n");printf("6.  Clear OUTPUT lines....");    status = dioWrite ((UINT32)UPPER_BITS_TST, 0x0000);    if (status == ERROR)        {        printf ("Error returned from dioWrite()\n");        return (ERROR);        }printf("done.\n");    mask = (UINT32)LOWER_BITS_TST;printf("7.  Enable interrupts on INPUT lines....");    /* enable interrupt lines 0 - 5, 12 - 13 */    status = dioIntEnable (mask);    if (status == ERROR)        {        printf ("Error returned from dioIntEnable()\n");        return (ERROR);        }printf("done.\n");printf("8.  Write to OUTPUT Lines...");    status = dioWrite ((UINT32)UPPER_BITS_TST, UPPER_BITS_TST);    if (status == ERROR)        {        printf ("Error returned from dioWrite()\n");        return (ERROR);        }printf("done.\n");printf("9.  Wait for interrupts to occur...");taskDelay(20);printf("done.\n");printf("10. Check Results...");    if (strncmp((char *)intPatt, dioIntBuf, 32) != 0)       status=ERROR;    else       status=OK;printf("done.\n");printf("\n-------------------\n");printf("Test Complete.");if (status == OK)    printf(" Pass.\n");else    printf(" Fail.\n");printf("-------------------\n");   /* clear all pending interrupts caused by this test */    sysOutWordNoSwap ((UINT32)FPGA_DIO_MSB_INTSTAT, dioCpuConfig);return(status);}/******************** Function Header ************************       dioIntIsr() - Interrupt service routine**       This will modify some area of memory with a distinct*       value per ISR in consecutive locations in memory.*       then return.********************* End Function Header ********************/void dioIntIsr1()    {    *(UINT32*)isr_base_addr = 0xdeadbeef;    }void dioIntIsr2()    {    *(UINT32*)(isr_base_addr + 0x4) = 0xdefaced;    }void dioIntIsr3()    {    *(UINT32*)(isr_base_addr + 0x8) = 0xbeaddeaf;    }void dioIntIsr4()    {    *(UINT32*)(isr_base_addr + 0xc) = 0xdeadfeed;    }void dioIntIsr5()    {    *(UINT32*)(isr_base_addr + 0x10) = 0xeffaced;    }void dioIntIsr6()    {    *(UINT32*)(isr_base_addr + 0x14) = 0xdeafbead;    }void dioIntIsr7()    {    *(UINT32*)(isr_base_addr + 0x18) = 0xdabadaba;    }

⌨️ 快捷键说明

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