2014-09-26 08:46:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 by Amaury Pouly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-08-21 18:16:26 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QDebug>
|
2014-02-09 01:16:43 +00:00
|
|
|
#include <QFileInfo>
|
2016-02-07 21:48:40 +00:00
|
|
|
#include <QFont>
|
2013-08-21 18:16:26 +00:00
|
|
|
#include "backend.h"
|
|
|
|
|
2014-04-07 09:28:04 +00:00
|
|
|
/**
|
|
|
|
* SocFile
|
|
|
|
*/
|
|
|
|
SocFile::SocFile()
|
2016-02-06 15:08:43 +00:00
|
|
|
:m_valid(true)
|
2014-04-07 09:28:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SocFile::SocFile(const QString& filename)
|
|
|
|
:m_filename(filename)
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_desc::error_context_t ctx;
|
|
|
|
m_valid = soc_desc::parse_xml(filename.toStdString(), m_soc, ctx);
|
2014-04-07 09:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SocFile::IsValid()
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_desc::soc_ref_t SocFile::GetSocRef()
|
2014-04-07 09:28:04 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
if(m_valid)
|
|
|
|
return soc_desc::soc_ref_t(&m_soc);
|
|
|
|
else
|
|
|
|
return soc_desc::soc_ref_t();
|
2014-04-07 09:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SocFile::GetFilename()
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
/**
|
|
|
|
* Backend
|
|
|
|
*/
|
|
|
|
|
2013-08-21 18:16:26 +00:00
|
|
|
Backend::Backend()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-07 09:28:04 +00:00
|
|
|
|
|
|
|
QList< SocFileRef > Backend::GetSocFileList()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
QList< SocFileRef > list;
|
|
|
|
for(std::list< SocFile >::iterator it = m_socs.begin(); it != m_socs.end(); ++it)
|
2016-02-06 15:08:43 +00:00
|
|
|
{
|
|
|
|
if(it->IsValid())
|
|
|
|
list.append(SocFileRef(&(*it)));
|
|
|
|
}
|
2014-04-07 09:28:04 +00:00
|
|
|
return list;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
QList< soc_desc::soc_ref_t > Backend::GetSocList()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
QList< soc_desc::soc_ref_t > list;
|
2014-04-07 09:28:04 +00:00
|
|
|
for(std::list< SocFile >::iterator it = m_socs.begin(); it != m_socs.end(); ++it)
|
2016-02-06 15:08:43 +00:00
|
|
|
{
|
|
|
|
soc_desc::soc_ref_t r = it->GetSocRef();
|
|
|
|
if(r.valid())
|
|
|
|
list.append(r);
|
|
|
|
}
|
2014-04-07 09:28:04 +00:00
|
|
|
return list;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Backend::LoadSocDesc(const QString& filename)
|
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
SocFile f(filename);
|
|
|
|
if(!f.IsValid())
|
|
|
|
return false;
|
|
|
|
m_socs.push_back(f);
|
2016-02-06 15:08:43 +00:00
|
|
|
emit OnSocAdded(SocFileRef(&m_socs.back()));
|
2014-04-07 09:28:04 +00:00
|
|
|
return true;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IoBackend *Backend::CreateFileIoBackend(const QString& filename)
|
|
|
|
{
|
|
|
|
return new FileIoBackend(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
IoBackend *Backend::CreateDummyIoBackend()
|
|
|
|
{
|
|
|
|
return new DummyIoBackend();
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
|
|
|
IoBackend *Backend::CreateHWStubIoBackend(HWStubDevice *dev)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-03 23:18:51 +00:00
|
|
|
return new HWStubIoBackend(dev);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
/**
|
|
|
|
* DummyIoBackend
|
|
|
|
*/
|
|
|
|
|
|
|
|
DummyIoBackend::DummyIoBackend()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::IsValid()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DummyIoBackend::GetSocName()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::ReadRegister(soc_addr_t addr, soc_word_t& value,
|
|
|
|
unsigned width)
|
|
|
|
{
|
|
|
|
Q_UNUSED(addr);
|
|
|
|
Q_UNUSED(value);
|
|
|
|
Q_UNUSED(width);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::Reload()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::IsReadOnly()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::WriteRegister(soc_addr_t addr, soc_word_t value,
|
|
|
|
unsigned width, WriteMode mode)
|
|
|
|
{
|
|
|
|
Q_UNUSED(addr);
|
|
|
|
Q_UNUSED(value);
|
|
|
|
Q_UNUSED(mode);
|
|
|
|
Q_UNUSED(width);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::IsDirty()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyIoBackend::Commit()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
/**
|
2014-09-30 13:51:02 +00:00
|
|
|
* RamIoBackend
|
2014-02-03 23:18:51 +00:00
|
|
|
*/
|
2014-09-30 13:51:02 +00:00
|
|
|
RamIoBackend::RamIoBackend(const QString& soc_name)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-05-11 17:51:55 +00:00
|
|
|
m_soc = soc_name;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool RamIoBackend::IsValid()
|
|
|
|
{
|
|
|
|
return m_soc != "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RamIoBackend::GetSocName()
|
|
|
|
{
|
|
|
|
return m_soc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RamIoBackend::SetSocName(const QString& soc_name)
|
|
|
|
{
|
|
|
|
m_soc = soc_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RamIoBackend::RamIoBackend::Reload()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RamIoBackend::IsReadOnly()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RamIoBackend::ReadRegister(soc_addr_t addr, soc_word_t& value,
|
|
|
|
unsigned width)
|
|
|
|
{
|
|
|
|
Q_UNUSED(width);
|
|
|
|
QMap<soc_addr_t, soc_word_t>::const_iterator it = m_map.find(addr);
|
2014-10-22 15:51:41 +00:00
|
|
|
if(it == m_map.end())
|
2013-08-21 18:16:26 +00:00
|
|
|
return false;
|
2014-10-22 15:51:41 +00:00
|
|
|
value = it.value();
|
2013-08-21 18:16:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-30 13:51:02 +00:00
|
|
|
void RamIoBackend::DeleteAll()
|
|
|
|
{
|
|
|
|
m_map.clear();
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool RamIoBackend::WriteRegister(soc_addr_t addr, soc_word_t value,
|
|
|
|
unsigned width, WriteMode mode)
|
2014-09-30 13:51:02 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
Q_UNUSED(width);
|
2014-09-30 13:51:02 +00:00
|
|
|
switch(mode)
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
case Write: m_map[addr] = value; return true;
|
|
|
|
case Set: m_map[addr] |= value; return true;
|
|
|
|
case Clear: m_map[addr] &= ~value; return true;
|
|
|
|
case Toggle: m_map[addr] ^= value; return true;
|
2014-09-30 13:51:02 +00:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool RamIoBackend::IsDirty()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-30 13:51:02 +00:00
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool RamIoBackend::Commit()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-30 13:51:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FileIoBackend
|
|
|
|
*/
|
|
|
|
|
|
|
|
FileIoBackend::FileIoBackend(const QString& filename, const QString& soc_name)
|
|
|
|
:RamIoBackend(soc_name)
|
|
|
|
{
|
|
|
|
m_filename = filename;
|
|
|
|
m_valid = false;
|
|
|
|
Reload();
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool FileIoBackend::IsValid()
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
2014-09-30 13:51:02 +00:00
|
|
|
|
2013-08-21 18:16:26 +00:00
|
|
|
bool FileIoBackend::Reload()
|
|
|
|
{
|
2014-09-27 19:23:38 +00:00
|
|
|
m_valid = false;
|
2013-08-21 18:16:26 +00:00
|
|
|
QFile file(m_filename);
|
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
return false;
|
2014-09-30 13:51:02 +00:00
|
|
|
DeleteAll();
|
2013-08-21 18:16:26 +00:00
|
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
while(!in.atEnd())
|
|
|
|
{
|
|
|
|
QString line = in.readLine();
|
|
|
|
int idx = line.indexOf('=');
|
|
|
|
if(idx == -1)
|
|
|
|
continue;
|
2016-02-06 15:08:43 +00:00
|
|
|
QString key_str = line.left(idx).trimmed();
|
|
|
|
QString val_str = line.mid(idx + 1).trimmed();
|
|
|
|
bool key_ok,val_ok;
|
|
|
|
soc_word_t val = val_str.toULong(&val_ok, 0);
|
|
|
|
soc_word_t key = key_str.toULong(&key_ok, 0);
|
|
|
|
if(key_str == "soc")
|
|
|
|
m_soc = val_str;
|
|
|
|
else if(key_ok && val_ok)
|
|
|
|
RamIoBackend::WriteRegister(key, val, 32, Write);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2014-02-09 01:16:43 +00:00
|
|
|
m_readonly = !QFileInfo(file).isWritable();
|
|
|
|
m_dirty = false;
|
2014-09-27 19:23:38 +00:00
|
|
|
m_valid = true;
|
2014-02-09 01:16:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool FileIoBackend::WriteRegister(soc_addr_t addr, soc_word_t value,
|
|
|
|
unsigned width, WriteMode mode)
|
2014-02-09 01:16:43 +00:00
|
|
|
{
|
|
|
|
m_dirty = true;
|
2016-02-06 15:08:43 +00:00
|
|
|
return RamIoBackend::WriteRegister(addr, value, width, mode);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 01:16:43 +00:00
|
|
|
bool FileIoBackend::Commit()
|
|
|
|
{
|
|
|
|
if(!m_dirty)
|
|
|
|
return true;
|
|
|
|
QFile file(m_filename);
|
|
|
|
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
QTextStream out(&file);
|
2016-02-06 15:08:43 +00:00
|
|
|
out << "soc = " << m_soc << "\n";
|
|
|
|
QMapIterator< soc_addr_t, soc_word_t > it(m_map);
|
2014-02-09 01:16:43 +00:00
|
|
|
while(it.hasNext())
|
|
|
|
{
|
|
|
|
it.next();
|
2016-02-06 15:08:43 +00:00
|
|
|
out << hex << showbase << it.key() << " = " << hex << showbase << it.value() << "\n";
|
2014-02-09 01:16:43 +00:00
|
|
|
}
|
|
|
|
out.flush();
|
|
|
|
return file.flush();
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool FileIoBackend::IsReadOnly()
|
|
|
|
{
|
|
|
|
return m_readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileIoBackend::IsDirty()
|
|
|
|
{
|
|
|
|
return m_dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FileIoBackend::GetFileName()
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
|
|
|
/**
|
2016-02-07 21:48:40 +00:00
|
|
|
* HWStubManager
|
2014-02-03 23:18:51 +00:00
|
|
|
*/
|
2016-02-07 21:48:40 +00:00
|
|
|
HWStubManager *HWStubManager::g_inst = nullptr;
|
|
|
|
|
|
|
|
HWStubManager::HWStubManager()
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
Add("Default", QString::fromStdString(hwstub::uri::default_uri().full_uri()));
|
2014-05-11 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
HWStubManager::~HWStubManager()
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
HWStubManager *HWStubManager::Get()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
if(g_inst == nullptr)
|
|
|
|
g_inst = new HWStubManager();
|
|
|
|
return g_inst;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
bool HWStubManager::Add(const QString& name, const QString& uri)
|
|
|
|
{
|
|
|
|
struct Context ctx;
|
|
|
|
ctx.name = name;
|
|
|
|
ctx.uri = uri;
|
|
|
|
ctx.context = hwstub::uri::create_context(uri.toStdString());
|
|
|
|
if(!ctx.context)
|
|
|
|
return false;
|
|
|
|
ctx.context->start_polling();
|
|
|
|
beginInsertRows(QModelIndex(), m_list.size(), m_list.size());
|
|
|
|
m_list.push_back(ctx);
|
|
|
|
endInsertRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubManager::Clear()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
m_list.clear();
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
int HWStubManager::rowCount(const QModelIndex& parent) const
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
return m_list.size();
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
int HWStubManager::columnCount(const QModelIndex& parent) const
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
return 2;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
std::shared_ptr< hwstub::context > HWStubManager::GetContext(int row)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
if(row < 0 || (size_t)row >= m_list.size())
|
|
|
|
return std::shared_ptr< hwstub::context >();
|
|
|
|
else
|
|
|
|
return m_list[row].context;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HWStubManager::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
if(index.row() < 0 || (size_t)index.row() >= m_list.size())
|
|
|
|
return QVariant();
|
|
|
|
int section = index.column();
|
|
|
|
const Context& ctx = m_list[index.row()];
|
|
|
|
if(section == GetNameColumn())
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
if(role == Qt::DisplayRole || role == Qt::EditRole)
|
|
|
|
return QVariant(ctx.name);
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
2016-02-07 21:48:40 +00:00
|
|
|
else if(section == GetUriColumn())
|
2014-05-05 21:18:04 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
return QVariant(ctx.uri);
|
2014-05-05 21:18:04 +00:00
|
|
|
}
|
2016-02-07 21:48:40 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
QVariant HWStubManager::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if(orientation == Qt::Vertical)
|
|
|
|
return QVariant();
|
|
|
|
if(role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
|
|
|
if(section == GetNameColumn())
|
|
|
|
return QVariant("Name");
|
|
|
|
else if(section == GetUriColumn())
|
|
|
|
return QVariant("URI");
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags HWStubManager::flags(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
int section = index.column();
|
|
|
|
if(section == GetNameColumn())
|
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
return flags;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
bool HWStubManager::setData(const QModelIndex& index, const QVariant& value, int role)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
if(role != Qt::EditRole)
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
2016-02-07 21:48:40 +00:00
|
|
|
if(index.row() < 0 || (size_t)index.row() >= m_list.size())
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
2016-02-07 21:48:40 +00:00
|
|
|
if(index.column() != GetNameColumn())
|
|
|
|
return false;
|
|
|
|
m_list[index.row()].name = value.toString();
|
|
|
|
emit dataChanged(index, index);
|
2014-02-03 23:18:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
int HWStubManager::GetNameColumn() const
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
return 0;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
int HWStubManager::GetUriColumn() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HWStubManager::GetFriendlyName(std::shared_ptr< hwstub::device > device)
|
|
|
|
{
|
|
|
|
/* try to open the device */
|
|
|
|
std::shared_ptr< hwstub::handle > handle;
|
|
|
|
hwstub::error err = device->open(handle);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
goto Lfallback;
|
|
|
|
/* get target descriptor */
|
|
|
|
struct hwstub_target_desc_t target_desc;
|
|
|
|
err = handle->get_target_desc(target_desc);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
goto Lfallback;
|
|
|
|
return QString::fromStdString(target_desc.bName);
|
|
|
|
|
|
|
|
/* fallback: don't open the device */
|
|
|
|
Lfallback:
|
|
|
|
hwstub::usb::device *udev = dynamic_cast< hwstub::usb::device* >(device.get());
|
|
|
|
if(udev)
|
|
|
|
{
|
|
|
|
return QString("USB Bus %1 Device %2: ID %3:%4")
|
|
|
|
.arg(udev->get_bus_number()).arg(udev->get_address(), 3, 10, QChar('0'))
|
|
|
|
.arg(udev->get_vid(), 4, 16, QChar('0')).arg(udev->get_pid(), 4, 16, QChar('0'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QString("<Unknown device>");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HWStubContextModel
|
|
|
|
*/
|
|
|
|
HWStubContextModel::HWStubContextModel(QObject *parent)
|
|
|
|
:QAbstractTableModel(parent), m_has_dummy(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubContextModel::~HWStubContextModel()
|
|
|
|
{
|
|
|
|
SetContext(std::shared_ptr< hwstub::context >());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubContextModel::SetContext(std::shared_ptr< hwstub::context > context)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
int first_row = m_has_dummy ? 1: 0;
|
|
|
|
/* clear previous model if any */
|
|
|
|
if(m_list.size() > 0)
|
|
|
|
{
|
|
|
|
beginRemoveRows(QModelIndex(), first_row, first_row + m_list.size() - 1);
|
|
|
|
m_list.clear();
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
/* don't forget to unregister callback if context still exists */
|
|
|
|
std::shared_ptr< hwstub::context > ctx = m_context.lock();
|
|
|
|
if(ctx)
|
|
|
|
ctx->unregister_callback(m_callback_ref);
|
|
|
|
/* get new context */
|
|
|
|
m_context = context;
|
|
|
|
if(context)
|
|
|
|
{
|
|
|
|
/* register new callback */
|
|
|
|
m_callback_ref = context->register_callback(
|
|
|
|
std::bind(&HWStubContextModel::OnDevChangeLow, this, std::placeholders::_1,
|
|
|
|
std::placeholders::_2, std::placeholders::_3));
|
|
|
|
/* get dev list */
|
|
|
|
std::vector< std::shared_ptr< hwstub::device > > list;
|
|
|
|
hwstub::error err = context->get_device_list(list);
|
|
|
|
if(err == hwstub::error::SUCCESS)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), first_row, first_row + list.size() - 1);
|
|
|
|
for(auto& d : list)
|
|
|
|
{
|
|
|
|
Device dev;
|
|
|
|
dev.name = GetFriendlyName(d);
|
|
|
|
dev.device = d;
|
|
|
|
m_list.push_back(dev);
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubContextModel::EnableDummy(bool en, const QString& text)
|
|
|
|
{
|
|
|
|
/* if needed, create/remove raw */
|
|
|
|
if(m_has_dummy && !en)
|
|
|
|
{
|
|
|
|
/* remove row */
|
|
|
|
beginRemoveRows(QModelIndex(), 0, 0);
|
|
|
|
m_has_dummy = false;
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
else if(!m_has_dummy && en)
|
|
|
|
{
|
|
|
|
/* add row */
|
|
|
|
beginInsertRows(QModelIndex(), 0, 0);
|
|
|
|
m_has_dummy = true;
|
|
|
|
m_dummy_text = text;
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
else if(en)
|
|
|
|
{
|
|
|
|
/* text change only */
|
|
|
|
emit dataChanged(index(0, GetNameColumn()), index(0, GetNameColumn()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int HWStubContextModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return m_list.size() + (m_has_dummy ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int HWStubContextModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HWStubContextModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
int first_row = m_has_dummy ? 1: 0;
|
|
|
|
/* special case for dummy */
|
|
|
|
if(m_has_dummy && index.row() == 0)
|
|
|
|
{
|
|
|
|
int section = index.column();
|
|
|
|
if(section == GetNameColumn())
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
return QVariant(m_dummy_text);
|
|
|
|
else if(role == Qt::FontRole)
|
|
|
|
{
|
|
|
|
QFont font;
|
|
|
|
font.setItalic(true);
|
|
|
|
return QVariant(font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index.row() < first_row || (size_t)index.row() >= first_row + m_list.size())
|
|
|
|
return QVariant();
|
|
|
|
int section = index.column();
|
|
|
|
if(section == GetNameColumn())
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
return QVariant(m_list[index.row() - first_row].name);
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HWStubContextModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if(orientation == Qt::Vertical)
|
|
|
|
return QVariant();
|
|
|
|
if(role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
|
|
|
if(section == GetNameColumn())
|
|
|
|
return QVariant("Friendly name");
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags HWStubContextModel::flags(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(index);
|
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HWStubContextModel::GetNameColumn() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr< hwstub::device > HWStubContextModel::GetDevice(int row)
|
|
|
|
{
|
|
|
|
int first_row = m_has_dummy ? 1: 0;
|
|
|
|
/* special case for dummy */
|
|
|
|
if(row < first_row || (size_t)row >= first_row + m_list.size())
|
|
|
|
return std::shared_ptr< hwstub::device >();
|
|
|
|
else
|
|
|
|
return m_list[row - first_row].device;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HWStubContextModel::GetFriendlyName(std::shared_ptr< hwstub::device > device)
|
|
|
|
{
|
|
|
|
return HWStubManager::GetFriendlyName(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct dev_change_t
|
|
|
|
{
|
|
|
|
std::shared_ptr< hwstub::context > ctx;
|
|
|
|
bool arrived;
|
|
|
|
std::shared_ptr< hwstub::device > device;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubContextModel::OnDevChangeLow(std::shared_ptr< hwstub::context > ctx,
|
|
|
|
bool arrived, std::shared_ptr< hwstub::device > device)
|
|
|
|
{
|
|
|
|
/* calling Qt function from non-Qt thread is unsafe. Since the polling thread
|
|
|
|
* is a pthread, the safest way to use Qt invoke mecanism to make it run
|
|
|
|
* on the event loop */
|
|
|
|
dev_change_t *evt = new dev_change_t;
|
|
|
|
evt->ctx = ctx;
|
|
|
|
evt->arrived = arrived;
|
|
|
|
evt->device = device;
|
|
|
|
QMetaObject::invokeMethod(this, "OnDevChangeUnsafe", Q_ARG(void *, (void *)evt));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubContextModel::OnDevChangeUnsafe(void *data)
|
|
|
|
{
|
|
|
|
dev_change_t *evt = (dev_change_t *)data;
|
|
|
|
OnDevChange(evt->ctx, evt->arrived, evt->device);
|
|
|
|
delete evt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HWStubContextModel::OnDevChange(std::shared_ptr< hwstub::context > ctx, bool arrived,
|
|
|
|
std::shared_ptr< hwstub::device > device)
|
|
|
|
{
|
|
|
|
int first_row = m_has_dummy ? 1: 0;
|
|
|
|
Q_UNUSED(ctx);
|
|
|
|
if(arrived)
|
|
|
|
{
|
|
|
|
Device dev;
|
|
|
|
dev.name = GetFriendlyName(device);
|
|
|
|
dev.device = device;
|
|
|
|
beginInsertRows(QModelIndex(), first_row + m_list.size(),
|
|
|
|
first_row + m_list.size());
|
|
|
|
m_list.push_back(dev);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* find device in the list */
|
|
|
|
auto it = m_list.begin();
|
|
|
|
int idx = 0;
|
|
|
|
for(; it != m_list.end(); ++it, ++idx)
|
|
|
|
if(it->device == device)
|
|
|
|
break;
|
|
|
|
if(it == m_list.end())
|
|
|
|
return;
|
|
|
|
/* remove it */
|
|
|
|
beginRemoveRows(QModelIndex(), first_row + idx, first_row + idx);
|
|
|
|
m_list.erase(it);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HWStubDevice
|
|
|
|
*/
|
|
|
|
HWStubDevice::HWStubDevice(std::shared_ptr< hwstub::device > device)
|
|
|
|
{
|
|
|
|
m_valid = Probe(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubDevice::~HWStubDevice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubDevice::Probe(std::shared_ptr<hwstub::device> device)
|
|
|
|
{
|
|
|
|
if(!device)
|
|
|
|
return false;
|
|
|
|
hwstub::error err = device->open(m_handle);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
2016-02-07 21:48:40 +00:00
|
|
|
// get target information
|
|
|
|
err = m_handle->get_target_desc(m_hwdev_target);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
return false;
|
|
|
|
// get STMP/PP information
|
|
|
|
if(m_hwdev_target.dID == HWSTUB_TARGET_STMP)
|
|
|
|
{
|
|
|
|
err = m_handle->get_stmp_desc(m_hwdev_stmp);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(m_hwdev_target.dID == HWSTUB_TARGET_PP)
|
|
|
|
{
|
|
|
|
err = m_handle->get_pp_desc(m_hwdev_pp);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(m_hwdev_target.dID == HWSTUB_TARGET_JZ)
|
|
|
|
{
|
|
|
|
err = m_handle->get_jz_desc(m_hwdev_jz);
|
|
|
|
if(err != hwstub::error::SUCCESS)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_name = HWStubManager::GetFriendlyName(device);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubDevice::ReadMem(soc_addr_t addr, size_t length, void *buffer)
|
|
|
|
{
|
|
|
|
size_t len = length;
|
|
|
|
hwstub::error err = m_handle->read(addr, buffer, len, true);
|
|
|
|
return err == hwstub::error::SUCCESS && len == length;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 01:16:43 +00:00
|
|
|
bool HWStubDevice::WriteMem(soc_addr_t addr, size_t length, void *buffer)
|
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
size_t len = length;
|
|
|
|
hwstub::error err = m_handle->write(addr, buffer, len, true);
|
|
|
|
return err == hwstub::error::SUCCESS && len == length;
|
2014-02-09 01:16:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
bool HWStubDevice::IsValid()
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
QString HWStubDevice::GetFriendlyName()
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HWStubIoBackend
|
|
|
|
*/
|
|
|
|
|
|
|
|
HWStubIoBackend::HWStubIoBackend(HWStubDevice *dev)
|
|
|
|
{
|
|
|
|
m_dev = dev;
|
2016-02-07 21:48:40 +00:00
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
struct hwstub_target_desc_t target = m_dev->GetTargetInfo();
|
|
|
|
if(target.dID == HWSTUB_TARGET_STMP)
|
|
|
|
{
|
|
|
|
struct hwstub_stmp_desc_t stmp = m_dev->GetSTMPInfo();
|
|
|
|
if(stmp.wChipID == 0x3780)
|
|
|
|
m_soc = "imx233";
|
|
|
|
else if(stmp.wChipID >= 0x3700 && stmp.wChipID < 0x3780)
|
|
|
|
m_soc = "stmp3700";
|
|
|
|
else if(stmp.wChipID >= 0x3600 && stmp.wChipID < 0x3700)
|
|
|
|
m_soc = "stmp3600";
|
|
|
|
else
|
|
|
|
m_soc = QString("stmp%1").arg(stmp.wChipID, 4, 16, QChar('0'));
|
|
|
|
}
|
2016-02-07 21:48:40 +00:00
|
|
|
else if(target.dID == HWSTUB_TARGET_JZ)
|
|
|
|
{
|
|
|
|
struct hwstub_jz_desc_t jz = m_dev->GetJZInfo();
|
|
|
|
m_soc = QString("jz%1").arg(jz.wChipID, 4, 16, QChar('0'));
|
|
|
|
if(jz.bRevision != 0)
|
|
|
|
m_soc.append(QChar(jz.bRevision).toLower());
|
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
else if(target.dID == HWSTUB_TARGET_RK27)
|
|
|
|
m_soc = "rk27x";
|
2014-05-05 21:18:04 +00:00
|
|
|
else if(target.dID == HWSTUB_TARGET_PP)
|
|
|
|
{
|
|
|
|
struct hwstub_pp_desc_t pp = m_dev->GetPPInfo();
|
|
|
|
if(pp.wChipID == 0x6110 )
|
|
|
|
m_soc = "pp6110";
|
|
|
|
else
|
|
|
|
m_soc = QString("pp%1").arg(pp.wChipID, 4, 16, QChar('0'));
|
|
|
|
}
|
2016-02-06 15:08:43 +00:00
|
|
|
else if(target.dID == HWSTUB_TARGET_ATJ)
|
|
|
|
m_soc = "atj213x";
|
2014-02-03 23:18:51 +00:00
|
|
|
else
|
|
|
|
m_soc = target.bName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HWStubIoBackend::GetSocName()
|
|
|
|
{
|
|
|
|
return m_soc;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubIoBackend::~HWStubIoBackend()
|
|
|
|
{
|
2014-05-11 17:51:55 +00:00
|
|
|
delete m_dev;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool HWStubIoBackend::IsValid()
|
|
|
|
{
|
|
|
|
return m_dev->IsValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubIoBackend::IsReadOnly()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubIoBackend::IsDirty()
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
return false;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool HWStubIoBackend::Commit()
|
2014-02-09 01:16:43 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWStubDevice *HWStubIoBackend::GetDevice()
|
|
|
|
{
|
|
|
|
return m_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubIoBackend::ReadRegister(soc_addr_t addr, soc_word_t& value,
|
|
|
|
unsigned width)
|
|
|
|
{
|
|
|
|
if(width != 8 && width != 16 && width != 32)
|
|
|
|
return false;
|
|
|
|
return m_dev->ReadMem(addr, width / 8, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HWStubIoBackend::WriteRegister(soc_addr_t addr, soc_word_t value,
|
|
|
|
unsigned width, WriteMode mode)
|
|
|
|
{
|
|
|
|
if(width != 8 && width != 16 && width != 32)
|
|
|
|
return false;
|
2014-02-10 22:10:21 +00:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Set: addr += 4; break;
|
|
|
|
case Clear: addr += 8; break;
|
|
|
|
case Toggle: addr += 12; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2016-02-06 15:08:43 +00:00
|
|
|
return m_dev->WriteMem(addr, width / 8, &value);
|
2014-02-09 01:16:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:18:51 +00:00
|
|
|
bool HWStubIoBackend::Reload()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:00:56 +00:00
|
|
|
#endif /* HAVE_HWSTUB */
|
2014-02-03 23:18:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BackendHelper
|
|
|
|
*/
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
BackendHelper::BackendHelper(IoBackend *io_backend, const soc_desc::soc_ref_t& soc)
|
2013-08-21 18:16:26 +00:00
|
|
|
:m_io_backend(io_backend), m_soc(soc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
QString BackendHelper::GetPath(const soc_desc::node_inst_t& inst)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
if(!inst.valid() || inst.is_root())
|
|
|
|
return QString();
|
|
|
|
QString s = GetPath(inst.parent());
|
|
|
|
if(!s.isEmpty())
|
|
|
|
s += ".";
|
|
|
|
s += inst.name().c_str();
|
|
|
|
if(inst.is_indexed())
|
|
|
|
s = QString("%1[%2]").arg(s).arg(inst.index());
|
|
|
|
return s;
|
2014-02-10 22:10:21 +00:00
|
|
|
}
|
2014-02-03 23:18:51 +00:00
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_desc::node_inst_t BackendHelper::ParsePath(const QString& path)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_desc::node_inst_t inst = m_soc.root_inst();
|
|
|
|
/* empty path is root */
|
|
|
|
if(path.isEmpty())
|
|
|
|
return inst;
|
|
|
|
int pos = 0;
|
|
|
|
while(pos < path.size())
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
/* try to find the next separator */
|
|
|
|
int next = path.indexOf('.', pos);
|
|
|
|
if(next == -1)
|
|
|
|
next = path.size();
|
|
|
|
/* try to find the index, if any */
|
|
|
|
int lidx = path.indexOf('[', pos);
|
|
|
|
if(lidx == -1 || lidx > next)
|
|
|
|
lidx = next;
|
|
|
|
/* extract name */
|
|
|
|
std::string name = path.mid(pos, lidx - pos).toStdString();
|
|
|
|
/* and index */
|
|
|
|
if(lidx < next)
|
|
|
|
{
|
|
|
|
int ridx = path.indexOf(']', lidx + 1);
|
|
|
|
/* syntax error ? */
|
|
|
|
if(ridx == -1 || ridx > next)
|
|
|
|
return soc_desc::node_inst_t();
|
|
|
|
/* invalid number ? */
|
|
|
|
bool ok = false;
|
|
|
|
size_t idx = path.mid(lidx + 1, ridx - lidx - 1).toUInt(&ok);
|
|
|
|
if(ok)
|
|
|
|
inst = inst.child(name, idx);
|
|
|
|
else
|
|
|
|
inst = soc_desc::node_inst_t();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
inst = inst.child(name);
|
|
|
|
/* advance right after the separator */
|
|
|
|
pos = next + 1;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
2016-02-06 15:08:43 +00:00
|
|
|
return inst;
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool BackendHelper::ReadRegister(const soc_desc::node_inst_t& inst,
|
|
|
|
soc_word_t& v)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_addr_t addr;
|
|
|
|
if(!GetRegisterAddress(inst, addr))
|
|
|
|
return false;
|
|
|
|
return m_io_backend->ReadRegister(addr, v, inst.node().reg().get()->width);
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool BackendHelper::WriteRegister(const soc_desc::node_inst_t& inst,
|
|
|
|
soc_word_t v, IoBackend::WriteMode mode)
|
2014-02-03 23:18:51 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_addr_t addr;
|
|
|
|
if(!GetRegisterAddress(inst, addr))
|
|
|
|
return false;
|
|
|
|
return m_io_backend->WriteRegister(addr, v, inst.node().reg().get()->width, mode);
|
2014-02-03 23:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool BackendHelper::GetRegisterAddress(const soc_desc::node_inst_t& inst,
|
2014-02-03 23:18:51 +00:00
|
|
|
soc_addr_t& addr)
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
if(!inst.valid())
|
2014-02-03 23:18:51 +00:00
|
|
|
return false;
|
2016-02-06 15:08:43 +00:00
|
|
|
addr = inst.addr();
|
2014-02-03 23:18:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool BackendHelper::ReadRegisterField(const soc_desc::node_inst_t& inst,
|
2014-02-03 23:18:51 +00:00
|
|
|
const QString& field, soc_word_t& v)
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
soc_desc::field_ref_t ref = inst.node().reg().field(field.toStdString());
|
|
|
|
if(!ref.valid())
|
2013-08-21 18:16:26 +00:00
|
|
|
return false;
|
2016-02-06 15:08:43 +00:00
|
|
|
if(!ReadRegister(inst, v))
|
2013-08-21 18:16:26 +00:00
|
|
|
return false;
|
2016-02-06 15:08:43 +00:00
|
|
|
v = (v & ref.get()->bitmask()) >> ref.get()->pos;
|
2013-08-21 18:16:26 +00:00
|
|
|
return true;
|
2014-02-10 22:10:21 +00:00
|
|
|
}
|
2014-05-11 17:51:55 +00:00
|
|
|
|
2014-09-30 13:51:38 +00:00
|
|
|
bool BackendHelper::DumpAllRegisters(const QString& filename, bool ignore_errors)
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
FileIoBackend b(filename, QString::fromStdString(m_soc.get()->name));
|
2014-09-30 13:51:38 +00:00
|
|
|
bool ret = DumpAllRegisters(&b, ignore_errors);
|
|
|
|
return ret && b.Commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackendHelper::DumpAllRegisters(IoBackend *backend, bool ignore_errors)
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
BackendHelper helper(backend, m_soc);
|
|
|
|
return DumpAllRegisters(&helper, m_soc.root_inst(), ignore_errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackendHelper::DumpAllRegisters(BackendHelper *bh,
|
|
|
|
const soc_desc::node_inst_t& inst, bool ignore_errors)
|
|
|
|
{
|
2014-09-30 13:51:38 +00:00
|
|
|
bool ret = true;
|
2016-02-06 15:08:43 +00:00
|
|
|
if(inst.node().reg().valid())
|
|
|
|
{
|
|
|
|
soc_word_t val;
|
|
|
|
if(!ReadRegister(inst, val))
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
if(!ignore_errors)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(!bh->WriteRegister(inst, val))
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
if(!ignore_errors)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::vector< soc_desc::node_inst_t > list = inst.children();
|
|
|
|
for(size_t i = 0; i < list.size(); i++)
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
if(!DumpAllRegisters(bh, list[i], ignore_errors))
|
2014-05-11 17:51:55 +00:00
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
ret = false;
|
|
|
|
if(!ignore_errors)
|
|
|
|
return false;
|
2014-05-11 17:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-30 13:51:38 +00:00
|
|
|
return ret;
|
2014-05-11 17:51:55 +00:00
|
|
|
}
|