@@ -1,75 +1,85 | |||
|
1 | 1 | #include "memtester.h" |
|
2 | 2 | #include <socexplorerengine.h> |
|
3 | 3 | #include <socexplorerproxy.h> |
|
4 | 4 | |
|
5 | 5 | MemTester::MemTester(QObject* parent) |
|
6 | 6 | :QObject(parent) |
|
7 | 7 | { |
|
8 | 8 | |
|
9 | 9 | } |
|
10 | 10 | |
|
11 | 11 | MemTester::~MemTester() |
|
12 | 12 | { |
|
13 | 13 | |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | unsigned int p_pow2(unsigned int v) |
|
18 | 18 | { |
|
19 | 19 | static const char LogTable256[256] = |
|
20 | 20 | { |
|
21 | 21 | #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n |
|
22 | 22 | -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, |
|
23 | 23 | LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6), |
|
24 | 24 | LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7) |
|
25 | 25 | }; |
|
26 | 26 | |
|
27 | 27 | unsigned int r; // r will be lg(v) |
|
28 | 28 | register unsigned int t, tt; // temporaries |
|
29 | 29 | |
|
30 | 30 | if (tt = v >> 16) |
|
31 | 31 | { |
|
32 | 32 | r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt]; |
|
33 | 33 | } |
|
34 | 34 | else |
|
35 | 35 | { |
|
36 | 36 | r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v]; |
|
37 | 37 | } |
|
38 | 38 | return r; |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | unsigned int MemTester::measureMemSize(socexplorerplugin *plugin, unsigned int address, unsigned int maxSize) |
|
42 | 42 | { |
|
43 | 43 | unsigned int curVal=1,testAddress=address; |
|
44 | 44 | unsigned int size=0; |
|
45 | 45 | if(Q_UNLIKELY(!plugin || !plugin->isConnected()))return 0; |
|
46 | 46 | plugin->Write(&curVal,1,testAddress); |
|
47 | 47 | plugin->Read(&curVal,1,testAddress); |
|
48 | 48 | if(Q_UNLIKELY(curVal!=1)) |
|
49 | 49 | return size; |
|
50 | 50 | unsigned int max= p_pow2((0xFFFFFFFFFFFFFFFF - address))+1; |
|
51 | 51 | register unsigned int maxSizeLg=p_pow2(maxSize)-1; |
|
52 | 52 | if(max>maxSizeLg) |
|
53 | 53 | max=maxSizeLg; |
|
54 | 54 | if(max>32)max=32; |
|
55 | 55 | for(size=2;size<max;size++) //check each address bit |
|
56 | 56 | { |
|
57 | 57 | testAddress = (unsigned int)(address+(1<<size)); |
|
58 | 58 | curVal = (unsigned int)(1<<size); |
|
59 | 59 | plugin->Write(&curVal,1,testAddress); |
|
60 | plugin->Read(&curVal,1,testAddress); | |
|
61 | if((unsigned int)curVal!=(unsigned int)(1<<size)) | |
|
62 | return (1<<(size)); | |
|
63 | plugin->Read(&curVal,1,address); | |
|
64 | if((curVal==(unsigned int)(1<<size)) && (size!=0)) | |
|
65 | return (1<<(size)); | |
|
60 | if(!MemTester::m_check_space(plugin,address,size)) | |
|
61 | return (1<<(size)); | |
|
66 | 62 | } |
|
67 | 63 | return (1<<(size+1)); |
|
68 | 64 | } |
|
69 | 65 | |
|
70 | 66 | unsigned int MemTester::measureMemSize(const QString &plugin, unsigned int address, unsigned int maxSize) |
|
71 | 67 | { |
|
72 | return measureMemSize(socexplorerproxy::findPlugin(plugin),address,maxSize); | |
|
68 | return measureMemSize(socexplorerproxy::findPlugin(plugin),address,maxSize); | |
|
69 | } | |
|
70 | ||
|
71 | bool MemTester::m_check_space(socexplorerplugin *plugin,unsigned int address, unsigned int pow) | |
|
72 | { | |
|
73 | unsigned int currentAddress=4; | |
|
74 | unsigned int curVal=0xffffff; | |
|
75 | while (currentAddress<=(1<<pow)) | |
|
76 | { | |
|
77 | plugin->Read(&curVal,1,address+currentAddress); | |
|
78 | if(curVal!=currentAddress) | |
|
79 | return false; | |
|
80 | currentAddress = currentAddress <<1; | |
|
81 | } | |
|
82 | return true; | |
|
73 | 83 | } |
|
74 | 84 | |
|
75 | 85 |
@@ -1,19 +1,21 | |||
|
1 | 1 | #ifndef MEMTESTER_H |
|
2 | 2 | #define MEMTESTER_H |
|
3 | 3 | #include <socexplorerplugin.h> |
|
4 | 4 | #include <QObject> |
|
5 | 5 | |
|
6 | 6 | class MemTester : public QObject |
|
7 | 7 | { |
|
8 | 8 | Q_OBJECT |
|
9 | 9 | public: |
|
10 | 10 | MemTester(QObject *parent=0); |
|
11 | 11 | ~MemTester(); |
|
12 | 12 | |
|
13 | 13 | static unsigned int measureMemSize(socexplorerplugin* plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF); |
|
14 | 14 | static unsigned int measureMemSize(const QString& plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF); |
|
15 | 15 | public slots: |
|
16 | 16 | |
|
17 | private: | |
|
18 | static bool m_check_space(socexplorerplugin* plugin,unsigned int address, unsigned int pow); | |
|
17 | 19 | }; |
|
18 | 20 | |
|
19 | 21 | #endif // MEMTESTER_H |
General Comments 0
You need to be logged in to leave comments.
Login now