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

📄 pklib.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	   if (bcmp ((char *) p->ptR,(char *) p->ptW, p->size) != 0)	       {	       (p->countErr) ++;	       printErr ("    Loop  :0x%08x\n", iLoop);	       printErr ("    Buffer:0x%08x\n", iRead);               printErr ("pkTestUnit: buffer compare error : ERROR\n");	       /* check for abort on Error */	       if (p->abortOnError == TRUE)		   return (OK);	       }            p->curPattern ++;            } /* nbBufRead */        /* inc start pattern for the next cycle */	p->curStartPattern ++;        } /* nbLoop */    /* release resources */    free (p->ptR);    free (p->ptW);    return (p->countErr);    }/********************************************************************************* pkTestOneUnit - test one SCSI unit** This routine creates a SCSI device as specified by <devId> and <devLun> then* calls pkTestUnit() to perform a read/write test on the device.* Because it uses a global RW_TEST_UNIT structure it is not reentrant.** If <bufSize> = 0, use default of DEF_BUF_SIZE.* If <nbBuf>   = 0, use default of DEF_NB_BUF.* If <nbLoop>  = 0, write/read entire device.** NOTE:* Warning!  This routine calls scsiPhysDevCreate() and scsiBlkDevCreate().* All data on the file system will be erased.** RETURNS: OK, or ERROR if test fails.** SEE ALSO: pkTestUnit()*/STATUS pkTestOneUnit    (    int devId,			/* scsi id of the device */    int devLun,			/* lun id of the devicer */    UINT32 bufSize,		/* buffer size to use */    int nbBuf,			/* number of buffers to write */    int nbLoop			/* number of loops to perform */    )    {    SCSI_PHYS_DEV *pPhysDev;    BLK_DEV *pBlkDev;    STATUS status;    /* create physical SCSI device */    if ((pPhysDev=scsiPhysDevIdGet(0,devId,devLun))==(SCSI_PHYS_DEV *)NULL)        if ((pPhysDev=scsiPhysDevCreate(pSysScsiCtrl,devId,devLun,0,NONE,0,0,0))         == (SCSI_PHYS_DEV *) NULL)            {	    printErr ("pkTestOneUnit: scsiPhysDevCreate() failed : ERROR\n");	    return (ERROR);	    }    /* create logical SCSI device */    if ((pBlkDev = scsiBlkDevCreate (pPhysDev, 0, 0)) == NULL)	{        printErr ("pkTestOneUnit: scsiBlkDevCreate() failed : ERROR\n");	return (ERROR);        }    /* fill in the RW_TEST_UNIT information */    pTestUnit->pBlk = pBlkDev;    pTestUnit->size = (bufSize == 0) ? DEF_BUF_SIZE : bufSize;    pTestUnit->nbBuf = (nbBuf == 0) ? DEF_NB_BUF : nbBuf;    if (nbLoop == 0)        {        /* entire device */        UINT32 nbblock       = ((SCSI_BLK_DEV *) pBlkDev)->blkDev.bd_nBlocks;        UINT32 blsize        = BLK_TO_PHYS (pBlkDev, blockSize);        pTestUnit->nbBuf  = nbblock / (pTestUnit->size / blsize);        pTestUnit->nbLoop = 1;        }    else        pTestUnit->nbLoop = nbLoop;    pTestUnit->startPattern = ST_PATTERN;	/* start pattern */    pTestUnit->law          = DEF_LAW;		/* fill law */    pTestUnit->abortOnError = TRUE;		/* set abort on data error */    pTestUnit->abort        = FALSE;		/* disable abort flag */    /* call pkTestUnit() */    status = (pkTestUnit (pTestUnit) || pTestUnit->countErr) ? ERROR : OK;    /* releases resources and return */    scsiPhysDevDelete (pPhysDev);    if (status == OK)        printf("PASS\n");    else        printf("ERROR\n");    return (status);    }#endif /* INCLUDE_SCSI *//********************************************************************************* pkPrintTest - print the given string to the console.** This routine prints the given string.** RETURNS: N/A*/void pkPrintTest    (    char *mesg,		/* message to be printed */    int delayTime	/* task delay if required */    )    {    taskDelay(delayTime);    printf("%s\n",mesg);    }/********************************************************************************* pkPrintTest1 - print the given string to the console.** This routine prints the given string.** RETURNS: N/A*/void pkPrintTest1    (    int fd,    char *mesg,		/* message to be printed */    int delayTime	/* task delay if required */    )    {    taskDelay(delayTime);    write(fd, mesg, strlen(mesg));    }/********************************************************************************* pkDivideZeroTest - used to check for divide by zero exception.*** RETURNS: N/A*/void  pkDivideZeroTest (void)      {      int a;      int b=5;      int c=0;      taskDelay(200);      a=b/c;      printf("The value of a is %d\n", a);      }/******************************************************************************** pkUdpEchoT - main routine to open sockets, send and receive packets** This routine opens an internet socket with a remote target, which is assumed* to be running a UDP echo server.  Once connected, a loop is entered where* UDP packets of differing sizes are sent to, and received from, the target.* Each returning packet is checked for the correct size and content.  A* packet sent, but not received back within the timeout may be resent by* alarm_handler().  The test passes, exiting with value 0, if all packets* were sent and received, regardless of how many individual packets* needed to be resent. The IP address of the remote target has to be supplied* with all individual bytes as seperate arguments.** RETURNS: exit status: 0 if OK*/void pkUdpEchoT    (    int addr1,  /* first byte in the IP address */    int addr2,    int addr3,    int addr4,  /* last byte in the IP address */    int	    packetsToSend,    int	    timeout    )    {    int    div;				/* divisor for status messages */    int    tenth = 0;			/* status message counter */    int	   ix, iy;                      /* loop counters */    int    cnt;				/* count of bytes sent/received */    int    prevPktSiz = -99;		/* packet size just sent */    int    localSktAddrLen;		/* local copy of sktAddrLen */    short  *pShort;                     /* counter to form output buffer */    struct sockaddr_in cli_addr;        /* host socket data */    int    sktBufSiz;    struct fd_set readFs;    int	   ret;    struct timeval pktTimeout;    u_long  inetAdrs;    char inetDotAdrs[60];    sprintf(inetDotAdrs, "%d.%d.%d.%d", addr1, addr2, addr3, addr4);    inetAdrs = inet_addr(inetDotAdrs);    /* convert command line args */    if (packetsToSend < 1)	{	printf ("Error: no packets to send\n");	fflush (stdout);	exit (9);	}    /* check if inet address is non-null */    if (inetAdrs == 0)        {        printf ("Error: illegal inet address\n");        exit (9);        }    /* turn off timer if bad arg */    packetTMO = timeout;    if (packetTMO < 0)	packetTMO = 0;    pktTimeout.tv_sec  = 0;    pktTimeout.tv_usec = packetTMO * 1000;    /* open the socket */    skt = socket (AF_INET, SOCK_DGRAM, 0);    if (skt < 0)        {        printf ("Error: socket() failure\n");	fflush (stdout);        exit (2);        }    /* prepare our sock addr */    sktAddrLen = sizeof (struct sockaddr_in);    (void) memset (&cli_addr, 0, sktAddrLen);           /* clr it */    cli_addr.sin_family = AF_INET;                      /* fill in family */    cli_addr.sin_port = 0;                              /* port */    /* bind our addr to the socket */    if (bind (skt, (struct sockaddr *) &cli_addr, sktAddrLen) < 0)        {        printf ("Error: bind() failure\n");	fflush (stdout);        close (skt);        exit (3);        }    /* specify max buffer size on send/receive */    sktBufSiz = sizeof (buf);         /* increase size of socket buffers */    if (setsockopt (skt, SOL_SOCKET, SO_SNDBUF, (char *) &sktBufSiz,        sizeof (sktBufSiz)) < 0)        {        close (skt);        printf ("Error: setsockopt() failure\n");	fflush (stdout);        exit (3);        }    if (setsockopt (skt, SOL_SOCKET, SO_RCVBUF, (char *) &sktBufSiz,        sizeof (sktBufSiz)) < 0)        {        close (skt);        printf ("Error: setsockopt() failure\n");	fflush (stdout);        exit (4);        }    /* prepare server's sock addr */    (void) memset (&serv_addr, 0, sktAddrLen);          /* clr it */    serv_addr.sin_family = AF_INET;                     /* fill in family */    serv_addr.sin_addr.s_addr = inetAdrs;   		/* get IP addr */    serv_addr.sin_port = htons(IPPORT_ECHO);            /* the ECHO port */    /*     * Prepare the outgoing data.     * The buffer is treated as an array of short integers,     * each is sequentially numbered, starting from zero.     */    pShort = (short *) dataOut;    for (ix = 0; ix < (MAX_PKT/sizeof (short)); ix++)        *pShort++ = ix;    /* Main loop.  Send a packet and wait for it to come back */    div=packetsToSend/10;    printf("Sending %d packets\n", packetsToSend);    fflush (stdout);    for (packetNum = 0; packetNum < packetsToSend; packetNum++)        {        /* print status message */        if (div > 0)	    if ((packetNum % div) == (div -1))	        printf ("%d/10 through UDP echo test\n", ++tenth);		fflush (stdout);        curPktSiz = pktSizes [packetNum % N_SIZES];        /* send a packet */        cnt = sendto (skt, dataOut, curPktSiz, 0,		      (struct sockaddr *) &serv_addr, sktAddrLen);        /* check that entire packet was sent */        if (cnt != curPktSiz)            {            printf ("Error: could not send packet #%d, size %d\n",		    packetNum, curPktSiz);	    fflush (stdout);            exit (4);            }        /* expect it back - clear out previously resent packets */        do {            FD_ZERO (&readFs);            FD_SET (skt, &readFs);            ret = select (skt +1, &readFs, NULL, NULL, &pktTimeout);            if (ret == 0)               {    	       if (resendCnt++ == RESEND)	           {	           /* already resent specified times - fail */                   close (skt);	           printf ("Error: timed out waiting for packet #%d\n",	                    packetNum);                   printf ("UDP echo test failed\n");                   fflush (stdout);	           exit (7);	           }               else                   {	           resendTotal ++;   /* bump counter */                   printf("Timed out Resending packet:%d trial:%d\n",                             packetNum, resendCnt);                   fflush (stdout);                   cnt = sendto (skt, dataOut, curPktSiz, 0,	         	      (struct sockaddr *) &serv_addr, sktAddrLen);                   /* check that entire packet was sent */                   if (cnt != curPktSiz)                      {                      printf ("Error: could not send packet #%d, size %d\n",		               packetNum, curPktSiz);	              fflush (stdout);                      exit (4);                      }                   }               }            else if (ret == ERROR)               {               printf ("Error: select failed\n");               close (skt);               exit(9);               }            else               {               localSktAddrLen = sktAddrLen;               cnt = recvfrom (skt, dataIn, curPktSiz, 0,			    (struct sockaddr *) &serv_addr, &localSktAddrLen);	       }	} while ((cnt == prevPktSiz) || (cnt == -1));        resendCnt = 0;	/* check that packet received is correct size */        if (cnt != curPktSiz)            {            printf ("Error: remote host echoed wrong size in packet #%d\n",		    packetNum);	    fflush (stdout);	    close (skt);            exit (5);            }        /* verify the received data */        for (iy = curPktSiz; iy--;)            {            if (dataIn [iy] != dataOut [iy])                {                printf ("Error: echoed data does not match in packet #%d\n",			packetNum);		close (skt);	        fflush (stdout);                exit (6);                }            }        prevPktSiz = curPktSiz;        }    /* print exit messages - test passed */    printf ("\n\nTotal packets resent: %d\n", resendTotal);    printf ("UDP echo test passed\n");    printf ("END OF UDP TEST\n");    fflush (stdout);    close (skt);    exit (0);    }/********************************************************************************* pkIntGet - read an int at a given address** RETURNS: content of address.** SEE ALSO: pkTestSet()*/int pkIntGet   (   int	*pMem   )   {   return *pMem;   }/*******************************************************

⌨️ 快捷键说明

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