📄 ks_diag.c
字号:
*
* Format: "hwpoll BankNum RegAddr BitMask BitPattern TimeOut"
*
******************************************************************/
int hwpoll
(
unsigned char BankNum,
unsigned long RegAddr,
unsigned long BitMask,
unsigned long BitPattern,
unsigned long TimeOut
)
{
unsigned long RegData=0;
#ifdef DEF_VXWORKS
PHARDWARE phw = gpDrvCtrl[0]->pHW;
#endif
/*
* Validate parameters
*/
if ( !(isValidBank( BankNum )) )
return FALSE;
if ( !(isValidRegAddr( RegAddr )) )
return FALSE;
if ( phw == NULL )
{
DisplayErrRetMsg( 3 ) ;
return FALSE;
}
/*
* Poll the register
*/
while ( TimeOut-- )
{
/* Check if bit pattern exists */
#ifdef KS_ISA_BUS
HardwareReadRegWord( phw,
(UCHAR)BankNum,
(UCHAR)RegAddr,
(PUSHORT)&RegData
);
#else /* PCI BUS */
if ( RegAddr < MAX_DWORD_OFFSET )
{
HW_READ_DWORD( phw,
(ULONG)RegAddr,
(PULONG)&RegData
);
}
else
{
HW_READ_WORD( phw,
(ULONG)RegAddr,
(PUSHORT)&RegData
);
}
#endif
RegData &= BitMask;
if (RegData == BitPattern)
break ;
if (!TimeOut)
/* Fail if we're out of time */
DisplayErrRetMsg( 4 ) ;
else
/* Delay 1 microsecond of time to check */
DelayMillisec( 1 ) ;
}
DBG_PRINT( NEWLINE);
return TRUE ;
}
/*****************************************************************
*
* Command: hwbufread
*
* Format: "hwbufread BufNum BufOffset Length"
*
******************************************************************/
int hwbufread
(
unsigned long BufNum,
unsigned long BufOffset,
unsigned long CountTotal
)
{
#define ITEMS_PER_ROW 16
unsigned long CountRowItems ;
if (BufferInit() != TRUE)
{
return FALSE ;
}
/*
* Validate parameters
*/
if (BufNum >= BUFFER_COUNT)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
if (BufOffset >= BUFFER_LENGTH)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
if ( (BufOffset+CountTotal) > BUFFER_LENGTH)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
CountRowItems = ITEMS_PER_ROW ;
/*
* Read and display Count number of data bytes
*/
while (CountTotal--)
{
/* Exit if reference is outside of buffer */
if (BufOffset >= BUFFER_LENGTH)
{
break ;
}
/* Check if time to display new row of data bytes */
if (CountRowItems == ITEMS_PER_ROW)
{
DBG_PRINT( NEWLINE"%08lx ", BufOffset ) ;
CountRowItems = 0 ;
}
/* Display delimiter between data bytes */
if (CountRowItems == (ITEMS_PER_ROW / 2))
{
DBG_PRINT( " - " ) ;
}
else
{
DBG_PRINT( " " ) ;
}
/* Display current data byte */
DBG_PRINT( "%02x", apbBuffer[ BufNum ][ BufOffset ] ) ;
/* Reference next data byte */
BufOffset++ ;
CountRowItems++ ;
}
DBG_PRINT( NEWLINE);
DBG_PRINT( NEWLINE);
return TRUE ;
}
/*****************************************************************
*
* Command: hwbufwrite
*
* Format: "hwbufwrite BufNum BufOffset BufData [...]"
*
******************************************************************/
int hwbufwrite
(
unsigned long BufNum,
unsigned long BufOffset,
unsigned char FAR *BufData
)
{
#if !defined( _WIN32 ) && !defined( DEF_LINUX ) && !defined( KS_ARM )
char FAR * pHolder = NULL;
char FAR * tok;
if (BufferInit() != TRUE)
{
return FALSE ;
}
/*
* Validate parameters
*/
if (BufNum >= BUFFER_COUNT)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
if (BufOffset >= BUFFER_LENGTH)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
/*
* Write data bytes to buffer
*/
#if defined (M16C_62P) || defined (_EZ80L92)
tok = (char FAR * )strtok_p ( (char FAR *)BufData, (const char FAR *)SPACE, (char FAR **)&pHolder );
#else
tok = strtok_r ( BufData, SPACE, &pHolder );
#endif
apbBuffer[ BufNum ][ BufOffset++ ] = (unsigned char FAR) strtol ( tok, NULL, 16 ) ;
while (pHolder != NULL)
{
/* Exit if reference is outside of buffer */
if (BufOffset >= BUFFER_LENGTH)
break ;
/* Write current data byte */
#if defined (M16C_62P) || defined (_EZ80L92)
tok = strtok_p( pHolder, (const char FAR *)SPACE, &pHolder );
#else
tok = strtok_r ( NULL, SPACE, &pHolder );
#endif
apbBuffer[ BufNum ][ BufOffset++ ] = (unsigned char FAR) strtol ( tok, NULL, 16 ) ;
}
#ifndef KS_QC_TEST
DBG_PRINT( NEWLINE);
#endif
#endif
return TRUE ;
}
/*****************************************************************
*
* Command: hwbuffill
*
* Format: "hwbuffill BufNum BufOffset BufData BufInc Length"
*
******************************************************************/
int hwbuffill
(
unsigned char BufNum,
unsigned long BufOffset,
unsigned long BufData,
unsigned long BufInc,
unsigned long Count
)
{
if (BufferInit() != TRUE)
{
return FALSE ;
}
/*
* Validate parameters
*/
if (BufNum >= BUFFER_COUNT)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
if (BufOffset >= BUFFER_LENGTH)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
if ( (BufOffset+Count) >= BUFFER_LENGTH)
{
DisplayErrRetMsg( 1 ) ;
return FALSE ;
}
/*
* Write data byte to buffer
*/
while (Count--)
{
/*
* Exit if reference is outside of buffer
*/
if (BufOffset >= BUFFER_LENGTH)
{
break ;
}
apbBuffer[ BufNum ][ BufOffset++ ] = (unsigned char FAR) BufData ;
BufData += BufInc ;
}
#ifndef KS_QC_TEST
DBG_PRINT( NEWLINE);
#endif
return TRUE ;
}
#ifdef DEF_VXWORKS
/*****************************************************************************
*
* hwbuftx_vxWorks - Tx packet to ks884X on Renesas SH7751R vxWorks platform.
* hwbufrx_vxWorks - Rx packet from ks884X on Renesas SH7751R vxWorks platform.
*
******************************************************************************/
static void hwbuftx_vxWorks
(
unsigned long Port,
unsigned long BufNum,
unsigned long BufLen,
unsigned long RepeatCount,
BOOLEAN SameBuf,
unsigned long ms_delay
)
{
PHARDWARE phw = gpDrvCtrl[0]->pHW;
M_BLK_ID pMblk= NULL;
UCHAR * pCluster = NULL;
DRV_CTRL * pDrvCtrl; /* device ptr */
pDrvCtrl = gpDrvCtrl[0];
if ( (phw == NULL) || ( pDrvCtrl == NULL) )
{
DisplayErrRetMsg( 3 ) ;
return;
}
/* Set "fPollSendFromCLI" to indicate that ks884xEndPollSend from CLI command */
pDrvCtrl->fPollSendFromCLI = TRUE;
/* Set trasnmit destination port */
phw->m_bPortTX = Port;
/*
* Transmit the buffer data
*/
/* Grab a Mblock\ClBlk\Cluster block */
#ifdef KS_PCI_BUS
if ( (pMblk = (M_BLK_ID)ks884xAllocMblk(pDrvCtrl, &pCluster, NULL) ) == NULL )
#else
if ( (pMblk = (M_BLK_ID)ks884xSHAllocMblk(pDrvCtrl, &pCluster, NULL) ) == NULL )
#endif
{
DisplayErrRetMsg( 3 ) ;
return ;
}
/* Point data buffer to the MBlock\ClBlk\Cluster structure */
pMblk->mBlkHdr.mData = (char *)apbBuffer[BufNum];
pMblk->mBlkHdr.mFlags |= M_PKTHDR;
pMblk->mBlkHdr.mLen = BufLen;
pMblk->mBlkHdr.mNext = NULL;
while ( RepeatCount > 0 )
{
#ifdef KS_PCI_BUS
if ( ks884xEndSend ( pDrvCtrl, pMblk ) == 0 )
#else
if ( ks884xSHEndSend ( pDrvCtrl, pMblk ) == 0 )
#endif
{
RepeatCount--;
}
/* Find next buffer to transmit */
if ( !SameBuf )
{
if (++BufNum >= BUFFER_COUNT)
BufNum = 0 ;
}
/* else, use same buffer to repeat transmit */
/* Delay in ms if requested */
if ( ms_delay > 0 )
{
taskDelay( ms_delay ) ;
}
} /* while ( RepeatCount > 0 ) */
/* Done, free Mblk\ClBlk */
netMblkClChainFree (pMblk);
/* Clear "fPollSendFromCLI" */
pDrvCtrl->fPollSendFromCLI = FALSE;
}
static unsigned long hwbufrx_vxWorks
(
unsigned long BufNum,
long timeOutCount
)
{
PHARDWARE phw = gpDrvCtrl[0]->pHW;
M_BLK_ID pMblk;
UCHAR * pCluster = NULL;
DRV_CTRL * pDrvCtrl; /* device ptr */
int len;
unsigned long totalRxPacket=0;
pDrvCtrl = gpDrvCtrl[0];
if ( (phw == NULL) || ( pDrvCtrl == NULL) )
{
DisplayErrRetMsg( 3 ) ;
return (totalRxPacket);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -