##// END OF EJS Templates
Now plugins show their instance name in the dock widget tab.
jeandet -
r6:3120bace1c2e default
parent child
Show More
@@ -1,199 +1,198
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) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - 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 "APBUARTPLUGIN.h"
22 #include "APBUARTPLUGIN.h"
23 #include <socexplorerengine.h>
23 #include <socexplorerengine.h>
24
24
25
25
26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
27 {
27 {
28 this->UI = new ApbUartPluginUi();
28 this->UI = new ApbUartPluginUi();
29 this->setWindowTitle(tr("APBUART"));
30 this->setWidget((QWidget*)this->UI);
29 this->setWidget((QWidget*)this->UI);
31 this->useLoopBack = false;
30 this->useLoopBack = false;
32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
31 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
32 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
34 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
33 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
35 }
34 }
36
35
37
36
38 ApbUartPlugin::~ApbUartPlugin()
37 ApbUartPlugin::~ApbUartPlugin()
39 {
38 {
40
39
41 }
40 }
42
41
43 void ApbUartPlugin::closeMe()
42 void ApbUartPlugin::closeMe()
44 {
43 {
45 emit this->closePlugin(this);
44 emit this->closePlugin(this);
46 }
45 }
47
46
48 void ApbUartPlugin::postInstantiationTrigger()
47 void ApbUartPlugin::postInstantiationTrigger()
49 {
48 {
50 if(this->isEnabled())
49 if(this->isEnabled())
51 {
50 {
52 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
51 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
53 loopbackChangeState(Qt::Checked);
52 loopbackChangeState(Qt::Checked);
54 }
53 }
55 }
54 }
56
55
57 void ApbUartPlugin::loopbackChangeState(int state)
56 void ApbUartPlugin::loopbackChangeState(int state)
58 {
57 {
59 if(state==Qt::Checked)
58 if(state==Qt::Checked)
60 {
59 {
61 enableLoopback();
60 enableLoopback();
62 }
61 }
63 else
62 else
64 {
63 {
65 disableLoopback();
64 disableLoopback();
66 }
65 }
67 }
66 }
68
67
69 void ApbUartPlugin::uartReadout()
68 void ApbUartPlugin::uartReadout()
70 {
69 {
71 #ifdef WIN32
70 #ifdef WIN32
72 int readcnt=0;
71 int readcnt=0;
73 #endif
72 #endif
74 if(this->isEnabled() && parent!=NULL)
73 if(this->isEnabled() && parent!=NULL)
75 {
74 {
76 if(this->useLoopBack)
75 if(this->useLoopBack)
77 {
76 {
78 if(this->baseAddress()!=-1)
77 if(this->baseAddress()!=-1)
79 {
78 {
80 this->loopBackTimer.stop();
79 this->loopBackTimer.stop();
81 unsigned int status_reg,data;
80 unsigned int status_reg,data;
82 char ch;
81 char ch;
83 QString printdata="";
82 QString printdata="";
84 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
83 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
85 while ((status_reg&4)==0) {
84 while ((status_reg&4)==0) {
86 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
85 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
87 ch = (char)(0xff & data);
86 ch = (char)(0xff & data);
88 printdata+=ch;
87 printdata+=ch;
89 #ifdef WIN32
88 #ifdef WIN32
90 readcnt++;
89 readcnt++;
91 if(readcnt>=32)
90 if(readcnt>=32)
92 {
91 {
93 qApp->processEvents();
92 qApp->processEvents();
94 break;
93 break;
95 }
94 }
96 #endif
95 #endif
97 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
96 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
98 }
97 }
99 if(printdata!="")
98 if(printdata!="")
100 emit apbUartTextReceived(printdata);
99 emit apbUartTextReceived(printdata);
101 this->loopBackTimer.start(200);
100 this->loopBackTimer.start(200);
102 }
101 }
103 else
102 else
104 {
103 {
105 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
104 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
106 this->enableLoopback();
105 this->enableLoopback();
107 }
106 }
108 }
107 }
109 }
108 }
110 }
109 }
111
110
112 void ApbUartPlugin::activate(bool flag)
111 void ApbUartPlugin::activate(bool flag)
113 {
112 {
114 this->setEnabled(flag);
113 this->setEnabled(flag);
115 emit this->activateSig(flag);
114 emit this->activateSig(flag);
116 if(this->isEnabled())
115 if(this->isEnabled())
117 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
116 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
118
117
119 loopbackChangeState(Qt::Checked);
118 loopbackChangeState(Qt::Checked);
120 }
119 }
121 }
120 }
122
121
123 void ApbUartPlugin::activateScan(bool flag)
122 void ApbUartPlugin::activateScan(bool flag)
124 {
123 {
125 if(flag)
124 if(flag)
126 this->loopBackTimer.start(200);
125 this->loopBackTimer.start(200);
127 else
126 else
128 this->loopBackTimer.stop();
127 this->loopBackTimer.stop();
129 }
128 }
130
129
131 int ApbUartPlugin::enableLoopback()
130 int ApbUartPlugin::enableLoopback()
132 {
131 {
133
132
134 this->useLoopBack = true;
133 this->useLoopBack = true;
135 this->loopBackTimer.start(200);
134 this->loopBackTimer.start(200);
136 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
135 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
137 if(parent==NULL)
136 if(parent==NULL)
138 {
137 {
139 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
138 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
140 return -1;
139 return -1;
141 }
140 }
142 if(this->baseAddress()==-1)
141 if(this->baseAddress()==-1)
143 {
142 {
144 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
143 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
145 if(this->baseAddress()==-1)
144 if(this->baseAddress()==-1)
146 return -1;
145 return -1;
147 }
146 }
148 unsigned int ctrl_reg= 0x843;
147 unsigned int ctrl_reg= 0x843;
149 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
148 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
150 return 0;
149 return 0;
151 }
150 }
152
151
153 int ApbUartPlugin::disableLoopback()
152 int ApbUartPlugin::disableLoopback()
154 {
153 {
155 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
154 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
156 if(parent==NULL)
155 if(parent==NULL)
157 {
156 {
158 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
157 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
159 return -1;
158 return -1;
160 }
159 }
161 if(this->baseAddress()==-1)
160 if(this->baseAddress()==-1)
162 {
161 {
163 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
162 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
164 if(this->baseAddress()==-1)
163 if(this->baseAddress()==-1)
165 return -1;
164 return -1;
166 }
165 }
167 unsigned int ctrl_reg;
166 unsigned int ctrl_reg;
168 this->loopBackTimer.stop();
167 this->loopBackTimer.stop();
169 /* Firts get Control reg value*/
168 /* Firts get Control reg value*/
170 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
169 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
171 ctrl_reg = ctrl_reg & (~(1<<11));
170 ctrl_reg = ctrl_reg & (~(1<<11));
172 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
171 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
173 this->useLoopBack = false;
172 this->useLoopBack = false;
174 return 0;
173 return 0;
175 }
174 }
176
175
177
176
178 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
177 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
179 {
178 {
180 if(parent!=NULL)
179 if(parent!=NULL)
181 return parent->Read(Value,count,address);
180 return parent->Read(Value,count,address);
182 return 0;
181 return 0;
183 }
182 }
184
183
185
184
186 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
185 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
187 {
186 {
188 if(parent!=NULL)
187 if(parent!=NULL)
189 return parent->Write(Value,count,address);
188 return parent->Write(Value,count,address);
190 return 0;
189 return 0;
191 }
190 }
192
191
193
192
194
193
195
194
196
195
197
196
198
197
199
198
@@ -1,468 +1,467
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 this->setWindowTitle(tr("AHB UART"));
43 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
42 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
44 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)));
45 this->pyObject = new ahbuartPywrapper(this);
44 this->pyObject = new ahbuartPywrapper(this);
46 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)));
47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
48 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)));
49 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>)));
50 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
49 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
51 this->portListcompleter = NULL;
50 this->portListcompleter = NULL;
52 this->scanDone = false;
51 this->scanDone = false;
53 updatePortList();
52 updatePortList();
54 }
53 }
55
54
56
55
57 ahbuartplugin::~ahbuartplugin()
56 ahbuartplugin::~ahbuartplugin()
58 {
57 {
59 if(this->port!=(rs232port_t)NULL)
58 if(this->port!=(rs232port_t)NULL)
60 {
59 {
61 rs232close(this->port);
60 rs232close(this->port);
62 this->port = (rs232port_t)NULL;
61 this->port = (rs232port_t)NULL;
63 }
62 }
64 this->UI->close();
63 this->UI->close();
65 this->UI->~ahbUartPluginUI();
64 this->UI->~ahbUartPluginUI();
66 }
65 }
67
66
68
67
69 void ahbuartplugin::closeMe()
68 void ahbuartplugin::closeMe()
70 {
69 {
71 if(this->port!=(rs232port_t)NULL)
70 if(this->port!=(rs232port_t)NULL)
72 {
71 {
73 rs232close(this->port);
72 rs232close(this->port);
74 this->port = (rs232port_t)NULL;
73 this->port = (rs232port_t)NULL;
75 }
74 }
76 emit this->closePlugin(this);
75 emit this->closePlugin(this);
77 }
76 }
78
77
79 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
78 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
80 {
79 {
81 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
80 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
82 this->closeAction = this->menu->addAction(tr("Close plugin"));
81 this->closeAction = this->menu->addAction(tr("Close plugin"));
83 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
82 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
84 return 1;
83 return 1;
85 }
84 }
86
85
87
86
88
87
89
88
90 bool ahbuartplugin::checkConnection()
89 bool ahbuartplugin::checkConnection()
91 {
90 {
92 QTime timeout;
91 QTime timeout;
93 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};
94 char test2[1024];
93 char test2[1024];
95 int writen =0;
94 int writen =0;
96 int read = 0;
95 int read = 0;
97 timeout.start();
96 timeout.start();
98 SocExplorerEngine::message(this,"Check connection",2);
97 SocExplorerEngine::message(this,"Check connection",2);
99 while(writen!=5)
98 while(writen!=5)
100 {
99 {
101 writen+=rs232write(this->port,test+writen,5-writen);
100 writen+=rs232write(this->port,test+writen,5-writen);
102 if(timeout.elapsed()>1000)
101 if(timeout.elapsed()>1000)
103 {
102 {
104 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
103 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
105 return false;
104 return false;
106 }
105 }
107 }
106 }
108 #ifdef WIN32
107 #ifdef WIN32
109 usleep(1000);
108 usleep(1000);
110 #endif
109 #endif
111 timeout.restart();
110 timeout.restart();
112 while(read!=4)
111 while(read!=4)
113 {
112 {
114 read += rs232read(this->port,test2,4-read);
113 read += rs232read(this->port,test2,4-read);
115 if(timeout.elapsed()>1000) break;
114 if(timeout.elapsed()>1000) break;
116 }
115 }
117 if(read>0)
116 if(read>0)
118 {
117 {
119 SocExplorerEngine::message(this,"Connection Ok",2);
118 SocExplorerEngine::message(this,"Connection Ok",2);
120 return true;
119 return true;
121 }
120 }
122 else
121 else
123 {
122 {
124 SocExplorerEngine::message(this,"Connection Error",2);
123 SocExplorerEngine::message(this,"Connection Error",2);
125 return false;
124 return false;
126 }
125 }
127
126
128 }
127 }
129
128
130 void ahbuartplugin::connectPort(QString PortName, int baudrate)
129 void ahbuartplugin::connectPort(QString PortName, int baudrate)
131 {
130 {
132 QTime timeout;
131 QTime timeout;
133 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
132 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
134 timeout.start();
133 timeout.start();
135 if(this->port==(rs232port_t)NULL)
134 if(this->port==(rs232port_t)NULL)
136 {
135 {
137 SocExplorerEngine::message(this,"Open port "+PortName,2);
136 SocExplorerEngine::message(this,"Open port "+PortName,2);
138 this->port=rs232open((char*)PortName.toStdString().c_str());
137 this->port=rs232open((char*)PortName.toStdString().c_str());
139 }
138 }
140 if(this->port!=badPortValue)
139 if(this->port!=badPortValue)
141 {
140 {
142 SocExplorerEngine::message(this,"Port opened "+PortName,2);
141 SocExplorerEngine::message(this,"Port opened "+PortName,2);
143 SocExplorerEngine::message(this,"Configure port "+PortName,2);
142 SocExplorerEngine::message(this,"Configure port "+PortName,2);
144 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
143 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
145 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
144 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
146 char test2[1024];
145 char test2[1024];
147 SAFEWRITE(test,1,timeout,2000,return);
146 SAFEWRITE(test,1,timeout,2000,return);
148 SAFEWRITE((test+1),1,timeout,2000,return);
147 SAFEWRITE((test+1),1,timeout,2000,return);
149 APPENDTOLOG(QString("Flush port "));
148 APPENDTOLOG(QString("Flush port "));
150 rs232read(this->port,test2,512);
149 rs232read(this->port,test2,512);
151 int read = 0;
150 int read = 0;
152 for(int i=0;i<10;i++)
151 for(int i=0;i<10;i++)
153 {
152 {
154 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
153 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
155 SAFEWRITE(test+2,5,timeout,2000,return);
154 SAFEWRITE(test+2,5,timeout,2000,return);
156 SocExplorerEngine::message(this,"Read Result",2);
155 SocExplorerEngine::message(this,"Read Result",2);
157 read=rs232read(this->port,test2+read,16);
156 read=rs232read(this->port,test2+read,16);
158 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
157 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
159 if(read>0)
158 if(read>0)
160 {
159 {
161 SocExplorerEngine::message(this,"Flush port ",2);
160 SocExplorerEngine::message(this,"Flush port ",2);
162 while(rs232read(this->port,test2,1)>0);
161 while(rs232read(this->port,test2,1)>0);
163 this->Connected = true;
162 this->Connected = true;
164 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
163 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
165 emit this->activate(true);
164 emit this->activate(true);
166 if(this->scanDone==false)
165 if(this->scanDone==false)
167 {
166 {
168 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
167 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
169 this->scanDone=true;
168 this->scanDone=true;
170 }
169 }
171 break;
170 break;
172 }
171 }
173 }
172 }
174 }
173 }
175 else
174 else
176 {
175 {
177 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
176 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
178 this->port = (rs232port_t)NULL;
177 this->port = (rs232port_t)NULL;
179 this->Connected = false;
178 this->Connected = false;
180 emit this->activateSig(false);
179 emit this->activateSig(false);
181 return;
180 return;
182 }
181 }
183 if(this->Connected == false)
182 if(this->Connected == false)
184 {
183 {
185 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
184 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
186 rs232close(this->port);
185 rs232close(this->port);
187 this->port = (rs232port_t)NULL;
186 this->port = (rs232port_t)NULL;
188 emit this->activateSig(false);
187 emit this->activateSig(false);
189 }
188 }
190
189
191 }
190 }
192
191
193 bool ahbuartplugin::open(QString PortName,int baudrate)
192 bool ahbuartplugin::open(QString PortName,int baudrate)
194 {
193 {
195 if(this->port!=(rs232port_t)NULL)
194 if(this->port!=(rs232port_t)NULL)
196 this->close();
195 this->close();
197 this->UI->setconfig(PortName,baudrate);
196 this->UI->setconfig(PortName,baudrate);
198 this->connectPort(PortName,baudrate);
197 this->connectPort(PortName,baudrate);
199 return (this->port!=(rs232port_t)NULL);
198 return (this->port!=(rs232port_t)NULL);
200 }
199 }
201
200
202 void ahbuartplugin::close()
201 void ahbuartplugin::close()
203 {
202 {
204 if(this->port!=(rs232port_t)NULL)
203 if(this->port!=(rs232port_t)NULL)
205 {
204 {
206 rs232close(this->port);
205 rs232close(this->port);
207 this->port = (rs232port_t)NULL;
206 this->port = (rs232port_t)NULL;
208 this->Connected = false;
207 this->Connected = false;
209 emit this->activateSig(false);
208 emit this->activateSig(false);
210 }
209 }
211 }
210 }
212
211
213 void ahbuartplugin::togglePort(QString PortName,int baudrate)
212 void ahbuartplugin::togglePort(QString PortName,int baudrate)
214 {
213 {
215 if(this->port!=(rs232port_t)NULL)
214 if(this->port!=(rs232port_t)NULL)
216 {
215 {
217 this->close();
216 this->close();
218 }
217 }
219 else
218 else
220 {
219 {
221 this->connectPort(PortName,baudrate);
220 this->connectPort(PortName,baudrate);
222 }
221 }
223 }
222 }
224
223
225
224
226 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
225 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
227 {
226 {
228 QTime timeout;
227 QTime timeout;
229 timeout.start();
228 timeout.start();
230 unsigned int read=0;
229 unsigned int read=0;
231 unsigned int cnt=count;
230 unsigned int cnt=count;
232 unsigned int nextUpdateTrig=0,updateStep=512;
231 unsigned int nextUpdateTrig=0,updateStep=512;
233 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
232 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
234 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
233 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
235 {
234 {
236 if(!this->portMutex->tryLock())
235 if(!this->portMutex->tryLock())
237 return 0;
236 return 0;
238 if(!this->checkConnection())
237 if(!this->checkConnection())
239 {
238 {
240 this->Connected = false;
239 this->Connected = false;
241 emit this->activateSig(false);
240 emit this->activateSig(false);
242 this->portMutex->unlock();
241 this->portMutex->unlock();
243 return 0;
242 return 0;
244 }
243 }
245 QProgressBar* progress=NULL;
244 QProgressBar* progress=NULL;
246 if(cnt>128)
245 if(cnt>128)
247 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
246 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
248 char CMD[5];
247 char CMD[5];
249 char* result = (char*)malloc(count*4);
248 char* result = (char*)malloc(count*4);
250 while(count>32)
249 while(count>32)
251 {
250 {
252 CMD[0] = 0x80 | (32-1);
251 CMD[0] = 0x80 | (32-1);
253 CMD[1] = (char)((address>>24)&0xFF);
252 CMD[1] = (char)((address>>24)&0xFF);
254 CMD[2] = (char)((address>>16)&0xFF);
253 CMD[2] = (char)((address>>16)&0xFF);
255 CMD[3] = (char)((address>>8)&0xFF);
254 CMD[3] = (char)((address>>8)&0xFF);
256 CMD[4] = (char)((address)&0xFF);
255 CMD[4] = (char)((address)&0xFF);
257 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
256 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
258 SAFEWRITE(CMD,5,timeout,1000,return 0);
257 SAFEWRITE(CMD,5,timeout,1000,return 0);
259 #ifdef WIN32
258 #ifdef WIN32
260 usleep(1000);
259 usleep(1000);
261 #endif
260 #endif
262 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
261 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
263 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
262 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
264 count-=32;
263 count-=32;
265 address+=32*4;
264 address+=32*4;
266 if(cnt>128)
265 if(cnt>128)
267 {
266 {
268
267
269 if((cnt-count)>=nextUpdateTrig)
268 if((cnt-count)>=nextUpdateTrig)
270 {
269 {
271 progress->setValue(cnt-count);
270 progress->setValue(cnt-count);
272 qApp->processEvents();
271 qApp->processEvents();
273 nextUpdateTrig+=updateStep;
272 nextUpdateTrig+=updateStep;
274 }
273 }
275 }
274 }
276 }
275 }
277 if(count>0)
276 if(count>0)
278 {
277 {
279 CMD[0] = 0x80 | (count-1);
278 CMD[0] = 0x80 | (count-1);
280 CMD[1] = (char)((address>>24)&0xFF);
279 CMD[1] = (char)((address>>24)&0xFF);
281 CMD[2] = (char)((address>>16)&0xFF);
280 CMD[2] = (char)((address>>16)&0xFF);
282 CMD[3] = (char)((address>>8)&0xFF);
281 CMD[3] = (char)((address>>8)&0xFF);
283 CMD[4] = (char)((address)&0xFF);
282 CMD[4] = (char)((address)&0xFF);
284 SAFEWRITE(CMD,5,timeout,1000,return 0);
283 SAFEWRITE(CMD,5,timeout,1000,return 0);
285 #ifdef WIN32
284 #ifdef WIN32
286 usleep(1000);
285 usleep(1000);
287 #endif
286 #endif
288 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
287 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
289 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
288 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
290 }
289 }
291 if(cnt>128)
290 if(cnt>128)
292 {
291 {
293 progress->setValue(cnt-count);
292 progress->setValue(cnt-count);
294 qApp->processEvents();
293 qApp->processEvents();
295 }
294 }
296 for(int i=0;(unsigned int)i<cnt;i++)
295 for(int i=0;(unsigned int)i<cnt;i++)
297 {
296 {
298 for(int j =0;j<4;j++)
297 for(int j =0;j<4;j++)
299 {
298 {
300 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
299 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
301 }
300 }
302 read = cnt*4;
301 read = cnt*4;
303
302
304 }
303 }
305 if(cnt>128)
304 if(cnt>128)
306 SocExplorerEngine::deleteProgressBar(progress);
305 SocExplorerEngine::deleteProgressBar(progress);
307 free(result);
306 free(result);
308 this->portMutex->unlock();
307 this->portMutex->unlock();
309 }
308 }
310 return read/4;
309 return read/4;
311 }
310 }
312
311
313 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
312 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
314 {
313 {
315 QTime timeout;
314 QTime timeout;
316 timeout.start();
315 timeout.start();
317 unsigned int writen=0;
316 unsigned int writen=0;
318 unsigned int nextUpdateTrig=0,updateStep=512;
317 unsigned int nextUpdateTrig=0,updateStep=512;
319 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
318 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
320 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
319 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
321 {
320 {
322 if(!this->portMutex->tryLock())
321 if(!this->portMutex->tryLock())
323 return 0;
322 return 0;
324 if(!this->checkConnection())
323 if(!this->checkConnection())
325 {
324 {
326 emit this->activateSig(false);
325 emit this->activateSig(false);
327 this->Connected = false;
326 this->Connected = false;
328 this->portMutex->unlock();
327 this->portMutex->unlock();
329 return 0;
328 return 0;
330 }
329 }
331 QProgressBar* progress = NULL;
330 QProgressBar* progress = NULL;
332 if(count>128)
331 if(count>128)
333 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
332 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
334 int offset = 0;
333 int offset = 0;
335 char* CMD= (char*)malloc((32*4)+5);
334 char* CMD= (char*)malloc((32*4)+5);
336 while(count>32)
335 while(count>32)
337 {
336 {
338 writen=0;
337 writen=0;
339 CMD[0] = 0xC0 | (32-1);
338 CMD[0] = 0xC0 | (32-1);
340 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
339 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
341 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
340 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
342 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
341 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
343 CMD[4] = (char)(((unsigned int)address)&0xFF);
342 CMD[4] = (char)(((unsigned int)address)&0xFF);
344 for(int i=0;i<32;i++)
343 for(int i=0;i<32;i++)
345 {
344 {
346 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
345 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
347 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
346 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
348 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
347 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
349 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
348 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
350 }
349 }
351 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
350 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
352 writen+=32;
351 writen+=32;
353 count-=32;
352 count-=32;
354 offset+=32;
353 offset+=32;
355 address+=32*4;
354 address+=32*4;
356 if(offset>=nextUpdateTrig && progress!=NULL)
355 if(offset>=nextUpdateTrig && progress!=NULL)
357 {
356 {
358 progress->setValue(offset);
357 progress->setValue(offset);
359 qApp->processEvents();
358 qApp->processEvents();
360 nextUpdateTrig +=updateStep;
359 nextUpdateTrig +=updateStep;
361 }
360 }
362
361
363 }
362 }
364 if(count>0)
363 if(count>0)
365 {
364 {
366 CMD[0] = 0xC0 | (count-1);
365 CMD[0] = 0xC0 | (count-1);
367 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
366 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
368 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
367 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
369 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
368 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
370 CMD[4] = (char)(((unsigned int)address)&0xFF);
369 CMD[4] = (char)(((unsigned int)address)&0xFF);
371 for(int i=0;(unsigned int) i<(count);i++)
370 for(int i=0;(unsigned int) i<(count);i++)
372 {
371 {
373 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
372 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);
373 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);
374 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
376 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
375 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
377 }
376 }
378 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
377 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
379 writen+=count;
378 writen+=count;
380 }
379 }
381 if(progress!=NULL)
380 if(progress!=NULL)
382 {
381 {
383 progress->setValue(writen);
382 progress->setValue(writen);
384 qApp->processEvents();
383 qApp->processEvents();
385 SocExplorerEngine::deleteProgressBar(progress);
384 SocExplorerEngine::deleteProgressBar(progress);
386 }
385 }
387 free(CMD);
386 free(CMD);
388 this->portMutex->unlock();
387 this->portMutex->unlock();
389 return writen;
388 return writen;
390 }
389 }
391 return 0;
390 return 0;
392 }
391 }
393
392
394
393
395
394
396
395
397 void ahbuartplugin::updatePortList()
396 void ahbuartplugin::updatePortList()
398 {
397 {
399 if(this->portListcompleter==(QCompleter*)NULL)
398 if(this->portListcompleter==(QCompleter*)NULL)
400 {
399 {
401 this->portListcompleter=new QCompleter(this);
400 this->portListcompleter=new QCompleter(this);
402 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
401 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
403 this->portListcompleterModel = new QStringListModel(this);
402 this->portListcompleterModel = new QStringListModel(this);
404 this->portListcompleter->setModel(this->portListcompleterModel);
403 this->portListcompleter->setModel(this->portListcompleterModel);
405 this->UI->setCompleter(this->portListcompleter);
404 this->UI->setCompleter(this->portListcompleter);
406 }
405 }
407 rs232portslist_t* portlist = rs232getportlist();
406 rs232portslist_t* portlist = rs232getportlist();
408 rs232portslist_t* portlistenum = portlist;
407 rs232portslist_t* portlistenum = portlist;
409 QStringList wordList;
408 QStringList wordList;
410 while(portlistenum!=NULL)
409 while(portlistenum!=NULL)
411 {
410 {
412 wordList << portlistenum->name;
411 wordList << portlistenum->name;
413 portlistenum = portlistenum->next;
412 portlistenum = portlistenum->next;
414 }
413 }
415 rs232deleteportlist(portlist);
414 rs232deleteportlist(portlist);
416 this->portListcompleterModel->setStringList(wordList);
415 this->portListcompleterModel->setStringList(wordList);
417 }
416 }
418
417
419 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
418 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
420 {
419 {
421 unsigned int data[(count/4)+1];
420 unsigned int data[(count/4)+1];
422 QVariantList result;
421 QVariantList result;
423 this->Read(data,(count/4)+1,address);
422 this->Read(data,(count/4)+1,address);
424 for(unsigned int i = 0;i<count/4;i++)
423 for(unsigned int i = 0;i<count/4;i++)
425 {
424 {
426 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
425 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
427 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
426 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
428 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
427 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
429 result.append(QVariant((int)(0x0FF&(data[i]))));
428 result.append(QVariant((int)(0x0FF&(data[i]))));
430 }
429 }
431
430
432 for(int i=0;i<(count%4);i++)
431 for(int i=0;i<(count%4);i++)
433 {
432 {
434 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
433 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
435 }
434 }
436
435
437 return result;
436 return result;
438 }
437 }
439
438
440 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
439 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
441 {
440 {
442 unsigned int data[dataList.count()/4];
441 unsigned int data[dataList.count()/4];
443 for(int i = 0;i<(dataList.count()/4);i++)
442 for(int i = 0;i<(dataList.count()/4);i++)
444 {
443 {
445 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
444 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
446 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
445 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
447 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
446 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
448 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
447 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
449 }
448 }
450 this->Write(data,dataList.count()/4,address);
449 this->Write(data,dataList.count()/4,address);
451 }
450 }
452
451
453
452
454
453
455
454
456
455
457
456
458
457
459
458
460
459
461
460
462
461
463
462
464
463
465
464
466
465
467
466
468
467
@@ -1,93 +1,92
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) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - 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 "ambaplugin.h"
22 #include "ambaplugin.h"
23
23
24
24
25 ambaplugin::ambaplugin(QWidget *parent):socexplorerplugin(parent,true)
25 ambaplugin::ambaplugin(QWidget *parent):socexplorerplugin(parent,true)
26 {
26 {
27 this->UI = new ambaPluginUI(this);
27 this->UI = new ambaPluginUI(this);
28 this->setWindowTitle(tr("AMBA Driver"));
29 this->setWidget((QWidget*)this->UI);
28 this->setWidget((QWidget*)this->UI);
30 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
29 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
31 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
30 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
32 connect(this,SIGNAL(activateSig(bool)),this,SLOT(activatePlugin(bool)));
31 connect(this,SIGNAL(activateSig(bool)),this,SLOT(activatePlugin(bool)));
33 }
32 }
34
33
35
34
36 ambaplugin::~ambaplugin()
35 ambaplugin::~ambaplugin()
37 {
36 {
38
37
39 }
38 }
40
39
41
40
42 void ambaplugin::closeMe()
41 void ambaplugin::closeMe()
43 {
42 {
44 emit this->closePlugin(this);
43 emit this->closePlugin(this);
45 }
44 }
46
45
47 void ambaplugin::postInstantiationTrigger()
46 void ambaplugin::postInstantiationTrigger()
48 {
47 {
49 if(this->parent->isConnected())
48 if(this->parent->isConnected())
50 {
49 {
51 this->UI->scanAll();
50 this->UI->scanAll();
52 }
51 }
53 }
52 }
54
53
55 void ambaplugin::activatePlugin(bool flag)
54 void ambaplugin::activatePlugin(bool flag)
56 {
55 {
57 if(flag)
56 if(flag)
58 {
57 {
59 this->UI->scanAll();
58 this->UI->scanAll();
60 }
59 }
61 }
60 }
62
61
63 int ambaplugin::registermenu(QMainWindow *menuHolder)
62 int ambaplugin::registermenu(QMainWindow *menuHolder)
64 {
63 {
65 this->menu = menuHolder->menuBar()->addMenu(tr("&ambaplugin"));
64 this->menu = menuHolder->menuBar()->addMenu(tr("&ambaplugin"));
66 this->closeAction = this->menu->addAction(tr("Close plugin"));
65 this->closeAction = this->menu->addAction(tr("Close plugin"));
67 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
66 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
68 return 1;
67 return 1;
69 }
68 }
70
69
71
70
72
71
73 unsigned int ambaplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
72 unsigned int ambaplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
74 {
73 {
75 if(parent!=NULL)
74 if(parent!=NULL)
76 return parent->Read(Value,count,address);
75 return parent->Read(Value,count,address);
77 return 0;
76 return 0;
78 }
77 }
79
78
80 unsigned int ambaplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
79 unsigned int ambaplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
81 {
80 {
82 if(parent!=NULL)
81 if(parent!=NULL)
83 return parent->Write(Value,count,address);
82 return parent->Write(Value,count,address);
84 return 0;
83 return 0;
85 }
84 }
86
85
87
86
88
87
89
88
90
89
91
90
92
91
93
92
@@ -1,226 +1,225
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "dsu3plugin.h"
22 #include "dsu3plugin.h"
23 #include <QFileDialog>
23 #include <QFileDialog>
24 #include <QDir>
24 #include <QDir>
25 #include "dsu3pluginpywrapper.h"
25 #include "dsu3pluginpywrapper.h"
26 #include <socexplorerengine.h>
26 #include <socexplorerengine.h>
27
27
28 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
28 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
29 {
29 {
30 this->UI = new dsu3pluginui();
30 this->UI = new dsu3pluginui();
31 this->setWindowTitle(tr("DSU3 Driver"));
32 this->setWidget((QWidget*)this->UI);
31 this->setWidget((QWidget*)this->UI);
33 this->elfparserInst = new elfparser();
32 this->elfparserInst = new elfparser();
34 this->pyObject = new dsu3pluginPywrapper(this);
33 this->pyObject = new dsu3pluginPywrapper(this);
35 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
34 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
36 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
35 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
37 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
36 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
38 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
37 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
39 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
38 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
40 connect(this->UI,SIGNAL(run()),this,SLOT(run()));
39 connect(this->UI,SIGNAL(run()),this,SLOT(run()));
41 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
40 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
42 }
41 }
43
42
44
43
45 dsu3plugin::~dsu3plugin()
44 dsu3plugin::~dsu3plugin()
46 {
45 {
47
46
48 }
47 }
49
48
50
49
51 void dsu3plugin::openFile()
50 void dsu3plugin::openFile()
52 {
51 {
53 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
52 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
54 if(filename!="")
53 if(filename!="")
55 {
54 {
56 this->openFile(filename);
55 this->openFile(filename);
57 }
56 }
58 }
57 }
59
58
60 void dsu3plugin::openFile(QString fileName)
59 void dsu3plugin::openFile(QString fileName)
61 {
60 {
62 this->elfparserInst->setFilename(fileName);
61 this->elfparserInst->setFilename(fileName);
63 emit this->updateInfo(this->elfparserInst);
62 emit this->updateInfo(this->elfparserInst);
64 }
63 }
65
64
66 bool dsu3plugin::configureTarget()
65 bool dsu3plugin::configureTarget()
67 {
66 {
68 if(parent==NULL)
67 if(parent==NULL)
69 return false;
68 return false;
70 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
69 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
71 if(DSUBASEADDRESS == (unsigned int)-1)
70 if(DSUBASEADDRESS == (unsigned int)-1)
72 DSUBASEADDRESS = 0x90000000;
71 DSUBASEADDRESS = 0x90000000;
73 unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0);
72 unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0);
74 if(MCTRLBASEADDRESS == (unsigned int)-1)
73 if(MCTRLBASEADDRESS == (unsigned int)-1)
75 return false;
74 return false;
76
75
77 //Force a debug break
76 //Force a debug break
78 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
77 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
79 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
78 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
80 //Clear time tag counter
79 //Clear time tag counter
81 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
80 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
82
81
83 //Clear ASR registers
82 //Clear ASR registers
84 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
83 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
85 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
84 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
86 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
85 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
87 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
86 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
88 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
87 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
89 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
88 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
90
89
91
90
92
91
93 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
92 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
94
93
95
94
96 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
95 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
97 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
96 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
98
97
99 unsigned int buff=0;
98 unsigned int buff=0;
100 // for(int i=0;i<1567;i++)
99 // for(int i=0;i<1567;i++)
101 // {
100 // {
102 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
101 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
103 // }
102 // }
104 memSet(DSUBASEADDRESS+0x300000,0,1567);
103 memSet(DSUBASEADDRESS+0x300000,0,1567);
105 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
104 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
106 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);
105 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);
107 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
106 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
108
107
109 //Disable interrupts
108 //Disable interrupts
110 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
109 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
111 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
110 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
112 return false;
111 return false;
113 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
112 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
114 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
113 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
115 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
114 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
116
115
117 //Set up timer
116 //Set up timer
118 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
117 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
119 if(APBTIMERBASEADD == (unsigned int)-1)
118 if(APBTIMERBASEADD == (unsigned int)-1)
120 return false;
119 return false;
121 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
120 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
122 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
121 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
123 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
122 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
124 return true;
123 return true;
125 }
124 }
126
125
127 bool dsu3plugin::flashTarget()
126 bool dsu3plugin::flashTarget()
128 {
127 {
129 configureTarget();
128 configureTarget();
130
129
131 /*Write .text*/
130 /*Write .text*/
132 this->writeSection(".text");
131 this->writeSection(".text");
133 /*Write .data*/
132 /*Write .data*/
134 this->writeSection(".data");
133 this->writeSection(".data");
135 return true;
134 return true;
136 }
135 }
137
136
138 void dsu3plugin::run()
137 void dsu3plugin::run()
139 {
138 {
140 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
139 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
141 if(DSUBASEADDRESS == (unsigned int)-1)
140 if(DSUBASEADDRESS == (unsigned int)-1)
142 DSUBASEADDRESS = 0x90000000;
141 DSUBASEADDRESS = 0x90000000;
143 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
142 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
144 }
143 }
145
144
146 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
145 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
147 {
146 {
148 unsigned int* buff;
147 unsigned int* buff;
149 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
148 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
150 for(int i=0;i<Values.count();i++)
149 for(int i=0;i<Values.count();i++)
151 {
150 {
152 buff[i]=Values.at(i);
151 buff[i]=Values.at(i);
153 }
152 }
154 parent->Write(buff,(unsigned int)Values.count(),address);
153 parent->Write(buff,(unsigned int)Values.count(),address);
155 free(buff);
154 free(buff);
156 }
155 }
157
156
158 void dsu3plugin::writeSection(int index)
157 void dsu3plugin::writeSection(int index)
159 {
158 {
160 char* buffch=NULL;
159 char* buffch=NULL;
161 unsigned int* buff;
160 unsigned int* buff;
162 int size = this->elfparserInst->getSectionDatasz(index);
161 int size = this->elfparserInst->getSectionDatasz(index);
163 int sizeInt = size/4;
162 int sizeInt = size/4;
164 if(parent==NULL)
163 if(parent==NULL)
165 return;
164 return;
166 this->elfparserInst->getSectionData(index,&buffch);
165 this->elfparserInst->getSectionData(index,&buffch);
167 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
166 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
168 for(int i=0;i<sizeInt;i++)
167 for(int i=0;i<sizeInt;i++)
169 {
168 {
170 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
169 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
171 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
170 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
172 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
171 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
173 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
172 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
174 }
173 }
175 if(size%4)
174 if(size%4)
176 {
175 {
177 buff[sizeInt]=0;
176 buff[sizeInt]=0;
178 for(int i=(size%4);i>0;i--)
177 for(int i=(size%4);i>0;i--)
179 {
178 {
180 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
179 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
181 }
180 }
182 sizeInt++;
181 sizeInt++;
183 }
182 }
184 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
183 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
185 free(buff);
184 free(buff);
186 }
185 }
187
186
188 void dsu3plugin::writeSection(const QString &name)
187 void dsu3plugin::writeSection(const QString &name)
189 {
188 {
190 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
189 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
191 {
190 {
192 if(!this->elfparserInst->getSectionName(i).compare(name))
191 if(!this->elfparserInst->getSectionName(i).compare(name))
193 {
192 {
194 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
193 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
195 writeSection(i);
194 writeSection(i);
196 }
195 }
197 }
196 }
198 }
197 }
199
198
200
199
201 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
200 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
202 {
201 {
203 if(parent!=NULL)
202 if(parent!=NULL)
204 return parent->Write(Value,count,address);
203 return parent->Write(Value,count,address);
205 return 0;
204 return 0;
206 }
205 }
207
206
208 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
207 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
209 {
208 {
210 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
209 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
211 if(buffer!=NULL)
210 if(buffer!=NULL)
212 {
211 {
213 memset((void*)buffer,value,count*sizeof(unsigned int));
212 memset((void*)buffer,value,count*sizeof(unsigned int));
214 parent->Write(buffer,count,address);
213 parent->Write(buffer,count,address);
215 free(buffer );
214 free(buffer );
216 return true;
215 return true;
217 }
216 }
218 return false;
217 return false;
219 }
218 }
220
219
221 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
220 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
222 {
221 {
223 if(parent!=NULL)
222 if(parent!=NULL)
224 return parent->Read(Value,count,address);
223 return parent->Read(Value,count,address);
225 return 0;
224 return 0;
226 }
225 }
@@ -1,62 +1,61
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 "genericrwplugin.h"
22 #include "genericrwplugin.h"
23 #include "genericrwpluginpywrapper.h"
23 #include "genericrwpluginpywrapper.h"
24 genericrwplugin::genericrwplugin(QWidget *parent):socexplorerplugin(parent,false)
24 genericrwplugin::genericrwplugin(QWidget *parent):socexplorerplugin(parent,false)
25 {
25 {
26 this->UI = new genericrwpluginUi();
26 this->UI = new genericrwpluginUi();
27 this->setWindowTitle(tr("Generic Driver"));
28 this->setWidget((QWidget*)this->UI);
27 this->setWidget((QWidget*)this->UI);
29 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
28 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
30 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
29 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
31 this->pyObject = new genericRWpluginPyWrapper(this);
30 this->pyObject = new genericRWpluginPyWrapper(this);
32 //QObject::connect(this->pyObject,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
31 //QObject::connect(this->pyObject,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
33 //QObject::connect(this->pyObject,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
32 //QObject::connect(this->pyObject,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
34 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(refresh()),this->UI,SIGNAL(refresh()));
33 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(refresh()),this->UI,SIGNAL(refresh()));
35 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setAddress(quint32)),this->UI,SIGNAL(setAddress(quint32)));
34 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setAddress(quint32)),this->UI,SIGNAL(setAddress(quint32)));
36 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setLength(quint32)),this->UI,SIGNAL(setLength(quint32)));
35 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setLength(quint32)),this->UI,SIGNAL(setLength(quint32)));
37 }
36 }
38
37
39 genericrwplugin::~genericrwplugin()
38 genericrwplugin::~genericrwplugin()
40 {}
39 {}
41
40
42 int genericrwplugin::registermenu(QMainWindow *menuHolder)
41 int genericrwplugin::registermenu(QMainWindow *menuHolder)
43 {
42 {
44 this->menu = menuHolder->menuBar()->addMenu(tr("&Generic RW Driver"));
43 this->menu = menuHolder->menuBar()->addMenu(tr("&Generic RW Driver"));
45 this->closeAction = this->menu->addAction(tr("Close plugin"));
44 this->closeAction = this->menu->addAction(tr("Close plugin"));
46 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
45 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
47 return 1;
46 return 1;
48 }
47 }
49
48
50 unsigned int genericrwplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
49 unsigned int genericrwplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
51 {
50 {
52 if(parent!=NULL)
51 if(parent!=NULL)
53 return parent->Write(Value,count,address);
52 return parent->Write(Value,count,address);
54 return 0;
53 return 0;
55 }
54 }
56
55
57 unsigned int genericrwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
56 unsigned int genericrwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
58 {
57 {
59 if(parent!=NULL)
58 if(parent!=NULL)
60 return parent->Read(Value,count,address);
59 return parent->Read(Value,count,address);
61 return 0;
60 return 0;
62 }
61 }
@@ -1,86 +1,85
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 "memctrlrplugin.h"
22 #include "memctrlrplugin.h"
23 #include "memctrlrpywrapper.h"
23 #include "memctrlrpywrapper.h"
24
24
25 memctrlrplugin::memctrlrplugin(QWidget *parent):socexplorerplugin(parent,false)
25 memctrlrplugin::memctrlrplugin(QWidget *parent):socexplorerplugin(parent,false)
26 {
26 {
27 this->UI = new memctrlrPluginUi();
27 this->UI = new memctrlrPluginUi();
28 this->setWindowTitle(tr("Memctrlr Driver"));
29 this->setWidget((QWidget*)this->UI);
28 this->setWidget((QWidget*)this->UI);
30 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
29 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
31 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
30 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
32 this->pyObject = new memctrlrPyWrapper(this);
31 this->pyObject = new memctrlrPyWrapper(this);
33 connect(this->pyObject,SIGNAL(launchTest(uint,uint)),this,SLOT(launchTest(uint,uint)));
32 connect(this->pyObject,SIGNAL(launchTest(uint,uint)),this,SLOT(launchTest(uint,uint)));
34 }
33 }
35
34
36 memctrlrplugin::~memctrlrplugin()
35 memctrlrplugin::~memctrlrplugin()
37 {}
36 {}
38
37
39 int memctrlrplugin::registermenu(QMainWindow *menuHolder)
38 int memctrlrplugin::registermenu(QMainWindow *menuHolder)
40 {
39 {
41 this->menu = menuHolder->menuBar()->addMenu(tr("&Memory Controler"));
40 this->menu = menuHolder->menuBar()->addMenu(tr("&Memory Controler"));
42 this->closeAction = this->menu->addAction(tr("Close plugin"));
41 this->closeAction = this->menu->addAction(tr("Close plugin"));
43 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
42 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
44 return 1;
43 return 1;
45 }
44 }
46
45
47 unsigned int memctrlrplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
46 unsigned int memctrlrplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
48 {
47 {
49 if(parent)
48 if(parent)
50 return parent->Write(Value,count,address);
49 return parent->Write(Value,count,address);
51 return 0;
50 return 0;
52 }
51 }
53
52
54 unsigned int memctrlrplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
53 unsigned int memctrlrplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
55 {
54 {
56 if(parent)
55 if(parent)
57 return parent->Read(Value,count,address);
56 return parent->Read(Value,count,address);
58 return 0;
57 return 0;
59 }
58 }
60
59
61
60
62 bool memctrlrplugin::launchTest(unsigned int baseAddress,unsigned int size)
61 bool memctrlrplugin::launchTest(unsigned int baseAddress,unsigned int size)
63 {
62 {
64 if(parent==NULL)return false;
63 if(parent==NULL)return false;
65 unsigned int* dataLocal = (unsigned int*)malloc(size);
64 unsigned int* dataLocal = (unsigned int*)malloc(size);
66 unsigned int* dataOnBoard = (unsigned int*)malloc(size);
65 unsigned int* dataOnBoard = (unsigned int*)malloc(size);
67 bool res=true;
66 bool res=true;
68 for(int i=0;(unsigned int)i<(size>>2);i++)
67 for(int i=0;(unsigned int)i<(size>>2);i++)
69 {
68 {
70 dataLocal[i]= (0xFFFF&rand())+(rand()<<16);
69 dataLocal[i]= (0xFFFF&rand())+(rand()<<16);
71 }
70 }
72 parent->Write(dataLocal,size>>2,baseAddress);
71 parent->Write(dataLocal,size>>2,baseAddress);
73 parent->Read(dataOnBoard,size>>2,baseAddress);
72 parent->Read(dataOnBoard,size>>2,baseAddress);
74 for(int i=0;(unsigned int)i<(size>>2);i++)
73 for(int i=0;(unsigned int)i<(size>>2);i++)
75 {
74 {
76 if(dataLocal[i]!=dataOnBoard[i])
75 if(dataLocal[i]!=dataOnBoard[i])
77 res=false;
76 res=false;
78 }
77 }
79
78
80 free(dataLocal);
79 free(dataLocal);
81 free(dataOnBoard);
80 free(dataOnBoard);
82 return res;
81 return res;
83 }
82 }
84
83
85
84
86
85
@@ -1,50 +1,50
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 MEMCTRLRPLUGIN_H
22 #ifndef MEMCTRLRPLUGIN_H
23 #define MEMCTRLRPLUGIN_H
23 #define MEMCTRLRPLUGIN_H
24 #include "memctrlrpluginui.h"
24 #include "memctrlrpluginui.h"
25 #include <QMenuBar>
25 #include <QMenuBar>
26 #include <QMenu>
26 #include <QMenu>
27 #include <QAction>
27 #include <QAction>
28 #include <QMainWindow>
28 #include <QMainWindow>
29
29 #include <socexplorerplugin.h>
30
30
31 #include <socexplorerplugin.h>
31 #include <socexplorerplugin.h>
32
32
33 class memctrlrplugin : public socexplorerplugin
33 class memctrlrplugin : public socexplorerplugin
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 public:
36 public:
37 explicit memctrlrplugin(QWidget *parent = 0);
37 explicit memctrlrplugin(QWidget *parent = 0);
38 ~memctrlrplugin();
38 ~memctrlrplugin();
39 int registermenu(QMainWindow *menuHolder);
39 int registermenu(QMainWindow *menuHolder);
40 public slots:
40 public slots:
41 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
41 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
42 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
42 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
43 bool launchTest(unsigned int baseAddress,unsigned int size);
43 bool launchTest(unsigned int baseAddress,unsigned int size);
44 signals:
44 signals:
45
45
46 private:
46 private:
47 memctrlrPluginUi* UI;
47 memctrlrPluginUi* UI;
48 };
48 };
49
49
50 #endif // MEMCTRLRPLUGIN_H
50 #endif // MEMCTRLRPLUGIN_H
@@ -1,45 +1,45
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -------------------------------------------------------------------------------*/
2 -------------------------------------------------------------------------------*/
3 /*-- Author : Alexis Jeandet
3 /*-- Author : Alexis Jeandet
4 -- Mail : alexis.jeandet@member.fsf.org
4 -- Mail : alexis.jeandet@member.fsf.org
5 ----------------------------------------------------------------------------*/
5 ----------------------------------------------------------------------------*/
6 #ifndef spwplugin_H
6 #ifndef spwplugin_H
7 #define spwplugin_H
7 #define spwplugin_H
8 #include <QMenuBar>
8 #include <QMenuBar>
9 #include <QMenu>
9 #include <QMenu>
10 #include <QAction>
10 #include <QAction>
11 #include <QLayout>
11 #include <QLayout>
12
12
13 #include <abstractspwbridge.h>
13 #include <socexplorerplugin.h>
14 #include <socexplorerplugin.h>
14 #include <abstractspwbridge.h>
15
15
16
16
17 class spwplugin : public socexplorerplugin
17 class spwplugin : public socexplorerplugin
18 {
18 {
19 Q_OBJECT
19 Q_OBJECT
20 public:
20 public:
21 explicit spwplugin(QWidget *parent = 0);
21 explicit spwplugin(QWidget *parent = 0);
22 ~spwplugin();
22 ~spwplugin();
23 /* You can implement the folowing function if you want to overwrite
23 /* You can implement the folowing function if you want to overwrite
24 * their default behavior
24 * their default behavior
25 */
25 */
26 /*
26 /*
27 int registermenu(QMainWindow *menuHolder);
27 int registermenu(QMainWindow *menuHolder);
28 int isConnected();
28 int isConnected();
29 int connect();
29 int connect();
30 int VID(){return driver_VID;}
30 int VID(){return driver_VID;}
31 int PID(){return driver_PID;}
31 int PID(){return driver_PID;}
32 */
32 */
33
33
34 public slots:
34 public slots:
35 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
35 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
36 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
36 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
37 signals:
37 signals:
38
38
39 private:
39 private:
40 abstractSpwBridge* bridge;
40 abstractSpwBridge* bridge;
41
41
42 };
42 };
43
43
44 #endif // spwplugin_H
44 #endif // spwplugin_H
45
45
General Comments 0
You need to be logged in to leave comments. Login now