diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-04 00:18:51 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-10 23:14:25 +0100 |
commit | 0e0c610df0d3d4044d0b21ddc1752a5dacd7f86e (patch) | |
tree | aca4cf3c5dd86384ee8018d9049e2c3469d597ea /utils/regtools/qeditor/backend.h | |
parent | 81dfed27cf7ca1008b9cf21c084310eaeae082ac (diff) | |
download | rockbox-0e0c610df0d3d4044d0b21ddc1752a5dacd7f86e.tar.gz rockbox-0e0c610df0d3d4044d0b21ddc1752a5dacd7f86e.zip |
utils/regtools: make qeditor able to poke directly at a hwstub device
This commit add the very handy feature of being able to read registers
directly from a device using hwstub. This is mostly trivial using the hwstub
library and the biggest change here is actually:
- being able to read registers by name and/or addresses
- being able to enumerate devives
The UI code currently doesn't handle hotplug but the backend does so it should
be trivial to add in the future. It also opens up the possibility the write
registers from hwstub or save the register values to a file.
Since it relies on both hwstub and libusb, a switch has been introduced in
qmake to disable it (use -config nohwstub).
Change-Id: I5d7d7a2a7c97ecd7407227357c8553c2773ea6cc
Diffstat (limited to 'utils/regtools/qeditor/backend.h')
-rw-r--r-- | utils/regtools/qeditor/backend.h | 113 |
1 files changed, 108 insertions, 5 deletions
diff --git a/utils/regtools/qeditor/backend.h b/utils/regtools/qeditor/backend.h index 536eb8cec5..55f31cce52 100644 --- a/utils/regtools/qeditor/backend.h +++ b/utils/regtools/qeditor/backend.h | |||
@@ -4,16 +4,29 @@ | |||
4 | #include <QObject> | 4 | #include <QObject> |
5 | #include <QStringList> | 5 | #include <QStringList> |
6 | #include <QMap> | 6 | #include <QMap> |
7 | #include <QVector> | ||
7 | #include "soc_desc.hpp" | 8 | #include "soc_desc.hpp" |
9 | #ifdef HAVE_HWSTUB | ||
10 | #include "hwstub.h" | ||
11 | #endif | ||
8 | 12 | ||
9 | class IoBackend : public QObject | 13 | class IoBackend : public QObject |
10 | { | 14 | { |
11 | Q_OBJECT | 15 | Q_OBJECT |
12 | public: | 16 | public: |
13 | IoBackend(); | 17 | IoBackend() {} |
18 | virtual ~IoBackend() {} | ||
14 | 19 | ||
20 | enum AccessType | ||
21 | { | ||
22 | ByName, | ||
23 | ByAddress, | ||
24 | }; | ||
25 | |||
26 | virtual bool SupportAccess(AccessType type) = 0; | ||
15 | virtual QString GetSocName() = 0; | 27 | virtual QString GetSocName() = 0; |
16 | virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0; | 28 | virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0; |
29 | virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) = 0; | ||
17 | virtual bool Reload() = 0; | 30 | virtual bool Reload() = 0; |
18 | }; | 31 | }; |
19 | 32 | ||
@@ -21,11 +34,15 @@ class DummyIoBackend : public IoBackend | |||
21 | { | 34 | { |
22 | Q_OBJECT | 35 | Q_OBJECT |
23 | public: | 36 | public: |
24 | DummyIoBackend(); | 37 | DummyIoBackend() {} |
25 | 38 | ||
26 | virtual QString GetSocName(); | 39 | virtual bool SupportAccess(AccessType type) { (void) type; return false; } |
27 | virtual bool ReadRegister(const QString& name, soc_word_t& value); | 40 | virtual QString GetSocName() { return ""; } |
28 | virtual bool Reload(); | 41 | virtual bool ReadRegister(const QString& name, soc_word_t& value) |
42 | { (void) name; (void) value; return false; } | ||
43 | virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) | ||
44 | { (void) addr; (void) value; return false; } | ||
45 | virtual bool Reload() { return false; } | ||
29 | }; | 46 | }; |
30 | 47 | ||
31 | class FileIoBackend : public IoBackend | 48 | class FileIoBackend : public IoBackend |
@@ -34,8 +51,11 @@ class FileIoBackend : public IoBackend | |||
34 | public: | 51 | public: |
35 | FileIoBackend(const QString& filename); | 52 | FileIoBackend(const QString& filename); |
36 | 53 | ||
54 | virtual bool SupportAccess(AccessType type) { return type == ByName; } | ||
37 | virtual QString GetSocName(); | 55 | virtual QString GetSocName(); |
38 | virtual bool ReadRegister(const QString& name, soc_word_t& value); | 56 | virtual bool ReadRegister(const QString& name, soc_word_t& value); |
57 | virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value) | ||
58 | { (void) addr; (void) value; return false; } | ||
39 | virtual bool Reload(); | 59 | virtual bool Reload(); |
40 | 60 | ||
41 | protected: | 61 | protected: |
@@ -44,6 +64,82 @@ protected: | |||
44 | QMap< QString, soc_word_t > m_map; | 64 | QMap< QString, soc_word_t > m_map; |
45 | }; | 65 | }; |
46 | 66 | ||
67 | #ifdef HAVE_HWSTUB | ||
68 | class HWStubDevice | ||
69 | { | ||
70 | public: | ||
71 | HWStubDevice(struct libusb_device *dev); | ||
72 | ~HWStubDevice(); | ||
73 | bool IsValid(); | ||
74 | bool Open(); | ||
75 | void Close(); | ||
76 | int GetBusNumber(); | ||
77 | int GetDevAddress(); | ||
78 | /* Calls below are cached and do not require the device to be opened */ | ||
79 | inline struct hwstub_version_desc_t GetVersionInfo() { return m_hwdev_ver; } | ||
80 | inline struct hwstub_target_desc_t GetTargetInfo() { return m_hwdev_target; } | ||
81 | inline struct hwstub_stmp_desc_t GetSTMPInfo() { return m_hwdev_stmp; } | ||
82 | /* Calls below require the device to be opened */ | ||
83 | bool ReadMem(soc_addr_t addr, size_t length, void *buffer); | ||
84 | |||
85 | protected: | ||
86 | bool Probe(); | ||
87 | |||
88 | bool m_valid; | ||
89 | struct libusb_device *m_dev; | ||
90 | libusb_device_handle *m_handle; | ||
91 | struct hwstub_device_t *m_hwdev; | ||
92 | struct hwstub_version_desc_t m_hwdev_ver; | ||
93 | struct hwstub_target_desc_t m_hwdev_target; | ||
94 | struct hwstub_stmp_desc_t m_hwdev_stmp; | ||
95 | }; | ||
96 | |||
97 | class HWStubIoBackend : public IoBackend | ||
98 | { | ||
99 | Q_OBJECT | ||
100 | public: | ||
101 | HWStubIoBackend(HWStubDevice *dev); | ||
102 | virtual ~HWStubIoBackend(); | ||
103 | |||
104 | virtual bool SupportAccess(AccessType type) { return type == ByAddress; } | ||
105 | virtual QString GetSocName(); | ||
106 | virtual bool ReadRegister(const QString& name, soc_word_t& value) | ||
107 | { (void) name; (void) value; return false; } | ||
108 | virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value); | ||
109 | virtual bool Reload(); | ||
110 | |||
111 | protected: | ||
112 | QString m_soc; | ||
113 | HWStubDevice *m_dev; | ||
114 | }; | ||
115 | |||
116 | #if LIBUSB_API_VERSION < 0x01000102 | ||
117 | #define LIBUSB_NO_HOTPLUG | ||
118 | #endif | ||
119 | |||
120 | class HWStubBackendHelper : public QObject | ||
121 | { | ||
122 | Q_OBJECT | ||
123 | public: | ||
124 | HWStubBackendHelper(); | ||
125 | ~HWStubBackendHelper(); | ||
126 | bool HasHotPlugSupport(); | ||
127 | QList< HWStubDevice* > GetDevList(); | ||
128 | |||
129 | signals: | ||
130 | void OnDevListChanged(bool arrived, struct libusb_device *dev); | ||
131 | |||
132 | protected: | ||
133 | #ifndef LIBUSB_NO_HOTPLUG | ||
134 | void OnHotPlug(bool arrived, struct libusb_device *dev); | ||
135 | static int HotPlugCallback(struct libusb_context *ctx, struct libusb_device *dev, | ||
136 | libusb_hotplug_event event, void *user_data); | ||
137 | libusb_hotplug_callback_handle m_hotplug_handle; | ||
138 | #endif | ||
139 | bool m_hotplug; | ||
140 | }; | ||
141 | #endif | ||
142 | |||
47 | class Backend : public QObject | 143 | class Backend : public QObject |
48 | { | 144 | { |
49 | Q_OBJECT | 145 | Q_OBJECT |
@@ -55,6 +151,9 @@ public: | |||
55 | bool GetSocByName(const QString& name, soc_t& s); | 151 | bool GetSocByName(const QString& name, soc_t& s); |
56 | IoBackend *CreateDummyIoBackend(); | 152 | IoBackend *CreateDummyIoBackend(); |
57 | IoBackend *CreateFileIoBackend(const QString& filename); | 153 | IoBackend *CreateFileIoBackend(const QString& filename); |
154 | #ifdef HAVE_HWSTUB | ||
155 | IoBackend *CreateHWStubIoBackend(HWStubDevice *dev); | ||
156 | #endif | ||
58 | 157 | ||
59 | signals: | 158 | signals: |
60 | void OnSocListChanged(); | 159 | void OnSocListChanged(); |
@@ -69,6 +168,10 @@ public: | |||
69 | bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v); | 168 | bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v); |
70 | bool ReadRegisterField(const QString& dev, const QString& reg, | 169 | bool ReadRegisterField(const QString& dev, const QString& reg, |
71 | const QString& field, soc_word_t& v); | 170 | const QString& field, soc_word_t& v); |
171 | bool GetDeviceDesc(const QString& dev, soc_dev_t& dev_desc, size_t& index); | ||
172 | bool GetRegisterDesc(const soc_dev_t& dev, const QString& reg, soc_reg_t& reg_desc, size_t& index); | ||
173 | bool GetFieldDesc(const soc_reg_t& reg_desc, const QString& field, soc_reg_field_t& field_desc); | ||
174 | bool GetRegisterAddress(const QString& dev, const QString& reg, soc_addr_t& addr); | ||
72 | private: | 175 | private: |
73 | IoBackend *m_io_backend; | 176 | IoBackend *m_io_backend; |
74 | soc_t m_soc; | 177 | soc_t m_soc; |