##// END OF EJS Templates
Added disconnection auto-detection to the spacewire plugin.
Jeandet Alexis -
r11:27ed47eb6044 default
parent child
Show More
@@ -1,3 +1,7
1 1 syntax: glob
2 2 *.pro.user
3 3 *.o
4 moc_*
5 *.so*
6 ui_*.h
7 Makefile
@@ -1,198 +1,198
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "APBUARTPLUGIN.h"
23 23 #include <socexplorerengine.h>
24 24
25 25
26 26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
27 27 {
28 28 this->UI = new ApbUartPluginUi();
29 29 this->setWidget((QWidget*)this->UI);
30 30 this->useLoopBack = false;
31 31 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
32 32 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
33 33 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
34 34 }
35 35
36 36
37 37 ApbUartPlugin::~ApbUartPlugin()
38 38 {
39 39
40 40 }
41 41
42 42 void ApbUartPlugin::closeMe()
43 43 {
44 44 emit this->closePlugin(this);
45 45 }
46 46
47 47 void ApbUartPlugin::postInstantiationTrigger()
48 48 {
49 49 if(this->isEnabled())
50 50 {
51 51 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
52 52 loopbackChangeState(Qt::Checked);
53 53 }
54 54 }
55 55
56 56 void ApbUartPlugin::loopbackChangeState(int state)
57 57 {
58 58 if(state==Qt::Checked)
59 59 {
60 60 enableLoopback();
61 61 }
62 62 else
63 63 {
64 64 disableLoopback();
65 65 }
66 66 }
67 67
68 68 void ApbUartPlugin::uartReadout()
69 69 {
70 70 #ifdef WIN32
71 71 int readcnt=0;
72 72 #endif
73 73 if(this->isEnabled() && parent!=NULL)
74 74 {
75 75 if(this->useLoopBack)
76 76 {
77 77 if(this->baseAddress()!=-1)
78 78 {
79 79 this->loopBackTimer.stop();
80 80 unsigned int status_reg,data;
81 81 char ch;
82 82 QString printdata="";
83 83 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
84 84 while ((status_reg&4)==0) {
85 85 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
86 86 ch = (char)(0xff & data);
87 87 printdata+=ch;
88 88 #ifdef WIN32
89 89 readcnt++;
90 90 if(readcnt>=32)
91 91 {
92 92 qApp->processEvents();
93 93 break;
94 94 }
95 95 #endif
96 96 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
97 97 }
98 98 if(printdata!="")
99 99 emit apbUartTextReceived(printdata);
100 100 this->loopBackTimer.start(200);
101 101 }
102 102 else
103 103 {
104 104 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
105 105 this->enableLoopback();
106 106 }
107 107 }
108 108 }
109 109 }
110 110
111 111 void ApbUartPlugin::activate(bool flag)
112 112 {
113 113 this->setEnabled(flag);
114 114 emit this->activateSig(flag);
115 115 if(this->isEnabled())
116 116 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
117 117
118 118 loopbackChangeState(Qt::Checked);
119 119 }
120 120 }
121 121
122 122 void ApbUartPlugin::activateScan(bool flag)
123 123 {
124 124 if(flag)
125 125 this->loopBackTimer.start(200);
126 126 else
127 127 this->loopBackTimer.stop();
128 128 }
129 129
130 130 int ApbUartPlugin::enableLoopback()
131 131 {
132 132
133 133 this->useLoopBack = true;
134 134 this->loopBackTimer.start(200);
135 135 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
136 136 if(parent==NULL)
137 137 {
138 138 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
139 139 return -1;
140 140 }
141 141 if(this->baseAddress()==-1)
142 142 {
143 143 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
144 144 if(this->baseAddress()==-1)
145 145 return -1;
146 146 }
147 147 unsigned int ctrl_reg= 0x843;
148 148 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
149 149 return 0;
150 150 }
151 151
152 152 int ApbUartPlugin::disableLoopback()
153 153 {
154 154 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
155 155 if(parent==NULL)
156 156 {
157 157 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
158 158 return -1;
159 159 }
160 160 if(this->baseAddress()==-1)
161 161 {
162 162 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
163 163 if(this->baseAddress()==-1)
164 164 return -1;
165 165 }
166 166 unsigned int ctrl_reg;
167 167 this->loopBackTimer.stop();
168 168 /* Firts get Control reg value*/
169 169 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
170 170 ctrl_reg = ctrl_reg & (~(1<<11));
171 171 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
172 172 this->useLoopBack = false;
173 173 return 0;
174 174 }
175 175
176 176
177 177 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
178 178 {
179 179 if(parent!=NULL)
180 180 return parent->Read(Value,count,address);
181 181 return 0;
182 182 }
183 183
184 184
185 185 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
186 186 {
187 187 if(parent!=NULL)
188 188 return parent->Write(Value,count,address);
189 189 return 0;
190 190 }
191 191
192 192
193 193
194 194
195 195
196 196
197 197
198 198
@@ -1,69 +1,69
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTPLUGIN_H
23 23 #define APBUARTPLUGIN_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28
29 29 #include <socexplorerplugin.h>
30 30 #include <apbuartpluginui.h>
31 31 #include <QTimer>
32 32
33 33 #define APB_UART_DATA_REG 0x0
34 34 #define APB_UART_STATUS_REG 0x4
35 35 #define APB_UART_CONTROL_REG 0x8
36 36 #define APB_UART_SCALE_REG 0xC
37 37 #define APB_UART_FIFO_DEBUG_REG 0x10
38 38
39 39
40 40 class ApbUartPlugin : public socexplorerplugin
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 explicit ApbUartPlugin(QWidget *parent = 0);
45 45 ~ApbUartPlugin();
46 46 int VID(){return driver_VID;}
47 47 int PID(){return driver_PID;}
48 48
49 49 public slots:
50 50 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
51 51 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
52 52 void closeMe();
53 53 void postInstantiationTrigger();
54 54 void loopbackChangeState( int state );
55 55 void uartReadout();
56 56 void activateScan(bool flag);
57 57 void activate(bool flag);
58 58 signals:
59 59 void apbUartTextReceived(QString text);
60 60 private:
61 61 ApbUartPluginUi* UI;
62 62 bool useLoopBack;
63 63 QTimer loopBackTimer;
64 64 int enableLoopback();
65 65 int disableLoopback();
66 66 };
67 67
68 68 #endif // APBUARTPLUGIN_H
69 69
@@ -1,33 +1,33
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuartcfg.h"
23 23
24 24 ApbUartCfg::ApbUartCfg(QWidget *parent) :
25 25 QWidget(parent)
26 26 {
27 27 this->mainLayout = new QGridLayout(this);
28 28 this->loopbackChkBx = new QCheckBox(tr("Enable loopback"),this);
29 29 this->loopbackChkBx->setChecked(true);
30 30 this->mainLayout->addWidget(this->loopbackChkBx);
31 31 this->setLayout(this->mainLayout);
32 32 connect(this->loopbackChkBx,SIGNAL(stateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
33 33 }
@@ -1,46 +1,46
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTCFG_H
23 23 #define APBUARTCFG_H
24 24
25 25 #include <QWidget>
26 26 #include <QCheckBox>
27 27 #include <QLabel>
28 28 #include <QGridLayout>
29 29
30 30 class ApbUartCfg : public QWidget
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 explicit ApbUartCfg(QWidget *parent = 0);
35 35
36 36 signals:
37 37 void loopbackChkBxStateChanged( int state );
38 38 public slots:
39 39
40 40 private:
41 41 QCheckBox* loopbackChkBx;
42 42 QGridLayout* mainLayout;
43 43
44 44 };
45 45
46 46 #endif // APBUARTCFG_H
@@ -1,34 +1,34
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuartpluginui.h"
23 23
24 24 ApbUartPluginUi::ApbUartPluginUi(QWidget *parent) :
25 25 QTabWidget(parent)
26 26 {
27 27 this->terminal = new ApbUartTerminal(this);
28 28 this->cfg = new ApbUartCfg(this);
29 29
30 30 this->addTab(this->cfg,"Config");
31 31 this->addTab(this->terminal,"terminal");
32 32 connect(this->cfg,SIGNAL(loopbackChkBxStateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
33 33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->terminal,SIGNAL(apbUartTextReceived(QString)));
34 34 }
@@ -1,51 +1,51
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTPLUGINUI_H
23 23 #define APBUARTPLUGINUI_H
24 24
25 25 #include "apbuartcfg.h"
26 26 #include <QWidget>
27 27 #include <QGridLayout>
28 28 #include <QTabWidget>
29 29 #include <QCheckBox>
30 30 #include <QLabel>
31 31 #include <QLineEdit>
32 32 #include <QTextEdit>
33 33 #include "apbuartterminal.h"
34 34
35 35 class ApbUartPluginUi : public QTabWidget
36 36 {
37 37 Q_OBJECT
38 38 public:
39 39 explicit ApbUartPluginUi(QWidget *parent = 0);
40 40
41 41 signals:
42 42 void loopbackChkBxStateChanged( int state );
43 43 void apbUartTextReceived(QString text);
44 44 public slots:
45 45
46 46 private:
47 47 ApbUartCfg* cfg;
48 48 ApbUartTerminal* terminal;
49 49 };
50 50
51 51 #endif // APBUARTPLUGINUI_H
@@ -1,28 +1,28
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuartterminal.h"
23 23
24 24 ApbUartTerminal::ApbUartTerminal(QWidget *parent) :
25 25 QTextEdit(parent)
26 26 {
27 27 connect(this,SIGNAL(apbUartTextReceived(QString)),this,SLOT(append(QString)));
28 28 }
@@ -1,41 +1,41
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTTERMINAL_H
23 23 #define APBUARTTERMINAL_H
24 24
25 25 #include <QWidget>
26 26 #include <QTextEdit>
27 27
28 28
29 29 class ApbUartTerminal : public QTextEdit
30 30 {
31 31 Q_OBJECT
32 32 public:
33 33 explicit ApbUartTerminal(QWidget *parent = 0);
34 34
35 35 signals:
36 36 void apbUartTextReceived(QString text);
37 37 public slots:
38 38
39 39 };
40 40
41 41 #endif // APBUARTTERMINAL_H
@@ -1,467 +1,467
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include <socexplorerengine.h>
23 23 #include "ahbuartplugin.h"
24 24 #include <unistd.h>
25 25 #include <errno.h>
26 26 #include <QApplication>
27 27 #include <QProgressBar>
28 28 #include <stdio.h>
29 29 #include <QThread>
30 30 #include "ahbuartpywrapper.h"
31 31 #include <QCompleter>
32 32 #include <QStringList>
33 33 #include <QLineEdit>
34 34 #include <socexplorerproxy.h>
35 35
36 36 ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false)
37 37 {
38 38 this->port =(rs232port_t)NULL;
39 39 this->portMutex = new QMutex(QMutex::Recursive);
40 40 this->UI = new ahbUartPluginUI();
41 41 this->setWidget((QWidget*)this->UI);
42 42 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
43 43 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
44 44 this->pyObject = new ahbuartPywrapper(this);
45 45 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
46 46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
47 47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
48 48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
49 49 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
50 50 this->portListcompleter = NULL;
51 51 this->scanDone = false;
52 52 updatePortList();
53 53 }
54 54
55 55
56 56 ahbuartplugin::~ahbuartplugin()
57 57 {
58 58 if(this->port!=(rs232port_t)NULL)
59 59 {
60 60 rs232close(this->port);
61 61 this->port = (rs232port_t)NULL;
62 62 }
63 63 this->UI->close();
64 64 this->UI->~ahbUartPluginUI();
65 65 }
66 66
67 67
68 68 void ahbuartplugin::closeMe()
69 69 {
70 70 if(this->port!=(rs232port_t)NULL)
71 71 {
72 72 rs232close(this->port);
73 73 this->port = (rs232port_t)NULL;
74 74 }
75 75 emit this->closePlugin(this);
76 76 }
77 77
78 78 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
79 79 {
80 80 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
81 81 this->closeAction = this->menu->addAction(tr("Close plugin"));
82 82 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
83 83 return 1;
84 84 }
85 85
86 86
87 87
88 88
89 89 bool ahbuartplugin::checkConnection()
90 90 {
91 91 QTime timeout;
92 92 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
93 93 char test2[1024];
94 94 int writen =0;
95 95 int read = 0;
96 96 timeout.start();
97 97 SocExplorerEngine::message(this,"Check connection",2);
98 98 while(writen!=5)
99 99 {
100 100 writen+=rs232write(this->port,test+writen,5-writen);
101 101 if(timeout.elapsed()>1000)
102 102 {
103 103 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
104 104 return false;
105 105 }
106 106 }
107 107 #ifdef WIN32
108 108 usleep(1000);
109 109 #endif
110 110 timeout.restart();
111 111 while(read!=4)
112 112 {
113 113 read += rs232read(this->port,test2,4-read);
114 114 if(timeout.elapsed()>1000) break;
115 115 }
116 116 if(read>0)
117 117 {
118 118 SocExplorerEngine::message(this,"Connection Ok",2);
119 119 return true;
120 120 }
121 121 else
122 122 {
123 123 SocExplorerEngine::message(this,"Connection Error",2);
124 124 return false;
125 125 }
126 126
127 127 }
128 128
129 129 void ahbuartplugin::connectPort(QString PortName, int baudrate)
130 130 {
131 131 QTime timeout;
132 132 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
133 133 timeout.start();
134 134 if(this->port==(rs232port_t)NULL)
135 135 {
136 136 SocExplorerEngine::message(this,"Open port "+PortName,2);
137 137 this->port=rs232open((char*)PortName.toStdString().c_str());
138 138 }
139 139 if(this->port!=badPortValue)
140 140 {
141 141 SocExplorerEngine::message(this,"Port opened "+PortName,2);
142 142 SocExplorerEngine::message(this,"Configure port "+PortName,2);
143 143 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
144 144 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
145 145 char test2[1024];
146 146 SAFEWRITE(test,1,timeout,2000,return);
147 147 SAFEWRITE((test+1),1,timeout,2000,return);
148 148 APPENDTOLOG(QString("Flush port "));
149 149 rs232read(this->port,test2,512);
150 150 int read = 0;
151 151 for(int i=0;i<10;i++)
152 152 {
153 153 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
154 154 SAFEWRITE(test+2,5,timeout,2000,return);
155 155 SocExplorerEngine::message(this,"Read Result",2);
156 156 read=rs232read(this->port,test2+read,16);
157 157 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
158 158 if(read>0)
159 159 {
160 160 SocExplorerEngine::message(this,"Flush port ",2);
161 161 while(rs232read(this->port,test2,1)>0);
162 162 this->Connected = true;
163 163 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
164 164 emit this->activate(true);
165 165 if(this->scanDone==false)
166 166 {
167 167 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
168 168 this->scanDone=true;
169 169 }
170 170 break;
171 171 }
172 172 }
173 173 }
174 174 else
175 175 {
176 176 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
177 177 this->port = (rs232port_t)NULL;
178 178 this->Connected = false;
179 179 emit this->activateSig(false);
180 180 return;
181 181 }
182 182 if(this->Connected == false)
183 183 {
184 184 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
185 185 rs232close(this->port);
186 186 this->port = (rs232port_t)NULL;
187 187 emit this->activateSig(false);
188 188 }
189 189
190 190 }
191 191
192 192 bool ahbuartplugin::open(QString PortName,int baudrate)
193 193 {
194 194 if(this->port!=(rs232port_t)NULL)
195 195 this->close();
196 196 this->UI->setconfig(PortName,baudrate);
197 197 this->connectPort(PortName,baudrate);
198 198 return (this->port!=(rs232port_t)NULL);
199 199 }
200 200
201 201 void ahbuartplugin::close()
202 202 {
203 203 if(this->port!=(rs232port_t)NULL)
204 204 {
205 205 rs232close(this->port);
206 206 this->port = (rs232port_t)NULL;
207 207 this->Connected = false;
208 208 emit this->activateSig(false);
209 209 }
210 210 }
211 211
212 212 void ahbuartplugin::togglePort(QString PortName,int baudrate)
213 213 {
214 214 if(this->port!=(rs232port_t)NULL)
215 215 {
216 216 this->close();
217 217 }
218 218 else
219 219 {
220 220 this->connectPort(PortName,baudrate);
221 221 }
222 222 }
223 223
224 224
225 225 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
226 226 {
227 227 QTime timeout;
228 228 timeout.start();
229 229 unsigned int read=0;
230 230 unsigned int cnt=count;
231 231 unsigned int nextUpdateTrig=0,updateStep=512;
232 232 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
233 233 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
234 234 {
235 235 if(!this->portMutex->tryLock())
236 236 return 0;
237 237 if(!this->checkConnection())
238 238 {
239 239 this->Connected = false;
240 240 emit this->activateSig(false);
241 241 this->portMutex->unlock();
242 242 return 0;
243 243 }
244 244 QProgressBar* progress=NULL;
245 245 if(cnt>128)
246 246 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
247 247 char CMD[5];
248 248 char* result = (char*)malloc(count*4);
249 249 while(count>32)
250 250 {
251 251 CMD[0] = 0x80 | (32-1);
252 252 CMD[1] = (char)((address>>24)&0xFF);
253 253 CMD[2] = (char)((address>>16)&0xFF);
254 254 CMD[3] = (char)((address>>8)&0xFF);
255 255 CMD[4] = (char)((address)&0xFF);
256 256 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
257 257 SAFEWRITE(CMD,5,timeout,1000,return 0);
258 258 #ifdef WIN32
259 259 usleep(1000);
260 260 #endif
261 261 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
262 262 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
263 263 count-=32;
264 264 address+=32*4;
265 265 if(cnt>128)
266 266 {
267 267
268 268 if((cnt-count)>=nextUpdateTrig)
269 269 {
270 270 progress->setValue(cnt-count);
271 271 qApp->processEvents();
272 272 nextUpdateTrig+=updateStep;
273 273 }
274 274 }
275 275 }
276 276 if(count>0)
277 277 {
278 278 CMD[0] = 0x80 | (count-1);
279 279 CMD[1] = (char)((address>>24)&0xFF);
280 280 CMD[2] = (char)((address>>16)&0xFF);
281 281 CMD[3] = (char)((address>>8)&0xFF);
282 282 CMD[4] = (char)((address)&0xFF);
283 283 SAFEWRITE(CMD,5,timeout,1000,return 0);
284 284 #ifdef WIN32
285 285 usleep(1000);
286 286 #endif
287 287 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
288 288 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
289 289 }
290 290 if(cnt>128)
291 291 {
292 292 progress->setValue(cnt-count);
293 293 qApp->processEvents();
294 294 }
295 295 for(int i=0;(unsigned int)i<cnt;i++)
296 296 {
297 297 for(int j =0;j<4;j++)
298 298 {
299 299 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
300 300 }
301 301 read = cnt*4;
302 302
303 303 }
304 304 if(cnt>128)
305 305 SocExplorerEngine::deleteProgressBar(progress);
306 306 free(result);
307 307 this->portMutex->unlock();
308 308 }
309 309 return read/4;
310 310 }
311 311
312 312 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
313 313 {
314 314 QTime timeout;
315 315 timeout.start();
316 316 unsigned int writen=0;
317 317 unsigned int nextUpdateTrig=0,updateStep=512;
318 318 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
319 319 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
320 320 {
321 321 if(!this->portMutex->tryLock())
322 322 return 0;
323 323 if(!this->checkConnection())
324 324 {
325 325 emit this->activateSig(false);
326 326 this->Connected = false;
327 327 this->portMutex->unlock();
328 328 return 0;
329 329 }
330 330 QProgressBar* progress = NULL;
331 331 if(count>128)
332 332 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
333 333 int offset = 0;
334 334 char* CMD= (char*)malloc((32*4)+5);
335 335 while(count>32)
336 336 {
337 337 writen=0;
338 338 CMD[0] = 0xC0 | (32-1);
339 339 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
340 340 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
341 341 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
342 342 CMD[4] = (char)(((unsigned int)address)&0xFF);
343 343 for(int i=0;i<32;i++)
344 344 {
345 345 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
346 346 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
347 347 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
348 348 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
349 349 }
350 350 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
351 351 writen+=32;
352 352 count-=32;
353 353 offset+=32;
354 354 address+=32*4;
355 355 if(offset>=nextUpdateTrig && progress!=NULL)
356 356 {
357 357 progress->setValue(offset);
358 358 qApp->processEvents();
359 359 nextUpdateTrig +=updateStep;
360 360 }
361 361
362 362 }
363 363 if(count>0)
364 364 {
365 365 CMD[0] = 0xC0 | (count-1);
366 366 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
367 367 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
368 368 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
369 369 CMD[4] = (char)(((unsigned int)address)&0xFF);
370 370 for(int i=0;(unsigned int) i<(count);i++)
371 371 {
372 372 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
373 373 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
374 374 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
375 375 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
376 376 }
377 377 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
378 378 writen+=count;
379 379 }
380 380 if(progress!=NULL)
381 381 {
382 382 progress->setValue(writen);
383 383 qApp->processEvents();
384 384 SocExplorerEngine::deleteProgressBar(progress);
385 385 }
386 386 free(CMD);
387 387 this->portMutex->unlock();
388 388 return writen;
389 389 }
390 390 return 0;
391 391 }
392 392
393 393
394 394
395 395
396 396 void ahbuartplugin::updatePortList()
397 397 {
398 398 if(this->portListcompleter==(QCompleter*)NULL)
399 399 {
400 400 this->portListcompleter=new QCompleter(this);
401 401 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
402 402 this->portListcompleterModel = new QStringListModel(this);
403 403 this->portListcompleter->setModel(this->portListcompleterModel);
404 404 this->UI->setCompleter(this->portListcompleter);
405 405 }
406 406 rs232portslist_t* portlist = rs232getportlist();
407 407 rs232portslist_t* portlistenum = portlist;
408 408 QStringList wordList;
409 409 while(portlistenum!=NULL)
410 410 {
411 411 wordList << portlistenum->name;
412 412 portlistenum = portlistenum->next;
413 413 }
414 414 rs232deleteportlist(portlist);
415 415 this->portListcompleterModel->setStringList(wordList);
416 416 }
417 417
418 418 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
419 419 {
420 420 unsigned int data[(count/4)+1];
421 421 QVariantList result;
422 422 this->Read(data,(count/4)+1,address);
423 423 for(unsigned int i = 0;i<count/4;i++)
424 424 {
425 425 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
426 426 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
427 427 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
428 428 result.append(QVariant((int)(0x0FF&(data[i]))));
429 429 }
430 430
431 431 for(int i=0;i<(count%4);i++)
432 432 {
433 433 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
434 434 }
435 435
436 436 return result;
437 437 }
438 438
439 439 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
440 440 {
441 441 unsigned int data[dataList.count()/4];
442 442 for(int i = 0;i<(dataList.count()/4);i++)
443 443 {
444 444 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
445 445 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
446 446 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
447 447 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
448 448 }
449 449 this->Write(data,dataList.count()/4,address);
450 450 }
451 451
452 452
453 453
454 454
455 455
456 456
457 457
458 458
459 459
460 460
461 461
462 462
463 463
464 464
465 465
466 466
467 467
@@ -1,133 +1,133
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBUARTPLUGIN_H
23 23 #define AHBUARTPLUGIN_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include <QMutex>
29 29 #include <QProgressDialog>
30 30 #include <QStringListModel>
31 31 #include <QTime>
32 32 #include <socexplorerplugin.h>
33 33 #include "ahbuartpluginui.h"
34 34
35 35 #ifdef WinRs232
36 36 #include "librs232/RS232.h"
37 37 #else
38 38 #include <RS232.h>
39 39 #undef debug
40 40 #endif
41 41
42 42
43 43
44 44
45 45 #define APPENDTOLOG(message) this->UI->appendToLogFile(QTime::currentTime().toString() +":" + QString::number(QTime::currentTime().msec()) + ": " + message)
46 46
47 47 #define APENDTABLETOLOG(table,size,Qstr,message) \
48 48 Qstr.clear();\
49 49 Qstr+=message;\
50 50 for(int __i__tbllog__=0;(unsigned int)__i__tbllog__<size;__i__tbllog__++)\
51 51 {\
52 52 if(__i__tbllog__%16==0) Qstr += "\n"; \
53 53 Qstr += "0x" + QString::number((int)(0xff & table[__i__tbllog__]),16) +"\t";\
54 54 }\
55 55 APPENDTOLOG(Qstr);
56 56
57 57
58 58 #define SAFEWRITE(data,count,timer,timeout,error) \
59 59 while(1)\
60 60 {\
61 61 unsigned int __writen__=0; \
62 62 (timer).restart(); \
63 63 while(__writen__!=(count)) \
64 64 {\
65 65 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
66 66 if((timer).elapsed()>(timeout)) \
67 67 {\
68 68 APPENDTOLOG(QString("Timeout error while writing"));\
69 69 this->port = (rs232port_t)NULL; \
70 70 this->Connected = false; \
71 71 emit this->activateSig(false); \
72 72 error; \
73 73 } \
74 74 } \
75 75 break;\
76 76 }
77 77
78 78
79 79 #define SAFEREAD(data,count,timer,timeout,error) \
80 80 unsigned int __read__=0; \
81 81 (timer).restart(); \
82 82 while(__read__ != (count)) \
83 83 { \
84 84 __read__+=rs232read(this->port,((data)+__read__),((count)-__read__)); \
85 85 if((timer).elapsed()>(timeout)) \
86 86 { \
87 87 APPENDTOLOG(QString("Timeout error while reading"));\
88 88 this->Connected = false; \
89 89 emit this->activateSig(false); \
90 90 this->portMutex->unlock(); \
91 91 error; \
92 92 } \
93 93 } \
94 94
95 95
96 96
97 97 class ahbuartplugin : public socexplorerplugin
98 98 {
99 99 Q_OBJECT
100 100 public:
101 101 ahbuartplugin(QWidget *parent = 0);
102 102 ~ahbuartplugin();
103 103 int registermenu(QMainWindow *menuHolder);
104 104 int VID(){return driver_VID;}
105 105 int PID(){return driver_PID;}
106 106
107 107 public slots:
108 108 void togglePort(QString PortName,int baudrate);
109 109 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
110 110 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
111 111 void closeMe();
112 112 void close();
113 113 bool open(QString PortName,int baudrate);
114 114 void updatePortList();
115 115 QVariantList ReadBytes(unsigned int address,unsigned int count);
116 116 void WriteBytes(unsigned int address,QList<QVariant> dataList);
117 117 signals:
118 118 void setProgressValue(int progress);
119 119 private:
120 120 bool scanDone;
121 121 QProgressDialog* progress;
122 122 QLayout * mainLayout;
123 123 ahbUartPluginUI* UI;
124 124 QMutex* portMutex;
125 125 rs232port_t port;
126 126 QCompleter *portListcompleter;
127 127 QStringListModel *portListcompleterModel;
128 128 void connectPort(QString PortName,int baudrate);
129 129 bool checkConnection();
130 130
131 131 };
132 132
133 133 #endif // AHBUARTPLUGIN_H
@@ -1,124 +1,124
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbuartpluginui.h"
23 23 #include "ui_ahbuartpluginui.h"
24 24
25 25 ahbUartPluginUI::ahbUartPluginUI(QWidget *parent) :
26 26 QWidget(parent),
27 27 ui(new Ui::ahbUartPluginUI)
28 28 {
29 29 ui->setupUi(this);
30 30 connect(ui->OpenPort,SIGNAL(clicked()),this,SLOT(connectPort()));
31 31 connect(ui->PortspeedSlider,SIGNAL(valueChanged(int)),ui->baurateLCD,SLOT(display(int)));
32 32 connect(ui->logFileChooseBp,SIGNAL(clicked()),this,SLOT(chooseLogFile()));
33 33 connect(this,SIGNAL(setLogFileName(QString)),this->ui->logFileName,SLOT(setText(QString)));
34 34 connect(ui->rescanPorts,SIGNAL(clicked()),this,SIGNAL(rescanPorts()));
35 35 this->logFile = new QFile();
36 36 }
37 37
38 38 void ahbUartPluginUI::connectPort()
39 39 {
40 40 emit this->connectPortsig(ui->PortName->text(),ui->PortspeedSlider->value());
41 41 }
42 42
43 43 void ahbUartPluginUI::setConnected(bool connected)
44 44 {
45 45 if(connected == true)
46 46 {
47 47 ui->OpenPort->setText(tr("Close port"));
48 48 }
49 49 else
50 50 ui->OpenPort->setText(tr("Open port"));
51 51 }
52 52
53 53
54 54 ahbUartPluginUI::~ahbUartPluginUI()
55 55 {
56 56 delete ui;
57 57 }
58 58
59 59
60 60 void ahbUartPluginUI::chooseLogFile()
61 61 {
62 62 if(this->logFile->isOpen())
63 63 this->logFile->close();
64 64 this->logFile->setFileName(QFileDialog::getSaveFileName(this,tr("Open Log file"),QDir::homePath(), tr("Log Files (*.txt *.log)")));
65 65 if(this->logFile->open(QIODevice::WriteOnly))
66 66 {
67 67 this->logFileStrm = new QTextStream(this->logFile);
68 68 emit this->setLogFileName(this->logFile->fileName());
69 69 }
70 70 }
71 71
72 72 void ahbUartPluginUI::setconfig(QString PortName, int baudrate)
73 73 {
74 74 this->ui->PortName->setText(PortName);
75 75 this->ui->PortspeedSlider->setValue(baudrate);
76 76 }
77 77
78 78
79 79 void ahbUartPluginUI::logFileEnDisable(int state)
80 80 {
81 81 if(state==Qt::Checked)
82 82 {
83 83 this->logFileEn = true;
84 84 }
85 85 else if(state==Qt::Unchecked)
86 86 {
87 87 this->logFileEn = false;
88 88 }
89 89 }
90 90
91 91 bool ahbUartPluginUI::islogfileenable()
92 92 {
93 93 return this->logFileEn;
94 94 }
95 95
96 96 void ahbUartPluginUI::appendToLogFile(const QString & text)
97 97 {
98 98 if(this->logFileEn && this->logFile->isOpen())
99 99 {
100 100 *(this->logFileStrm) << text << endl;
101 101 }
102 102 }
103 103
104 104 void ahbUartPluginUI::setCompleter(QCompleter *completer)
105 105 {
106 106 this->ui->PortName->setCompleter(completer);
107 107 }
108 108
109 109 void ahbUartPluginUI::closeEvent(QCloseEvent *event)
110 110 {
111 111 if(this->logFile->isOpen())
112 112 {
113 113 this->logFileStrm->flush();
114 114 this->logFile->waitForBytesWritten(3000);
115 115 this->logFile->close();
116 116 }
117 117 event->accept();
118 118 }
119 119
120 120
121 121
122 122
123 123
124 124
@@ -1,71 +1,71
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBUARTPLUGINUI_H
23 23 #define AHBUARTPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QFile>
27 27 #include <QTextStream>
28 28 #include <QFileDialog>
29 29 #include <QDir>
30 30 #include <QCloseEvent>
31 31 #include <QCompleter>
32 32
33 33 namespace Ui {
34 34 class ahbUartPluginUI;
35 35 }
36 36
37 37 class ahbUartPluginUI : public QWidget
38 38 {
39 39 Q_OBJECT
40 40
41 41 public:
42 42 explicit ahbUartPluginUI(QWidget *parent = 0);
43 43 ~ahbUartPluginUI();
44 44 bool islogfileenable();
45 45 void appendToLogFile(const QString & text);
46 46 void closeEvent(QCloseEvent *event);
47 47 void setCompleter(QCompleter* completer);
48 48 public slots:
49 49 void setConnected(bool connected);
50 50 void connectPort();
51 51 void chooseLogFile();
52 52 void logFileEnDisable(int state);
53 53 void setconfig(QString PortName,int baudrate);
54 54
55 55 signals:
56 56 void connectPortsig(QString PortName,int baudrate);
57 57 void setLogFileName(QString FileName);
58 58 void rescanPorts();
59 59 private:
60 60 Ui::ahbUartPluginUI *ui;
61 61 QFile* logFile;
62 62 QTextStream* logFileStrm;
63 63 bool logFileEn;
64 64 };
65 65
66 66 #endif // AHBUARTPLUGINUI_H
67 67
68 68
69 69
70 70
71 71
@@ -1,32 +1,32
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbuartpywrapper.h"
23 23 #include <QObject>
24 24 #include <QFile>
25 25 #include <QTextStream>
26 26 #include <byteswap.h>
27 27 #include <stdint.h>
28 28
29 29 ahbuartPywrapper::ahbuartPywrapper(socexplorerplugin *parent) :
30 30 genericPySysdriver(parent)
31 31 {
32 32 }
@@ -1,74 +1,74
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbdevicelist.h"
23 23
24 24
25 25
26 26 ahbdevicelist::ahbdevicelist(QWidget *parent):QTableWidget(parent)
27 27 {
28 28 this->setColumnCount(7);
29 29 this->setHorizontalHeaderLabels(QStringList() << tr("Device Name")<<tr("BAR0")<<tr("BAR1")<<tr("BAR2")<<tr("BAR3")<<tr("Vendor ID")<<tr("Product ID"));
30 30 }
31 31
32 32 void ahbdevicelist::clearAHBdevicesList()
33 33 {
34 34 this->clear();
35 35 this->setRowCount(0);
36 36 this->setHorizontalHeaderLabels(QStringList() << tr("Device Name")<<tr("BAR0")<<tr("BAR1")<<tr("BAR2")<<tr("BAR3")<<tr("Vendor ID")<<tr("Product ID"));
37 37 }
38 38
39 39 void ahbdevicelist::addAHBdevice(ahbdeviceInfo* device)
40 40 {
41 41 if(this->rowCount()==0)
42 42 {
43 43 this->setRowCount(1);
44 44 }
45 45 else
46 46 {
47 47 this->insertRow(this->rowCount());
48 48 }
49 49
50 50 this->ahbdevices.append(device);
51 51 QTableWidgetItem *newItem = new QTableWidgetItem(*device->deviceName);
52 52 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
53 53 this->setItem(this->rowCount()-1, 0, newItem);
54 54
55 55 for(int i=0;i<4;i++)
56 56 {
57 57 if(device->BAR[i].size!=0)
58 58 {
59 59 newItem = new QTableWidgetItem("0x" + QString::number(device->BAR[i].address, 16)+" -> 0x"+ QString::number(device->BAR[i].address + device->BAR[i].size-1, 16)+" size = "+device->barAdressSize(i));
60 60 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
61 61 this->setItem(this->rowCount()-1, i+1, newItem);
62 62 }
63 63
64 64 }
65 65
66 66 newItem = new QTableWidgetItem("0x" + QString::number(device->VID , 16));
67 67 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
68 68 this->setItem(this->rowCount()-1, 5, newItem);
69 69 newItem = new QTableWidgetItem("0x" + QString::number(device->PID , 16));
70 70 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
71 71 this->setItem(this->rowCount()-1, 6, newItem);
72 72 this->resizeColumnsToContents();
73 73
74 74 }
@@ -1,104 +1,104
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBDEVICELIST_H
23 23 #define AHBDEVICELIST_H
24 24 #include <QTableWidget>
25 25 #include <QString>
26 26 #include <QList>
27 27
28 28 typedef struct
29 29 {
30 30 unsigned int address;
31 31 unsigned int size;
32 32 unsigned char type;
33 33 bool prefectchable;
34 34 bool cacheable;
35 35
36 36 }AHBbarreg;
37 37
38 38 class ahbdeviceInfo
39 39 {
40 40 public:
41 41 ahbdeviceInfo()
42 42 {
43 43 }
44 44
45 45 ahbdeviceInfo(const QString deviceName,AHBbarreg BAR0,AHBbarreg BAR1, AHBbarreg BAR2,AHBbarreg BAR3,int VID,int PID)
46 46 {
47 47 this->deviceName = new QString(deviceName);
48 48 this->BAR[0]=BAR0;
49 49 this->BAR[1]=BAR1;
50 50 this->BAR[2]=BAR2;
51 51 this->BAR[3]=BAR3;
52 52 this->VID = VID;
53 53 this->PID = PID;
54 54 }
55 55 QString barAdressSize(int barIndex)
56 56 {
57 57 int k=0;
58 58 unsigned int size=this->BAR[barIndex].size;
59 59 while(size>=1024){size=size>>10;k++;}
60 60 switch(k)
61 61 {
62 62 case 0:
63 63 return (QString::number(size, 10) + "B");
64 64 break;
65 65 case 1:
66 66 return (QString::number(size, 10) + "kB");
67 67 break;
68 68 case 2:
69 69 return (QString::number(size, 10) + "MB");
70 70 break;
71 71 case 3:
72 72 return (QString::number(size, 10) + "GB");
73 73 break;
74 74 case 4:
75 75 return (QString::number(size, 10) + "TB");
76 76 break;
77 77 default:
78 78 return (QString::number(this->BAR[barIndex].size, 10) + "B");
79 79 break;
80 80 }
81 81 }
82 82 QString* deviceName;
83 83 AHBbarreg BAR[4];
84 84 int VID;
85 85 int PID;
86 86 };
87 87
88 88 class ahbdevicelist: public QTableWidget
89 89 {
90 90 Q_OBJECT
91 91 public:
92 92 explicit ahbdevicelist(QWidget * parent = 0);
93 93
94 94 public slots:
95 95 void addAHBdevice(ahbdeviceInfo* device);
96 96 void clearAHBdevicesList();
97 97
98 98 private:
99 99 QList<ahbdeviceInfo*> ahbdevices;
100 100
101 101
102 102 };
103 103
104 104 #endif // AHBDEVICELIST_H
@@ -1,90 +1,90
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbpluginui.h"
23 23 #include <socexplorerengine.h>
24 24
25 25 ahbPluginUi::ahbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
26 26 QWidget(parent)
27 27 {
28 28 this->mainlayout = new QHBoxLayout;
29 29 this->scanBp = new QPushButton(tr("Scan AHB"));
30 30 this->deviceslst = new ahbdevicelist;
31 31 this->mainlayout->addWidget(this->deviceslst);
32 32 this->mainlayout->addWidget(this->scanBp);
33 33 this->setLayout(this->mainlayout);
34 34 this->_plugin = plugin;
35 35 connect(this,SIGNAL(addAHBdevice(ahbdeviceInfo*)),this->deviceslst,SLOT(addAHBdevice(ahbdeviceInfo*)));
36 36 connect(this,SIGNAL(clearAHBdevicesList()),this->deviceslst,SLOT(clearAHBdevicesList()));
37 37 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAHB()));
38 38 }
39 39
40 40
41 41
42 42 ahbdeviceInfo* ahbPluginUi::extractInfos(int *pnpregs)
43 43 {
44 44 AHBbarreg BAR[4];
45 45
46 46 int VID;
47 47 int PID;
48 48 for(int i=0;i<4;i++)
49 49 {
50 50 BAR[i].address = pnpregs[i+4] & 0xfff00000;
51 51 BAR[i].size = (pnpregs[i+4] & 0x0000fff0)<<16;
52 52 if(BAR[i].size!=0)
53 53 BAR[i].size = (((-1^BAR[i].size)|BAR[i].address)-BAR[i].address)+1;
54 54 BAR[i].cacheable = (bool)((pnpregs[i+4]&0x00010000)>>16);
55 55 BAR[i].prefectchable = (bool)((pnpregs[i+4]&0x00020000)>>17);
56 56 BAR[i].type = (unsigned char)(pnpregs[i+4]&0xf);
57 57 }
58 58
59 59 VID = (pnpregs[0]>>24)&0xff;
60 60 PID = (pnpregs[0]>>12)&0xfff;
61 61 QString devname = SocExplorerEngine::getDevName(VID,PID);
62 62 return new ahbdeviceInfo(devname,BAR[0],BAR[1],BAR[2],BAR[3],VID,PID);
63 63 }
64 64
65 65
66 66 void ahbPluginUi::scanAHB()
67 67 {
68 68 unsigned int size = AHB_PLUGNPLAY_SLAVE_STOP- AHB_PLUGNPLAY_MASTER_START;
69 69 int j=0;
70 70 unsigned long long i = AHB_PLUGNPLAY_MASTER_START;
71 71 int pnpregs[AHB_PLUGNPLAY_SLAVE_STOP- AHB_PLUGNPLAY_MASTER_START];
72 72 emit this->clearAHBdevicesList();
73 73 if( this->_plugin->Read((unsigned int*)pnpregs,size,(unsigned int)AHB_PLUGNPLAY_MASTER_START)==size)
74 74 {
75 75 while(i<AHB_PLUGNPLAY_SLAVE_STOP)
76 76 {
77 77 if(pnpregs[j]!=0)
78 78 {
79 79 ahbdeviceInfo* devinfo=this->extractInfos(pnpregs+j);
80 80 if(!devinfo->deviceName->compare("DSU3"))
81 81 SocExplorerEngine::addEnumDevice(this->_plugin,devinfo->VID,devinfo->PID,devinfo->BAR[0].address,*devinfo->deviceName);
82 82 emit this->addAHBdevice(devinfo);
83 83 }
84 84 i+=32;
85 85 j+=8;
86 86 }
87 87 }
88 88 }
89 89
90 90
@@ -1,59 +1,59
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBPLUGINUI_H
23 23 #define AHBPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QHBoxLayout>
27 27 #include <QPushButton>
28 28 #include "ahbdevicelist.h"
29 29 #include <socexplorerplugin.h>
30 30 #define AHB_PLUGNPLAY_MASTER_START ((unsigned int)(0xFFFFF000))
31 31 #define AHB_PLUGNPLAY_MASTER_STOP ((unsigned int)(0xFFFFF800))
32 32 #define AHB_PLUGNPLAY_SLAVE_START ((unsigned int)(0xFFFFF800))
33 33
34 34 #define AHB_PLUGNPLAY_SLAVE_STOP ((unsigned int)(0xFFFFFFFC))
35 35
36 36
37 37 class ahbPluginUi : public QWidget
38 38 {
39 39 Q_OBJECT
40 40 public:
41 41 explicit ahbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
42 42 ahbdeviceInfo* extractInfos(int* pnpregs);
43 43 public slots:
44 44 void scanAHB();
45 45 signals:
46 46 void addAHBdevice(ahbdeviceInfo* device);
47 47 void clearAHBdevicesList();
48 48 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
49 49 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
50 50 private:
51 51 QHBoxLayout* mainlayout;
52 52 QPushButton* scanBp;
53 53 ahbdevicelist* deviceslst;
54 54 socexplorerplugin* _plugin;
55 55
56 56
57 57 };
58 58
59 59 #endif // AHBPLUGINUI_H
@@ -1,74 +1,74
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbdevicelist.h"
23 23
24 24
25 25
26 26 apbdevicelist::apbdevicelist(QWidget *parent):QTableWidget(parent)
27 27 {
28 28 this->setColumnCount(4);
29 29 this->setHorizontalHeaderLabels(QStringList() << tr("Device Name")<<tr("BAR0")<<tr("Vendor ID")<<tr("Product ID"));
30 30 }
31 31
32 32 void apbdevicelist::clearAPBdevicesList()
33 33 {
34 34 this->clear();
35 35 this->setRowCount(0);
36 36 this->setHorizontalHeaderLabels(QStringList() << tr("Device Name")<<tr("BAR0")<<tr("Vendor ID")<<tr("Product ID"));
37 37 }
38 38
39 39 void apbdevicelist::addAPBdevice(apbdeviceInfo* device)
40 40 {
41 41 if(this->rowCount()==0)
42 42 {
43 43 this->setRowCount(1);
44 44 }
45 45 else
46 46 {
47 47 this->insertRow(this->rowCount());
48 48 }
49 49
50 50 this->apbdevices.append(device);
51 51 QTableWidgetItem *newItem = new QTableWidgetItem(device->deviceName);
52 52 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
53 53 this->setItem(this->rowCount()-1, 0, newItem);
54 54
55 55 for(int i=0;i<1;i++)
56 56 {
57 57 if(device->BAR[i].size!=0)
58 58 {
59 59 newItem = new QTableWidgetItem("0x" + QString::number(device->BAR[i].address, 16)+" -> 0x"+ QString::number(device->BAR[i].address + device->BAR[i].size-1, 16)+" size = "+device->barAdressSize(i));
60 60 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
61 61 this->setItem(this->rowCount()-1, i+1, newItem);
62 62 }
63 63
64 64 }
65 65
66 66 newItem = new QTableWidgetItem("0x" + QString::number(device->VID , 16));
67 67 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
68 68 this->setItem(this->rowCount()-1, 2, newItem);
69 69 newItem = new QTableWidgetItem("0x" + QString::number(device->PID , 16));
70 70 newItem->setFlags(newItem->flags() &~ Qt::ItemIsEditable);
71 71 this->setItem(this->rowCount()-1, 3, newItem);
72 72 this->resizeColumnsToContents();
73 73
74 74 }
@@ -1,99 +1,99
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBDEVICELIST_H
23 23 #define APBDEVICELIST_H
24 24 #include <QTableWidget>
25 25 #include <QString>
26 26 #include <QList>
27 27
28 28 typedef struct
29 29 {
30 30 unsigned int address;
31 31 unsigned int size;
32 32 unsigned char type;
33 33
34 34 }APBbarreg;
35 35
36 36 class apbdeviceInfo
37 37 {
38 38 public:
39 39 apbdeviceInfo()
40 40 {
41 41 }
42 42
43 43 apbdeviceInfo(const QString deviceName,APBbarreg BAR0,int VID,int PID)
44 44 {
45 45 this->deviceName = deviceName;
46 46 this->BAR[0]=BAR0;
47 47 this->VID = VID;
48 48 this->PID = PID;
49 49 }
50 50 QString barAdressSize(int barIndex)
51 51 {
52 52 int k=0;
53 53 unsigned int size=this->BAR[barIndex].size;
54 54 while(size>=1024){size=size>>10;k++;}
55 55 switch(k)
56 56 {
57 57 case 0:
58 58 return (QString::number(size, 10) + "B");
59 59 break;
60 60 case 1:
61 61 return (QString::number(size, 10) + "kB");
62 62 break;
63 63 case 2:
64 64 return (QString::number(size, 10) + "MB");
65 65 break;
66 66 case 3:
67 67 return (QString::number(size, 10) + "GB");
68 68 break;
69 69 case 4:
70 70 return (QString::number(size, 10) + "TB");
71 71 break;
72 72 default:
73 73 return (QString::number(this->BAR[barIndex].size, 10) + "B");
74 74 break;
75 75 }
76 76 }
77 77 QString deviceName;
78 78 APBbarreg BAR[1];
79 79 int VID;
80 80 int PID;
81 81 };
82 82
83 83 class apbdevicelist: public QTableWidget
84 84 {
85 85 Q_OBJECT
86 86 public:
87 87 explicit apbdevicelist(QWidget * parent = 0);
88 88
89 89 public slots:
90 90 void addAPBdevice(apbdeviceInfo* device);
91 91 void clearAPBdevicesList();
92 92
93 93 private:
94 94 QList<apbdeviceInfo*> apbdevices;
95 95
96 96
97 97 };
98 98
99 99 #endif // APBDEVICELIST_H
@@ -1,99 +1,99
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbpluginui.h"
23 23 #include <stdint.h>
24 24 #include <socexplorerengine.h>
25 25
26 26 apbPluginUi::apbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
27 27 QWidget(parent)
28 28 {
29 29 this->setWindowTitle(tr("APB Driver"));
30 30 this->mainlayout = new QHBoxLayout;
31 31 this->scanBp = new QPushButton(tr("Scan APB"));
32 32 this->deviceslst = new apbdevicelist;
33 33 this->mainlayout->addWidget(this->deviceslst);
34 34 this->mainlayout->addWidget(this->scanBp);
35 35 this->setLayout(this->mainlayout);
36 36 this->_plugin = plugin;
37 37 connect(this,SIGNAL(addAPBdevice(apbdeviceInfo*)),this->deviceslst,SLOT(addAPBdevice(apbdeviceInfo*)));
38 38 connect(this,SIGNAL(clearAPBdevicesList()),this->deviceslst,SLOT(clearAPBdevicesList()));
39 39 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAPB()));
40 40 }
41 41
42 42 void apbPluginUi::lockScanBp()
43 43 {
44 44 this->scanBp->setEnabled(false);
45 45 }
46 46
47 47
48 48 void apbPluginUi::unlockScanBp()
49 49 {
50 50 this->scanBp->setEnabled(true);
51 51 }
52 52
53 53
54 54
55 55 apbdeviceInfo* apbPluginUi::extractInfos(int *pnpregs)
56 56 {
57 57 APBbarreg BAR[1];
58 58
59 59 int VID;
60 60 int PID;
61 61 for(int i=0;i<1;i++)
62 62 {
63 63 BAR[i].address = ((uint32_t)(pnpregs[i+1] & 0xfff00000)>>12)+ APB_BUS_START;
64 64 BAR[i].size = ((pnpregs[i+1] & 0x00000ff0)>>4 )+1;
65 65 BAR[i].type = (unsigned char)(pnpregs[i+1]&0xf);
66 66 }
67 67
68 68 VID = (pnpregs[0]>>24)&0xff;
69 69 PID = (pnpregs[0]>>12)&0xfff;
70 70 QString devname = SocExplorerEngine::getDevName(VID,PID);
71 71 return new apbdeviceInfo(devname,BAR[0],VID,PID);
72 72 }
73 73
74 74 void apbPluginUi::scanAPB()
75 75 {
76 76 this->lockScanBp();
77 77 unsigned int size = APB_PLUGNPLAY_STOP - APB_PLUGNPLAY_START;
78 78 int j=0;
79 79 unsigned long long i = APB_PLUGNPLAY_START;
80 80 int pnpregs[APB_PLUGNPLAY_STOP - APB_PLUGNPLAY_START];
81 81 emit this->clearAPBdevicesList();
82 82 if(this->_plugin->Read((unsigned int*)pnpregs,size/4,(unsigned int)APB_PLUGNPLAY_START)==(size/4))
83 83 {
84 84 while(i<APB_PLUGNPLAY_STOP)
85 85 {
86 86 if(pnpregs[j]!=0)
87 87 {
88 88 apbdeviceInfo* devinfos=this->extractInfos(pnpregs+j);
89 89 SocExplorerEngine::addEnumDevice(this->_plugin,devinfos->VID,devinfos->PID,devinfos->BAR[0].address,devinfos->deviceName);
90 90 emit this->addAPBdevice(devinfos);
91 91 }
92 92 i+=8;
93 93 j+=2;
94 94 if(pnpregs[0]==pnpregs[j]&&pnpregs[1]==pnpregs[j+1])break;
95 95 }
96 96 }
97 97 this->unlockScanBp();
98 98 }
99 99
@@ -1,60 +1,60
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBPLUGINUI_H
23 23 #define APBPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QHBoxLayout>
27 27 #include <QPushButton>
28 28 #include "apbdevicelist.h"
29 29 #include <socexplorerplugin.h>
30 30
31 31 #define APB_BUS_START ((unsigned int)(0x80000000))
32 32 #define APB_PLUGNPLAY_START ((unsigned int)(0x800FF000))
33 33
34 34 #define APB_PLUGNPLAY_STOP ((unsigned int)(0x800FF000+(512*8)))
35 35
36 36
37 37 class apbPluginUi : public QWidget
38 38 {
39 39 Q_OBJECT
40 40 public:
41 41 explicit apbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
42 42 void lockScanBp();
43 43 void unlockScanBp();
44 44 apbdeviceInfo* extractInfos(int* pnpregs);
45 45
46 46 signals:
47 47 void addAPBdevice(apbdeviceInfo* device);
48 48 void clearAPBdevicesList();
49 49 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
50 50 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
51 51 public slots:
52 52 void scanAPB();
53 53 private:
54 54 QHBoxLayout* mainlayout;
55 55 QPushButton* scanBp;
56 56 apbdevicelist* deviceslst;
57 57 socexplorerplugin* _plugin;
58 58 };
59 59
60 60 #endif // APBPLUGINUI_H
@@ -1,92 +1,92
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ambaplugin.h"
23 23
24 24
25 25 ambaplugin::ambaplugin(QWidget *parent):socexplorerplugin(parent,true)
26 26 {
27 27 this->UI = new ambaPluginUI(this);
28 28 this->setWidget((QWidget*)this->UI);
29 29 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
30 30 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
31 31 connect(this,SIGNAL(activateSig(bool)),this,SLOT(activatePlugin(bool)));
32 32 }
33 33
34 34
35 35 ambaplugin::~ambaplugin()
36 36 {
37 37
38 38 }
39 39
40 40
41 41 void ambaplugin::closeMe()
42 42 {
43 43 emit this->closePlugin(this);
44 44 }
45 45
46 46 void ambaplugin::postInstantiationTrigger()
47 47 {
48 48 if(this->parent->isConnected())
49 49 {
50 50 this->UI->scanAll();
51 51 }
52 52 }
53 53
54 54 void ambaplugin::activatePlugin(bool flag)
55 55 {
56 56 if(flag)
57 57 {
58 58 this->UI->scanAll();
59 59 }
60 60 }
61 61
62 62 int ambaplugin::registermenu(QMainWindow *menuHolder)
63 63 {
64 64 this->menu = menuHolder->menuBar()->addMenu(tr("&ambaplugin"));
65 65 this->closeAction = this->menu->addAction(tr("Close plugin"));
66 66 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
67 67 return 1;
68 68 }
69 69
70 70
71 71
72 72 unsigned int ambaplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
73 73 {
74 74 if(parent!=NULL)
75 75 return parent->Read(Value,count,address);
76 76 return 0;
77 77 }
78 78
79 79 unsigned int ambaplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
80 80 {
81 81 if(parent!=NULL)
82 82 return parent->Write(Value,count,address);
83 83 return 0;
84 84 }
85 85
86 86
87 87
88 88
89 89
90 90
91 91
92 92
@@ -1,56 +1,56
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef ambaplugin_H
23 23 #define ambaplugin_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include "ambapluginui.h"
29 29 #include <socexplorerplugin.h>
30 30
31 31
32 32
33 33 class ambaplugin : public socexplorerplugin
34 34 {
35 35 Q_OBJECT
36 36 public:
37 37 explicit ambaplugin(QWidget *parent = 0);
38 38 ~ambaplugin();
39 39 int registermenu(QMainWindow *menuHolder);
40 40 int VID(){return driver_VID;}
41 41 int PID(){return driver_PID;}
42 42
43 43 public slots:
44 44 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
45 45 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
46 46 void closeMe();
47 47 void postInstantiationTrigger();
48 48 void activatePlugin(bool flag);
49 49 signals:
50 50
51 51 private:
52 52 ambaPluginUI* UI;
53 53 };
54 54
55 55 #endif // ambaplugin_H
56 56
@@ -1,43 +1,43
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ambapluginui.h"
23 23
24 24 ambaPluginUI::ambaPluginUI(socexplorerplugin *plugin, QWidget *parent) :
25 25 QWidget(parent)
26 26 {
27 27 this->mainLayout=new QGridLayout();
28 28 this->ahbPlugin=new ahbPluginUi(plugin);
29 29 this->apbPlugin=new apbPluginUi(plugin);
30 30 this->mainLayout->addWidget(this->ahbPlugin,0,0,1,-1);
31 31 this->mainLayout->addWidget(this->apbPlugin,1,0,1,-1);
32 32 this->setLayout(this->mainLayout);
33 33 connect(this->ahbPlugin,SIGNAL(ReadSig(uint*,uint,uint)),this,SIGNAL(ReadSig(uint*,uint,uint)));
34 34 connect(this->ahbPlugin,SIGNAL(WriteSig(uint*,uint,uint)),this,SIGNAL(WriteSig(uint*,uint,uint)));
35 35 connect(this->apbPlugin,SIGNAL(ReadSig(uint*,uint,uint)),this,SIGNAL(ReadSig(uint*,uint,uint)));
36 36 connect(this->apbPlugin,SIGNAL(WriteSig(uint*,uint,uint)),this,SIGNAL(WriteSig(uint*,uint,uint)));
37 37 }
38 38
39 39 void ambaPluginUI::scanAll()
40 40 {
41 41 this->ahbPlugin->scanAHB();
42 42 this->apbPlugin->scanAPB();
43 43 }
@@ -1,49 +1,49
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AMBAPLUGINUI_H
23 23 #define AMBAPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QVBoxLayout>
27 27 #include <QGridLayout>
28 28 #include <QPushButton>
29 29 #include "AHB/ahbpluginui.h"
30 30 #include "APB/apbpluginui.h"
31 31
32 32 class ambaPluginUI : public QWidget
33 33 {
34 34 Q_OBJECT
35 35 public:
36 36 explicit ambaPluginUI(socexplorerplugin* plugin,QWidget *parent = 0);
37 37
38 38 signals:
39 39 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
40 40 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
41 41 public slots:
42 42 void scanAll();
43 43 private:
44 44 QGridLayout* mainLayout;
45 45 ahbPluginUi* ahbPlugin;
46 46 apbPluginUi* apbPlugin;
47 47 };
48 48
49 49 #endif // AMBAPLUGINUI_H
@@ -1,225 +1,225
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "dsu3plugin.h"
23 23 #include <QFileDialog>
24 24 #include <QDir>
25 25 #include "dsu3pluginpywrapper.h"
26 26 #include <socexplorerengine.h>
27 27
28 28 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
29 29 {
30 30 this->UI = new dsu3pluginui();
31 31 this->setWidget((QWidget*)this->UI);
32 32 this->elfparserInst = new elfparser();
33 33 this->pyObject = new dsu3pluginPywrapper(this);
34 34 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(openFile(QString)),this,SLOT(openFile(QString)));
35 35 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(loadFile()),this,SLOT(flashTarget()));
36 36 QObject::connect(((dsu3pluginPywrapper*)this->pyObject),SIGNAL(run()),this,SLOT(run()));
37 37 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
38 38 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
39 39 connect(this->UI,SIGNAL(run()),this,SLOT(run()));
40 40 connect(this,SIGNAL(updateInfo(elfparser*)),this->UI,SIGNAL(updateInfo(elfparser*)));
41 41 }
42 42
43 43
44 44 dsu3plugin::~dsu3plugin()
45 45 {
46 46
47 47 }
48 48
49 49
50 50 void dsu3plugin::openFile()
51 51 {
52 52 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
53 53 if(filename!="")
54 54 {
55 55 this->openFile(filename);
56 56 }
57 57 }
58 58
59 59 void dsu3plugin::openFile(QString fileName)
60 60 {
61 61 this->elfparserInst->setFilename(fileName);
62 62 emit this->updateInfo(this->elfparserInst);
63 63 }
64 64
65 65 bool dsu3plugin::configureTarget()
66 66 {
67 67 if(parent==NULL)
68 68 return false;
69 69 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
70 70 if(DSUBASEADDRESS == (unsigned int)-1)
71 71 DSUBASEADDRESS = 0x90000000;
72 72 unsigned int MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x04 , 0x00F,0);
73 73 if(MCTRLBASEADDRESS == (unsigned int)-1)
74 74 return false;
75 75
76 76 //Force a debug break
77 77 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
78 78 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
79 79 //Clear time tag counter
80 80 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
81 81
82 82 //Clear ASR registers
83 83 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
84 84 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
85 85 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
86 86 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
87 87 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
88 88 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
89 89
90 90
91 91
92 92 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
93 93
94 94
95 95 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
96 96 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
97 97
98 98 unsigned int buff=0;
99 99 // for(int i=0;i<1567;i++)
100 100 // {
101 101 // parent->Write(&buff,(unsigned int)1,DSUBASEADDRESS+0x300000+(4*i));
102 102 // }
103 103 memSet(DSUBASEADDRESS+0x300000,0,1567);
104 104 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
105 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);
106 106 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
107 107
108 108 //Disable interrupts
109 109 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
110 110 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
111 111 return false;
112 112 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
113 113 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
114 114 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
115 115
116 116 //Set up timer
117 117 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
118 118 if(APBTIMERBASEADD == (unsigned int)-1)
119 119 return false;
120 120 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
121 121 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
122 122 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
123 123 return true;
124 124 }
125 125
126 126 bool dsu3plugin::flashTarget()
127 127 {
128 128 configureTarget();
129 129
130 130 /*Write .text*/
131 131 this->writeSection(".text");
132 132 /*Write .data*/
133 133 this->writeSection(".data");
134 134 return true;
135 135 }
136 136
137 137 void dsu3plugin::run()
138 138 {
139 139 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
140 140 if(DSUBASEADDRESS == (unsigned int)-1)
141 141 DSUBASEADDRESS = 0x90000000;
142 142 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
143 143 }
144 144
145 145 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
146 146 {
147 147 unsigned int* buff;
148 148 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
149 149 for(int i=0;i<Values.count();i++)
150 150 {
151 151 buff[i]=Values.at(i);
152 152 }
153 153 parent->Write(buff,(unsigned int)Values.count(),address);
154 154 free(buff);
155 155 }
156 156
157 157 void dsu3plugin::writeSection(int index)
158 158 {
159 159 char* buffch=NULL;
160 160 unsigned int* buff;
161 161 int size = this->elfparserInst->getSectionDatasz(index);
162 162 int sizeInt = size/4;
163 163 if(parent==NULL)
164 164 return;
165 165 this->elfparserInst->getSectionData(index,&buffch);
166 166 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
167 167 for(int i=0;i<sizeInt;i++)
168 168 {
169 169 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
170 170 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
171 171 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
172 172 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
173 173 }
174 174 if(size%4)
175 175 {
176 176 buff[sizeInt]=0;
177 177 for(int i=(size%4);i>0;i--)
178 178 {
179 179 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
180 180 }
181 181 sizeInt++;
182 182 }
183 183 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfparserInst->getSectionPaddr(index));
184 184 free(buff);
185 185 }
186 186
187 187 void dsu3plugin::writeSection(const QString &name)
188 188 {
189 189 for(int i=0;i<this->elfparserInst->getSectioncount();i++)
190 190 {
191 191 if(!this->elfparserInst->getSectionName(i).compare(name))
192 192 {
193 193 printf("about to write section %s @ 0x%x size = %d\n",elfparserInst->getSectionName(i).toStdString().c_str(),elfparserInst->getSectionPaddr(i),elfparserInst->getSectionMemsz(i));
194 194 writeSection(i);
195 195 }
196 196 }
197 197 }
198 198
199 199
200 200 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
201 201 {
202 202 if(parent!=NULL)
203 203 return parent->Write(Value,count,address);
204 204 return 0;
205 205 }
206 206
207 207 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
208 208 {
209 209 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
210 210 if(buffer!=NULL)
211 211 {
212 212 memset((void*)buffer,value,count*sizeof(unsigned int));
213 213 parent->Write(buffer,count,address);
214 214 free(buffer );
215 215 return true;
216 216 }
217 217 return false;
218 218 }
219 219
220 220 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
221 221 {
222 222 if(parent!=NULL)
223 223 return parent->Read(Value,count,address);
224 224 return 0;
225 225 }
@@ -1,61 +1,61
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef DSU3PLUGIN_H
23 23 #define DSU3PLUGIN_H
24 24 #include "dsu3pluginui.h"
25 25 #include <QMenuBar>
26 26 #include <QMenu>
27 27 #include <QAction>
28 28 #include <QMainWindow>
29 29 #include <QList>
30 30 #include "elfparser.h"
31 31 #include <socexplorerplugin.h>
32 32 #include <socexplorerengine.h>
33 33
34 34 typedef QList<unsigned int> uIntlist;
35 35
36 36 class dsu3plugin : public socexplorerplugin
37 37 {
38 38 Q_OBJECT
39 39 public:
40 40 explicit dsu3plugin(QWidget *parent = 0);
41 41 ~dsu3plugin();
42 42 bool memSet(unsigned int address, int value, unsigned int count);
43 43 public slots:
44 44 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
45 45 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
46 46 void openFile();
47 47 void openFile(QString fileName);
48 48 bool configureTarget();
49 49 bool flashTarget();
50 50 void run();
51 51 signals:
52 52 void updateInfo(elfparser* parser);
53 53 private:
54 54 void WriteRegs(uIntlist Values, unsigned int address);
55 55 void writeSection(int index);
56 56 void writeSection(const QString& name);
57 57 dsu3pluginui* UI;
58 58 elfparser* elfparserInst;
59 59 };
60 60
61 61 #endif // DSU3PLUGIN_H
@@ -1,54 +1,54
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include <dsu3pluginui.h>
24 24
25 25 dsu3pluginui::dsu3pluginui(QWidget *parent)
26 26 :QWidget(parent)
27 27 {
28 28 this->openFileQpb = new QPushButton(tr("Open File"));
29 29 this->flashTargetQpb = new QPushButton(tr("Flash Target"));
30 30 this->runQpb = new QPushButton(tr("Run"));
31 31 this->mainLayout = new QGridLayout();
32 32 this->elfInfoWdgtInst = new elfInfoWdgt;
33 33 this->mainLayout->addWidget(this->openFileQpb,0,0,1,1);
34 34 this->mainLayout->addWidget(this->flashTargetQpb,0,1,1,1);
35 35 this->mainLayout->addWidget(this->runQpb,0,2,1,1);
36 36 this->mainLayout->addWidget(this->elfInfoWdgtInst,1,0,1,-1);
37 37 this->setLayout(this->mainLayout);
38 38 connect(this->openFileQpb,SIGNAL(clicked()),this,SIGNAL(openFile()));
39 39 connect(this->flashTargetQpb,SIGNAL(clicked()),this,SIGNAL(flashTarget()));
40 40 connect(this->runQpb,SIGNAL(clicked()),this,SIGNAL(run()));
41 41 connect(this,SIGNAL(updateInfo(elfparser*)),this->elfInfoWdgtInst,SLOT(updateInfo(elfparser*)));
42 42
43 43 }
44 44
45 45
46 46
47 47
48 48
49 49
50 50
51 51
52 52
53 53
54 54
@@ -1,58 +1,58
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef DSU3PLUGINUI_H
23 23 #define DSU3PLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QHBoxLayout>
27 27 #include <QPushButton>
28 28 #include <qhexedit.h>
29 29 #include <QSplitter>
30 30 #include <QVBoxLayout>
31 31 #include <QGridLayout>
32 32 #include "elfinfowdgt.h"
33 33
34 34 class dsu3pluginui : public QWidget
35 35 {
36 36 Q_OBJECT
37 37 public:
38 38 explicit dsu3pluginui(QWidget *parent = 0);
39 39
40 40 public slots:
41 41
42 42 signals:
43 43 void openFile();
44 44 void updateInfo(elfparser* parser);
45 45 bool flashTarget();
46 46 void run();
47 47 private:
48 48 QGridLayout* mainLayout;
49 49 QPushButton* openFileQpb;
50 50 QPushButton* flashTargetQpb;
51 51 QPushButton* runQpb;
52 52 elfInfoWdgt* elfInfoWdgtInst;
53 53
54 54 };
55 55
56 56 #endif // DSU3PLUGINUI_H
57 57
58 58
@@ -1,61 +1,61
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "genericrwplugin.h"
23 23 #include "genericrwpluginpywrapper.h"
24 24 genericrwplugin::genericrwplugin(QWidget *parent):socexplorerplugin(parent,false)
25 25 {
26 26 this->UI = new genericrwpluginUi();
27 27 this->setWidget((QWidget*)this->UI);
28 28 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
29 29 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
30 30 this->pyObject = new genericRWpluginPyWrapper(this);
31 31 //QObject::connect(this->pyObject,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
32 32 //QObject::connect(this->pyObject,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
33 33 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(refresh()),this->UI,SIGNAL(refresh()));
34 34 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setAddress(quint32)),this->UI,SIGNAL(setAddress(quint32)));
35 35 QObject::connect(((genericRWpluginPyWrapper*)this->pyObject),SIGNAL(setLength(quint32)),this->UI,SIGNAL(setLength(quint32)));
36 36 }
37 37
38 38 genericrwplugin::~genericrwplugin()
39 39 {}
40 40
41 41 int genericrwplugin::registermenu(QMainWindow *menuHolder)
42 42 {
43 43 this->menu = menuHolder->menuBar()->addMenu(tr("&Generic RW Driver"));
44 44 this->closeAction = this->menu->addAction(tr("Close plugin"));
45 45 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
46 46 return 1;
47 47 }
48 48
49 49 unsigned int genericrwplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
50 50 {
51 51 if(parent!=NULL)
52 52 return parent->Write(Value,count,address);
53 53 return 0;
54 54 }
55 55
56 56 unsigned int genericrwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
57 57 {
58 58 if(parent!=NULL)
59 59 return parent->Read(Value,count,address);
60 60 return 0;
61 61 }
@@ -1,56 +1,56
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef GENERICRWPLUGIN_H
23 23 #define GENERICRWPLUGIN_H
24 24 #include "genericrwpluginui.h"
25 25 #include <QMenuBar>
26 26 #include <QMenu>
27 27 #include <QAction>
28 28 #include <QMainWindow>
29 29
30 30
31 31
32 32 #include <socexplorerplugin.h>
33 33
34 34 #define AHB_PLUGNPLAY_MASTER_START 0xFFFFF000
35 35 #define AHB_PLUGNPLAY_MASTER_STOP 0xFFFFF800
36 36 #define AHB_PLUGNPLAY_SLAVE_START 0xFFFFF800
37 37 #define AHB_PLUGNPLAY_SLAVE_STOP 0xFFFFFFFC
38 38
39 39
40 40 class genericrwplugin : public socexplorerplugin
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 explicit genericrwplugin(QWidget *parent = 0);
45 45 ~genericrwplugin();
46 46 int registermenu(QMainWindow *menuHolder);
47 47 public slots:
48 48 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
49 49 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
50 50 signals:
51 51
52 52 private:
53 53 genericrwpluginUi* UI;
54 54 };
55 55
56 56 #endif // GENERICRWPLUGIN_H
@@ -1,27 +1,27
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "genericrwpluginpywrapper.h"
23 23
24 24 genericRWpluginPyWrapper::genericRWpluginPyWrapper(socexplorerplugin *parent) :
25 25 genericPySysdriver(parent)
26 26 {
27 27 }
@@ -1,40 +1,40
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef GENERICRWPLUGINPYWRAPPER_H
23 23 #define GENERICRWPLUGINPYWRAPPER_H
24 24 #include <genericPySysdriver.h>
25 25 class genericRWpluginPyWrapper : public genericPySysdriver
26 26 {
27 27 Q_OBJECT
28 28 public:
29 29 explicit genericRWpluginPyWrapper(socexplorerplugin *parent = 0);
30 30
31 31 signals:
32 32 void refresh();
33 33 void setAddress(quint32 address);
34 34 void setLength(quint32 length);
35 35
36 36 public slots:
37 37
38 38 };
39 39
40 40 #endif // GENERICRWPLUGINPYWRAPPER_H
@@ -1,41 +1,41
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "genericrwplugin.h"
23 23
24 24 genericrwpluginUi::genericrwpluginUi(QWidget *parent) :
25 25 QWidget(parent)
26 26 {
27 27
28 28 this->mainlayout = new QHBoxLayout;
29 29 this->tabWdgt = new QTabWidget;
30 30 this->mainlayout->addWidget(this->tabWdgt);
31 31 this->memEditorWdgt = new memEditor;
32 32 this->tabWdgt->addTab(this->memEditorWdgt,tr("Memory editor"));
33 33 this->setLayout(this->mainlayout);
34 34 connect(this->memEditorWdgt,SIGNAL(WriteSig(uint*,uint,uint)),this,SIGNAL(WriteSig(uint*,uint,uint)));
35 35 connect(this->memEditorWdgt,SIGNAL(ReadSig(uint*,uint,uint)),this,SIGNAL(ReadSig(uint*,uint,uint)));
36 36 connect(this,SIGNAL(refresh()),this->memEditorWdgt,SLOT(readMemSlt()));
37 37 connect(this,SIGNAL(setAddress(quint32)),this->memEditorWdgt,SLOT(setAddress(quint32)));
38 38 connect(this,SIGNAL(setLength(quint32)),this->memEditorWdgt,SLOT(setLength(quint32)));
39 39
40 40 }
41 41
@@ -1,54 +1,54
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBPLUGINUI_H
23 23 #define AHBPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QHBoxLayout>
27 27 #include <QTabWidget>
28 28 #include <QPushButton>
29 29 #include "memeditor.h"
30 30 #include <QSplitter>
31 31
32 32
33 33 class genericrwpluginUi : public QWidget
34 34 {
35 35 Q_OBJECT
36 36 public:
37 37 explicit genericrwpluginUi(QWidget *parent = 0);
38 38
39 39 signals:
40 40 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
41 41 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
42 42 void refresh();
43 43 void setAddress(quint32 address);
44 44 void setLength(quint32 length);
45 45
46 46 private:
47 47 QSplitter* verticalSpliter;
48 48 QHBoxLayout* mainlayout;
49 49 QTabWidget* tabWdgt;
50 50 memEditor* memEditorWdgt;
51 51
52 52 };
53 53
54 54 #endif // AHBPLUGINUI_H
@@ -1,98 +1,98
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "memeditor.h"
23 23 #include "malloc.h"
24 24
25 25 memEditor::memEditor(QWidget *parent) :
26 26 QWidget(parent)
27 27 {
28 28 this->verticalSpliter = new QSplitter;
29 29 this->ctrlWidget = new QWidget;
30 30 this->verticalSpliter->setOrientation(Qt::Horizontal);
31 31 this->mainLayout = new QHBoxLayout;
32 32 this->ctrlLayout = new QVBoxLayout;
33 33 this->hexEditor = new QHexEdit;
34 34 this->addressSpnBx = new QHexSpinBox;
35 35 this->SizeWidget = new MemSizeWdgt(256);
36 36 this->readMemQPb = new QPushButton(tr("Read Mem"));
37 37 this->writeMemQPb = new QPushButton(tr("Write Mem"));
38 38 this->ctrlLayout->addWidget(this->addressSpnBx);
39 39 this->ctrlLayout->addWidget(this->SizeWidget);
40 40 this->ctrlLayout->addWidget(this->readMemQPb);
41 41 this->ctrlLayout->addWidget(this->writeMemQPb);
42 42 this->ctrlWidget->setLayout(this->ctrlLayout);
43 43 this->verticalSpliter->addWidget(this->hexEditor);
44 44 this->verticalSpliter->addWidget(this->ctrlWidget);
45 45 this->mainLayout->addWidget(this->verticalSpliter);
46 46 this->setLayout(this->mainLayout);
47 47 connect(this->readMemQPb,SIGNAL(clicked()),this,SLOT(readMemSlt()));
48 48 connect(this->writeMemQPb,SIGNAL(clicked()),this,SLOT(writeMemSlt()));
49 49 this->SizeWidget->setMaximum(16384);
50 50 }
51 51
52 52 void memEditor::writeMemSlt()
53 53 {
54 54
55 55 QByteArray data = this->hexEditor->data();
56 56 unsigned int length = data.length()/4;
57 57 unsigned int* buffer=(unsigned int*)malloc(length*sizeof(int));
58 58 unsigned int address = this->hexEditor->addressOffset();
59 59 for(int i=0;(unsigned int)i<length;i++)
60 60 {
61 61 buffer[i]=((data[4*i]<<24)&0xFF000000)+((data[(4*i)+1]<<16)&0x00FF0000)+((data[(4*i)+2]<<8)&0x0000FF00)+(data[(4*i)+3]&0x000000FF);
62 62 }
63 63 emit this->WriteSig(buffer,length,address);
64 64 free(buffer);
65 65 }
66 66
67 67 void memEditor::setAddress(quint32 address)
68 68 {
69 69 this->addressSpnBx->setValue(address);
70 70 }
71 71
72 72 void memEditor::setLength(quint32 length)
73 73 {
74 74 this->SizeWidget->setSizeValue(length);
75 75 }
76 76
77 77 void memEditor::readMemSlt()
78 78 {
79 79 this->SizeWidget->updateSizeValue();
80 80 unsigned int size = this->SizeWidget->getsize()/4;
81 81 unsigned int buffer[16384];
82 82 unsigned char buffChar[16384*4];
83 83 unsigned int address = this->addressSpnBx->value();
84 84 if((emit this->ReadSig(buffer,size,address&(-4)))==size)
85 85 {
86 86 for(int i=0;(unsigned int)i<size;i++)
87 87 {
88 88 buffChar[4*i]=(buffer[i]>>24)&0xFF;
89 89 buffChar[(4*i)+1]=(buffer[i]>>16)&0xFF;
90 90 buffChar[(4*i)+2]=(buffer[i]>>8)&0xFF;
91 91 buffChar[(4*i)+3]=(buffer[i])&0xFF;
92 92 }
93 93 QByteArray data = QByteArray((char*)buffChar,size*4);
94 94 this->hexEditor->setData(data);
95 95 this->hexEditor->setAddressOffset(address&(-4));
96 96 this->addressSpnBx->setValue(address&(-4));
97 97 }
98 98 }
@@ -1,62 +1,62
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef MEMEDITOR_H
23 23 #define MEMEDITOR_H
24 24
25 25 #include <QWidget>
26 26 #include <QVBoxLayout>
27 27 #include <QHBoxLayout>
28 28 #include <QPushButton>
29 29 #include <QByteArray>
30 30 #include <QSplitter>
31 31 #include <qhexedit.h>
32 32 #include <qhexspinbox.h>
33 33 #include <memsizewdgt.h>
34 34
35 35 class memEditor : public QWidget
36 36 {
37 37 Q_OBJECT
38 38 public:
39 39 explicit memEditor(QWidget *parent = 0);
40 40
41 41 signals:
42 42 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
43 43 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
44 44
45 45 public slots:
46 46 void readMemSlt();
47 47 void writeMemSlt();
48 48 void setAddress(quint32 address);
49 49 void setLength(quint32 length);
50 50 private:
51 51 QWidget* ctrlWidget;
52 52 QSplitter* verticalSpliter;
53 53 QHBoxLayout* mainLayout;
54 54 QVBoxLayout* ctrlLayout;
55 55 QHexEdit* hexEditor;
56 56 QHexSpinBox* addressSpnBx;
57 57 QPushButton* readMemQPb;
58 58 QPushButton* writeMemQPb;
59 59 MemSizeWdgt* SizeWidget;
60 60 };
61 61
62 62 #endif // MEMEDITOR_H
@@ -1,85 +1,85
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "memctrlrplugin.h"
23 23 #include "memctrlrpywrapper.h"
24 24
25 25 memctrlrplugin::memctrlrplugin(QWidget *parent):socexplorerplugin(parent,false)
26 26 {
27 27 this->UI = new memctrlrPluginUi();
28 28 this->setWidget((QWidget*)this->UI);
29 29 connect(this->UI,SIGNAL(WriteSig(uint*,uint,uint)),this,SLOT(Write(uint*,uint,uint)));
30 30 connect(this->UI,SIGNAL(ReadSig(uint*,uint,uint)),this,SLOT(Read(uint*,uint,uint)));
31 31 this->pyObject = new memctrlrPyWrapper(this);
32 32 connect(this->pyObject,SIGNAL(launchTest(uint,uint)),this,SLOT(launchTest(uint,uint)));
33 33 }
34 34
35 35 memctrlrplugin::~memctrlrplugin()
36 36 {}
37 37
38 38 int memctrlrplugin::registermenu(QMainWindow *menuHolder)
39 39 {
40 40 this->menu = menuHolder->menuBar()->addMenu(tr("&Memory Controler"));
41 41 this->closeAction = this->menu->addAction(tr("Close plugin"));
42 42 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
43 43 return 1;
44 44 }
45 45
46 46 unsigned int memctrlrplugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
47 47 {
48 48 if(parent)
49 49 return parent->Write(Value,count,address);
50 50 return 0;
51 51 }
52 52
53 53 unsigned int memctrlrplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
54 54 {
55 55 if(parent)
56 56 return parent->Read(Value,count,address);
57 57 return 0;
58 58 }
59 59
60 60
61 61 bool memctrlrplugin::launchTest(unsigned int baseAddress,unsigned int size)
62 62 {
63 63 if(parent==NULL)return false;
64 64 unsigned int* dataLocal = (unsigned int*)malloc(size);
65 65 unsigned int* dataOnBoard = (unsigned int*)malloc(size);
66 66 bool res=true;
67 67 for(int i=0;(unsigned int)i<(size>>2);i++)
68 68 {
69 69 dataLocal[i]= (0xFFFF&rand())+(rand()<<16);
70 70 }
71 71 parent->Write(dataLocal,size>>2,baseAddress);
72 72 parent->Read(dataOnBoard,size>>2,baseAddress);
73 73 for(int i=0;(unsigned int)i<(size>>2);i++)
74 74 {
75 75 if(dataLocal[i]!=dataOnBoard[i])
76 76 res=false;
77 77 }
78 78
79 79 free(dataLocal);
80 80 free(dataOnBoard);
81 81 return res;
82 82 }
83 83
84 84
85 85
@@ -1,50 +1,50
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef MEMCTRLRPLUGIN_H
23 23 #define MEMCTRLRPLUGIN_H
24 24 #include "memctrlrpluginui.h"
25 25 #include <QMenuBar>
26 26 #include <QMenu>
27 27 #include <QAction>
28 28 #include <QMainWindow>
29 29 #include <socexplorerplugin.h>
30 30
31 31 #include <socexplorerplugin.h>
32 32
33 33 class memctrlrplugin : public socexplorerplugin
34 34 {
35 35 Q_OBJECT
36 36 public:
37 37 explicit memctrlrplugin(QWidget *parent = 0);
38 38 ~memctrlrplugin();
39 39 int registermenu(QMainWindow *menuHolder);
40 40 public slots:
41 41 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
42 42 unsigned int Read(unsigned int *Value,unsigned int count,unsigned int address=0);
43 43 bool launchTest(unsigned int baseAddress,unsigned int size);
44 44 signals:
45 45
46 46 private:
47 47 memctrlrPluginUi* UI;
48 48 };
49 49
50 50 #endif // MEMCTRLRPLUGIN_H
@@ -1,36 +1,36
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "memctrlrpluginui.h"
23 23
24 24 memctrlrPluginUi::memctrlrPluginUi(QWidget *parent) :
25 25 QWidget(parent)
26 26 {
27 27 this->mainlayout = new QHBoxLayout;
28 28 this->memorycheckWdgt = new memorycheck;
29 29 this->tabWdgt = new QTabWidget;
30 30 this->tabWdgt->addTab(this->memorycheckWdgt,QString(tr("Memory Check")));
31 31 this->mainlayout->addWidget(this->tabWdgt);
32 32 this->setLayout(this->mainlayout);
33 33 connect(this->memorycheckWdgt,SIGNAL(ReadSig(uint*,uint,uint)),this,SIGNAL(ReadSig(uint*,uint,uint)));
34 34 connect(this->memorycheckWdgt,SIGNAL(WriteSig(uint*,uint,uint)),this,SIGNAL(WriteSig(uint*,uint,uint)));
35 35 }
36 36
@@ -1,49 +1,49
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef MEMCTRLRPLUGINUI_H
23 23 #define MEMCTRLRPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QHBoxLayout>
27 27 #include <QPushButton>
28 28 #include <QTabWidget>
29 29 #include "memorycheck.h"
30 30
31 31
32 32 class memctrlrPluginUi : public QWidget
33 33 {
34 34 Q_OBJECT
35 35 public:
36 36 explicit memctrlrPluginUi(QWidget *parent = 0);
37 37
38 38 signals:
39 39 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
40 40 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
41 41
42 42 private:
43 43 QHBoxLayout* mainlayout;
44 44 QTabWidget* tabWdgt;
45 45 memorycheck* memorycheckWdgt;
46 46
47 47 };
48 48
49 49 #endif
@@ -1,51 +1,51
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "abstractspwbridge.h"
23 23
24 24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
25 25 :QObject((QObject*)parent)
26 26 {
27 27 this->plugin = parent;
28 28 this->p_GUI=NULL;
29 29 }
30 30
31 31 QWidget *abstractSpwBridge::getGUI()
32 32 {
33 33 return this->p_GUI;
34 34 }
35 35
36 36 bool abstractSpwBridge::connectBridge()
37 37 {
38 38 return false;
39 39 }
40 40
41 41 bool abstractSpwBridge::disconnectBridge()
42 42 {
43 43 return false;
44 44 }
45 45
46 46
47 47
48 48
49 49
50 50
51 51
@@ -1,50 +1,52
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef ABSTRACTSPWBRIDGE_H
23 23 #define ABSTRACTSPWBRIDGE_H
24 24
25 25 #include <QObject>
26 26 #include <socexplorerplugin.h>
27 27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
28 28 #include <spw.h>
29 29
30 30 class abstractSpwBridge : public QObject
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 explicit abstractSpwBridge(socexplorerplugin *parent);
35 35 QWidget *getGUI();
36 36
37 37 public slots:
38 38 virtual bool connectBridge();
39 39 virtual bool disconnectBridge();
40 40 virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
41 41 virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
42 42 virtual int pushRMAPPacket(char* packet,int size)=0;
43 signals:
44 void setConnected(bool connected);
43 45 protected:
44 46 socexplorerplugin* plugin;
45 47 QWidget* p_GUI;
46 48 private:
47 49
48 50 };
49 51
50 52 #endif // ABSTRACTSPWBRIDGE_H
@@ -1,213 +1,213
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef SPW_H
23 23 #define SPW_H
24 24 #include <stdint.h>
25 25
26 26 /*
27 27 ███████╗██████╗ ██╗ ██╗ ██████╗ ██████╗ ███╗ ███╗███╗ ███╗ ██████╗ ███╗ ██╗
28 28 ██╔════╝██╔══██╗██║ ██║ ██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔═══██╗████╗ ██║
29 29 ███████╗██████╔╝██║ █╗ ██║ ██║ ██║ ██║██╔████╔██║██╔████╔██║██║ ██║██╔██╗ ██║
30 30 ╚════██║██╔═══╝ ██║███╗██║ ██║ ██║ ██║██║╚██╔╝██║██║╚██╔╝██║██║ ██║██║╚██╗██║
31 31 ███████║██║ ╚███╔███╔╝ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║╚██████╔╝██║ ╚████║
32 32 ╚══════╝╚═╝ ╚══╝╚══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
33 33 */
34 34
35 35 enum SPW_PROTOCOL_IDs{
36 36 SPW_PROTO_ID_EXTEND =0,
37 37 SPW_PROTO_ID_RMAP = 1,
38 38 SPW_PROTO_ID_CCSDS = 2,
39 39 SPW_PROTO_ID_GOES_R = 238,
40 40 SPW_PROTO_ID_STUP = 239
41 41 };
42 42
43 43 static const unsigned char SPW_CRCTable[] = {
44 44 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75,
45 45 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b,
46 46 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69,
47 47 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67,
48 48 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d,
49 49 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43,
50 50 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51,
51 51 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f,
52 52 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05,
53 53 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b,
54 54 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19,
55 55 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17,
56 56 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d,
57 57 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33,
58 58 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21,
59 59 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f,
60 60 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95,
61 61 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b,
62 62 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89,
63 63 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87,
64 64 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad,
65 65 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3,
66 66 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1,
67 67 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf,
68 68 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5,
69 69 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb,
70 70 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9,
71 71 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7,
72 72 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd,
73 73 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3,
74 74 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1,
75 75 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf
76 76 };
77 77
78 78 inline unsigned char _spw_CRC_(unsigned char INCR, unsigned char INBYTE)
79 79 {
80 80 return SPW_CRCTable[INCR ^ INBYTE];
81 81 }
82 82
83 83 inline char spw_CRC(char* buffer, int size)
84 84 {
85 85 unsigned char CRC = 0;
86 86 for(int i=0;i<size;i++)
87 87 {
88 88 CRC = _spw_CRC_(CRC,(unsigned char)buffer[i]);
89 89 }
90 90 return CRC;
91 91 }
92 92
93 93 /*
94 94 ██████╗ ███╗ ███╗ █████╗ ██████╗ ██████╗ ██████╗ ██████╗ ████████╗ ██████╗ ██████╗ ██████╗ ██╗
95 95 ██╔══██╗████╗ ████║██╔══██╗██╔══██╗ ██╔══██╗██╔══██╗██╔═══██╗╚══██╔══╝██╔═══██╗██╔════╝██╔═══██╗██║
96 96 ██████╔╝██╔████╔██║███████║██████╔╝ ██████╔╝██████╔╝██║ ██║ ██║ ██║ ██║██║ ██║ ██║██║
97 97 ██╔══██╗██║╚██╔╝██║██╔══██║██╔═══╝ ██╔═══╝ ██╔══██╗██║ ██║ ██║ ██║ ██║██║ ██║ ██║██║
98 98 ██║ ██║██║ ╚═╝ ██║██║ ██║██║ ██║ ██║ ██║╚██████╔╝ ██║ ╚██████╔╝╚██████╗╚██████╔╝███████╗
99 99 ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
100 100 */
101 101
102 102 enum RMAP_CMD_CODE{
103 103 RMAP_CMD_CODE_invalid0, //0000
104 104 RMAP_CMD_CODE_invalid1, //0001
105 105 RMAP_CMD_CODE_read_Single, //0010
106 106 RMAP_CMD_CODE_read_Inc, //0011
107 107 RMAP_CMD_CODE_invalid2, //0100
108 108 RMAP_CMD_CODE_invalid3, //0101
109 109 RMAP_CMD_CODE_invalid4, //0110
110 110 RMAP_CMD_CODE_readModWri_Inc, //0111
111 111 RMAP_CMD_CODE_writeSingle_noVer_noRep, //1000
112 112 RMAP_CMD_CODE_writeInc_noVer_noRep, //1001
113 113 RMAP_CMD_CODE_writeSingle_noVer_Rep, //1010
114 114 RMAP_CMD_CODE_writeInc_noVer_Rep, //1011
115 115 RMAP_CMD_CODE_writeSingle_ver_noRep, //1100
116 116 RMAP_CMD_CODE_writeInc_ver_noRep, //1101
117 117 RMAP_CMD_CODE_writeSingle_ver_rep, //1110
118 118 RMAP_CMD_CODE_writeInc_ver_rep //1111
119 119 };
120 120
121 121 /*
122 122 * Rmap read command header:
123 123 *
124 124 * | Destination Logical Address | Protocol identifier | Packet type | Destination key |
125 125 * |-----------------------------|------------------------|------------------------|------------------------|
126 126 * | Source Logical Address | Transaction identifier | Transaction identifier | Extended read address |
127 127 * |-----------------------------|------------------------|------------------------|------------------------|
128 128 * | Read address MSB | Read address | Read address | Read address LSB |
129 129 * |-----------------------------|------------------------|------------------------|------------------------|
130 130 * | Data length MSB | Data length | Data length LSB | CRC |
131 131 * |-----------------------------|------------------------|------------------------|------------------------|
132 132 *
133 133 * Packet type field:
134 134 *
135 135 * | msb
136 136 * | reserved = 0 | Comand = 1| Read = 0 | Read = 0 | Read = 1 | Increment/ | Source Path | Source Path |
137 137 * | (Ack/NoAck) | No Inc. address | Address Length | Address Length |
138 138 *
139 139 */
140 140 #define RMAP_READ_HEADER_MIN_SZ 16
141 141
142 142 inline void RMAP_build_rx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer)
143 143 {
144 144 buffer[0] = destinationLogicalAddress;
145 145 buffer[1] = SPW_PROTO_ID_RMAP;
146 146 buffer[2] = 0b01001100;
147 147 buffer[3] = destKey;
148 148 buffer[4] = sourceLogicalAddress;
149 149 buffer[5] = (char)(transactionID >> 8);
150 150 buffer[6] = (char)(transactionID);
151 151 buffer[7] = 0;
152 152 buffer[8] = (char)(readAddress >> 24);
153 153 buffer[9] = (char)(readAddress >> 16);
154 154 buffer[10] = (char)(readAddress >> 8);
155 155 buffer[11] = (char)(readAddress);
156 156 buffer[12] = (char)(length >> 16);
157 157 buffer[13] = (char)(length >> 8);
158 158 buffer[14] = (char)(length);
159 159 buffer[15] = (char)spw_CRC(buffer,15);
160 160 }
161 161
162 162 inline int RMAP_get_transactionID(char *packet)
163 163 {
164 164 return ((((unsigned int)packet[5])<<8) + ((unsigned int)packet[6]));
165 165 }
166 166
167 167
168 168 /*
169 169 * Rmap Write command header:
170 170 *
171 171 * | Destination Logical Address | Protocol identifier | Packet type | Destination key |
172 172 * |-----------------------------|------------------------|------------------------|------------------------|
173 173 * | Source Logical Address | Transaction identifier | Transaction identifier | Extended write address |
174 174 * |-----------------------------|------------------------|------------------------|------------------------|
175 175 * | Write address MSB | Write address | Write address | Write address LSB |
176 176 * |-----------------------------|------------------------|------------------------|------------------------|
177 177 * | Data length MSB | Data length | Data length LSB | Header CRC |
178 178 * |-----------------------------|------------------------|------------------------|------------------------|
179 179 * | Data | (...) | Last data byte | Data CRC |
180 180 * |-----------------------------|------------------------|------------------------|------------------------|
181 181 *
182 182 * Packet type field:
183 183 *
184 184 * | msb
185 185 * | reserved = 0 | Comand = 1| Write = 1 | Verify data = 1 | Ack = 1 | Increment/ | Source Path | Source Path |
186 186 * | Don't Verify data = 0 | No Ack = 0 | No Inc. address | Address Length | Address Length |
187 187 *
188 188 */
189 189 #define RMAP_WRITE_HEADER_MIN_SZ 16
190 190 #define RMAP_WRITE_PACKET_MIN_SZ(bytesCnt) (RMAP_WRITE_HEADER_MIN_SZ+bytesCnt+1) //header=16 + data + data CRC=1
191 191
192 192 inline void RMAP_build_tx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer)
193 193 {
194 194 buffer[0] = destinationLogicalAddress;
195 195 buffer[1] = SPW_PROTO_ID_RMAP;
196 196 buffer[2] = 0b01101100;
197 197 buffer[3] = destKey;
198 198 buffer[4] = sourceLogicalAddress;
199 199 buffer[5] = (char)(transactionID >> 8);
200 200 buffer[6] = (char)(transactionID);
201 201 buffer[7] = 0;
202 202 buffer[8] = (char)(readAddress >> 24);
203 203 buffer[9] = (char)(readAddress >> 16);
204 204 buffer[10] = (char)(readAddress >> 8);
205 205 buffer[11] = (char)(readAddress);
206 206 buffer[12] = (char)(length >> 16);
207 207 buffer[13] = (char)(length >> 8);
208 208 buffer[14] = (char)(length);
209 209 buffer[15] = (char)spw_CRC(buffer,15);
210 210 buffer[16+length] = (char)spw_CRC(buffer+16,length);
211 211 }
212 212
213 213 #endif // SPW_H
@@ -1,103 +1,112
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "spwplugin.h"
24 24 #include "stardundeespw_usb.h"
25 25 #include <socexplorerproxy.h>
26 26
27 27 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,true)
28 28 {
29 29 Q_UNUSED(parent)
30 30 this->bridge = NULL;
31 31 this->scanDone = false;
32 32 this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this);
33 33 this->bridgeSelector = new QComboBox(this);
34 34 this->mainLayout = new QGridLayout(this);
35 35 this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter);
36 36 this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1);
37 37 this->mainGroupBox->setLayout(this->mainLayout);
38 38 this->setWidget(this->mainGroupBox);
39 39 this->bridgeSelector->addItem("none");
40 40 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
41 41 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
42 42 }
43 43
44 44
45 45 spwplugin::~spwplugin()
46 46 {
47 47
48 48 }
49 49
50 50
51 51
52 52 unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
53 53 {
54 54 if(Connected)
55 55 {
56 56 return bridge->Read(Value,count,address);
57 57 }
58 58 return 0;
59 59 }
60 60
61 61 void spwplugin::bridgeSelectionChanged(const QString &text)
62 62 {
63 63 printf("test");
64 64 if(text=="none")
65 65 {
66 66 if(this->bridge!=NULL)
67 67 {
68 68 this->mainLayout->removeWidget(this->bridge->getGUI());
69 this->disconnect(this,SLOT(setConnected(bool)));
69 70 delete this->bridge;
70 71 this->bridge= NULL;
71 72 }
72 73 }
73 74 if(text=="STAR-Dundee Spw USB Brick")
74 75 {
75 76 if(this->bridge!=NULL)
76 77 {
77 78 this->mainLayout->removeWidget(this->bridge->getGUI());
79 this->disconnect(this,SLOT(setConnected(bool)));
78 80 delete this->bridge;
79 81 }
80 82 this->bridge = new stardundeeSPW_USB(this);
81 83 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
84 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
82 85 }
83 86
84 87 }
85 88
89 void spwplugin::setConnected(bool connected)
90 {
91 this->Connected = connected;
92 emit activateSig(connected);
93 }
94
86 95
87 96
88 97 unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
89 98 {
90 99 if(Connected)
91 100 {
92 101 return bridge->Write(Value,count,address);
93 102 }
94 103 return 0;
95 104 }
96 105
97 106
98 107
99 108
100 109
101 110
102 111
103 112
@@ -1,70 +1,71
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef spwplugin_H
23 23 #define spwplugin_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include <QGroupBox>
29 29 #include <QComboBox>
30 30 #include <QLabel>
31 31
32 32 #include <abstractspwbridge.h>
33 33 #include <socexplorerplugin.h>
34 34
35 35
36 36 class spwplugin : public socexplorerplugin
37 37 {
38 38 Q_OBJECT
39 39 public:
40 40 explicit spwplugin(QWidget *parent = 0);
41 41 ~spwplugin();
42 42 /* You can implement the folowing function if you want to overwrite
43 43 * their default behavior
44 44 */
45 45 /*
46 46 int registermenu(QMainWindow *menuHolder);
47 47 int isConnected();
48 48 int connect();
49 49 int VID(){return driver_VID;}
50 50 int PID(){return driver_PID;}
51 51 */
52 52
53 53 public slots:
54 54 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
55 55 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
56 56
57 void bridgeSelectionChanged( const QString & text );
57 void bridgeSelectionChanged( const QString & text );
58 void setConnected(bool connected);
58 59
59 60 signals:
60 61
61 62 private:
62 63 abstractSpwBridge* bridge;
63 64 bool scanDone;
64 65 QGroupBox* mainGroupBox;
65 66 QComboBox* bridgeSelector;
66 67 QGridLayout* mainLayout;
67 68 };
68 69
69 70 #endif // spwplugin_H
70 71
@@ -1,104 +1,144
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>StarDundeeUI</class>
4 4 <widget class="QWidget" name="StarDundeeUI">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 <width>614</width>
10 <height>152</height>
9 <width>645</width>
10 <height>231</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QFormLayout" name="formLayout">
17 17 <property name="fieldGrowthPolicy">
18 18 <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
19 19 </property>
20 20 <item row="0" column="0">
21 21 <widget class="QLabel" name="selectBrickLbl">
22 22 <property name="text">
23 23 <string>Select Brick</string>
24 24 </property>
25 25 </widget>
26 26 </item>
27 27 <item row="0" column="1">
28 28 <widget class="QComboBox" name="selectBrickCmbx">
29 29 <item>
30 30 <property name="text">
31 31 <string>None</string>
32 32 </property>
33 33 </item>
34 34 </widget>
35 35 </item>
36 36 <item row="1" column="0">
37 37 <widget class="QLabel" name="selectLinkLbl">
38 38 <property name="text">
39 39 <string>Select link number</string>
40 40 </property>
41 41 </widget>
42 42 </item>
43 43 <item row="1" column="1">
44 44 <widget class="QComboBox" name="selectLinkCmbx">
45 45 <item>
46 46 <property name="text">
47 47 <string>1</string>
48 48 </property>
49 49 </item>
50 50 <item>
51 51 <property name="text">
52 52 <string>2</string>
53 53 </property>
54 54 </item>
55 55 </widget>
56 56 </item>
57 57 <item row="2" column="0">
58 58 <widget class="QLabel" name="selectLinkSpeedLbl">
59 59 <property name="text">
60 60 <string>Link Speed</string>
61 61 </property>
62 62 </widget>
63 63 </item>
64 64 <item row="2" column="1">
65 65 <widget class="QComboBox" name="setLinkSpeedCmbx">
66 66 <item>
67 67 <property name="text">
68 68 <string>10MHz</string>
69 69 </property>
70 70 </item>
71 71 </widget>
72 72 </item>
73 73 <item row="3" column="0">
74 74 <widget class="QLabel" name="setDestKeyLbl">
75 75 <property name="text">
76 76 <string>Destination key</string>
77 77 </property>
78 78 </widget>
79 79 </item>
80 80 <item row="3" column="1">
81 81 <widget class="QLineEdit" name="destKeyLineEdit">
82 82 <property name="inputMask">
83 <string comment="009"/>
83 <string comment="ddD"/>
84 84 </property>
85 85 <property name="text">
86 86 <string>32</string>
87 87 </property>
88 88 <property name="maxLength">
89 89 <number>3</number>
90 90 </property>
91 91 </widget>
92 92 </item>
93 <item row="4" column="0">
94 <widget class="QLabel" name="RMAPaddressLbl">
95 <property name="text">
96 <string>RMAP Target address</string>
97 </property>
98 </widget>
99 </item>
93 100 <item row="4" column="1">
94 <widget class="QPushButton" name="pushButton">
101 <widget class="QLineEdit" name="RMAPAddresslineEdit">
102 <property name="inputMask">
103 <string comment="ddD"/>
104 </property>
105 <property name="text">
106 <string>254</string>
107 </property>
108 <property name="maxLength">
109 <number>3</number>
110 </property>
111 </widget>
112 </item>
113 <item row="5" column="0">
114 <widget class="QLabel" name="RMAPKeyLbl">
115 <property name="text">
116 <string>RMAP Target key</string>
117 </property>
118 </widget>
119 </item>
120 <item row="5" column="1">
121 <widget class="QLineEdit" name="RMAPKeylineEdit">
122 <property name="inputMask">
123 <string comment="ddD"/>
124 </property>
125 <property name="text">
126 <string comment="ddD">2</string>
127 </property>
128 <property name="maxLength">
129 <number>3</number>
130 </property>
131 </widget>
132 </item>
133 <item row="6" column="1">
134 <widget class="QPushButton" name="connectQpb">
95 135 <property name="text">
96 136 <string>Connect</string>
97 137 </property>
98 138 </widget>
99 139 </item>
100 140 </layout>
101 141 </widget>
102 142 <resources/>
103 143 <connections/>
104 144 </ui>
@@ -1,9 +1,98
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
1 22 #include "stardundeegui.h"
2 23
3 24 #include "ui_stardundeeGUI.h"
4 25
5 26 StarDundeeGUI::StarDundeeGUI(QWidget *parent) :
6 27 QWidget(parent),ui(new Ui::StarDundeeUI)
7 28 {
8 29 this->ui->setupUi(this);
30 connect(this->ui->selectBrickCmbx,SIGNAL(currentIndexChanged(int)),this,SIGNAL(brickSelectionChanged(int)));
31 connect(this->ui->selectLinkCmbx,SIGNAL(currentIndexChanged(int)),this,SIGNAL(linkNumberSelectionChanged(int)));
32 connect(this->ui->setLinkSpeedCmbx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(linkSpeedSelectionChanged(QString)));
33 connect(this->ui->destKeyLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(destinationKeyChanged(QString)));
34 connect(this->ui->RMAPAddresslineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapAddressChanged(QString)));
35 connect(this->ui->RMAPKeylineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapKeyChanged(QString)));
36 connect(this->ui->connectQpb,SIGNAL(clicked()),this,SIGNAL(connectClicked()));
37
9 38 }
39
40 int StarDundeeGUI::getBrickSelection()
41 {
42 return ui->selectBrickCmbx->currentIndex();
43 }
44
45 int StarDundeeGUI::getLinkNumberSelection()
46 {
47 return ui->selectLinkCmbx->currentIndex();
48 }
49
50 QString StarDundeeGUI::getLinkSpeedSelection()
51 {
52 return ui->setLinkSpeedCmbx->currentText();
53 }
54
55 QString StarDundeeGUI::getDestinationKey()
56 {
57 return ui->destKeyLineEdit->text();
58 }
59
60 QString StarDundeeGUI::getRmapAddress()
61 {
62 return ui->RMAPAddresslineEdit->text();
63 }
64
65 QString StarDundeeGUI::getRmapKey()
66 {
67 return ui->RMAPKeylineEdit->text();
68 }
69
70
71
72 void StarDundeeGUI::lock(bool lock)
73 {
74 this->ui->selectBrickCmbx->setDisabled(lock);
75 this->ui->selectLinkCmbx->setDisabled(lock);
76 this->ui->setLinkSpeedCmbx->setDisabled(lock);
77 this->ui->destKeyLineEdit->setDisabled(lock);
78 this->ui->RMAPAddresslineEdit->setDisabled(lock);
79 this->ui->RMAPKeylineEdit->setDisabled(lock);
80 if(lock)
81 this->ui->connectQpb->setText("Disconnect");
82 else
83 this->ui->connectQpb->setText("Connect");
84 }
85
86 void StarDundeeGUI::updateAvailableBrickCount(int count)
87 {
88 this->ui->selectBrickCmbx->clear();
89 this->ui->selectBrickCmbx->addItem("none");
90 for(int i =0;i<32;i++)
91 {
92 if((count&1)==1)
93 {
94 this->ui->selectBrickCmbx->addItem("STAR-Dundee USB brick "+QString::number(i));
95 }
96 count>>=1;
97 }
98 }
@@ -1,24 +1,58
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
1 22 #ifndef STARDUNDEEGUI_H
2 23 #define STARDUNDEEGUI_H
3 24
4 25 #include <QWidget>
5 26
6 27 namespace Ui {
7 28 class StarDundeeUI;
8 29 }
9 30
10 31 class StarDundeeGUI : public QWidget
11 32 {
12 33 Q_OBJECT
13 34 public:
14 35 explicit StarDundeeGUI(QWidget *parent = 0);
15
36 int getBrickSelection();
37 int getLinkNumberSelection();
38 QString getLinkSpeedSelection();
39 QString getDestinationKey();
40 QString getRmapAddress();
41 QString getRmapKey();
16 42 signals:
17
43 void brickSelectionChanged(int brickIndex);
44 void linkNumberSelectionChanged(int linkIndex);
45 void linkSpeedSelectionChanged(const QString & linkSpeed);
46 void destinationKeyChanged(const QString & destKey);
47 void rmapAddressChanged(const QString & address);
48 void rmapKeyChanged(const QString & key);
49 void connectClicked();
18 50 public slots:
51 void lock(bool lock);
52 void updateAvailableBrickCount(int count);
19 53
20 54 private:
21 55 Ui::StarDundeeUI *ui;
22 56 };
23 57
24 58 #endif // STARDUNDEEGUI_H
@@ -1,522 +1,605
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "stardundeespw_usb.h"
24 24 #include <socexplorerengine.h>
25 25 #include <qhexedit.h>
26 26
27 27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
28 28 abstractSpwBridge(parent)
29 29 {
30 30 Q_UNUSED(parent)
31 31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
32 32 makeGUI(parent);
33 33 this->manager->start();
34 34 }
35 35
36 36 stardundeeSPW_USB::~stardundeeSPW_USB()
37 37 {
38 38 this->manager->requestInterruption();
39 39 delete this->p_GUI;
40 40 }
41 41
42 42 void stardundeeSPW_USB::toggleBridgeConnection()
43 43 {
44 44 if(this->plugin->isConnected())
45 45 {
46 46 if(this->disconnectBridge())
47 47 {
48 this->connectBridgeButton->setText("Connect");
48 ((StarDundeeGUI*)this->p_GUI)->lock(false);
49 emit setConnected(false);
49 50 }
50 51 }
51 52 else
52 53 {
53 54 if(this->connectBridge())
54 55 {
55 this->connectBridgeButton->setText("Disconnect");
56 ((StarDundeeGUI*)this->p_GUI)->lock(true);
57 emit setConnected(true);
56 58 }
57 59 }
58 60 }
59 61
60 62 bool stardundeeSPW_USB::connectBridge()
61 63 {
62 64 return this->manager->connectBridge();
63 65 }
64 66
65 67 bool stardundeeSPW_USB::disconnectBridge()
66 68 {
67 69 return this->manager->disconnectBridge();
68 70 }
69 71
70 72 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
71 73 {
72 74 return this->manager->sendPacket(packet,size);
73 75 }
74 76
75 77 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
76 78 {
77 79 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
78 writeBuffer[0]=1;//Link number
80 writeBuffer[0]=this->manager->linkNumber;//Link number
79 81 int transactionID = 0;
80 82 int written=0;
81 SocExplorerEngine::message(this->plugin,"Enter Write function");
83 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
82 84 QProgressBar* progress=NULL;
83 85 if(count>RMAP_MAX_XFER_SIZE)
84 86 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
85 87 //Quite stupide loop, I guess that I always get the number of byte I asked for!
86 88 while(count>=RMAP_MAX_XFER_SIZE)
87 89 {
88 90 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
89 91 {
90 92 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
91 93 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
92 94 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
93 95 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
94 96 }
95 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
97 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
96 98 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
97 99 written+=RMAP_MAX_XFER_SIZE;
98 100 count-=RMAP_MAX_XFER_SIZE;
99 101 progress->setValue(written);
100 102 qApp->processEvents();
101 103 }
102 104 if(count>0)
103 105 {
104 106 for(int i=0;i<((int)count);i++)
105 107 {
106 108 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
107 109 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
108 110 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
109 111 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
110 112 }
111 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
113 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),count*4,writeBuffer+1);
112 114 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
113 115 written+=count;
114 116 if(progress!=NULL)
115 117 {
116 118 progress->setValue(written);
117 119 qApp->processEvents();
118 120 }
119 121 }
120 122 if(progress!=NULL)
121 123 {
122 124 SocExplorerEngine::deleteProgressBar(progress);
123 125 }
124 126 return written;
125 127 }
126 128
127 129 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
128 130 {
129 131 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
130 132 char* RMAP_AnswerBuffer;
131 requestBuffer[0]=1;//Link number
133 requestBuffer[0]=this->manager->linkNumber;//Link number
132 134 int transactionID = 0;
133 135 int read=0;
134 136 QProgressBar* progress=NULL;
135 137 if(count>RMAP_MAX_XFER_SIZE)
136 138 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
137 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
139 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
138 140
139 141 //Quite stupide loop, I guess that I always get the number of byte I asked for!
140 142 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
141 143 {
142 144 transactionID = manager->getRMAPtransactionID();
143 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
144 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
145 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
146 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
145 147 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
146 148 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
149 if(len==-1)
150 {
151 this->toggleBridgeConnection();
152 return 0;
153 }
147 154 for(int i=0;i<((len-13)/4);i++)
148 155 {
149 156 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
150 157 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
151 158 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
152 159 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
153 160 }
154 161 free(RMAP_AnswerBuffer);
155 162 read+=RMAP_MAX_XFER_SIZE;
156 163 count-=RMAP_MAX_XFER_SIZE;
157 164 progress->setValue(read);
158 165 qApp->processEvents();
159 166 }
160 167 if((int)count>0)
161 168 {
162 169 transactionID = manager->getRMAPtransactionID();
163 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
164 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
165 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
166 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
167 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
168 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
170 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
171 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
172 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
173 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
174 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
175 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),count*4,requestBuffer+1);
169 176 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
170 177 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
178 if(len==-1)
179 {
180 this->toggleBridgeConnection();
181 return 0;
182 }
171 183 for(int i=0;i<((len-13)/4);i++)
172 184 {
173 185 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
174 186 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
175 187 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
176 188 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
177 189 }
178 190 free(RMAP_AnswerBuffer);
179 191 read+=count;
180 192 if(progress!=NULL)
181 193 {
182 194 progress->setValue(read);
183 195 qApp->processEvents();
184 196 }
185 197 }
186 198 if(progress!=NULL)
187 199 {
188 200 SocExplorerEngine::deleteProgressBar(progress);
189 201 }
190 202 return read;
191 203 }
192 204
193 void stardundeeSPW_USB::updateAvailableBrickCount(int count)
205 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
206 {
207 this->manager->selectedBrick = brickIndex-1;
208 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick));
209 }
210
211 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
212 {
213 this->manager->linkNumber = linkIndex + 1;
214 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber));
215 }
216
217 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
194 218 {
219 this->manager->linkSpeed = linkSpeed.toInt();
195 220
221 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed));
222 }
223
224 void stardundeeSPW_USB::destinationKeyChanged(const QString &destKey)
225 {
226 this->manager->destinationKey = destKey.toInt();
227 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->destinationKey));
228 }
229
230 void stardundeeSPW_USB::rmapAddressChanged(const QString &rmapaddress)
231 {
232 this->manager->rmapAddress = rmapaddress.toInt();
233 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->rmapAddress));
234 }
235
236 void stardundeeSPW_USB::rmapKeyChanged(const QString &key)
237 {
238 this->manager->rmapKey = key.toInt();
239 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->rmapKey));
196 240 }
197 241
198 242 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
199 243 {
200 this->p_GUI = new StarDundeeGUI(plugin);
201 this->mainLayout = new QGridLayout(this->p_GUI);
202 // connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
244 this->p_GUI = new StarDundeeGUI();
245 // this->mainLayout = new QGridLayout(this->p_GUI);
246 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
247 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
248 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
249 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
250 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
251 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
252 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(rmapAddressChanged(QString)));
253 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapKeyChanged(QString)),this,SLOT(rmapKeyChanged(QString)));
254 this->brickSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
255 this->linkNumberSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
256 this->linkSpeedSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
257 this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
258 this->rmapAddressChanged(((StarDundeeGUI*)this->p_GUI)->getRmapAddress());
259 this->rmapKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey());
260
203 261 }
204 262
205 263 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
206 264 :QThread((QObject*)parent)
207 265 {
266 this->RMAPtimeout = 2000;
208 267 this->handleMutex = new QMutex(QMutex::NonRecursive);
209 268 this->RMAP_AnswersSem = new QSemaphore(0);
210 269 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
211 270 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
212 271 this->plugin = plugin;
213 272 connected = false;
214 273 }
215 274
216 275 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
217 276 {
218 277 this->terminate();
219 278 while (!this->isFinished()) {
220 279 this->usleep(1000);
221 280 }
222 281 }
223 282
224 283
225 284 void stardundeeSPW_USB_Manager::run()
226 285 {
227 286 USB_SPACEWIRE_PACKET_PROPERTIES properties;
228 287 USB_SPACEWIRE_ID pIdentifier=NULL;
229 288 USB_SPACEWIRE_STATUS stat;
230 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
289 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
231 290 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
232 291 while (!this->isInterruptionRequested())
233 292 {
234 293 if(this->connected)
235 294 {
236 295 handleMutex->lock();
237 296 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
238 297 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
239 298 {
240 SocExplorerEngine::message(this->plugin,"Got packet");
299 SocExplorerEngine::message(this->plugin,"Got packet",2);
241 300 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
242 301 if (stat == TRANSFER_SUCCESS)
243 302 {
244 303 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
245 304 {
246 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
305 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
247 306 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
248 307 {
249 308 SocExplorerEngine::message(this->plugin,"Got end of packet");
250 309 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
251 310 {
252 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
253 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
311 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
312 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
254 313 if(properties.len>8)
255 314 {
256 315 char* packetbuffer = (char*)malloc(properties.len);
257 316 memcpy(packetbuffer,buffer,properties.len);
258 317 USBSpaceWire_FreeRead(hDevice, pIdentifier);
259 318 pIdentifier = NULL;
260 319 handleMutex->unlock();
261 320 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
262 321 RMAP_AnswersMtx->lock();
263 322 RMAP_Answers.append(packet);
264 323 RMAP_AnswersMtx->unlock();
265 324 RMAP_AnswersSem->release();
266 325
267 326 }
268 327 else //it's a RMAP write response
269 328 {
270 329 USBSpaceWire_FreeRead(hDevice, pIdentifier);
271 330 pIdentifier = NULL;
272 331 handleMutex->unlock();
273 332 }
274 333
275 334 }
276 335 else //any non-rmap packet will be pushed to the network
277 336 {
278 337 USBSpaceWire_FreeRead(hDevice, pIdentifier);
279 338 handleMutex->unlock();
280 SocExplorerEngine::message(this->plugin,"Got SPW packet");
339 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
281 340 }
282 341 }
283 342 else
284 343 {
285 SocExplorerEngine::message(this->plugin,"No EOP received");
344 SocExplorerEngine::message(this->plugin,"No EOP received",2);
286 345 }
287 346 }
288 347
289 348 }
290 349 else
291 350 {
292 351 USBSpaceWire_FreeRead(hDevice, pIdentifier);
293 352 handleMutex->unlock();
294 353 }
295 354 }
296 355 else
297 356 {
298 357 USBSpaceWire_FreeRead(hDevice, pIdentifier);
299 358 handleMutex->unlock();
300 359 }
301 360 }
302 361 else
303 362 {
304 363 sleep(1);
305 this->brickList = USBSpaceWire_ListDevices();
364 int list = USBSpaceWire_ListDevices();
365 if(this->brickList!=list)
366 {
367 this->brickList = list;
368 emit updateAvailableBrickCount(this->brickList);
369 }
306 370 }
307 371 usleep(1000);
308 372 }
309 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
373 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
310 374 }
311 375
312 376 bool stardundeeSPW_USB_Manager::connectBridge()
313 377 {
314 this->handleMutex->lock();
378 QMutexLocker mlock(this->handleMutex);
315 379 int status;
316 380 U32 statusControl;
317 int brickNumber=0;
318 int linkNumber=1;
319 381 this->connected = false;
320 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
382 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
321 383 {
322 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
323 this->handleMutex->unlock();
384 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
324 385 return false;
325 386 }
326 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
387 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
327 388
328 389 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
329 390 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
330 391 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
331 392
332 393 // Set the path and return path to the device
333 394 CFGSpaceWire_StackClear();
334 395 CFGSpaceWire_AddrStackPush(0);
335 396 CFGSpaceWire_AddrStackPush(254);
336 397 CFGSpaceWire_RetAddrStackPush(254);
337 398 // set the base transmit rate to 100 MHz
338 399 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
339 400 if (status != CFG_TRANSFER_SUCCESS)
340 401 {
341 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
402 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
342 403 return false;
343 404 }
344 405 else
345 406 {
346 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
407 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
347 408 }
348 409
349 410 // read the link status
350 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
411 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
351 412 {
352 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
413 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
353 414 return false;
354 415 }
355 416 else
356 417 {
357 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
418 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
358 419
359 420 // Set the link status control register properties
360 421 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
361 422 CFGSpaceWire_LSEnableStart(&statusControl, 1);
362 423 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
363 424 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
364 425 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
365 426
366 427 // Set the link status control register
367 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
428 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
368 429 {
369 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
430 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
370 431 return false;
371 432 }
372 433 else
373 434 {
374 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
435 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
375 436 }
376 437 }
377 438
378 439 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
379 440 {
380 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
441 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
381 442 return false;
382 443 }
383 444 else
384 445 {
385 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
446 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
386 447 }
387 448
388 449 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
389 450 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
390 451 USBSpaceWire_SetTimeout(hDevice,1.0);
391 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
392 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
393 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
452 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
453 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
454 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
394 455 this->connected = true;
395 this->handleMutex->unlock();
396 456 return true;
397 457 }
398 458
399 459 bool stardundeeSPW_USB_Manager::disconnectBridge()
400 460 {
401 461 this->handleMutex->lock();
402 462 USBSpaceWire_Close(hDevice); // Close the device
403 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
463 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
404 464 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
405 465 this->handleMutex->unlock();
466 this->RMAP_pending_transaction_IDsMtx->lock();
467 this->RMAP_pending_transaction_IDs.clear();
468 this->RMAP_pending_transaction_IDsMtx->unlock();
469 this->RMAP_AnswersMtx->lock();
470 this->RMAP_Answers.clear();
471 this->RMAP_AnswersMtx->unlock();
472 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
406 473 return true;
407 474 }
408 475
409 476 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
410 477 {
411 478 this->RMAP_pending_transaction_IDsMtx->lock();
412 479 int ID=0;
413 480 bool found=true;
414 while(ID<65536)
481 while(ID<511)
415 482 {
416 483 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
417 484 {
418 485 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
419 486 }
420 487 if(found==true)break;
421 488 ID++;
422 489 found = true;
423 490 }
424 491 if(found)
425 492 {
426 493 RMAP_pending_transaction_IDs.append(ID);
427 494 }
428 495 this->RMAP_pending_transaction_IDsMtx->unlock();
429 496 return ID;
430 497 }
431 498
432 499 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
433 500 {
501 QTime timeout;
434 502 *buffer=NULL;
435 503 int count=0;
504 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
505 timeout.start();
436 506 while (*buffer==NULL)
437 507 {
438 508 this->RMAP_AnswersMtx->lock();
509 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
510 SocExplorerEngine::message(this->plugin,QString("%2 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
439 511 for(int i=0;i<RMAP_Answers.count();i++)
440 512 {
441 513 if(RMAP_Answers[i]->transactionID==transactionID)
442 514 {
443 515 this->RMAP_pending_transaction_IDsMtx->lock();
516 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
444 517 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
445 518 {
446 519 if(RMAP_pending_transaction_IDs[j]==transactionID)
447 520 {
448 521 RMAP_pending_transaction_IDs.removeAt(j);
449 522 }
450 523 }
451 524 this->RMAP_pending_transaction_IDsMtx->unlock();
452 525 *buffer = RMAP_Answers[i]->data;
453 526 count = RMAP_Answers[i]->len;
454 527 RMAP_Answer* tmp=RMAP_Answers[i];
455 528 RMAP_Answers.removeAt(i);
456 529 delete tmp;
457 530 }
458 531 }
459 532 this->RMAP_AnswersMtx->unlock();
460 533 //if no answer found in the stack wait until a new packet is pushed
461 if(!buffer)
534 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
535 if(*buffer==NULL)
462 536 {
463 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
537 while (0==this->RMAP_AnswersSem->available())
538 {
539 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
540 if(timeout.elapsed()>=RMAPtimeout)
541 {
542 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
543 return -1;
544 }
545 usleep(1000);
546 }
464 547 this->RMAP_AnswersSem->acquire();
465 548 }
466 549 }
467 550 return count;
468 551 }
469 552
470 553 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
471 554 {
472 555 USB_SPACEWIRE_STATUS result;
473 556 USB_SPACEWIRE_ID pIdentifier;
474 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
557 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
475 558 this->handleMutex->lock();
476 559 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
477 560 if (result != TRANSFER_SUCCESS)
478 561 {
479 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
562 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
480 563 this->handleMutex->unlock();
481 564 return false;
482 565 }
483 566 else
484 567 {
485 SocExplorerEngine::message(this->plugin,"Packet sent");
568 SocExplorerEngine::message(this->plugin,"Packet sent",2);
486 569 USBSpaceWire_FreeSend(hDevice, pIdentifier);
487 570 }
488 571 this->handleMutex->unlock();
489 572 return true;
490 573 }
491 574
492 575 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
493 576 {
494 577 char* packetbuffer = (char*)malloc(len);
495 578 memcpy(packetbuffer,packet,len);
496 579 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
497 580 RMAP_AnswersMtx->lock();
498 581 RMAP_Answers.append(RMPAPpacket);
499 582 RMAP_AnswersMtx->unlock();
500 583 }
501 584
502 585
503 586
504 587
505 588
506 589
507 590
508 591
509 592
510 593
511 594
512 595
513 596
514 597
515 598
516 599
517 600
518 601
519 602
520 603
521 604
522 605
@@ -1,104 +1,118
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef STARDUNDEESPW_USB_H
23 23 #define STARDUNDEESPW_USB_H
24 24
25 25 #include <QObject>
26 26 #include <spw_usb_api.h>
27 27 #include <spw_config_library.h>
28 28 #include <socexplorerplugin.h>
29 29 #include <abstractspwbridge.h>
30 30 #include <QThread>
31 31 #include <QMutex>
32 32 #include <QSemaphore>
33 33 #include <QGridLayout>
34 34 #include <QPushButton>
35 35 #include <QComboBox>
36 36 #include <QLabel>
37 37 #include "stardundeegui.h"
38 38
39 39 class RMAP_Answer
40 40 {
41 41 public:
42 42 RMAP_Answer(int ID,char* data,int len)
43 43 {
44 44 transactionID = ID;
45 45 this->data = data;
46 46 this->len = len;
47 47 }
48 48 int transactionID;
49 49 char* data;
50 50 int len;
51 51 };
52 52
53 53 class stardundeeSPW_USB_Manager: public QThread
54 54 {
55 55 Q_OBJECT
56 56 public:
57 57 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
58 58 ~stardundeeSPW_USB_Manager();
59 59 void run();
60 60 bool connectBridge();
61 61 bool disconnectBridge();
62 62 int getRMAPtransactionID();
63 63 int getRMAPanswer(int transactionID,char** buffer);
64 64 bool sendPacket(char* packet,int size);
65
66 signals:
67 void updateAvailableBrickCount(int count);
65 68 private:
66 69 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
67 70 QSemaphore* RMAP_AnswersSem;
68 71 void pushRmapPacket(char* packet,int len);
69 72 star_device_handle hDevice;
70 73 socexplorerplugin* plugin;
71 74 bool connected;
72 75 char* SPWPacketBuff;
73 76 QList<RMAP_Answer*> RMAP_Answers;
74 77 QList<int> RMAP_pending_transaction_IDs;
78
79 public:
80 int selectedBrick;
75 81 int linkNumber;
76 82 int brickList;
83 int linkSpeed;
84 int destinationKey;
85 int rmapAddress;
86 int rmapKey;
87 int RMAPtimeout;
77 88 };
78 89
79 90 class stardundeeSPW_USB : public abstractSpwBridge
80 91 {
81 92 Q_OBJECT
82 93 public:
83 94 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
84 95 ~stardundeeSPW_USB();
85 96
86 97 signals:
87 98
88 99 public slots:
89 100 void toggleBridgeConnection();
90 101 bool connectBridge();
91 102 bool disconnectBridge();
92 103 int pushRMAPPacket(char* packet,int size);
93 104 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
94 105 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
95 void updateAvailableBrickCount(int count);
106 void brickSelectionChanged(int brickIndex);
107 void linkNumberSelectionChanged(int linkIndex);
108 void linkSpeedSelectionChanged(const QString & linkSpeed);
109 void destinationKeyChanged(const QString & destKey);
110 void rmapAddressChanged(const QString & rmapaddress);
111 void rmapKeyChanged(const QString & key);
96 112 private:
97 113 void makeGUI(socexplorerplugin *parent);
98 114 stardundeeSPW_USB_Manager* manager;
99 QGridLayout* mainLayout;
100 QPushButton* connectBridgeButton;
101 QComboBox* selectBrickQcmbx;
115 // QGridLayout* mainLayout;
102 116 };
103 117
104 118 #endif // STARDUNDEESPW_USB_H
General Comments 0
You need to be logged in to leave comments. Login now