##// END OF EJS Templates
Improved memory size measurement. Slower but generates less errors.
Jeandet Alexis -
r114:54b9f2f11e09 0.6 draft
parent child
Show More
@@ -1,75 +1,85
1 #include "memtester.h"
1 #include "memtester.h"
2 #include <socexplorerengine.h>
2 #include <socexplorerengine.h>
3 #include <socexplorerproxy.h>
3 #include <socexplorerproxy.h>
4
4
5 MemTester::MemTester(QObject* parent)
5 MemTester::MemTester(QObject* parent)
6 :QObject(parent)
6 :QObject(parent)
7 {
7 {
8
8
9 }
9 }
10
10
11 MemTester::~MemTester()
11 MemTester::~MemTester()
12 {
12 {
13
13
14 }
14 }
15
15
16
16
17 unsigned int p_pow2(unsigned int v)
17 unsigned int p_pow2(unsigned int v)
18 {
18 {
19 static const char LogTable256[256] =
19 static const char LogTable256[256] =
20 {
20 {
21 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
21 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
22 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
22 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
23 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
23 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
24 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
24 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
25 };
25 };
26
26
27 unsigned int r; // r will be lg(v)
27 unsigned int r; // r will be lg(v)
28 register unsigned int t, tt; // temporaries
28 register unsigned int t, tt; // temporaries
29
29
30 if (tt = v >> 16)
30 if (tt = v >> 16)
31 {
31 {
32 r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
32 r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
33 }
33 }
34 else
34 else
35 {
35 {
36 r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
36 r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
37 }
37 }
38 return r;
38 return r;
39 }
39 }
40
40
41 unsigned int MemTester::measureMemSize(socexplorerplugin *plugin, unsigned int address, unsigned int maxSize)
41 unsigned int MemTester::measureMemSize(socexplorerplugin *plugin, unsigned int address, unsigned int maxSize)
42 {
42 {
43 unsigned int curVal=1,testAddress=address;
43 unsigned int curVal=1,testAddress=address;
44 unsigned int size=0;
44 unsigned int size=0;
45 if(Q_UNLIKELY(!plugin || !plugin->isConnected()))return 0;
45 if(Q_UNLIKELY(!plugin || !plugin->isConnected()))return 0;
46 plugin->Write(&curVal,1,testAddress);
46 plugin->Write(&curVal,1,testAddress);
47 plugin->Read(&curVal,1,testAddress);
47 plugin->Read(&curVal,1,testAddress);
48 if(Q_UNLIKELY(curVal!=1))
48 if(Q_UNLIKELY(curVal!=1))
49 return size;
49 return size;
50 unsigned int max= p_pow2((0xFFFFFFFFFFFFFFFF - address))+1;
50 unsigned int max= p_pow2((0xFFFFFFFFFFFFFFFF - address))+1;
51 register unsigned int maxSizeLg=p_pow2(maxSize)-1;
51 register unsigned int maxSizeLg=p_pow2(maxSize)-1;
52 if(max>maxSizeLg)
52 if(max>maxSizeLg)
53 max=maxSizeLg;
53 max=maxSizeLg;
54 if(max>32)max=32;
54 if(max>32)max=32;
55 for(size=2;size<max;size++) //check each address bit
55 for(size=2;size<max;size++) //check each address bit
56 {
56 {
57 testAddress = (unsigned int)(address+(1<<size));
57 testAddress = (unsigned int)(address+(1<<size));
58 curVal = (unsigned int)(1<<size);
58 curVal = (unsigned int)(1<<size);
59 plugin->Write(&curVal,1,testAddress);
59 plugin->Write(&curVal,1,testAddress);
60 plugin->Read(&curVal,1,testAddress);
60 if(!MemTester::m_check_space(plugin,address,size))
61 if((unsigned int)curVal!=(unsigned int)(1<<size))
61 return (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));
66 }
62 }
67 return (1<<(size+1));
63 return (1<<(size+1));
68 }
64 }
69
65
70 unsigned int MemTester::measureMemSize(const QString &plugin, unsigned int address, unsigned int maxSize)
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 #ifndef MEMTESTER_H
1 #ifndef MEMTESTER_H
2 #define MEMTESTER_H
2 #define MEMTESTER_H
3 #include <socexplorerplugin.h>
3 #include <socexplorerplugin.h>
4 #include <QObject>
4 #include <QObject>
5
5
6 class MemTester : public QObject
6 class MemTester : public QObject
7 {
7 {
8 Q_OBJECT
8 Q_OBJECT
9 public:
9 public:
10 MemTester(QObject *parent=0);
10 MemTester(QObject *parent=0);
11 ~MemTester();
11 ~MemTester();
12
12
13 static unsigned int measureMemSize(socexplorerplugin* plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
13 static unsigned int measureMemSize(socexplorerplugin* plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
14 static unsigned int measureMemSize(const QString& plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
14 static unsigned int measureMemSize(const QString& plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
15 public slots:
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 #endif // MEMTESTER_H
21 #endif // MEMTESTER_H
General Comments 0
You need to be logged in to leave comments. Login now