##// END OF EJS Templates
dsu3plugin now support SRCTRLE_0WS and SRCTRLE_1WS....
jeandet -
r49:a5ab5a38b3a9 default
parent child
Show More
@@ -1,222 +1,234
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "uartpollingthread.h"
23 23 #include <socexplorerengine.h>
24 24
25 25 UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
26 26 QThread((QObject*)parent)
27 27 {
28 28 this->plugin = parent;
29 29 uartMutex = new QMutex();
30 30 uartOpened = false;
31 31 fifoDebugConfigured = false;
32 32 p_fifoDebugEnabled = false;
33 33 this->moveToThread(this);
34 34 }
35 35
36 36 UARTPollingThread::~UARTPollingThread()
37 37 {
38 38 this->requestInterruption();
39 39 while(isRunning());
40 40 }
41 41
42 42 void UARTPollingThread::run()
43 43 {
44 44
45 45 char ch[4097];
46 46 int timeout =10;
47 47 SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3);
48 48 while (!this->isInterruptionRequested())
49 49 {
50 50 if(p_fifoDebugEnabled)
51 51 {
52 52 if(fifoDebugConfigured)
53 53 {
54 54 if(this->plugin->baseAddress()!=-1)
55 55 {
56 56 unsigned int status_reg,data;
57 57 char ch;
58 int cnt=0;
58 59 QString printdata="";
59 60 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
60 while ((status_reg & 4)==0) {
61 while ((status_reg & 4)==0)
62 {
61 63 plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
62 64 ch = (char)(0xff & data);
63 65 printdata+=ch;
64 66 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
67 cnt++;
68 if(Q_UNLIKELY(cnt>100))
69 {
70 break;
65 71 }
72 }
73 timeout = 100;
66 74 if(printdata!="")
67 75 emit apbUartTextReceived(printdata);
68 76 }
69 77 else
70 78 {
71 79 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
72 80 }
73 81 }
74 82 else
75 83 {
76 84 configFifoDebug(true);
77 85 }
78 86 }
79 87 else
80 88 {
81 89 int read =0,avail=0;
82 90 uartMutex->lock();
83 91 if(uartOpened)
84 92 {
85 93 avail = rs232availablebytes(this->uart);
86 94 SocExplorerEngine::message(this->plugin,QString("%1 available bytes on uart").arg(read),3);
87 95 if(avail)
88 96 {
89 97 if(avail>=4096)
90 98 {
91 99 read = rs232read(this->uart,ch,4096);
92 100 timeout = 0;
93 101 }
94 102 else
95 103 {
96 104 read = rs232read(this->uart,ch,avail);
97 105 timeout = 10;
98 106 }
99 107 SocExplorerEngine::message(this->plugin,QString("Read %1 bytes on uart").arg(read),3);
100 108 ch[read]='\0';
101 109 }
110 else
111 {
112 timeout = 100;
113 }
102 114 }
103 115 uartMutex->unlock();
104 116 if(read>=1)
105 117 {
106 118 SocExplorerEngine::message(this->plugin,QString("Received %1 char(s) from APBUART").arg(read),3);
107 119 emit this->apbUartTextReceived(QString(ch));
108 120 }
121 }
109 122 msleep(timeout);
110 123 }
111 124 }
112 }
113 125
114 126 void UARTPollingThread::sendChar(char c)
115 127 {
116 128 if(p_fifoDebugEnabled)
117 129 {
118 130 if(this->plugin->baseAddress()!=-1)
119 131 {
120 132 unsigned int i=0x0FF & c;
121 133 plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
122 134 }
123 135 }
124 136 else
125 137 {
126 138 uartMutex->lock();
127 139 rs232write(this->uart,&c,1);
128 140 uartMutex->unlock();
129 141 }
130 142 }
131 143
132 144 bool UARTPollingThread::openUart()
133 145 {
134 146 uartMutex->lock();
135 147 if(uartOpened)
136 148 {
137 149 closeUart();
138 150 }
139 151 SocExplorerEngine::message(this->plugin,"Opening UART "+this->portName,3);
140 152 this->uart = rs232open((char*)this->portName.toStdString().c_str());
141 153 if(this->uart!=badPortValue)
142 154 {
143 155 SocExplorerEngine::message(this->plugin,QString("Configuring UART, speed =%1").arg(this->uartSpeed),3);
144 156 rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop);
145 157 uartOpened = true;
146 158 }
147 159 uartMutex->unlock();
148 160 return uartOpened;
149 161 }
150 162
151 163 void UARTPollingThread::closeUart()
152 164 {
153 165 uartMutex->lock();
154 166 rs232close(this->uart);
155 167 uartOpened = false;
156 168 uartMutex->unlock();
157 169 }
158 170
159 171 void UARTPollingThread::setPortName(QString name)
160 172 {
161 173 SocExplorerEngine::message(this->plugin,"Changing UART port Name: "+name,3);
162 174 this->portName = name;
163 175 }
164 176
165 177 void UARTPollingThread::setPortSpeedStr(QString speed)
166 178 {
167 179 SocExplorerEngine::message(this->plugin,"Changing UART speed: "+speed,3);
168 180 this->uartSpeed = speed.toInt();
169 181 }
170 182
171 183 void UARTPollingThread::setPortSpeed(int speed)
172 184 {
173 185 SocExplorerEngine::message(this->plugin,QString("Changing UART speed: %1").arg(speed),3);
174 186 this->uartSpeed = speed;
175 187 }
176 188
177 189 void UARTPollingThread::setFifoDebugEable(bool enable)
178 190 {
179 191 if(enable)
180 192 SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3);
181 193 else
182 194 SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3);
183 195 if(uartOpened && enable)
184 196 {
185 197 closeUart();
186 198 }
187 199 this->fifoDebugConfigured = false;
188 200 configFifoDebug(enable);
189 201 this->p_fifoDebugEnabled = enable;
190 202 }
191 203
192 204 bool UARTPollingThread::fifoDebugEnabled()
193 205 {
194 206 return p_fifoDebugEnabled;
195 207 }
196 208
197 209 void UARTPollingThread::configFifoDebug(bool enable)
198 210 {
199 211 SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3);
200 212 if(this->plugin->baseAddress()==-1)
201 213 {
202 214 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
203 215 }
204 216 if(this->plugin->baseAddress()!=-1)
205 217 {
206 218 if(enable)
207 219 {
208 220 unsigned int ctrl_reg= 0x843;
209 221 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
210 222 this->fifoDebugConfigured = true;
211 223 }
212 224 else
213 225 {
214 226 unsigned int ctrl_reg;
215 227 /* Firts get Control reg value*/
216 228 this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
217 229 ctrl_reg = ctrl_reg & (~(1<<11));
218 230 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
219 231 this->fifoDebugConfigured = true;
220 232 }
221 233 }
222 234 }
@@ -1,508 +1,508
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include <socexplorerengine.h>
23 23 #include "ahbuartplugin.h"
24 24 #include <unistd.h>
25 25 #include <errno.h>
26 26 #include <QApplication>
27 27 #include <QProgressBar>
28 28 #include <stdio.h>
29 29 #include <QThread>
30 30 #include "ahbuartpywrapper.h"
31 31 #include <QCompleter>
32 32 #include <QStringList>
33 33 #include <QLineEdit>
34 34 #include <socexplorerproxy.h>
35 35
36 36 ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false)
37 37 {
38 38 this->port =(rs232port_t)NULL;
39 39 this->portMutex = new QMutex(QMutex::Recursive);
40 40 this->UI = new ahbUartPluginUI();
41 41 this->setWidget((QWidget*)this->UI);
42 42 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
43 43 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
44 44 this->pyObject = new ahbuartPywrapper(this);
45 45 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
46 46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
47 47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
48 48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
49 49 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
50 50 QObject::connect(this,SIGNAL(addReadBytes(int)),this->UI,SLOT(addReadBytes(int)));
51 51 QObject::connect(this,SIGNAL(addWritenBytes(int)),this->UI,SLOT(addWritenBytes(int)));
52 52 this->portListcompleter = NULL;
53 53 this->scanDone = false;
54 54 updatePortList();
55 55 }
56 56
57 57
58 58 ahbuartplugin::~ahbuartplugin()
59 59 {
60 60 if(this->port!=(rs232port_t)NULL)
61 61 {
62 62 rs232close(this->port);
63 63 this->port = (rs232port_t)NULL;
64 64 }
65 65 this->UI->close();
66 66 this->UI->~ahbUartPluginUI();
67 67 }
68 68
69 69
70 70 void ahbuartplugin::closeMe()
71 71 {
72 72 if(this->port!=(rs232port_t)NULL)
73 73 {
74 74 rs232close(this->port);
75 75 this->port = (rs232port_t)NULL;
76 76 }
77 77 emit this->closePlugin(this);
78 78 }
79 79
80 80 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
81 81 {
82 82 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
83 83 this->closeAction = this->menu->addAction(tr("Close plugin"));
84 84 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
85 85 return 1;
86 86 }
87 87
88 88
89 89 bool ahbuartplugin::checkConnection()
90 90 {
91 91 QTime timeout;
92 92 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
93 93 char test2[1024];
94 94 int writen =0;
95 95 int read = 0;
96 96 timeout.start();
97 97 SocExplorerEngine::message(this,"Check connection",2);
98 98 QMutexLocker lock(portMutex);
99 99 while(writen!=5)
100 100 {
101 101 writen+=rs232write(this->port,test+writen,5-writen);
102 102 if(timeout.elapsed()>1000)
103 103 {
104 104 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
105 105 return false;
106 106 }
107 107 }
108 108 #ifdef WIN32
109 109 usleep(1000);
110 110 #endif
111 111 timeout.restart();
112 112 int avail = 0;
113 113 do
114 114 {
115 115 avail = rs232availablebytes(this->port);
116 116 if(timeout.elapsed()>1000)
117 117 {
118 118 if(avail)
119 119 rs232read(this->port,test2,avail);
120 120 SocExplorerEngine::message(this,"Connection Error",2);
121 121 return false;
122 122 }
123 123 }while(avail<4);
124 124 read = rs232read(this->port,test2,avail);
125 125 if(read>0)
126 126 {
127 127 SocExplorerEngine::message(this,"Connection Ok",2);
128 128 return true;
129 129 }
130 130 else
131 131 {
132 132 SocExplorerEngine::message(this,"Connection Error",2);
133 133 return false;
134 134 }
135 135 }
136 136
137 137 void ahbuartplugin::connectPort(QString PortName, int baudrate)
138 138 {
139 139 QTime timeout;
140 140 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
141 141 timeout.start();
142 142 QMutexLocker lock(portMutex);
143 143 if(this->port==(rs232port_t)NULL)
144 144 {
145 145 SocExplorerEngine::message(this,"Open port "+PortName,2);
146 146 this->port=rs232open((char*)PortName.toStdString().c_str());
147 147 }
148 148 if(this->port!=badPortValue)
149 149 {
150 150 SocExplorerEngine::message(this,"Port opened "+PortName,2);
151 151 SocExplorerEngine::message(this,"Configure port "+PortName,2);
152 152 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
153 153 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
154 154 char test2[1024];
155 155 SAFEWRITE(test,1,timeout,2000,return);
156 156 SAFEWRITE((test+1),1,timeout,2000,return);
157 157 rs232read(this->port,test2,512);
158 158 int read = 0;
159 159 for(int i=0;i<10;i++)
160 160 {
161 161 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
162 162 SAFEWRITE(test+2,5,timeout,2000,return);
163 163 SocExplorerEngine::message(this,"Read Result",2);
164 164 read=rs232read(this->port,test2+read,16);
165 165 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
166 166 if(read>0)
167 167 {
168 168 SocExplorerEngine::message(this,"Flush port ",2);
169 169 while(rs232read(this->port,test2,1)>0);
170 170 this->Connected = true;
171 171 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
172 172 emit this->activate(true);
173 173 if(this->scanDone==false)
174 174 {
175 175 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
176 176 this->scanDone=true;
177 177 }
178 178 break;
179 179 }
180 180 }
181 181 }
182 182 else
183 183 {
184 184 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
185 185 this->port = (rs232port_t)NULL;
186 186 this->Connected = false;
187 187 emit this->activateSig(false);
188 188 return;
189 189 }
190 190 if(this->Connected == false)
191 191 {
192 192 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
193 193 rs232close(this->port);
194 194 this->port = (rs232port_t)NULL;
195 195 emit this->activateSig(false);
196 196 }
197 197
198 198 }
199 199
200 200 bool ahbuartplugin::open(QString PortName,int baudrate)
201 201 {
202 202 if(this->port!=(rs232port_t)NULL)
203 203 this->close();
204 204 this->UI->setconfig(PortName,baudrate);
205 205 this->connectPort(PortName,baudrate);
206 206 return (this->port!=(rs232port_t)NULL);
207 207 }
208 208
209 209 void ahbuartplugin::close()
210 210 {
211 211 if(this->port!=(rs232port_t)NULL)
212 212 {
213 213 rs232close(this->port);
214 214 this->port = (rs232port_t)NULL;
215 215 this->Connected = false;
216 216 emit this->activateSig(false);
217 217 }
218 218 }
219 219
220 220 void ahbuartplugin::togglePort(QString PortName,int baudrate)
221 221 {
222 222 if(this->port!=(rs232port_t)NULL)
223 223 {
224 224 this->close();
225 225 }
226 226 else
227 227 {
228 228 this->connectPort(PortName,baudrate);
229 229 }
230 230 }
231 231
232 232
233 233 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
234 234 {
235 235 QTime timeout;
236 236 timeout.start();
237 237 unsigned int read=0;
238 238 unsigned int cnt=count;
239 unsigned int nextUpdateTrig=0,updateStep=512;
239 unsigned int nextUpdateTrig=0,updateStep=1024;
240 240 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
241 241 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
242 242 {
243 243 QMutexLocker lock(portMutex);
244 244 if(!this->checkConnection())
245 245 {
246 246 this->Connected = false;
247 247 emit this->activateSig(false);
248 248 this->portMutex->unlock();
249 249 return 0;
250 250 }
251 251 QProgressBar* progress=NULL;
252 252 if(cnt>128)
253 253 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
254 254 char CMD[5];
255 255 char* result = (char*)malloc(count*4);
256 256 while(count>32)
257 257 {
258 258 CMD[0] = 0x80 | (32-1);
259 259 CMD[1] = (char)((address>>24)&0xFF);
260 260 CMD[2] = (char)((address>>16)&0xFF);
261 261 CMD[3] = (char)((address>>8)&0xFF);
262 262 CMD[4] = (char)((address)&0xFF);
263 263 SAFEWRITE(CMD,5,timeout,1000,return 0);
264 264 timeout.restart();
265 265 int avail=0;
266 266 do{
267 267 avail=rs232availablebytes(this->port);
268 268 if(timeout.elapsed()>1000)
269 269 {
270 270 rs232close(this->port);
271 271 this->port = (rs232port_t)NULL;
272 272 this->Connected = false;
273 273 emit this->activateSig(false);
274 274 return 0;
275 275 }
276 276 }while(avail<(32*4));
277 277 rs232read(this->port,result+((cnt-count)*4),32*4);
278 278 count-=32;
279 279 address+=32*4;
280 280 if(cnt>128)
281 281 {
282 282
283 283 if((cnt-count)>=nextUpdateTrig)
284 284 {
285 285 progress->setValue(cnt-count);
286 286 qApp->processEvents();
287 287 nextUpdateTrig+=updateStep;
288 288 }
289 289 }
290 290 }
291 291 if(count>0)
292 292 {
293 293 CMD[0] = 0x80 | (count-1);
294 294 CMD[1] = (char)((address>>24)&0xFF);
295 295 CMD[2] = (char)((address>>16)&0xFF);
296 296 CMD[3] = (char)((address>>8)&0xFF);
297 297 CMD[4] = (char)((address)&0xFF);
298 298 SAFEWRITE(CMD,5,timeout,1000,return 0);
299 299 timeout.restart();
300 300 int avail=0;
301 301 do{
302 302 avail=rs232availablebytes(this->port);
303 303 if(timeout.elapsed()>1000)
304 304 {
305 305 rs232close(this->port);
306 306 this->port = (rs232port_t)NULL;
307 307 this->Connected = false;
308 308 emit this->activateSig(false);
309 309 return 0;
310 310 }
311 311 }while(avail<(count*4));
312 312 rs232read(this->port,result+((cnt-count)*4),count*4);
313 313 }
314 314 if(cnt>128)
315 315 {
316 316 progress->setValue(cnt-count);
317 317 qApp->processEvents();
318 318 }
319 319 for(int i=0;(unsigned int)i<cnt;i++)
320 320 {
321 321 #if __BYTE_ORDER == __LITTLE_ENDIAN
322 322 // for(int j =0;j<4;j++)
323 323 // {
324 324 // Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
325 325 // }
326 326 Value[i]= socexplorerBswap32(((uint32_t*)result)[i]);
327 327 #elif __BYTE_ORDER == __BIG_ENDIAN
328 328 Value[i]= ((uint32_t*)result)[i];
329 329 #endif
330 330 }
331 331 read = cnt*4;
332 332 if(cnt>128)
333 333 SocExplorerEngine::deleteProgressBar(progress);
334 334 free(result);
335 335 }
336 336 emit this->addReadBytes(read);
337 337 return read/4;
338 338 }
339 339
340 340 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
341 341 {
342 342 QTime timeout;
343 343 timeout.start();
344 344 unsigned int writen=0;
345 unsigned int nextUpdateTrig=0,updateStep=512;
345 unsigned int nextUpdateTrig=0,updateStep=1024;
346 346 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
347 347 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
348 348 {
349 349 QMutexLocker lock(portMutex);
350 350 if(!this->checkConnection())
351 351 {
352 352 emit this->activateSig(false);
353 353 this->Connected = false;
354 354 this->portMutex->unlock();
355 355 return 0;
356 356 }
357 357 QProgressBar* progress = NULL;
358 358 if(count>128)
359 359 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
360 360 int offset = 0;
361 361 char* CMD= (char*)malloc((32*4)+5);
362 362 writen=0;
363 363 while(count>32)
364 364 {
365 365 CMD[0] = 0xC0 | (32-1);
366 366 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
367 367 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
368 368 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
369 369 CMD[4] = (char)(((unsigned int)address)&0xFF);
370 370 for(int i=0;i<32;i++)
371 371 {
372 372 #if __BYTE_ORDER == __LITTLE_ENDIAN
373 373 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
374 374 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
375 375 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
376 376 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
377 377 #elif __BYTE_ORDER == __BIG_ENDIAN
378 378 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset])&0xFF);
379 379 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
380 380 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
381 381 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
382 382 #endif
383 383 }
384 384 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
385 385 writen+=32;
386 386 count-=32;
387 387 offset+=32;
388 388 address+=32*4;
389 389 if(offset>=nextUpdateTrig && progress!=NULL)
390 390 {
391 391 progress->setValue(offset);
392 392 qApp->processEvents();
393 393 nextUpdateTrig +=updateStep;
394 394 }
395 395
396 396 }
397 397 if(count>0)
398 398 {
399 399 CMD[0] = 0xC0 | (count-1);
400 400 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
401 401 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
402 402 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
403 403 CMD[4] = (char)(((unsigned int)address)&0xFF);
404 404 for(int i=0;(unsigned int) i<(count);i++)
405 405 {
406 406 #if __BYTE_ORDER == __LITTLE_ENDIAN
407 407 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
408 408 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
409 409 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
410 410 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
411 411 #elif __BYTE_ORDER == __BIG_ENDIAN
412 412 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset])&0xFF);
413 413 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
414 414 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
415 415 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
416 416 #endif
417 417 }
418 418 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
419 419 writen+=count;
420 420 }
421 421 if(progress!=NULL)
422 422 {
423 423 progress->setValue(writen);
424 424 qApp->processEvents();
425 425 SocExplorerEngine::deleteProgressBar(progress);
426 426 }
427 427 free(CMD);
428 428 emit this->addWritenBytes(writen*4);
429 429 return writen;
430 430 }
431 431 return 0;
432 432 }
433 433
434 434
435 435
436 436
437 437 void ahbuartplugin::updatePortList()
438 438 {
439 439 if(this->portListcompleter==(QCompleter*)NULL)
440 440 {
441 441 this->portListcompleter=new QCompleter(this);
442 442 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
443 443 this->portListcompleterModel = new QStringListModel(this);
444 444 this->portListcompleter->setModel(this->portListcompleterModel);
445 445 this->UI->setCompleter(this->portListcompleter);
446 446 }
447 447 rs232portslist_t* portlist = rs232getportlist();
448 448 rs232portslist_t* portlistenum = portlist;
449 449 QStringList wordList;
450 450 while(portlistenum!=NULL)
451 451 {
452 452 wordList << portlistenum->name;
453 453 portlistenum = portlistenum->next;
454 454 }
455 455 rs232deleteportlist(portlist);
456 456 this->portListcompleterModel->setStringList(wordList);
457 457 }
458 458
459 459 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
460 460 {
461 461 unsigned int data[(count/4)+1];
462 462 QVariantList result;
463 463 this->Read(data,(count/4)+1,address);
464 464 for(unsigned int i = 0;i<count/4;i++)
465 465 {
466 466 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
467 467 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
468 468 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
469 469 result.append(QVariant((int)(0x0FF&(data[i]))));
470 470 }
471 471
472 472 for(int i=0;i<(count%4);i++)
473 473 {
474 474 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
475 475 }
476 476
477 477 return result;
478 478 }
479 479
480 480 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
481 481 {
482 482 unsigned int data[dataList.count()/4];
483 483 for(int i = 0;i<(dataList.count()/4);i++)
484 484 {
485 485 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
486 486 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
487 487 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
488 488 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
489 489 }
490 490 this->Write(data,dataList.count()/4,address);
491 491 }
492 492
493 493
494 494
495 495
496 496
497 497
498 498
499 499
500 500
501 501
502 502
503 503
504 504
505 505
506 506
507 507
508 508
@@ -1,92 +1,103
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbuartpluginui.h"
23 23 #include "ui_ahbuartpluginui.h"
24 24
25 25 ahbUartPluginUI::ahbUartPluginUI(QWidget *parent) :
26 26 QWidget(parent),
27 27 ui(new Ui::ahbUartPluginUI)
28 28 {
29 29 ui->setupUi(this);
30 30 connect(ui->OpenPort,SIGNAL(clicked()),this,SLOT(connectPort()));
31 connect(ui->PortspeedSlider,SIGNAL(valueChanged(int)),ui->baurateLCD,SLOT(display(int)));
31 // connect(ui->PortspeedSlider,SIGNAL(valueChanged(int)),ui->baurateLCD,SLOT(display(int)));
32 32 connect(ui->rescanPorts,SIGNAL(clicked()),this,SIGNAL(rescanPorts()));
33 QStringList allowedSpeeds;
34 allowedSpeeds<<"0"<<"50"<<"75"<<"110"<<"134"<<"150"<<
35 "200"<<"300"<<"600"<<"1200"<<"1800"<<"2400"<<
36 "4800"<<"9600"<<"19200"<<"38400"<<"57600"<<
37 "115200"<<"230400"<<"460800"<<"500000"<<"576000"<<
38 "921600"<<"1000000"<<"1152000"<<"1500000"<<"2000000"<<
39 "2500000"<<"3000000"<<"3500000"<<"4000000";
40
41 portSpeedCompleter = new QCompleter(allowedSpeeds);
42 this->ui->portSpeed->setCompleter(portSpeedCompleter);
33 43 this->writtenBytes = 0;
34 44 this->readBytes = 0;
35 45 }
36 46
37 47 void ahbUartPluginUI::connectPort()
38 48 {
39 emit this->connectPortsig(ui->PortName->text(),ui->PortspeedSlider->value());
49 int baudrate = ui->portSpeed->text().toInt();
50 emit this->connectPortsig(ui->PortName->text(),baudrate);
40 51 }
41 52
42 53 void ahbUartPluginUI::setConnected(bool connected)
43 54 {
44 55 if(connected == true)
45 56 {
46 57 ui->OpenPort->setText(tr("Close port"));
47 58 }
48 59 else
49 60 ui->OpenPort->setText(tr("Open port"));
50 61 }
51 62
52 63
53 64 ahbUartPluginUI::~ahbUartPluginUI()
54 65 {
55 66 delete ui;
56 67 }
57 68
58 69
59 70 void ahbUartPluginUI::setconfig(QString PortName, int baudrate)
60 71 {
61 72 this->ui->PortName->setText(PortName);
62 this->ui->PortspeedSlider->setValue(baudrate);
73 this->ui->portSpeed->setText(QString::number(baudrate));
63 74 }
64 75
65 76 void ahbUartPluginUI::addWritenBytes(int count)
66 77 {
67 78 this->writtenBytes+=count;
68 79 this->ui->WrBytesLCD->display(this->writtenBytes);
69 80 }
70 81
71 82 void ahbUartPluginUI::addReadBytes(int count)
72 83 {
73 84 this->readBytes+=count;
74 85 this->ui->RdBytesLCD->display(this->readBytes);
75 86 }
76 87
77 88
78 89 void ahbUartPluginUI::setCompleter(QCompleter *completer)
79 90 {
80 91 this->ui->PortName->setCompleter(completer);
81 92 }
82 93
83 94 void ahbUartPluginUI::closeEvent(QCloseEvent *event)
84 95 {
85 96 event->accept();
86 97 }
87 98
88 99
89 100
90 101
91 102
92 103
@@ -1,68 +1,69
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBUARTPLUGINUI_H
23 23 #define AHBUARTPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QFile>
27 27 #include <QTextStream>
28 28 #include <QFileDialog>
29 29 #include <QDir>
30 30 #include <QCloseEvent>
31 31 #include <QCompleter>
32 32
33 33 namespace Ui {
34 34 class ahbUartPluginUI;
35 35 }
36 36
37 37 class ahbUartPluginUI : public QWidget
38 38 {
39 39 Q_OBJECT
40 40
41 41 public:
42 42 explicit ahbUartPluginUI(QWidget *parent = 0);
43 43 ~ahbUartPluginUI();
44 44 void closeEvent(QCloseEvent *event);
45 45 void setCompleter(QCompleter* completer);
46 46 public slots:
47 47 void setConnected(bool connected);
48 48 void connectPort();
49 49 void setconfig(QString PortName,int baudrate);
50 50 void addWritenBytes(int count);
51 51 void addReadBytes(int count);
52 52
53 53 signals:
54 54 void connectPortsig(QString PortName,int baudrate);
55 55 void setLogFileName(QString FileName);
56 56 void rescanPorts();
57 57 private:
58 58 int writtenBytes;
59 59 int readBytes;
60 60 Ui::ahbUartPluginUI *ui;
61 QCompleter* portSpeedCompleter;
61 62 };
62 63
63 64 #endif // AHBUARTPLUGINUI_H
64 65
65 66
66 67
67 68
68 69
@@ -1,143 +1,118
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>ahbUartPluginUI</class>
4 4 <widget class="QWidget" name="ahbUartPluginUI">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 <width>768</width>
10 <height>196</height>
9 <width>884</width>
10 <height>221</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout_2">
17 17 <item row="4" column="0" colspan="3">
18 18 <widget class="QGroupBox" name="Statistiques">
19 19 <property name="title">
20 20 <string>Statistics</string>
21 21 </property>
22 22 <layout class="QGridLayout" name="gridLayout">
23 23 <item row="0" column="2">
24 24 <widget class="QLCDNumber" name="WrBytesLCD">
25 25 <property name="digitCount">
26 26 <number>8</number>
27 27 </property>
28 28 <property name="segmentStyle">
29 29 <enum>QLCDNumber::Flat</enum>
30 30 </property>
31 31 </widget>
32 32 </item>
33 33 <item row="1" column="2">
34 34 <widget class="QLCDNumber" name="RdBytesLCD">
35 35 <property name="digitCount">
36 36 <number>8</number>
37 37 </property>
38 38 <property name="segmentStyle">
39 39 <enum>QLCDNumber::Flat</enum>
40 40 </property>
41 41 </widget>
42 42 </item>
43 43 <item row="1" column="0">
44 44 <widget class="QLabel" name="RdBytesLbl">
45 45 <property name="text">
46 46 <string>Read Bytes</string>
47 47 </property>
48 48 </widget>
49 49 </item>
50 50 <item row="0" column="0">
51 51 <widget class="QLabel" name="WrBytesLbl">
52 52 <property name="text">
53 53 <string>Writen Bytes</string>
54 54 </property>
55 55 </widget>
56 56 </item>
57 57 </layout>
58 58 </widget>
59 59 </item>
60 <item row="1" column="1">
61 <widget class="QSlider" name="PortspeedSlider">
62 <property name="maximum">
63 <number>3000000</number>
64 </property>
65 <property name="singleStep">
66 <number>9600</number>
67 </property>
68 <property name="pageStep">
69 <number>1</number>
70 </property>
71 <property name="value">
72 <number>921600</number>
73 </property>
74 <property name="orientation">
75 <enum>Qt::Horizontal</enum>
76 </property>
77 </widget>
78 </item>
79 60 <item row="1" column="0">
80 61 <widget class="QLabel" name="label_2">
81 62 <property name="text">
82 63 <string>Port Speed</string>
83 64 </property>
84 65 </widget>
85 66 </item>
86 67 <item row="0" column="0">
87 68 <widget class="QLabel" name="label">
88 69 <property name="text">
89 70 <string>Port Name</string>
90 71 </property>
91 72 </widget>
92 73 </item>
93 74 <item row="0" column="2">
94 75 <widget class="QPushButton" name="rescanPorts">
95 76 <property name="text">
96 77 <string>SCAN</string>
97 78 </property>
98 79 </widget>
99 80 </item>
100 81 <item row="0" column="1">
101 82 <widget class="QLineEdit" name="PortName"/>
102 83 </item>
103 <item row="1" column="2">
104 <widget class="QLCDNumber" name="baurateLCD">
105 <property name="font">
106 <font>
107 <weight>75</weight>
108 <bold>true</bold>
109 </font>
110 </property>
111 <property name="digitCount">
112 <number>7</number>
113 </property>
114 <property name="segmentStyle">
115 <enum>QLCDNumber::Flat</enum>
116 </property>
117 </widget>
118 </item>
119 84 <item row="3" column="0">
120 85 <spacer name="verticalSpacer">
121 86 <property name="orientation">
122 87 <enum>Qt::Vertical</enum>
123 88 </property>
124 89 <property name="sizeHint" stdset="0">
125 90 <size>
126 91 <width>20</width>
127 92 <height>40</height>
128 93 </size>
129 94 </property>
130 95 </spacer>
131 96 </item>
132 97 <item row="3" column="1" colspan="2">
133 98 <widget class="QPushButton" name="OpenPort">
134 99 <property name="text">
135 100 <string>Open Port</string>
136 101 </property>
137 102 </widget>
138 103 </item>
104 <item row="1" column="1" colspan="2">
105 <widget class="QLineEdit" name="portSpeed">
106 <property name="inputMask">
107 <string>00000000</string>
108 </property>
109 <property name="text">
110 <string>115200</string>
111 </property>
112 </widget>
113 </item>
139 114 </layout>
140 115 </widget>
141 116 <resources/>
142 117 <connections/>
143 118 </ui>
@@ -1,323 +1,333
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "dsu3plugin.h"
23 23 #include <QFileDialog>
24 24 #include <QDir>
25 25 #include "dsu3pluginpywrapper.h"
26 26 #include <socexplorerengine.h>
27 27
28 28
29 29 struct acceptedMemctrlr_str
30 30 {
31 31 int vid;
32 32 int pid;
33 33 const char* name;
34 34 };
35 35
36 36 const struct acceptedMemctrlr_str acceptedMemctrlr[]=
37 37 {
38 38 {0x04,0x0f,"MCTRL"},
39 39 {0x01,0x51,"FTSRCTRL"},
40 40 {0x20,0x01,"SRCTRLE_0WS" },
41 41 {0x20,0x02,"SRCTRLE_1WS" }
42 42 };
43 43
44 44 #define acceptedMemctrlrCnt 4
45 45
46 46 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
47 47 {
48 48 this->UI = new dsu3pluginui();
49 49 this->setWidget((QWidget*)this->UI);
50 50 this->elfparserInst = new elfparser();
51 51 this->pyObject = new dsu3pluginPywrapper(this);
52 52 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
53 53 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
54 54 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
55 55 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(stop()),this,SLOT(stop()));
56 56 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(cacheEnable()),this,SLOT(cacheEnable()));
57 57 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(cacheDisable()),this,SLOT(cacheDisable()));
58 58 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(setCacheEnable(bool)),this,SLOT(setCacheEnable(bool)));
59 59
60 60 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
61 61 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
62 62 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
63 63 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
64 64 this->running = false;
65 65 }
66 66
67 67
68 68 dsu3plugin::~dsu3plugin()
69 69 {
70 70
71 71 }
72 72
73 73
74 74 void dsu3plugin::openFile()
75 75 {
76 76 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
77 77 if(filename!="")
78 78 {
79 79 this->openFile(filename);
80 80 }
81 81 }
82 82
83 83 void dsu3plugin::openFile(QString fileName)
84 84 {
85 85 this->elfparserInst->setFilename(fileName);
86 86 emit this->updateInfo(this->elfparserInst);
87 87 }
88 88
89 89 bool dsu3plugin::configureTarget()
90 90 {
91 int detectedMctrlr=-1;
91 92 if(parent==NULL)
92 93 return false;
93 94 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
94 95 if(DSUBASEADDRESS == (unsigned int)-1)
95 96 DSUBASEADDRESS = 0x90000000;
96 97 unsigned int MCTRLBASEADDRESS =-1;
97 98 for(int i=0; i<acceptedMemctrlrCnt;i++)
98 99 {
99 100 MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,acceptedMemctrlr[i].vid , acceptedMemctrlr[i].pid,0);
100 101 if(MCTRLBASEADDRESS != (unsigned int)-1)
101 102 {
102 103 SocExplorerEngine::message(this,QString("Found %1 @%2").arg(acceptedMemctrlr[i].name).arg(MCTRLBASEADDRESS,8,16),1);
104 detectedMctrlr=i;
103 105 break;
104 106 }
105 107 }
106 108 if(MCTRLBASEADDRESS == (unsigned int)-1)
107 109 {
108 110 SocExplorerEngine::message(this,"Can't any compatible memory controller",1);
109 111 return false;
110 112 }
111 113
112 114
113 115 //Force a debug break
114 116 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
115 117 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
116 118 //Clear time tag counter
117 119 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
118 120
119 121 //Clear ASR registers
120 122 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
121 123 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
122 124 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
123 125 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
124 126 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
125 127 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
126 128
127
128
129 // {0x04,0x0f,"MCTRL"},
130 // {0x01,0x51,"FTSRCTRL"},
131 // {0x20,0x01,"SRCTRLE_0WS" },
132 // {0x20,0x02,"SRCTRLE_1WS" }
133 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="MCTRL" || QString(acceptedMemctrlr[detectedMctrlr].name)=="FTSRCTRL" )
134 {
129 135 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
136 }
137 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_0WS" || QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_1WS" )
138 {
139 //let's perform a mem Wash
140 unsigned int val = ReadReg(MCTRLBASEADDRESS);
141 val |=1<<31;
142 WriteRegs(uIntlist()<<val,(unsigned int)MCTRLBASEADDRESS);
143 usleep(1000*1000);
144 }
130 145
131 146
132 147 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
133 148 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
134 149
135 unsigned int buff=0;
136 // for(int i=0;i<1567;i++)
137 // {
138 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
139 // }
140 150 memSet(DSUBASEADDRESS+0x300000,0,1567);
141 151 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
142 152 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);
143 153 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
144 154
145 155 //Disable interrupts
146 156 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
147 157 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
148 158 return false;
149 159 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
150 160 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
151 161 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
152 162
153 163 //Set up timer
154 164 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
155 165 if(APBTIMERBASEADD == (unsigned int)-1)
156 166 return false;
157 167 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
158 168 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
159 169 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
160 170 return true;
161 171 }
162 172
163 173 bool dsu3plugin::cacheDisable()
164 174 {
165 175 return setCacheEnable(false);
166 176 }
167 177
168 178 bool dsu3plugin::cacheEnable()
169 179 {
170 180 return setCacheEnable(true);
171 181 }
172 182
173 183 bool dsu3plugin::setCacheEnable(bool enabled)
174 184 {
175 185 if(parent==NULL)
176 186 return false;
177 187 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
178 188 if(DSUBASEADDRESS == (unsigned int)-1)
179 189 DSUBASEADDRESS = 0x90000000;
180 190 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
181 191 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
182 192 if(enabled)
183 193 {
184 194 WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000);
185 195 //flushes cache.
186 196 WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000);
187 197 }
188 198 else
189 199 {
190 200 WriteRegs(uIntlist()<<((!0x0001000F)&reg),DSUBASEADDRESS+0x700000);
191 201 WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000);
192 202 }
193 203 return true;
194 204 }
195 205
196 206 bool dsu3plugin::flashTarget()
197 207 {
198 208 stop();
199 209 cacheDisable();
200 210 configureTarget();
201 211 /*Write .text*/
202 212 this->writeSection(".text");
203 213 /*Write .data*/
204 214 this->writeSection(".data");
205 215 return true;
206 216 }
207 217
208 218 void dsu3plugin::run()
209 219 {
210 220 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
211 221 if(DSUBASEADDRESS == (unsigned int)-1)
212 222 DSUBASEADDRESS = 0x90000000;
213 223 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
214 224 this->running = true;
215 225 this->UI->setRunning(true);
216 226 }
217 227
218 228 void dsu3plugin::stop()
219 229 {
220 230 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
221 231 if(DSUBASEADDRESS == (unsigned int)-1)
222 232 DSUBASEADDRESS = 0x90000000;
223 233 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
224 234 this->running = false;
225 235 this->UI->setRunning(false);
226 236 }
227 237
228 238 void dsu3plugin::toggleRun()
229 239 {
230 240 if(this->running)
231 241 this->stop();
232 242 else
233 243 this->run();
234 244 }
235 245
236 246 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
237 247 {
238 248 unsigned int* buff;
239 249 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
240 250 for(int i=0;i<Values.count();i++)
241 251 {
242 252 buff[i]=Values.at(i);
243 253 }
244 254 parent->Write(buff,(unsigned int)Values.count(),address);
245 255 free(buff);
246 256 }
247 257
248 258 unsigned int dsu3plugin::ReadReg(unsigned int address)
249 259 {
250 260 unsigned int buff;
251 261 parent->Read(&buff,1,address);
252 262 return buff;
253 263 }
254 264
255 265 void dsu3plugin::writeSection(int index)
256 266 {
257 267 char* buffch=NULL;
258 268 unsigned int* buff;
259 269 int size = this->elfparserInst->getSectionDatasz(index);
260 270 int sizeInt = size/4;
261 271 if(parent==NULL)
262 272 return;
263 273 this->elfparserInst->getSectionData(index,&buffch);
264 274 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
265 275 for(int i=0;i<sizeInt;i++)
266 276 {
267 277 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
268 278 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
269 279 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
270 280 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
271 281 }
272 282 if(size%4)
273 283 {
274 284 buff[sizeInt]=0;
275 285 for(int i=(size%4);i>0;i--)
276 286 {
277 287 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
278 288 }
279 289 sizeInt++;
280 290 }
281 291 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
282 292 free(buff);
283 293 }
284 294
285 295 void dsu3plugin::writeSection(const QString &name)
286 296 {
287 297 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
288 298 {
289 299 if(!this->elfparserInst->getSectionName(i).compare(name))
290 300 {
291 301 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
292 302 writeSection(i);
293 303 }
294 304 }
295 305 }
296 306
297 307
298 308 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
299 309 {
300 310 if(parent!=NULL)
301 311 return parent->Write(Value,count,address);
302 312 return 0;
303 313 }
304 314
305 315 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
306 316 {
307 317 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
308 318 if(buffer!=NULL)
309 319 {
310 320 memset((void*)buffer,value,count*sizeof(unsigned int));
311 321 parent->Write(buffer,count,address);
312 322 free(buffer );
313 323 return true;
314 324 }
315 325 return false;
316 326 }
317 327
318 328 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
319 329 {
320 330 if(parent!=NULL)
321 331 return parent->Read(Value,count,address);
322 332 return 0;
323 333 }
General Comments 0
You need to be logged in to leave comments. Login now