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

📄 pklib.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        while ((semTake (tsTmoSem, NO_WAIT)) != OK)	    {            taskDelay (2);	    tsBucket = pkTimestamp (locked);	    }        *pCountPtr++ = pkTimestampRoll (tickCounter);        *pTickPtr++ = pkTimestamp (locked);	printf ("pkTimestampTest: %d/%d through test\n", (ix + 1), nslices);	}    /* convert to total ticks */    for (pTickPtr = pTickVal, pCountPtr = pCountVal, ix = 0; 	 ix < (nslices << 1); ix++, pTickPtr++, pCountPtr++)	{	*pTickPtr += *pCountPtr * sysTimestampPeriod();	}    /* convert to relative ticks and compute percent error */    printf ("\ncalculated ticks: %u\n", calcTicks);    pTickPtr = pTickVal;    for (ix = 0, pCountPtr = pCountVal; ix < nslices; ix++, pCountPtr++)	{	/* the following two lines put the difference between two consecutive	 * entries in the pTickVal array into the appropriate slot in the 	 * pCountVal array.	 */	*pCountPtr = *pTickPtr++;	*pCountPtr = *pTickPtr++ - *pCountPtr;	/* calculate *percent* error */	errorVal = 100 * ((float) calcTicks - (float) *pCountPtr) /			  (float) calcTicks;	printf ("Period %d:  measured ticks: %u,  percent error: %f\n",	    (ix + 1), *pCountPtr, errorVal);        if (errorVal < 0)	    errorVal *= -1;        if (errorVal > (float) PK_TS_ERR)	    retValue = ERROR;        }    if (retValue == ERROR)    	printf("FAIL: long-term timestamp test\n");    else    	printf("PASS: long-term timestamp test\n");pkTimestampTestLongExit:    free (pCountVal);    free (pTickVal);    }#endif	/* INCLUDE_TIMESTAMP */#ifdef INCLUDE_SCSI/* the following are for testing SCSI *//********************************************************************************* pkBufFillPattern - write a pattern to a memory buffer** This routine write a pattern in a memory buffer.  <startPattern> indicates* the* pattern and the buffer will be fill with data0, data0+inc,....,datan+inc* according to the filling law chosen.** INTERNAL:* Only the law with the increment 0x01010101 is implemented.* A another law should be to write:* data0, ~data0,data0+inc,~data0+inc, ...,datan+inc,~datan+inc.** RETURNS: OK or ERROR.*/STATUS pkBufFillPattern    (    UINT8 *pBuffer,		/* pointer to the buffer              */    UINT32 size,		/* size in bytes of the buf to fill   */    int law,			/* rules to fill the buffer           */    int *startPattern,		/* value of the start pattern         */    int *endPattern		/* where return the end value pattern */    )    {    EQUI_INT_UINT8  pattern;    int 	ix;    int 	iy;    int 	firstBlock;    int 	lastBlock;    int *	pt = (int *)pBuffer;    UCHAR *	upt;    if (pBuffer == NULL)	return (ERROR);    if (size < sizeof (pattern.ival))	return (ERROR);    switch (law)	{	case PATTERN_INC_LAW:	    {	    /* incremental law */	    iy = 0;	    pattern.ival = *startPattern;	    firstBlock = size / sizeof (pattern.ival);	    lastBlock = size % sizeof (pattern.ival);	    for (ix = 0; ix <= (firstBlock-1); ix ++)		{		*pt = pattern.ival;		pattern.ival = pattern.ival + (int) 0x01010101;		pt ++;		}	    /* fill last block in byte mode if the remain modulo exist */	    ix = (ix * 4) - 1;	    upt = (UCHAR *) pt;	    while (lastBlock != 0)		{		 *upt = pattern.uint8val[ix % 4];		if ((iy % 4) == 3)		    pattern.ival = pattern.ival + 0x01010101;		ix ++;		iy ++;		upt ++;		lastBlock --;		}	    break;	    }	default:	    {	    printErr ("pkBufFillPattern: law not implemented : ERROR\n");	    return (ERROR);	    }	}    *endPattern = pattern.ival;    return (OK);    }/********************************************************************************* pkBlkWrite - write blocks to a SCSI device** Write a buffer to a SCSI device.  The buffer size must be a multiple* of the block size of the device.  <blockNumber> is used both to describe* the writing position and next free position when the function returns.** RETURNS: OK, or ERROR if parameters don't match or the write failed.*/STATUS pkBlkWrite    (    SCSI_BLK_DEV *pBlkDev,	/* pointer to the block device     */    char *pBuffer,		/* pointer to the buffer Read      */    UINT32 size,		/* size of the pBuffer area        */    int *blockNumber		/* logical # of the block to write */    )    {    int numSects;    int secSize = BLK_TO_PHYS(pBlkDev,blockSize);    /* check pBlkDev */    if  (pBlkDev == (SCSI_BLK_DEV *)NULL)	{	printErr ("pkBlkWrite: pBlkDev is NULL : ERROR\n");	return (ERROR);	}    /* check for range block */    if (((* blockNumber) > ((SCSI_BLK_DEV *) pBlkDev)->blkDev.bd_nBlocks) ||        ((* blockNumber) < ((SCSI_BLK_DEV *) pBlkDev)->blockOffset))	{	printErr ("scsiWriteBlocks: blockNumber out of range : ERROR\n");	return (ERROR);	}    /* check if size ok */    if (size == (int) NULL)	{        printErr ("scsiWriteBlocks: buffer size is NULL : ERROR\n");	return (ERROR);	}    /* check if buffer size fits sector size */    IF_BAD_BUFSIZE (pBlkDev,size)	{        printErr ("scsiWriteBlocks: buffer size invalid : ERROR\n");	return (ERROR);	}    numSects = size / secSize;    if (scsiWrtSecs (pBlkDev,*blockNumber,numSects, pBuffer) == ERROR)	{	printErr ("pkBlkWrite: returned ERROR\n");	return (ERROR);	}    *blockNumber = *blockNumber + numSects;    return (OK);    }/********************************************************************************* pkBlkRead - read blocks from a SCSI device** Read a buffer from a SCSI device.  The buffer size must be a multiple* of the block size of the device.  <blockNumber> is used both to describe* the reading position and next free position when the function returns.** RETURNS: OK, or ERROR if parameters don't match or the read failed.*/STATUS pkBlkRead    (    SCSI_BLK_DEV *pBlkDev,	/* pointer to the block device     */    char *pBuffer,		/* pointer to the buffer Read      */    UINT32 size,		/* size of the pBuffer area        */    int *blockNumber		/* logical # of the block to write */    )    {    int numSects;    int secSize = BLK_TO_PHYS(pBlkDev,blockSize);    /* check pBlkDev */    if  (pBlkDev == (SCSI_BLK_DEV *) NULL)	{	printErr ("pkBlkRead: pBlkDev is NULL : ERROR\n");	return (ERROR);	}    /* check for range block */    if (((* blockNumber) > ((SCSI_BLK_DEV *) pBlkDev)->blkDev.bd_nBlocks) ||        ((* blockNumber) < ((SCSI_BLK_DEV *) pBlkDev)->blockOffset))	{	printErr ("pkBlkRead: blockNumber out of range : ERROR\n");	}    /* check if size ok */    if (size == 0)        {        printErr ("pkBlkRead: buffer size is 0 : ERROR\n");        return (ERROR);        }    /* make sure the buffer size fits the sector size */    IF_BAD_BUFSIZE (pBlkDev,size)	{        printErr ("pkBlkRead: buffer size not a multiple of block size : ERROR\n");	return (ERROR);	}    /* use previous IF_BAD_BUFSIZE to get an integer sector count */    numSects = size / secSize;    if (scsiRdSecs (pBlkDev,*blockNumber,numSects, pBuffer) == ERROR)	{	printErr ("pkBlkRead: returning ERROR\n");	return (ERROR);	}    *blockNumber = *blockNumber + numSects;    return (OK);    }/********************************************************************************* pkTestUnit - test a SCSI device by writing, reading and verifying data** This routine tests write and read operation to a SCSI device.* The unique parameter is pointer to a structure info.  First it writes* a pattern to a range of blocks on the device.  Then it reads the range* of blocks and verifies the pattern.  The pattern is generated by* pkBufFillPattern().** RETURNS: OK, or ERROR if the parameters are bad or the test fails.** SEE ALSO: pkBufFillPattern()*/STATUS pkTestUnit    (    RW_TEST_UNIT *pTestInfo 	/* structure describes test to run */    )    {    FAST RW_TEST_UNIT *		p = pTestInfo;    FAST SCSI_BLK_DEV *		pB = (SCSI_BLK_DEV *) (p->pBlk);    int iWrite;    int iRead;    int iLoop;    int temp;    int curEndPattern;    /* check parameters */    if (pB == (SCSI_BLK_DEV *) NULL)	{        printErr ("pkTestUnit: pBlkDev is NULL : ERROR\n");        return (ERROR);	}    if (p->nbLoop == 0)	{        printErr ("pkTestUnit: nbLoop is 0 : ERROR\n");        return (ERROR);	}    if (p->size == 0)	{        printErr ("pkTestUnit: bufSize is 0 : ERROR\n");        return (ERROR);	}    if (p->nbBuf == 0)	{        printErr ("pkTestUnit: nbBufWrite is 0 : ERROR\n");        return (ERROR);	}    IF_BAD_BUFSIZE(pB, p->size)	{        printErr ("pkTestUnit: bufSize not a multiple of block size : ERROR\n");	return (ERROR);	}    /* check if enough place on the device for a cycle */    temp = ((p->size / BLK_TO_PHYS(pB, blockSize)) *  p->nbBuf);    if ((temp > (pB->blkDev.bd_nBlocks)) ||	((temp + p->stBlk) > (pB->blkDev.bd_nBlocks + pB->blockOffset)))	{        printErr ("pkTestUnit: not enough room for a cycle : ERROR\n");	return (ERROR);	}    /* allocate buffers */    if ((p->ptR = (UINT8 *) malloc(p->size)) == NULL)	{        printErr ("pkTestUnit: ptRead allocation failed : ERROR\n");	return (ERROR);	}    if ((p->ptW = (UINT8 *) malloc(p->size)) == NULL)	{        printErr ("pkTestUnit: ptWrite allocation failed : ERROR\n");        free (p->ptR);	return (ERROR);	}    /* main loop on nbLoop */    p->curStartPattern = p->startPattern;    p->countErr = 0;    for (iLoop = 0; iLoop < p->nbLoop; iLoop ++)	{	p->curBlk = p->stBlk;	p->curPattern = p->curStartPattern;	/* refresh curCycle for spy */        p->curCycle = iLoop;	/* check for abort */	if (p->abort == TRUE)	   return (OK);	/* write loop */        for (iWrite = 0; iWrite < p->nbBuf; iWrite ++)	    {	    if (iWrite == 0)		{		printf ("pkTestUnit: beginning write loop\n");		}	    if (iWrite == p->nbBuf / 2)		{		printf ("pkTestUnit: half way through write loop\n");		}	    /* check for abort */	    if (p->abort == TRUE)               return (OK);	    /* fill the buffer with pattern according to the law */	    if ((pkBufFillPattern (p->ptW, p->size, p->law,		                     &p->curPattern,			             &curEndPattern)) == ERROR)                {		printErr ("pkTestUnit: fatal fill buffer error : ERROR\n");		return (ERROR);		}	    if (pkBlkWrite (pB, (char *) p->ptW, p->size, &p->curBlk) == ERROR)                {		printErr ("pkTestUnit: fatal write error : ERROR\n");		return (ERROR);		}            (p->curPattern) ++;            }	p->curBlk = p->stBlk;	p->curPattern = p->curStartPattern;	/* read loop */        for (iRead = 0; iRead < p->nbBuf; iRead ++)	    {	    if (iRead == 0)		{		printf ("pkTestUnit: beginning read loop\n");		}	    if (iRead == p->nbBuf / 2)		{		printf ("pkTestUnit: half way through read loop\n");		}	    /* check for abort */	    if (p->abort == TRUE)		{		return (OK);		}	    if ((pkBufFillPattern (p->ptW, p->size, p->law,			             &p->curPattern, &curEndPattern)) == ERROR)                {		printErr ("pkTestUnit: fatal fill buffer error : ERROR\n");		return (ERROR);		}	    if (pkBlkRead (pB, (char *) p->ptR , p->size, &p->curBlk) == ERROR)                {		printErr ("pkTestUnit: fatal read error : ERROR\n");		return (ERROR);		}           /* compare buffers */

⌨️ 快捷键说明

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