Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions scopeprotocols/I2CDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ using namespace std;

I2CDecoder::I2CDecoder(const string& color)
: PacketDecoder(color, CAT_BUS)
, m_addrFormat(m_parameters["Address Format"])
{
CreateInput<InputConstraintStreamType>("sda", Stream::STREAM_TYPE_DIGITAL);
CreateInput<InputConstraintStreamType>("scl", Stream::STREAM_TYPE_DIGITAL);

m_addrFormat = FilterParameter(FilterParameter::TYPE_ENUM, Unit(Unit::UNIT_COUNTS));
m_addrFormat.AddEnumValue("Right Justified", RIGHT);
m_addrFormat.AddEnumValue("Left Justified", LEFT);
m_addrFormat.SetIntVal(RIGHT);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -203,7 +209,7 @@ void I2CDecoder::InnerLoop(T* sda, U* scl, I2CWaveform* cap)

if(pack)
{
pack->m_headers["Address"] = to_string_hex(current_byte & 0xfe);
pack->m_headers["Address"] = to_string_hex((LEFT == m_addrFormat.GetIntVal()) ? (current_byte & 0xfe) : (current_byte >> 1));
if(current_byte & 1)
{
pack->m_headers["Op"] = "Read";
Expand Down Expand Up @@ -312,6 +318,7 @@ void I2CDecoder::Refresh(
auto cap = SetupEmptyWaveform<I2CWaveform>(sda, 0);
cap->m_timescale = 1;
cap->m_triggerPhase = 0;
cap->m_addrFormat = m_addrFormat.GetIntVal();
cap->PrepareForCpuAccess();

if(usda && uscl)
Expand Down Expand Up @@ -378,9 +385,9 @@ string I2CWaveform::GetText(size_t i)
break;
case I2CSymbol::TYPE_ADDRESS:
if(s.m_data & 1)
snprintf(tmp, sizeof(tmp), "R:%02x", s.m_data & 0xfe);
snprintf(tmp, sizeof(tmp), "R:%02x", (I2CDecoder::LEFT == m_addrFormat) ? (s.m_data & 0xfe) : (s.m_data >> 1));
else
snprintf(tmp, sizeof(tmp), "W:%02x", s.m_data & 0xfe);
snprintf(tmp, sizeof(tmp), "W:%02x", (I2CDecoder::LEFT == m_addrFormat) ? (s.m_data & 0xfe) : (s.m_data >> 1));
break;
case I2CSymbol::TYPE_DATA:
snprintf(tmp, sizeof(tmp), "%02x", s.m_data);
Expand Down
9 changes: 9 additions & 0 deletions scopeprotocols/I2CDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ class I2CWaveform : public SparseWaveform<I2CSymbol>
I2CWaveform () : SparseWaveform<I2CSymbol>() {};
virtual std::string GetText(size_t) override;
virtual std::string GetColor(size_t) override;

uint8_t m_addrFormat = 0;
};

class I2CDecoder : public PacketDecoder
{
public:
enum AddressJustification
{
RIGHT,
LEFT
};

I2CDecoder(const std::string& color);

virtual void Refresh(vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue) override;
Expand All @@ -92,6 +100,7 @@ class I2CDecoder : public PacketDecoder
PROTOCOL_DECODER_INITPROC(I2CDecoder)

protected:
FilterParameter& m_addrFormat;
template<class T, class U> void InnerLoop(T* sda, U* scl, I2CWaveform* cap);
};

Expand Down
13 changes: 11 additions & 2 deletions scopeprotocols/I2CRegisterDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ I2CRegisterDecoder::I2CRegisterDecoder(const string& color)
m_addrbytes.SetIntVal(1);

m_baseaddr = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_HEXNUM));
m_baseaddr.SetIntVal(0x90);
m_baseaddr.SetIntVal(0x48);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -100,6 +100,15 @@ void I2CRegisterDecoder::Refresh(

din->PrepareForCpuAccess();

//The bus address is entered in the same format displayed by the upstream I2C decoder:
//either right (no R/W bit) or left justified (with the R/W bit in bit 0).
//The raw bus byte from the I2C decoder is left justified, so extract the address bits
//from it and compare against the address exactly as entered.
auto GetAddressBits = [&] (uint8_t data)
{
return (I2CDecoder::LEFT == din->m_addrFormat) ? (data & 0xfe) : (data >> 1);
};

//Pull out our settings
uint8_t base_addr = m_baseaddr.GetIntVal();
int pointer_bytes = m_addrbytes.GetIntVal();
Expand Down Expand Up @@ -153,7 +162,7 @@ void I2CRegisterDecoder::Refresh(
if(s.m_stype == I2CSymbol::TYPE_ADDRESS)
{
//If address bits don't match, discard it
if( (s.m_data & 0xfe) != base_addr)
if( GetAddressBits(s.m_data) != base_addr)
{
state = 0;
continue;
Expand Down