##// END OF EJS Templates
Sync
jeandet -
r10:c68f11fff944 default
parent child
Show More
@@ -0,0 +1,104
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>StarDundeeUI</class>
4 <widget class="QWidget" name="StarDundeeUI">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>614</width>
10 <height>152</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Form</string>
15 </property>
16 <layout class="QFormLayout" name="formLayout">
17 <property name="fieldGrowthPolicy">
18 <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
19 </property>
20 <item row="0" column="0">
21 <widget class="QLabel" name="selectBrickLbl">
22 <property name="text">
23 <string>Select Brick</string>
24 </property>
25 </widget>
26 </item>
27 <item row="0" column="1">
28 <widget class="QComboBox" name="selectBrickCmbx">
29 <item>
30 <property name="text">
31 <string>None</string>
32 </property>
33 </item>
34 </widget>
35 </item>
36 <item row="1" column="0">
37 <widget class="QLabel" name="selectLinkLbl">
38 <property name="text">
39 <string>Select link number</string>
40 </property>
41 </widget>
42 </item>
43 <item row="1" column="1">
44 <widget class="QComboBox" name="selectLinkCmbx">
45 <item>
46 <property name="text">
47 <string>1</string>
48 </property>
49 </item>
50 <item>
51 <property name="text">
52 <string>2</string>
53 </property>
54 </item>
55 </widget>
56 </item>
57 <item row="2" column="0">
58 <widget class="QLabel" name="selectLinkSpeedLbl">
59 <property name="text">
60 <string>Link Speed</string>
61 </property>
62 </widget>
63 </item>
64 <item row="2" column="1">
65 <widget class="QComboBox" name="setLinkSpeedCmbx">
66 <item>
67 <property name="text">
68 <string>10MHz</string>
69 </property>
70 </item>
71 </widget>
72 </item>
73 <item row="3" column="0">
74 <widget class="QLabel" name="setDestKeyLbl">
75 <property name="text">
76 <string>Destination key</string>
77 </property>
78 </widget>
79 </item>
80 <item row="3" column="1">
81 <widget class="QLineEdit" name="destKeyLineEdit">
82 <property name="inputMask">
83 <string comment="009"/>
84 </property>
85 <property name="text">
86 <string>32</string>
87 </property>
88 <property name="maxLength">
89 <number>3</number>
90 </property>
91 </widget>
92 </item>
93 <item row="4" column="1">
94 <widget class="QPushButton" name="pushButton">
95 <property name="text">
96 <string>Connect</string>
97 </property>
98 </widget>
99 </item>
100 </layout>
101 </widget>
102 <resources/>
103 <connections/>
104 </ui>
@@ -0,0 +1,9
1 #include "stardundeegui.h"
2
3 #include "ui_stardundeeGUI.h"
4
5 StarDundeeGUI::StarDundeeGUI(QWidget *parent) :
6 QWidget(parent),ui(new Ui::StarDundeeUI)
7 {
8 this->ui->setupUi(this);
9 }
@@ -0,0 +1,24
1 #ifndef STARDUNDEEGUI_H
2 #define STARDUNDEEGUI_H
3
4 #include <QWidget>
5
6 namespace Ui {
7 class StarDundeeUI;
8 }
9
10 class StarDundeeGUI : public QWidget
11 {
12 Q_OBJECT
13 public:
14 explicit StarDundeeGUI(QWidget *parent = 0);
15
16 signals:
17
18 public slots:
19
20 private:
21 Ui::StarDundeeUI *ui;
22 };
23
24 #endif // STARDUNDEEGUI_H
@@ -1,69 +1,74
1 1 #
2 2 # Project created by QtCreator 2011-09-20T08:15:30
3 3 #
4 4 #-------------------------------------------------
5 5
6 6 CONFIG += socexplorerplugin
7 7 win32:CONFIG += dll
8 8 win32:CONFIG -= static
9 9 CONFIG(debug, debug|release) {
10 10 DEBUG_EXT = _d
11 11 } else {
12 12 DEBUG_EXT =
13 13 }
14 14 TARGET = spwplugin$${DEBUG_EXT}
15 15 DEFINES += PLUGIN=spwplugin
16 16 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
17 17 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
18 18 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
19 19 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
20 20 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
21 21 DEFINES += driver_can_be_root=1
22 22 DEFINES += driver_can_be_child=0
23 23 DEFINES += driver_VID=0
24 24 DEFINES += driver_PID=0
25 25
26 26 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
27 27
28 28 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
29 29 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
30 30
31 31 INCLUDEPATH += \
32 32 $${PWD} \
33 33 $$STARTDUNDEEPATH/inc \
34 34
35 35 HEADERS += \
36 36 spwplugin.h \
37 37 stardundeespw_usb.h \
38 38 abstractspwbridge.h \
39 spw.h
39 spw.h \
40 stardundeegui.h
40 41
41 42
42 43 SOURCES += \
43 44 spwplugin.cpp \
44 45 stardundeespw_usb.cpp \
45 abstractspwbridge.cpp
46 abstractspwbridge.cpp \
47 stardundeegui.cpp
48
49 FORMS += \
50 stardundeeGUI.ui
46 51
47 52
48 53
49 54
50 55
51 56
52 57
53 58
54 59
55 60
56 61
57 62
58 63
59 64
60 65
61 66
62 67
63 68
64 69
65 70
66 71
67 72
68 73
69 74
@@ -1,521 +1,522
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - 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 makeGUI(socexplorerplugin *parent);
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 48 this->connectBridgeButton->setText("Connect");
49 49 }
50 50 }
51 51 else
52 52 {
53 53 if(this->connectBridge())
54 54 {
55 55 this->connectBridgeButton->setText("Disconnect");
56 56 }
57 57 }
58 58 }
59 59
60 60 bool stardundeeSPW_USB::connectBridge()
61 61 {
62 62 return this->manager->connectBridge();
63 63 }
64 64
65 65 bool stardundeeSPW_USB::disconnectBridge()
66 66 {
67 67 return this->manager->disconnectBridge();
68 68 }
69 69
70 70 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
71 71 {
72 72 return this->manager->sendPacket(packet,size);
73 73 }
74 74
75 75 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
76 76 {
77 77 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
78 78 writeBuffer[0]=1;//Link number
79 79 int transactionID = 0;
80 80 int written=0;
81 81 SocExplorerEngine::message(this->plugin,"Enter Write function");
82 82 QProgressBar* progress=NULL;
83 83 if(count>RMAP_MAX_XFER_SIZE)
84 84 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
85 85 //Quite stupide loop, I guess that I always get the number of byte I asked for!
86 86 while(count>=RMAP_MAX_XFER_SIZE)
87 87 {
88 88 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
89 89 {
90 90 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
91 91 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
92 92 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
93 93 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
94 94 }
95 95 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
96 96 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
97 97 written+=RMAP_MAX_XFER_SIZE;
98 98 count-=RMAP_MAX_XFER_SIZE;
99 99 progress->setValue(written);
100 100 qApp->processEvents();
101 101 }
102 102 if(count>0)
103 103 {
104 104 for(int i=0;i<((int)count);i++)
105 105 {
106 106 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
107 107 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
108 108 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
109 109 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
110 110 }
111 111 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
112 112 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
113 113 written+=count;
114 114 if(progress!=NULL)
115 115 {
116 116 progress->setValue(written);
117 117 qApp->processEvents();
118 118 }
119 119 }
120 120 if(progress!=NULL)
121 121 {
122 122 SocExplorerEngine::deleteProgressBar(progress);
123 123 }
124 124 return written;
125 125 }
126 126
127 127 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
128 128 {
129 129 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
130 130 char* RMAP_AnswerBuffer;
131 131 requestBuffer[0]=1;//Link number
132 132 int transactionID = 0;
133 133 int read=0;
134 134 QProgressBar* progress=NULL;
135 135 if(count>RMAP_MAX_XFER_SIZE)
136 136 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
137 137 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
138 138
139 139 //Quite stupide loop, I guess that I always get the number of byte I asked for!
140 140 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
141 141 {
142 142 transactionID = manager->getRMAPtransactionID();
143 143 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
144 144 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
145 145 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
146 146 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
147 147 for(int i=0;i<((len-13)/4);i++)
148 148 {
149 149 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
150 150 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
151 151 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
152 152 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
153 153 }
154 154 free(RMAP_AnswerBuffer);
155 155 read+=RMAP_MAX_XFER_SIZE;
156 156 count-=RMAP_MAX_XFER_SIZE;
157 157 progress->setValue(read);
158 158 qApp->processEvents();
159 159 }
160 160 if((int)count>0)
161 161 {
162 162 transactionID = manager->getRMAPtransactionID();
163 163 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
164 164 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
165 165 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
166 166 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
167 167 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
168 168 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
169 169 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
170 170 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
171 171 for(int i=0;i<((len-13)/4);i++)
172 172 {
173 173 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
174 174 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
175 175 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
176 176 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
177 177 }
178 178 free(RMAP_AnswerBuffer);
179 179 read+=count;
180 180 if(progress!=NULL)
181 181 {
182 182 progress->setValue(read);
183 183 qApp->processEvents();
184 184 }
185 185 }
186 186 if(progress!=NULL)
187 187 {
188 188 SocExplorerEngine::deleteProgressBar(progress);
189 189 }
190 190 return read;
191 191 }
192 192
193 void stardundeeSPW_USB::updateAvailableBrickCount(int count)
194 {
195
196 }
197
193 198 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
194 199 {
195 this->p_GUI = new QWidget(parent);
200 this->p_GUI = new StarDundeeGUI(plugin);
196 201 this->mainLayout = new QGridLayout(this->p_GUI);
197 this->p_GUI->setLayout(mainLayout);
198 this->connectBridgeButton = new QPushButton("Connect");
199 this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1);
200 connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
202 // connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
201 203 }
202 204
203 205 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
204 206 :QThread((QObject*)parent)
205 207 {
206 208 this->handleMutex = new QMutex(QMutex::NonRecursive);
207 209 this->RMAP_AnswersSem = new QSemaphore(0);
208 210 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
209 211 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
210 212 this->plugin = plugin;
211 213 connected = false;
212 214 }
213 215
214 216 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
215 217 {
216 218 this->terminate();
217 219 while (!this->isFinished()) {
218 220 this->usleep(1000);
219 221 }
220 222 }
221 223
222 224
223 225 void stardundeeSPW_USB_Manager::run()
224 226 {
225 227 USB_SPACEWIRE_PACKET_PROPERTIES properties;
226 228 USB_SPACEWIRE_ID pIdentifier=NULL;
227 229 USB_SPACEWIRE_STATUS stat;
228 230 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
229 231 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
230 232 while (!this->isInterruptionRequested())
231 233 {
232 234 if(this->connected)
233 235 {
234 236 handleMutex->lock();
235 237 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
236 238 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
237 239 {
238 240 SocExplorerEngine::message(this->plugin,"Got packet");
239 241 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
240 242 if (stat == TRANSFER_SUCCESS)
241 243 {
242 244 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
243 245 {
244 246 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
245 247 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
246 248 {
247 249 SocExplorerEngine::message(this->plugin,"Got end of packet");
248 250 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
249 251 {
250 252 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
251 253 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
252 254 if(properties.len>8)
253 255 {
254 256 char* packetbuffer = (char*)malloc(properties.len);
255 257 memcpy(packetbuffer,buffer,properties.len);
256 258 USBSpaceWire_FreeRead(hDevice, pIdentifier);
257 259 pIdentifier = NULL;
258 260 handleMutex->unlock();
259 261 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
260 262 RMAP_AnswersMtx->lock();
261 263 RMAP_Answers.append(packet);
262 264 RMAP_AnswersMtx->unlock();
263 265 RMAP_AnswersSem->release();
264 266
265 267 }
266 268 else //it's a RMAP write response
267 269 {
268 270 USBSpaceWire_FreeRead(hDevice, pIdentifier);
269 271 pIdentifier = NULL;
270 272 handleMutex->unlock();
271 273 }
272 274
273 275 }
274 276 else //any non-rmap packet will be pushed to the network
275 277 {
276 278 USBSpaceWire_FreeRead(hDevice, pIdentifier);
277 279 handleMutex->unlock();
278 280 SocExplorerEngine::message(this->plugin,"Got SPW packet");
279 281 }
280 282 }
281 283 else
282 284 {
283 285 SocExplorerEngine::message(this->plugin,"No EOP received");
284 286 }
285 287 }
286 288
287 289 }
288 290 else
289 291 {
290 292 USBSpaceWire_FreeRead(hDevice, pIdentifier);
291 293 handleMutex->unlock();
292 294 }
293 295 }
294 296 else
295 297 {
296 298 USBSpaceWire_FreeRead(hDevice, pIdentifier);
297 299 handleMutex->unlock();
298 300 }
299 301 }
300 302 else
301 303 {
302 304 sleep(1);
303 SocExplorerEngine::message(this->plugin,"Bridge not connected");
305 this->brickList = USBSpaceWire_ListDevices();
304 306 }
305 307 usleep(1000);
306 // sleep(2);
307 308 }
308 309 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
309 310 }
310 311
311 312 bool stardundeeSPW_USB_Manager::connectBridge()
312 313 {
313 314 this->handleMutex->lock();
314 315 int status;
315 316 U32 statusControl;
316 317 int brickNumber=0;
317 318 int linkNumber=1;
318 319 this->connected = false;
319 320 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
320 321 {
321 322 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
322 323 this->handleMutex->unlock();
323 324 return false;
324 325 }
325 326 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
326 327
327 328 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
328 329 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
329 330 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
330 331
331 332 // Set the path and return path to the device
332 333 CFGSpaceWire_StackClear();
333 334 CFGSpaceWire_AddrStackPush(0);
334 335 CFGSpaceWire_AddrStackPush(254);
335 336 CFGSpaceWire_RetAddrStackPush(254);
336 337 // set the base transmit rate to 100 MHz
337 338 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
338 339 if (status != CFG_TRANSFER_SUCCESS)
339 340 {
340 341 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
341 342 return false;
342 343 }
343 344 else
344 345 {
345 346 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
346 347 }
347 348
348 349 // read the link status
349 350 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
350 351 {
351 352 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
352 353 return false;
353 354 }
354 355 else
355 356 {
356 357 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
357 358
358 359 // Set the link status control register properties
359 360 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
360 361 CFGSpaceWire_LSEnableStart(&statusControl, 1);
361 362 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
362 363 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
363 364 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
364 365
365 366 // Set the link status control register
366 367 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
367 368 {
368 369 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
369 370 return false;
370 371 }
371 372 else
372 373 {
373 374 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
374 375 }
375 376 }
376 377
377 378 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
378 379 {
379 380 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
380 381 return false;
381 382 }
382 383 else
383 384 {
384 385 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
385 386 }
386 387
387 388 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
388 389 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
389 390 USBSpaceWire_SetTimeout(hDevice,1.0);
390 391 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
391 392 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
392 393 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
393 394 this->connected = true;
394 395 this->handleMutex->unlock();
395 396 return true;
396 397 }
397 398
398 399 bool stardundeeSPW_USB_Manager::disconnectBridge()
399 400 {
400 401 this->handleMutex->lock();
401 402 USBSpaceWire_Close(hDevice); // Close the device
402 403 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
403 404 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
404 405 this->handleMutex->unlock();
405 406 return true;
406 407 }
407 408
408 409 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
409 410 {
410 411 this->RMAP_pending_transaction_IDsMtx->lock();
411 412 int ID=0;
412 413 bool found=true;
413 414 while(ID<65536)
414 415 {
415 416 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
416 417 {
417 418 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
418 419 }
419 420 if(found==true)break;
420 421 ID++;
421 422 found = true;
422 423 }
423 424 if(found)
424 425 {
425 426 RMAP_pending_transaction_IDs.append(ID);
426 427 }
427 428 this->RMAP_pending_transaction_IDsMtx->unlock();
428 429 return ID;
429 430 }
430 431
431 432 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
432 433 {
433 434 *buffer=NULL;
434 435 int count=0;
435 436 while (*buffer==NULL)
436 437 {
437 438 this->RMAP_AnswersMtx->lock();
438 439 for(int i=0;i<RMAP_Answers.count();i++)
439 440 {
440 441 if(RMAP_Answers[i]->transactionID==transactionID)
441 442 {
442 443 this->RMAP_pending_transaction_IDsMtx->lock();
443 444 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
444 445 {
445 446 if(RMAP_pending_transaction_IDs[j]==transactionID)
446 447 {
447 448 RMAP_pending_transaction_IDs.removeAt(j);
448 449 }
449 450 }
450 451 this->RMAP_pending_transaction_IDsMtx->unlock();
451 452 *buffer = RMAP_Answers[i]->data;
452 453 count = RMAP_Answers[i]->len;
453 454 RMAP_Answer* tmp=RMAP_Answers[i];
454 455 RMAP_Answers.removeAt(i);
455 456 delete tmp;
456 457 }
457 458 }
458 459 this->RMAP_AnswersMtx->unlock();
459 460 //if no answer found in the stack wait until a new packet is pushed
460 461 if(!buffer)
461 462 {
462 463 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
463 464 this->RMAP_AnswersSem->acquire();
464 465 }
465 466 }
466 467 return count;
467 468 }
468 469
469 470 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
470 471 {
471 472 USB_SPACEWIRE_STATUS result;
472 473 USB_SPACEWIRE_ID pIdentifier;
473 474 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
474 475 this->handleMutex->lock();
475 476 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
476 477 if (result != TRANSFER_SUCCESS)
477 478 {
478 479 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
479 480 this->handleMutex->unlock();
480 481 return false;
481 482 }
482 483 else
483 484 {
484 485 SocExplorerEngine::message(this->plugin,"Packet sent");
485 486 USBSpaceWire_FreeSend(hDevice, pIdentifier);
486 487 }
487 488 this->handleMutex->unlock();
488 489 return true;
489 490 }
490 491
491 492 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
492 493 {
493 494 char* packetbuffer = (char*)malloc(len);
494 495 memcpy(packetbuffer,packet,len);
495 496 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
496 497 RMAP_AnswersMtx->lock();
497 498 RMAP_Answers.append(RMPAPpacket);
498 499 RMAP_AnswersMtx->unlock();
499 500 }
500 501
501 502
502 503
503 504
504 505
505 506
506 507
507 508
508 509
509 510
510 511
511 512
512 513
513 514
514 515
515 516
516 517
517 518
518 519
519 520
520 521
521 522
@@ -1,99 +1,104
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - 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 #include <QComboBox>
36 #include <QLabel>
37 #include "stardundeegui.h"
35 38
36 39 class RMAP_Answer
37 40 {
38 41 public:
39 42 RMAP_Answer(int ID,char* data,int len)
40 43 {
41 44 transactionID = ID;
42 45 this->data = data;
43 46 this->len = len;
44 47 }
45 48 int transactionID;
46 49 char* data;
47 50 int len;
48 51 };
49 52
50 53 class stardundeeSPW_USB_Manager: public QThread
51 54 {
52 55 Q_OBJECT
53 56 public:
54 57 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
55 58 ~stardundeeSPW_USB_Manager();
56 59 void run();
57 60 bool connectBridge();
58 61 bool disconnectBridge();
59 62 int getRMAPtransactionID();
60 63 int getRMAPanswer(int transactionID,char** buffer);
61 64 bool sendPacket(char* packet,int size);
62 65 private:
63 66 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
64 67 QSemaphore* RMAP_AnswersSem;
65 68 void pushRmapPacket(char* packet,int len);
66 69 star_device_handle hDevice;
67 70 socexplorerplugin* plugin;
68 71 bool connected;
69 72 char* SPWPacketBuff;
70 73 QList<RMAP_Answer*> RMAP_Answers;
71 74 QList<int> RMAP_pending_transaction_IDs;
72 75 int linkNumber;
76 int brickList;
73 77 };
74 78
75 79 class stardundeeSPW_USB : public abstractSpwBridge
76 80 {
77 81 Q_OBJECT
78 82 public:
79 83 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
80 84 ~stardundeeSPW_USB();
81 85
82 86 signals:
83 87
84 88 public slots:
85 89 void toggleBridgeConnection();
86 90 bool connectBridge();
87 91 bool disconnectBridge();
88 92 int pushRMAPPacket(char* packet,int size);
89 93 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
90 94 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
91
95 void updateAvailableBrickCount(int count);
92 96 private:
93 97 void makeGUI(socexplorerplugin *parent);
94 98 stardundeeSPW_USB_Manager* manager;
95 99 QGridLayout* mainLayout;
96 100 QPushButton* connectBridgeButton;
101 QComboBox* selectBrickQcmbx;
97 102 };
98 103
99 104 #endif // STARDUNDEESPW_USB_H
General Comments 0
You need to be logged in to leave comments. Login now