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