📄 pklib.c
字号:
if ((((* count) & 1) && odd) || ((!((* count) & 1)) && !odd)) (* count) ++;#ifdef INCLUDE_SM_NET /* use the utility routine, if available */ if (smUtilTasClearRtn != NULL) (smUtilTasClearRtn)(semaphore); else#endif /* INCLUDE_SM_NET */ * semaphore = 0; /* enter busy-wait loop to give other task a chance */ for (busyWait = 0; busyWait < delay; busyWait ++) ; /* wait */ } }/********************************************************************************* pkTestRamByte - test read and write access to one byte of RAM** This routine uses vxMemProbe() to check that <adrs> may be written to* and read from.** RETURNS: OK, or ERROR if <adrs> is not both readable and writable.*/STATUS pkTestRamByte ( char *adrs /* address to test */ ) { char testR; /* scratchpad for read */ char write1; /* 1st value to write */ char write2; /* 2nd value to write */ (void) vxMemProbe (adrs, VX_READ, 1, &write2); /* save current value */ write1 = (write2 == 3) ? 1 : 3; /* write1 != write2 */ return ((vxMemProbe (adrs, VX_WRITE, 1, &write1) != OK) || (vxMemProbe (adrs, VX_READ, 1, &testR) != OK) || (testR != write1) || (vxMemProbe (adrs, VX_WRITE, 1, &write2) != OK) || (vxMemProbe (adrs, VX_READ, 1, &testR) != OK) || (testR != write2)) ? ERROR : OK; }#ifdef NV_RAM_SIZEchar vtsOrigBootLine [NV_RAM_SIZE + 2]; /* original boot line */unsigned char vtsNvRamBuf1 [NV_RAM_SIZE + 2]; /* scratch buffer 1 */unsigned char vtsNvRamBuf2 [NV_RAM_SIZE + 2]; /* scratch buffer 2 *//********************************************************************************* pkTestNvRam - collection of non-volatile RAM tests** This routine contains several tests to check the board's non-volatile* RAM. The parameter <testNum> indicates which test will be run.** If the macro NV_RAM_SIZE_WRITEABLE is defined, only that number of bytes* is used for tests which write to nvram.** The tests in this routine write and read various patterns to and from nvram,* making sure no errors are detected. Additionally, parameter checking is* performed on the sysNvRamGet() and sysNvRamSet() routines.** RETURNS: OK, or ERROR if <testNum> is invalid or the test fails.*/STATUS pkTestNvRam ( int testNum /* test number (1-8) */ ) { static int writeableSize; /* writeable nvram sz */ FAST int ii; /* scratch loop index */ STATUS retValue = ERROR; /* return value */ int offset = -NV_BOOT_OFFSET; /* offset to nv start */#ifdef NV_RAM_SIZE_WRITEABLE writeableSize=NV_RAM_SIZE_WRITEABLE;#else /* NV_RAM_SIZE_WRITEABLE */ writeableSize=NV_RAM_SIZE;#endif /* NV_RAM_SIZE_WRITEABLE */ if (writeableSize > NV_RAM_SIZE) return(retValue); switch (testNum) { case 1: /* sysNvRamGet() of boot line */ { if (sysNvRamGet((char *)vtsNvRamBuf1, NV_RAM_SIZE, offset) == ERROR) break; /* store the original bootline */ bcopy ((char *) vtsNvRamBuf1, (char *) vtsNvRamBuf2, NV_RAM_SIZE); bcopy ((char *) vtsNvRamBuf1, vtsOrigBootLine, NV_RAM_SIZE); for (ii = 0; ii < NV_RAM_SIZE; ii ++) /* complement string */ vtsNvRamBuf1 [ii] ^= 0xff; (void) sysNvRamGet ((char *) vtsNvRamBuf1, NV_RAM_SIZE, offset); if (memcmp((char *)vtsNvRamBuf1, (char *)vtsNvRamBuf2, NV_RAM_SIZE) == 0) retValue = OK; break; } case 2: /* sysNvRamSet() and sysNvRamGet() of complemented boot line */ { if (sysNvRamGet((char *)vtsNvRamBuf1, NV_RAM_SIZE, offset) == ERROR) break; for (ii = 0; ii < NV_RAM_SIZE; ii ++) /* complement string */ vtsNvRamBuf1 [ii] ^= 0xff; if (sysNvRamSet((char *)vtsNvRamBuf1, writeableSize, offset) == ERROR) break; (void) sysNvRamGet ((char *) vtsNvRamBuf2, NV_RAM_SIZE, offset); if (memcmp((char *)vtsNvRamBuf1,(char *)vtsNvRamBuf2, writeableSize) == 0) retValue = OK; break; } case 3: /* sysNvRamGet() with length zero */ { if (NV_RAM_SIZE < 3) break; vtsNvRamBuf1 [0] = '1'; vtsNvRamBuf1 [1] = '2'; vtsNvRamBuf1 [2] = '3'; if (sysNvRamGet ((char *) (vtsNvRamBuf1 + 1), 0, offset) == ERROR) break; /* verify a zero in vtsNvRamBuf [1], while vtsNvRamBuf [0] and vtsNvRamBuf [2] unchanged */ if ((vtsNvRamBuf1 [0] == '1') && (vtsNvRamBuf1 [1] == 0) && (vtsNvRamBuf1 [2] == '3')) retValue = OK; break; } case 4: /* sysNvRamSet() parameter checking */ { if ((sysNvRamSet((char *)vtsNvRamBuf1, -1, offset) == ERROR) && (sysNvRamSet((char *)vtsNvRamBuf1, 0, offset - 1) == ERROR) && (sysNvRamSet((char *)vtsNvRamBuf1, writeableSize + 1, offset) == ERROR) && (sysNvRamSet((char *)vtsNvRamBuf1,0, offset + writeableSize + 1) == ERROR) && (sysNvRamSet((char *)vtsNvRamBuf1, writeableSize / 2 + 1, offset + (writeableSize / 2) + 1) == ERROR)) { retValue = OK; } break; } case 5: /* sysNvRamGet() parameter checking */ { if ((sysNvRamGet((char *)vtsNvRamBuf1, -1, offset) == ERROR) && (sysNvRamGet((char *)vtsNvRamBuf1, 0, offset - 1) == ERROR) && (sysNvRamGet((char *)vtsNvRamBuf1, NV_RAM_SIZE + 1, offset) == ERROR) && (sysNvRamGet((char *)vtsNvRamBuf1, 0, offset + NV_RAM_SIZE + 1) == ERROR) && (sysNvRamGet((char *)vtsNvRamBuf1, NV_RAM_SIZE / 2 + 1, offset + (NV_RAM_SIZE / 2) + 1) == ERROR)) { retValue = OK; } break; } case 6: /* sysNvRamSet() and sysNvRamGet() of 0xff data */ { if (writeableSize < 4) break; vtsNvRamBuf1 [0] = vtsNvRamBuf1 [1] = vtsNvRamBuf1 [2] = vtsNvRamBuf1 [3] = 0xff; vtsNvRamBuf2 [0] = vtsNvRamBuf2 [1] = vtsNvRamBuf2 [2] = vtsNvRamBuf2 [3] = 0x55; if (sysNvRamSet ((char *) vtsNvRamBuf1, 4, offset) == ERROR) break; if (sysNvRamGet ((char *) vtsNvRamBuf2, 3, offset) == ERROR) break; if ((vtsNvRamBuf2 [0] == 0xff) && (vtsNvRamBuf2 [1] == 0xff) && (vtsNvRamBuf2 [2] == 0xff) && (vtsNvRamBuf2 [3] == 0x00)) { retValue = OK; } break; } case 7: /* sysNvRamSet() and sysNvRamGet() of 0x00 data */ { if (writeableSize < 4) break; vtsNvRamBuf1 [0] = vtsNvRamBuf1 [1] = vtsNvRamBuf1 [2] = vtsNvRamBuf1 [3] = 0x00; vtsNvRamBuf2 [0] = vtsNvRamBuf2 [1] = vtsNvRamBuf2 [2] = vtsNvRamBuf2 [3] = 0xff; if (sysNvRamSet ((char *) vtsNvRamBuf1, 4, offset) == ERROR) break; if (sysNvRamGet ((char *) vtsNvRamBuf2, 3, offset) == ERROR) break; if ((vtsNvRamBuf2 [0] == 0x00) && (vtsNvRamBuf2 [1] == 0x00) && (vtsNvRamBuf2 [2] == 0x00) && (vtsNvRamBuf2 [3] == 0x00)) { retValue = OK; } break; } case 8: /* sysNvRamSet() and sysNvRamGet() of boot line */ { if (sysNvRamSet (vtsOrigBootLine, writeableSize, offset) == ERROR) break; if (sysNvRamGet((char *)vtsNvRamBuf1, NV_RAM_SIZE, offset) == ERROR) break; if (memcmp(vtsOrigBootLine, (char *)vtsNvRamBuf1, writeableSize) == 0) retValue = OK; break; } default: { break; } } return (retValue); }#endif /* NV_RAM_SIZE *//********************************************************************************* pkConsoleEcho - routine to put console into echo mode** This routine puts the serial console in raw mode, then turns on the character* echo mode bit. The console will remain in echo mode until <numToEcho>* characters have been echoed, or an "eof" (ASCII 0x04) is received. If* <numToEcho> is zero, the only way to exit echo mode is to send an "eof".** RETURNS: OK or ERROR.*/STATUS pkConsoleEcho ( int numToEcho /* number of characters to echo (0 means infinite) */ ) { if (numToEcho < 0) { printf ("pkConsoleEcho: invalid parameter\n"); return (ERROR); } /* set the serial console to echo chars */ (void) ioctl (0, FIOSETOPTIONS, OPT_RAW); (void) ioctl (1, FIOSETOPTIONS, OPT_RAW); (void) ioctl (0, FIOSETOPTIONS, OPT_ECHO); /* continue to echo until <numToEcho> exhausted or "eof" received */ while ( ! pkConsoleEchoAbort) { getc(stdin) ; if (numToEcho) if (-- numToEcho == 0) break; } /* reset the console back to terminal mode */ (void) ioctl (0, FIOSETOPTIONS, OPT_TERMINAL); (void) ioctl (1, FIOSETOPTIONS, OPT_TERMINAL); return (OK); }/********************************************************************************* pkSeqLoopHook - sequential serial loopback test input hook routine** This routine monitors serial inputs for the sequential serial loopback test.* Whenever a character is written to serial port <channel>, this routine is* called. It updates the count of characters written to <channel> and checks* that <inChar> matches the expected character from the sequential pattern* being sent in pkLoopbackTest(0,X,X,X).** RETURNS: TRUE.*/LOCAL BOOL pkSeqLoopHook ( int channel, /* channel number */ int inChar /* input character */ ) { char matchChar; /* expected input character */ if ((channel >= 0) && (channel < NUM_TTY)) { ++ pkSeqLoopCount [channel][0]; /* bump character counter */ /* find next character in pattern, and bump state counter */ if (loopState [channel] < PK_LOOP_OUT_LEN - 1) matchChar = 0x00 + ((loopState [channel] ++) % PK_LOOP_PAT_LEN); else { /* output buffer turned over */ matchChar = '0' + (channel % 10); /* '0' ... '9' */ loopState [channel] = 0; } if (inChar != matchChar) /* mismatch? */ { ++ pkSeqLoopCount [channel][1]; /* bump error counter */ loopState [channel]++; /* compensate for dropped char */ } } return (TRUE); /* no further processing of the character */ }/********************************************************************************* pkMultiLoopHook - multiple loopback test input hook routine** This routine monitors serial inputs for the multiple serial loopback test.* Whenever a character is written to serial port <channel>, this routine is* called. It updates the count of characters written to <channel> from the* task (pkLoopbackTest(1,X,X,X)) associated with <inChar>.** RETURNS: TRUE.*/LOCAL BOOL pkMultiLoopHook ( int channel, /* channel number */ int inChar /* input character */ ) { int offset; /* offset to access correct data location */ if ((channel >= 0) && (channel < NUM_TTY)) { offset = inChar - 'A'; ++ pkMultiLoopCount [channel][offset]; /* bump character counter */ } return (TRUE); /* no further processing of the character */ }/********************************************************************************* pkLoopbackTest - loopback test routine** This routine is called to perform either one of two tests, based upon* the value of <mTest>.** If <mTest> is 0, the sequential serial loopback test is run. This test will* write a sequential pattern of characters over and over, until <numToSend>* chars are sent. If <numToSend>=0, then an infinite number of chars are sent.* Characters are sent at <baud> baud rate to serial port <channel>.** Else, if <mTest> is 1, the multiple serial test is started. This test will* recursively call pkLoopbackTest() until PK_LOOP_TASK_NUM number of calls* have taken place. Each call results in a task that will write <numToSend>* unique characters to serial port <channel> at baud rate <baud>.* If <numToSend>=0, then an infinite number of chars are sent. The initial* pkLoopbackTest opens the file descriptor to the serial port, makes the* recursive calls, waits for the other tasks to end, and then closes the file* descriptor.** NOTE: Transmission will abort if the global variable <pkLoopbackAbort> is* set to a non-zero value.** RETURNS: OK or ERROR.*/STATUS pkLoopbackTest ( int mTest, /* 0 = sequential test, 1 = multiple task test */ int channel, /* channel number to test */ int baud, /* baud rate for test */ int numToSend /* number of chars to send (0 means infinite) */ ) { char loopName [10]; /* more than enough chars for "tyCo/NN" */ char inBuf; /* one character input buffer */ char letterL = 'L'; /* one character output buffer */ char outBuf [PK_LOOP_OUT_LEN]; /* loopback pattern output buffer */ int call=0; /* number of tasks open in multiple test */ int loopFd; /* file descriptor for <channel> */ int mule; /* scratch */ int numSent=0; /* characters sent so far in loop */ /* check for valid parameters */ if ((channel == CONSOLE_TTY) || (channel < 0) || (channel >= NUM_TTY) || (baud == 0) || (numToSend < 0) || ((mTest != 0) && (mTest != 1))) { printf ("pkLoopbackTest: Error: invalid parameter\n"); return (ERROR); } /* if running multiple loopback test, initialize data structures (once) */ if (mTest == 1) { if (pkLoopInit == 0) { pkLoopInit = 1; for (mule = 0; mule < NUM_TTY; mule ++) pkLoopTask [mule] = 0; }#if (PK_LOOP_TASK_NUM < 1) printf ("pkLoopbackTest: Error: set for too few tasks\n"); return (ERROR);#else /* PK_LOOP_TASK_NUM */ /* increment number of multiple loopback tasks open */ call = pkLoopTask [channel] ++;#endif /* PK_LOOP_TASK_NUM */ } /* on first call of multiple - always on sequential */ if (call == 0) { /* open file descriptor for the loopback device */ sprintf (loopName,"/tyCo/%d",channel); pkLoopFd [channel] = open (loopName, O_RDWR, 0); loopFd = pkLoopFd [channel]; if (loopFd == ERROR) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -