📄 chipdefbase.cpp
字号:
if ( Flags & GN_BITS )
{
int LeftBit, RightBit;
bitpos32( m_Features[iFeature].RegMask, &LeftBit, &RightBit );
if ( LeftBit == RightBit )
iName += sprintf( Name+iName, ( (Flags & GN_SHORT) ? "b%d":"Bit%d" ), RightBit );
else
iName += sprintf( Name+iName, ( (Flags & GN_SHORT) ? "b%d:%d":"Bits %d:%d" ), LeftBit, RightBit );
strcat( Name, " " );
iName = strlen( Name );
}
else if ( Flags & GN_REG )
{
int LeftBit, RightBit;
if ( (Flags&GN_NAME) > 0 )
iName += sprintf( Name+iName, "(" );
if ( m_Features[iFeature].RegSpan )
{
iName += sprintf( Name+iName, "REG[SPAN]" );
if ( m_Features[iFeature].NeedCode )
iName += sprintf( Name+iName, "+CODE" );
}
else if ( m_Features[iFeature].RegIndex == 0xFFFFFFFF )
{
iName += sprintf( Name+iName, "CODE" );
}
else
{
iName += sprintf( Name+iName, "REG[%0*Xh", m_DefaultRegIndexField, m_Features[iFeature].RegIndex );
bitpos32( m_Features[iFeature].RegMask, &LeftBit, &RightBit );
if ( RightBit==0 && LeftBit==15 )
iName += sprintf( Name+iName, "]" );
else if ( LeftBit == RightBit )
iName += sprintf( Name+iName, ((Flags&GN_SHORT)?"-b%d]":"] Bit %d"), RightBit );
else
iName += sprintf( Name+iName, ((Flags&GN_SHORT)?"-b%d:%d]":"] Bits %d:%d"), LeftBit, RightBit );
if ( m_Features[iFeature].NeedCode )
iName += sprintf( Name+iName, "+CODE" );
}
if ( (Flags&GN_NAME) > 0 )
iName += sprintf( Name+iName, ")" );
strcat( Name, " " );
iName = strlen( Name );
}
if ( Flags & GN_ATTRS )
{
bool Reserved = m_Features[iFeature].Reserved && MatchToCurrentProduct(m_Features[iFeature].Reserved);
if ( m_Features[iFeature].ReadOnly || m_Features[iFeature].WriteOnly || Reserved )
strcat( Name, "[" );
if ( m_Features[iFeature].ReadOnly )
strcat( Name, ((Flags&GN_SHORT)?"RO,":"READONLY,") );
else if ( m_Features[iFeature].WriteOnly )
strcat( Name, ((Flags&GN_SHORT)?"WO,":"WRITEONLY,") );
if ( Reserved )
strcat( Name, ((Flags&GN_SHORT)?"RSVD,":"RESERVED,") );
if ( m_Features[iFeature].ReadOnly || m_Features[iFeature].WriteOnly || Reserved )
{
iName = strlen( Name ); // First get rid of comma.
Name[iName-1] = '\0';
strcat( Name, "] " );
}
iName = strlen( Name );
}
// Get rid of last space.
iName = strlen(Name) - 1;
if ( Name[iName] == ' ' )
Name[iName] = '\0';
}
return Name;
}
assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!
return 0;
}
const char* ChipDefBase::GetFeatureDesc( in const char* Keyname )
{
UInt32 iFeature;
if ( LookupFeature(Keyname,&iFeature) )
{
if ( m_Features[iFeature].Desc && m_Features[iFeature].Desc[0] )
return m_Features[iFeature].Desc;
else
{
// It's probably a LSB|ISB|MSB feature, so fetch the name from the span parent.
const char* Suffix = NULL;
const char* SpanParent = GetFeatureSpanParent( m_Features[iFeature].Keyname, &Suffix );
if ( SpanParent )
{
char* Desc = GetCircularStr( m_SP );
const char* Word = NULL;
switch ( Suffix[0] )
{
case 'L': Word="Least"; break;
case 'I': Word="Intermediate"; break;
case 'M': Word="Most"; break;
}
sprintf( Desc, "The %s Significant Bits (%s) of the %s.", Word, Suffix, GetFeatureName(SpanParent,GN_NAME) );
return Desc;
}
}
return "";
}
assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!
return NULL;
}
const char* ChipDefBase::GetFeatureSummary( in const char* Keyname, inout char* TextBuf, in char* LinePrefix, in char* LineTerminator, in bool ShowMargin, in int NumTextCols )
//
// MARGIN@20===========TEXT======================================================== (LINES WRAP @ NumTextCols)
{
UInt32 iFeature;
int MarginWidth = ( ShowMargin ? 20 : 0 );
TextBuf[0] = '\0';
if ( LookupFeature(Keyname,&iFeature) )
{
char* RegFormula = GetCircularStr( m_SP );
char* RegProof = GetCircularStr( m_SP );
char* RegTerm = GetCircularStr( m_SP );
UInt32 RawValue = 0;
UInt32 ToRawValue = 0;
int iLine = 0;
bool IsComplexTerm = false;
const char* FeatureDesc = GetFeatureDesc( Keyname );
// Print feature name.
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
strcat( TextBuf, GetFeatureName(Keyname,GN_NAME|GN_ATTRS) );
if ( FeatureDesc )
{
for ( int iDesc=0; iDesc<(int)strlen(FeatureDesc); )
{
// Print a line of the description.
int TextBufLen, nWrap;
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
TextBufLen = strlen( TextBuf );
nWrap = DetectWordWrap( FeatureDesc+iDesc, NumTextCols-MarginWidth );
for ( int i=nWrap; i>=0; i-- )
TextBuf[TextBufLen+i] = FeatureDesc[iDesc+i];
TextBuf[TextBufLen+nWrap+1] = '\0';
iDesc += nWrap+1;
}
}
if ( m_Features[iFeature].RegSpan )
{
// REG[004C-b5:0]<<32 + REG[004A-b5:0]<<16 + REG[0048-b15:0]
char TempKeyname[16];
int LeftBit, RightBit;
int nShift = 0;
UInt32 iTempFeature;
for ( int i=0; i<3; i++ )
{
strcpy( TempKeyname, Keyname );
switch ( i )
{
case 0: strcat(TempKeyname,"LSB"); break;
case 1: strcat(TempKeyname,"ISB"); break;
case 2: strcat(TempKeyname,"MSB"); break;
}
if ( LookupFeature(TempKeyname,&iTempFeature) )
{
if ( IsComplexTerm )
{
strpre( RegFormula, " + " );
if ( !IsFeatureWriteOnly(TempKeyname) )
strpre( RegProof, " + " );
}
if ( nShift == 0 )
{
strpre( RegFormula, GetFeatureName(TempKeyname,GN_REG|GN_SHORT) );
if ( !IsFeatureWriteOnly(TempKeyname) )
{
sprintf( RegTerm, "%Xh", GetFeatureRawValue(TempKeyname) );
strpre( RegProof, RegTerm );
}
}
else
{
sprintf( RegTerm, "%s<<%d", GetFeatureName(TempKeyname,GN_REG|GN_SHORT), nShift );
strpre( RegFormula, RegTerm );
if ( !IsFeatureWriteOnly(TempKeyname) )
{
sprintf( RegTerm, "%Xh<<%d", GetFeatureRawValue(TempKeyname), nShift );
strpre( RegProof, RegTerm );
}
}
bitpos32( m_Features[iTempFeature].RegMask, &LeftBit, &RightBit );
nShift += LeftBit - RightBit + 1;
IsComplexTerm = true;
}
else
assert( i==1 ); // Only ISB is optional.
}
}
else
{
if ( m_Features[iFeature].Type!=FT_TEXT && m_Features[iFeature].Type!=FT_SEQU )
{
strcpy( RegFormula, GetFeatureName(Keyname,GN_REG|GN_SHORT) );
if ( m_Features[iFeature].RegIndex != 0xFFFFFFFF )
if ( !IsFeatureWriteOnly(Keyname) )
sprintf( RegProof, "%Xh", GetFeatureRawValue(Keyname) );
}
}
switch ( m_Features[iFeature].Type )
{
case FT_NUMB:
case FT_ADDR:
case FT_FREQ:
// Show formula.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = ", Keyname );
if ( m_Features[iFeature].Op2 ) strcat( TextBuf, "(" );
if ( m_Features[iFeature].Op1 && IsComplexTerm ) strcat( TextBuf, "(" );
strcat( TextBuf, RegFormula );
if ( m_Features[iFeature].Op1 && IsComplexTerm ) strcat( TextBuf, ")" );
if ( m_Features[iFeature].Op1 ) sprintf( TextBuf+strlen(TextBuf), " %c %s", m_Features[iFeature].Op1[0], m_Features[iFeature].Op1+1 );
if ( m_Features[iFeature].Op2 ) sprintf( TextBuf+strlen(TextBuf), ") %c %s", m_Features[iFeature].Op2[0], m_Features[iFeature].Op2+1 );
// Show proof.
if ( (IsComplexTerm||m_Features[iFeature].Op1||m_Features[iFeature].Op2) && !IsFeatureWriteOnly(Keyname) && m_Features[iFeature].RegIndex!=0xFFFFFFFF )
{
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = ", Keyname );
if ( m_Features[iFeature].Op2 ) strcat( TextBuf, "(" );
if ( m_Features[iFeature].Op1 && IsComplexTerm ) strcat( TextBuf, "(" );
strcat( TextBuf, RegProof );
if ( m_Features[iFeature].Op1 && IsComplexTerm ) strcat( TextBuf, ")" );
if ( m_Features[iFeature].Op1 ) sprintf( TextBuf+strlen(TextBuf), " %c %s", m_Features[iFeature].Op1[0], m_Features[iFeature].Op1+1 );
if ( m_Features[iFeature].Op2 ) sprintf( TextBuf+strlen(TextBuf), ") %c %s", m_Features[iFeature].Op2[0], m_Features[iFeature].Op2+1 );
}
// Show final value.
if ( !IsFeatureWriteOnly(Keyname) )
{
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
if ( m_Features[iFeature].RegIndex == 0xFFFFFFFF )
sprintf( TextBuf+strlen(TextBuf), " %s = %s", Keyname, GetFeatureStrValue(Keyname) );
else
sprintf( TextBuf+strlen(TextBuf), " %s = %Xh (%s)", Keyname, GetFeatureRawValue(Keyname), GetFeatureStrValue(Keyname) );
}
break;
case FT_TEXT:
// Show formula.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = %s", Keyname, RegFormula );
// Show value
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = \"%s\"", Keyname, GetFeatureStrValue(Keyname,true) );
break;
case FT_LIST:
case FT_BOOL:
// Show formula.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = %s", Keyname, RegFormula );
// Show value.
if ( !IsFeatureWriteOnly(Keyname) )
{
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = %Xh (%s)", Keyname, GetFeatureRawValue(Keyname), GetFeatureStrValue(Keyname) );
}
break;
case FT_SEQU:
// Show value
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " %s = %s", Keyname, GetFeatureStrValue(Keyname,true) );
break;
}
// Show possible values.
switch ( m_Features[iFeature].Type )
{
case FT_LIST:
case FT_BOOL:
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
strcat( TextBuf, "Possible Values:" );
if ( m_Features[iFeature].NumValues == 0 )
{
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
sprintf( TextBuf+strlen(TextBuf), " 0h = %s", GetFeatureStrValue(Keyname) );
}
else
{
for ( int i=0; GetFeatureListValues(Keyname,i,&RawValue,&ToRawValue); i++ )
{
if ( MatchToCurrentProduct(m_Features[iFeature].Values[i].Product) && (m_DebugMode || !(m_Features[iFeature].Values[i].Reserved && MatchToCurrentProduct(m_Features[iFeature].Values[i].Reserved))) )
{
if ( IsFeatureListIndexRWDiff(Keyname,RawValue) )
{
if ( !IsFeatureListIndexWriteOnly(Keyname,RawValue) )
{
// Show [ON READ] value.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
if ( RawValue == ToRawValue )
sprintf( TextBuf+strlen(TextBuf), " %Xh [ON READ] = %s", RawValue, GetFeatureStrValue(Keyname,RawValue,true) );
else
sprintf( TextBuf+strlen(TextBuf), " %Xh-%Xh [ON READ] = %s", RawValue, ToRawValue, GetFeatureStrValue(Keyname,RawValue,true) );
}
if ( !IsFeatureListIndexReadOnly(Keyname,RawValue) )
{
// Show [ON WRITE] value.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
if ( RawValue == ToRawValue )
sprintf( TextBuf+strlen(TextBuf), " %Xh [ON WRITE] = %s", RawValue, GetFeatureStrValue(Keyname,RawValue,false) );
else
sprintf( TextBuf+strlen(TextBuf), " %Xh-%Xh [ON WRITE] = %s", RawValue, ToRawValue, GetFeatureStrValue(Keyname,RawValue,false) );
}
}
else
{
// Show value.
if (LineTerminator) strcat( TextBuf, LineTerminator );
if (LinePrefix) strcat( TextBuf, LinePrefix );
if (ShowMargin) strcat( TextBuf, GetFeatureSummaryMargin(iFeature,MarginWidth,iLine++) );
if ( RawValue == ToRawValue )
sprintf( TextBuf+strlen(TextBuf), " %Xh = %s", RawValue, GetFeatureStrValue(Keyname,RawValue) );
else
sprintf( TextBuf+strlen(TextBuf), " %Xh-%Xh = %s", RawValue, ToRawValue, GetFeatureStrValue(Keyname,RawValue) );
}
}
}
}
break;
}
return TextBuf;
}
assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!
return NULL;
}
const char* ChipDefBase::GetFeatureUnitType( in const char* Keyname )
{
UInt32 iFeature;
if ( LookupFeature(Keyname,&iFeature) )
return (m_Features[iFeature].Unit==NULL) ? "" : m_Features[iFeature].Unit;
assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!
return NULL;
}
const char* ChipDefBase::GetFeatureSpanParent( in const char* Keyname, out const char* *Suffix )
{
UInt32 iEnd = strlen( Keyname );
if ( Keyname[iEnd-2]=='S' && Keyname[iEnd-1]=='B' ) // LSB or ISB or MSB (must always be caps).
{
char* SpanFeature = GetCircularStr( m_SP );
if ( Suffix )
*Suffix = Keyname + iEnd - 3;
strcpy( SpanFeature, Keyname );
SpanFeature[iEnd-3] = '\0';
return SpanFeature;
}
if ( Suffix )
*Suffix = NULL;
return NULL;
}
UInt32 ChipDefBase::GetFeatureRawValue( in const char* Keyname )
{
UInt32 iFeature;
if ( LookupFeature(Keyname,&iFeature) )
{
UInt32 RetVal = 0;
int nShift = 0;
assert( m_Features[iFeature].Type!=FT_TEXT );
assert( m_Features[iFeature].WriteOnly==false );
if ( m_Features[iFeature].RegSpan )
{
// "keynameMSB"&MSBmask<<(ISBmaskwidth+LSBmaskwidth) + "keynameISB"&ISBmask<<LSBmaskwidth + "keynameLSB"&LSBmask
char TempKeyname[16];
UInt32 iTempFeature;
int LeftBit, RightBit;
for ( int i=0; i<3; i++ )
{
strcpy( TempKeyname, Keyname );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -