##// END OF EJS Templates
dsu3 wip
jeandet -
r37:934336d3c2c5 default
parent child
Show More
@@ -1,247 +1,255
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "dsu3plugin.h"
22 #include "dsu3plugin.h"
23 #include <QFileDialog>
23 #include <QFileDialog>
24 #include <QDir>
24 #include <QDir>
25 #include "dsu3pluginpywrapper.h"
25 #include "dsu3pluginpywrapper.h"
26 #include <socexplorerengine.h>
26 #include <socexplorerengine.h>
27
27
28 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
28 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
29 {
29 {
30 this->UI = new dsu3pluginui();
30 this->UI = new dsu3pluginui();
31 this->setWidget((QWidget*)this->UI);
31 this->setWidget((QWidget*)this->UI);
32 this->elfparserInst = new elfparser();
32 this->elfparserInst = new elfparser();
33 this->pyObject = new dsu3pluginPywrapper(this);
33 this->pyObject = new dsu3pluginPywrapper(this);
34 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
34 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
35 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
35 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
36 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
36 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
37 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(stop()),this,SLOT(stop()));
37 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(stop()),this,SLOT(stop()));
38 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
38 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
39 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
39 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
40 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
40 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
41 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
41 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
42 this->running = false;
42 this->running = false;
43 }
43 }
44
44
45
45
46 dsu3plugin::~dsu3plugin()
46 dsu3plugin::~dsu3plugin()
47 {
47 {
48
48
49 }
49 }
50
50
51
51
52 void dsu3plugin::openFile()
52 void dsu3plugin::openFile()
53 {
53 {
54 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
54 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
55 if(filename!="")
55 if(filename!="")
56 {
56 {
57 this->openFile(filename);
57 this->openFile(filename);
58 }
58 }
59 }
59 }
60
60
61 void dsu3plugin::openFile(QString fileName)
61 void dsu3plugin::openFile(QString fileName)
62 {
62 {
63 this->elfparserInst->setFilename(fileName);
63 this->elfparserInst->setFilename(fileName);
64 emit this->updateInfo(this->elfparserInst);
64 emit this->updateInfo(this->elfparserInst);
65 }
65 }
66
66
67 bool dsu3plugin::configureTarget()
67 bool dsu3plugin::configureTarget()
68 {
68 {
69 if(parent==NULL)
69 if(parent==NULL)
70 return false;
70 return false;
71 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
71 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
72 if(DSUBASEADDRESS == (unsigned int)-1)
72 if(DSUBASEADDRESS == (unsigned int)-1)
73 DSUBASEADDRESS = 0x90000000;
73 DSUBASEADDRESS = 0x90000000;
74 unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0);
74 unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0);
75 if(MCTRLBASEADDRESS == (unsigned int)-1)
75 if(MCTRLBASEADDRESS == (unsigned int)-1)
76 return false;
76 {
77 SocExplorerEngine::message(this,"Can't find MemCtrlr",1);
78 MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x051,0);
79 if(MCTRLBASEADDRESS == (unsigned int)-1)
80 {
81 SocExplorerEngine::message(this,"Can't find FTMemCtrlr",1);
82 return false;
83 }
84 }
77
85
78 //Force a debug break
86 //Force a debug break
79 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
87 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
80 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
88 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
81 //Clear time tag counter
89 //Clear time tag counter
82 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
90 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
83
91
84 //Clear ASR registers
92 //Clear ASR registers
85 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
93 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
86 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
94 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
87 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
95 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
88 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
96 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
89 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
97 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
90 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
98 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
91
99
92
100
93
101
94 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
102 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
95
103
96
104
97 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
105 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
98 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
106 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
99
107
100 unsigned int buff=0;
108 unsigned int buff=0;
101 // for(int i=0;i<1567;i++)
109 // for(int i=0;i<1567;i++)
102 // {
110 // {
103 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
111 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
104 // }
112 // }
105 memSet(DSUBASEADDRESS+0x300000,0,1567);
113 memSet(DSUBASEADDRESS+0x300000,0,1567);
106 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
114 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
107 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0x403ffff0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x300020);
115 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0x403ffff0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x300020);
108 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
116 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
109
117
110 //Disable interrupts
118 //Disable interrupts
111 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
119 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
112 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
120 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
113 return false;
121 return false;
114 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
122 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
115 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
123 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
116 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
124 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
117
125
118 //Set up timer
126 //Set up timer
119 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
127 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
120 if(APBTIMERBASEADD == (unsigned int)-1)
128 if(APBTIMERBASEADD == (unsigned int)-1)
121 return false;
129 return false;
122 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
130 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
123 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
131 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
124 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
132 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
125 return true;
133 return true;
126 }
134 }
127
135
128 bool dsu3plugin::flashTarget()
136 bool dsu3plugin::flashTarget()
129 {
137 {
130 configureTarget();
138 configureTarget();
131
139
132 /*Write .text*/
140 /*Write .text*/
133 this->writeSection(".text");
141 this->writeSection(".text");
134 /*Write .data*/
142 /*Write .data*/
135 this->writeSection(".data");
143 this->writeSection(".data");
136 return true;
144 return true;
137 }
145 }
138
146
139 void dsu3plugin::run()
147 void dsu3plugin::run()
140 {
148 {
141 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
149 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
142 if(DSUBASEADDRESS == (unsigned int)-1)
150 if(DSUBASEADDRESS == (unsigned int)-1)
143 DSUBASEADDRESS = 0x90000000;
151 DSUBASEADDRESS = 0x90000000;
144 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
152 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
145 this->running = true;
153 this->running = true;
146 this->UI->setRunning(true);
154 this->UI->setRunning(true);
147 }
155 }
148
156
149 void dsu3plugin::stop()
157 void dsu3plugin::stop()
150 {
158 {
151 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
159 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
152 if(DSUBASEADDRESS == (unsigned int)-1)
160 if(DSUBASEADDRESS == (unsigned int)-1)
153 DSUBASEADDRESS = 0x90000000;
161 DSUBASEADDRESS = 0x90000000;
154 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
162 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
155 this->running = false;
163 this->running = false;
156 this->UI->setRunning(false);
164 this->UI->setRunning(false);
157 }
165 }
158
166
159 void dsu3plugin::toggleRun()
167 void dsu3plugin::toggleRun()
160 {
168 {
161 if(this->running)
169 if(this->running)
162 this->stop();
170 this->stop();
163 else
171 else
164 this->run();
172 this->run();
165 }
173 }
166
174
167 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
175 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
168 {
176 {
169 unsigned int* buff;
177 unsigned int* buff;
170 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
178 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
171 for(int i=0;i<Values.count();i++)
179 for(int i=0;i<Values.count();i++)
172 {
180 {
173 buff[i]=Values.at(i);
181 buff[i]=Values.at(i);
174 }
182 }
175 parent->Write(buff,(unsigned int)Values.count(),address);
183 parent->Write(buff,(unsigned int)Values.count(),address);
176 free(buff);
184 free(buff);
177 }
185 }
178
186
179 void dsu3plugin::writeSection(int index)
187 void dsu3plugin::writeSection(int index)
180 {
188 {
181 char* buffch=NULL;
189 char* buffch=NULL;
182 unsigned int* buff;
190 unsigned int* buff;
183 int size = this->elfparserInst->getSectionDatasz(index);
191 int size = this->elfparserInst->getSectionDatasz(index);
184 int sizeInt = size/4;
192 int sizeInt = size/4;
185 if(parent==NULL)
193 if(parent==NULL)
186 return;
194 return;
187 this->elfparserInst->getSectionData(index,&buffch);
195 this->elfparserInst->getSectionData(index,&buffch);
188 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
196 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
189 for(int i=0;i<sizeInt;i++)
197 for(int i=0;i<sizeInt;i++)
190 {
198 {
191 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
199 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
192 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
200 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
193 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
201 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
194 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
202 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
195 }
203 }
196 if(size%4)
204 if(size%4)
197 {
205 {
198 buff[sizeInt]=0;
206 buff[sizeInt]=0;
199 for(int i=(size%4);i>0;i--)
207 for(int i=(size%4);i>0;i--)
200 {
208 {
201 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
209 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
202 }
210 }
203 sizeInt++;
211 sizeInt++;
204 }
212 }
205 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
213 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
206 free(buff);
214 free(buff);
207 }
215 }
208
216
209 void dsu3plugin::writeSection(const QString &name)
217 void dsu3plugin::writeSection(const QString &name)
210 {
218 {
211 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
219 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
212 {
220 {
213 if(!this->elfparserInst->getSectionName(i).compare(name))
221 if(!this->elfparserInst->getSectionName(i).compare(name))
214 {
222 {
215 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
223 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
216 writeSection(i);
224 writeSection(i);
217 }
225 }
218 }
226 }
219 }
227 }
220
228
221
229
222 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
230 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
223 {
231 {
224 if(parent!=NULL)
232 if(parent!=NULL)
225 return parent->Write(Value,count,address);
233 return parent->Write(Value,count,address);
226 return 0;
234 return 0;
227 }
235 }
228
236
229 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
237 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
230 {
238 {
231 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
239 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
232 if(buffer!=NULL)
240 if(buffer!=NULL)
233 {
241 {
234 memset((void*)buffer,value,count*sizeof(unsigned int));
242 memset((void*)buffer,value,count*sizeof(unsigned int));
235 parent->Write(buffer,count,address);
243 parent->Write(buffer,count,address);
236 free(buffer );
244 free(buffer );
237 return true;
245 return true;
238 }
246 }
239 return false;
247 return false;
240 }
248 }
241
249
242 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
250 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
243 {
251 {
244 if(parent!=NULL)
252 if(parent!=NULL)
245 return parent->Read(Value,count,address);
253 return parent->Read(Value,count,address);
246 return 0;
254 return 0;
247 }
255 }
General Comments 0
You need to be logged in to leave comments. Login now