diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-09 02:13:53 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-10 23:14:26 +0100 |
commit | 3d07706c05c46878533f55f26bbe02d7904efd75 (patch) | |
tree | f1b549c275f7a27f9e7038e5fc4eccb94bf8be45 /utils/regtools/qeditor/backend.h | |
parent | 8358707d8276dd297655395b922560e3c65631e1 (diff) | |
download | rockbox-3d07706c05c46878533f55f26bbe02d7904efd75.tar.gz rockbox-3d07706c05c46878533f55f26bbe02d7904efd75.zip |
regtools/qeditor: rewrite soc handling
The code was a mess with respect to soc handling: some code just plain copied
the SoC descriptor which are big objects, some was using indexes. The new soc
factor out everything in a few classes which hide these ugly details so that
descriptors are never copied.
Change-Id: I17af8b47f997a528b58221621389d42d24fded93
Diffstat (limited to 'utils/regtools/qeditor/backend.h')
-rw-r--r-- | utils/regtools/qeditor/backend.h | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/utils/regtools/qeditor/backend.h b/utils/regtools/qeditor/backend.h index 55f31cce52..879b88c42c 100644 --- a/utils/regtools/qeditor/backend.h +++ b/utils/regtools/qeditor/backend.h @@ -23,10 +23,14 @@ public: ByAddress, }; + /* report whether backend supports register access type */ virtual bool SupportAccess(AccessType type) = 0; + /* get SoC name */ virtual QString GetSocName() = 0; + /* read a register by name or address */ virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0; virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) = 0; + /* reload content (if it makes sense) */ virtual bool Reload() = 0; }; @@ -140,6 +144,56 @@ protected: }; #endif +class SocRef +{ +public: + SocRef():m_soc(0) {} + SocRef(const soc_t *soc):m_soc(soc) {} + const soc_t& GetSoc() const { return *m_soc; } +protected: + const soc_t *m_soc; +}; + +class SocDevRef : public SocRef +{ +public: + SocDevRef() {} + SocDevRef(const SocRef& soc, int dev_idx, int dev_addr_idx) + :SocRef(soc), m_dev_idx(dev_idx), m_dev_addr_idx(dev_addr_idx) {} + int GetDevIndex() const { return m_dev_idx; } + const soc_dev_t& GetDev() const { return GetSoc().dev[GetDevIndex()]; } + int GetDevAddrIndex() const { return m_dev_addr_idx; } + const soc_dev_addr_t& GetDevAddr() const { return GetDev().addr[GetDevAddrIndex()]; } +protected: + int m_dev_idx, m_dev_addr_idx; +}; + +class SocRegRef : public SocDevRef +{ +public: + SocRegRef() {} + SocRegRef(const SocDevRef& dev, int reg_idx, int reg_addr_idx) + :SocDevRef(dev), m_reg_idx(reg_idx), m_reg_addr_idx(reg_addr_idx) {} + int GetRegIndex() const { return m_reg_idx; } + const soc_reg_t& GetReg() const { return GetDev().reg[GetRegIndex()]; } + int GetRegAddrIndex() const { return m_reg_addr_idx; } + const soc_reg_addr_t& GetRegAddr() const { return GetReg().addr[GetRegAddrIndex()]; } +protected: + int m_reg_idx, m_reg_addr_idx; +}; + +class SocFieldRef : public SocRegRef +{ +public: + SocFieldRef(){} + SocFieldRef(const SocRegRef& reg, int field_idx) + :SocRegRef(reg), m_field_idx(field_idx) {} + int GetFieldIndex() const { return m_field_idx; } + const soc_reg_field_t& GetField() const { return GetReg().field[GetFieldIndex()]; } +protected: + int m_field_idx; +}; + class Backend : public QObject { Q_OBJECT @@ -148,7 +202,7 @@ public: QStringList GetSocNameList(); bool LoadSocDesc(const QString& filename); - bool GetSocByName(const QString& name, soc_t& s); + bool GetSocByName(const QString& name, SocRef& s); IoBackend *CreateDummyIoBackend(); IoBackend *CreateFileIoBackend(const QString& filename); #ifdef HAVE_HWSTUB @@ -158,23 +212,23 @@ public: signals: void OnSocListChanged(); private: - std::vector< soc_t > m_socs; + std::list< soc_t > m_socs; }; class BackendHelper { public: - BackendHelper(IoBackend *io_backend, const soc_t& soc); + BackendHelper(IoBackend *io_backend, const SocRef& soc); bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v); bool ReadRegisterField(const QString& dev, const QString& reg, const QString& field, soc_word_t& v); - bool GetDeviceDesc(const QString& dev, soc_dev_t& dev_desc, size_t& index); - bool GetRegisterDesc(const soc_dev_t& dev, const QString& reg, soc_reg_t& reg_desc, size_t& index); - bool GetFieldDesc(const soc_reg_t& reg_desc, const QString& field, soc_reg_field_t& field_desc); + bool GetDevRef(const QString& dev, SocDevRef& ref); + bool GetRegRef(const SocDevRef& dev, const QString& reg, SocRegRef& ref); + bool GetFieldRef(const SocRegRef& reg, const QString& field, SocFieldRef& ref); bool GetRegisterAddress(const QString& dev, const QString& reg, soc_addr_t& addr); private: IoBackend *m_io_backend; - soc_t m_soc; + const SocRef& m_soc; }; #endif /* __BACKEND_H__ */ |