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