📄 slim_pro.c
字号:
unsigned char ucMaskByte = 0;
unsigned char ucCurBit = 0;
for ( uiIndex = 0; uiIndex < a_uiDataSize; uiIndex++ ) {
if ( uiIndex % 8 == 0 ) {
if ( g_usDataType & TDO_DATA ) {
/*************************************************************
* *
* If the TDO_DATA flag is set, then grab the next byte from *
* the algo array and increment the TDO index. *
* *
*************************************************************/
ucTDOByte = GetByte( g_iTDOIndex++, 1 );
}
else {
/*************************************************************
* *
* If TDO_DATA is not set, then DTDO_DATA must be set. If *
* the compression counter exists, then the next TDO byte *
* must be 0xFF. If it doesn't exist, then get next byte *
* from data file array. *
* *
*************************************************************/
if ( g_ucCompressCounter ) {
g_ucCompressCounter--;
ucTDOByte = ( unsigned char ) 0xFF;
}
else {
ucTDOByte = GetByte( g_iMovingDataIndex++, 0 );
/*************************************************************
* *
* If the frame is compressed and the byte is 0xFF, then the *
* next couple bytes must be read to determine how many *
* repetitions of 0xFF are there. That value will be stored *
* in the variable g_ucCompressCounter. *
* *
*************************************************************/
if ( ( g_usDataType & COMPRESS_FRAME ) && ( ucTDOByte == ( unsigned char ) 0xFF ) ) {
g_ucCompressCounter = GetByte( g_iMovingDataIndex++, 0 );
g_ucCompressCounter--;
}
}
}
if ( g_usDataType & MASK_DATA ) {
ucMaskByte = GetByte( g_iMASKIndex++, 1 );
}
else {
ucMaskByte = ( unsigned char ) 0xFF;
}
}
ucCurBit = readPort();
if ( ( ( ( ucMaskByte << uiIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ) ) {
if ( ucCurBit != ( unsigned char ) ( ( ( ucTDOByte << uiIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ) ) {
usErrorCount++;
}
}
/*************************************************************
* *
* Always shift 0x01 into TDI pin when reading. *
* *
*************************************************************/
writePort( pinTDI, ( unsigned char ) 0x01 );
if ( uiIndex < a_uiDataSize - 1 ) {
sclock();
}
}
if ( usErrorCount > 0 ) {
return -1;
}
return 0;
}
/*************************************************************
* *
* ISPVMSEND *
* *
* INPUT: *
* a_uiDataSize: this argument is the size of the *
* command. *
* *
* RETURN: *
* None. *
* *
* DESCRIPTION: *
* This function sends a data stream to the device. *
* *
*************************************************************/
void ispVMSend( unsigned int a_uiDataSize )
{
unsigned int iIndex;
unsigned char ucCurByte = 0;
unsigned char ucBitState = 0;
/*************************************************************
* *
* Begin processing the data to the device. *
* *
*************************************************************/
for ( iIndex = 0; iIndex < a_uiDataSize; iIndex++ ) {
if ( iIndex % 8 == 0 ) {
if ( g_usDataType & TDI_DATA ) {
/*************************************************************
* *
* If the TDI_DATA flag is set, then grab the next byte from *
* the algo array and increment the TDI index. *
* *
*************************************************************/
ucCurByte = GetByte( g_iTDIIndex++, 1 );
}
else {
/*************************************************************
* *
* If TDI_DATA flag is not set, then DTDI_DATA flag must have *
* already been set. If the compression counter exists, then *
* the next TDI byte must be 0xFF. If it doesn't exist, then *
* get next byte from data file array. *
* *
*************************************************************/
if ( g_ucCompressCounter ) {
g_ucCompressCounter--;
ucCurByte = ( unsigned char ) 0xFF;
}
else {
ucCurByte = GetByte( g_iMovingDataIndex++, 0 );
/*************************************************************
* *
* If the frame is compressed and the byte is 0xFF, then the *
* next couple bytes must be read to determine how many *
* repetitions of 0xFF are there. That value will be stored *
* in the variable g_ucCompressCounter. *
* *
*************************************************************/
if ( ( g_usDataType & COMPRESS_FRAME ) && ( ucCurByte == ( unsigned char ) 0xFF ) ) {
g_ucCompressCounter = GetByte( g_iMovingDataIndex++, 0 );
g_ucCompressCounter--;
}
}
}
}
ucBitState = ( unsigned char ) ( ( ( ucCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 );
writePort( pinTDI, ucBitState );
if ( iIndex < a_uiDataSize - 1 ) {
sclock();
}
}
}
/*************************************************************
* *
* ISPVMSTATEMACHINE *
* *
* INPUT: *
* a_cNextState: this is the opcode of the next JTAG *
* state. *
* *
* RETURN: *
* This functions returns 0 when passing, and -1 when *
* failure occurs. *
* *
* DESCRIPTION: *
* This function is called to move the device into *
* different JTAG states. *
* *
*************************************************************/
void ispVMStateMachine( char a_cNextState )
{
char cPathIndex, cStateIndex;
if ( g_cCurrentJTAGState == a_cNextState ) {
return;
}
for ( cStateIndex = 0; cStateIndex < 20; cStateIndex++ ) {
if ( ( g_cCurrentJTAGState == iStates[ cStateIndex ].CurState ) && ( a_cNextState == iStates[ cStateIndex ].NextState ) ) {
break;
}
}
#ifdef VME_DEBUG
switch ( a_cNextState ) {
case RESET:
printf( "RESET\n" );
break;
case IDLE:
printf( "IDLE\n" );
break;
case IRPAUSE:
printf( "IRPAUSE\n" );
break;
case DRPAUSE:
printf( "DRPAUSE\n" );
break;
case SHIFTIR:
printf( "SHIFTIR\n" );
break;
case SHIFTDR:
printf( "SHIFTDR\n" );
break;
default:
printf( "UNKNOWN\n" );
}
#endif /* VME_DEBUG */
g_cCurrentJTAGState = a_cNextState;
for ( cPathIndex = 0; cPathIndex < iStates[ cStateIndex ].Pulses; cPathIndex++ ) {
if ( ( iStates[ cStateIndex ].Pattern << cPathIndex ) & 0x80 ) {
writePort( pinTMS, ( unsigned char ) 0x01 );
}
else {
writePort( pinTMS, ( unsigned char ) 0x00 );
}
sclock();
}
writePort( pinTDI, 0x00 );
writePort( pinTMS, 0x00 );
}
/*************************************************************
* *
* ISPVMCLOCKS *
* *
* INPUT: *
* a_usClocks: number of clocks to apply. *
* *
* RETURN: *
* None. *
* *
* DESCRIPTION: *
* This procedure applies the specified number of pulses *
* to TCK. *
* *
*************************************************************/
void ispVMClocks( unsigned int a_uiClocks )
{
#ifdef VME_DEBUG
printf( "%d\n", a_uiClocks );
#endif /* VME_DEBUG */
for ( ; a_uiClocks > 0; a_uiClocks-- ) {
sclock();
}
}
/*************************************************************
* *
* ISPVMBYPASS *
* *
* INPUT: *
* a_siLength: this argument is the length of the *
* command. *
* *
* RETURN: *
* None. *
* *
* DESCRIPTION: *
* This function takes care of the HIR, HDR, TIR, and TDR *
* for the purpose of putting the other devices into *
* bypass mode. *
* *
*************************************************************/
void ispVMBypass( unsigned int a_uiLength )
{
/*************************************************************
* *
* Issue a_siLength number of 0x01 to the TDI pin to bypass. *
* *
*************************************************************/
for ( ; a_uiLength > 1; a_uiLength-- ) {
writePort( pinTDI, ( char ) 0x01 );
sclock();
}
writePort( pinTDI, ( char ) 0x01 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -