##// END OF EJS Templates
STAR-Dundee USB Brick driver ready for testing.
STAR-Dundee USB Brick driver ready for testing.

File last commit:

r12:2be2e1f2c5d6 STAR-Dundee USB brick ready for testing default
r12:2be2e1f2c5d6 STAR-Dundee USB brick ready for testing default
Show More
stardundeespw_usb.cpp
607 lines | 24.4 KiB | text/x-c | CppLexer
/ spwplugin / stardundeespw_usb.cpp
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 /*------------------------------------------------------------------------------
-- This file is a part of the SocExplorer Software
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 --
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------*/
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
First init /!\ outdated spwplugin!
r0 #include "stardundeespw_usb.h"
#include <socexplorerengine.h>
#include <qhexedit.h>
stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
abstractSpwBridge(parent)
{
Q_UNUSED(parent)
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 this->manager = new stardundeeSPW_USB_Manager(parent,this);
Sync
r10 makeGUI(parent);
First init /!\ outdated spwplugin!
r0 this->manager->start();
}
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 stardundeeSPW_USB::~stardundeeSPW_USB()
{
this->manager->requestInterruption();
delete this->p_GUI;
}
void stardundeeSPW_USB::toggleBridgeConnection()
{
if(this->plugin->isConnected())
{
if(this->disconnectBridge())
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 ((StarDundeeGUI*)this->p_GUI)->lock(false);
emit setConnected(false);
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 }
}
else
{
if(this->connectBridge())
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 ((StarDundeeGUI*)this->p_GUI)->lock(true);
emit setConnected(true);
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 }
}
}
First init /!\ outdated spwplugin!
r0 bool stardundeeSPW_USB::connectBridge()
{
return this->manager->connectBridge();
}
bool stardundeeSPW_USB::disconnectBridge()
{
return this->manager->disconnectBridge();
}
int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
{
return this->manager->sendPacket(packet,size);
}
unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
{
Jeandet Alexis
Working Snapshot
r1 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 writeBuffer[0]=this->manager->linkNumber;//Link number
First init /!\ outdated spwplugin!
r0 int transactionID = 0;
int written=0;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
Jeandet Alexis
Working Snapshot
r1 QProgressBar* progress=NULL;
if(count>RMAP_MAX_XFER_SIZE)
progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
First init /!\ outdated spwplugin!
r0 //Quite stupide loop, I guess that I always get the number of byte I asked for!
Jeandet Alexis
Working Snapshot
r1 while(count>=RMAP_MAX_XFER_SIZE)
First init /!\ outdated spwplugin!
r0 {
for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
{
Jeandet Alexis
Working Snapshot
r1 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
First init /!\ outdated spwplugin!
r0 }
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
First init /!\ outdated spwplugin!
r0 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
written+=RMAP_MAX_XFER_SIZE;
Jeandet Alexis
Working Snapshot
r1 count-=RMAP_MAX_XFER_SIZE;
progress->setValue(written);
qApp->processEvents();
First init /!\ outdated spwplugin!
r0 }
if(count>0)
{
for(int i=0;i<((int)count);i++)
{
Jeandet Alexis
Working Snapshot
r1 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
First init /!\ outdated spwplugin!
r0 }
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),count*4,writeBuffer+1);
First init /!\ outdated spwplugin!
r0 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
written+=count;
Jeandet Alexis
Working Snapshot
r1 if(progress!=NULL)
{
progress->setValue(written);
qApp->processEvents();
}
}
if(progress!=NULL)
{
SocExplorerEngine::deleteProgressBar(progress);
First init /!\ outdated spwplugin!
r0 }
return written;
}
unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
{
char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
char* RMAP_AnswerBuffer;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 requestBuffer[0]=this->manager->linkNumber;//Link number
First init /!\ outdated spwplugin!
r0 int transactionID = 0;
int read=0;
Jeandet Alexis
Working Snapshot
r1 QProgressBar* progress=NULL;
if(count>RMAP_MAX_XFER_SIZE)
progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
First init /!\ outdated spwplugin!
r0
//Quite stupide loop, I guess that I always get the number of byte I asked for!
while((int)count>=(int)RMAP_MAX_XFER_SIZE)
{
transactionID = manager->getRMAPtransactionID();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
First init /!\ outdated spwplugin!
r0 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 if(len==-1)
{
this->toggleBridgeConnection();
return 0;
}
Jeandet Alexis
Working Snapshot
r1 for(int i=0;i<((len-13)/4);i++)
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Working Snapshot
r1 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
First init /!\ outdated spwplugin!
r0 }
free(RMAP_AnswerBuffer);
read+=RMAP_MAX_XFER_SIZE;
count-=RMAP_MAX_XFER_SIZE;
Jeandet Alexis
Working Snapshot
r1 progress->setValue(read);
qApp->processEvents();
First init /!\ outdated spwplugin!
r0 }
if((int)count>0)
{
transactionID = manager->getRMAPtransactionID();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),count*4,requestBuffer+1);
First init /!\ outdated spwplugin!
r0 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 if(len==-1)
{
this->toggleBridgeConnection();
return 0;
}
Jeandet Alexis
Working Snapshot
r1 for(int i=0;i<((len-13)/4);i++)
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Working Snapshot
r1 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
First init /!\ outdated spwplugin!
r0 }
free(RMAP_AnswerBuffer);
read+=count;
Jeandet Alexis
Working Snapshot
r1 if(progress!=NULL)
{
progress->setValue(read);
qApp->processEvents();
}
}
if(progress!=NULL)
{
SocExplorerEngine::deleteProgressBar(progress);
First init /!\ outdated spwplugin!
r0 }
return read;
}
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
{
this->manager->selectedBrick = brickIndex-1;
SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick));
}
void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
{
this->manager->linkNumber = linkIndex + 1;
SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber));
}
void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
Sync
r10 {
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 this->manager->linkSpeed = linkSpeed.toInt();
Sync
r10
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed));
}
void stardundeeSPW_USB::destinationKeyChanged(const QString &destKey)
{
this->manager->destinationKey = destKey.toInt();
SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->destinationKey));
}
void stardundeeSPW_USB::rmapAddressChanged(const QString &rmapaddress)
{
this->manager->rmapAddress = rmapaddress.toInt();
SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->rmapAddress));
}
void stardundeeSPW_USB::rmapKeyChanged(const QString &key)
{
this->manager->rmapKey = key.toInt();
SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->rmapKey));
Sync
r10 }
Jeandet Alexis
Sync
r9 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 this->p_GUI = new StarDundeeGUI();
// this->mainLayout = new QGridLayout(this->p_GUI);
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(rmapAddressChanged(QString)));
connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapKeyChanged(QString)),this,SLOT(rmapKeyChanged(QString)));
this->brickSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
this->linkNumberSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
this->linkSpeedSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
this->rmapAddressChanged(((StarDundeeGUI*)this->p_GUI)->getRmapAddress());
this->rmapKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey());
Jeandet Alexis
Sync
r9 }
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
First init /!\ outdated spwplugin!
r0 :QThread((QObject*)parent)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 this->RMAPtimeout = 2000;
First init /!\ outdated spwplugin!
r0 this->handleMutex = new QMutex(QMutex::NonRecursive);
this->RMAP_AnswersSem = new QSemaphore(0);
this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
Jeandet Alexis
Space wire plugin GUI Work In Progress.
r8 this->plugin = plugin;
First init /!\ outdated spwplugin!
r0 connected = false;
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 this->moveToThread(this);
First init /!\ outdated spwplugin!
r0 }
stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
{
this->terminate();
while (!this->isFinished()) {
this->usleep(1000);
}
}
void stardundeeSPW_USB_Manager::run()
{
USB_SPACEWIRE_PACKET_PROPERTIES properties;
USB_SPACEWIRE_ID pIdentifier=NULL;
USB_SPACEWIRE_STATUS stat;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
Jeandet Alexis
Working Snapshot
r1 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
First init /!\ outdated spwplugin!
r0 while (!this->isInterruptionRequested())
{
if(this->connected)
{
handleMutex->lock();
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
First init /!\ outdated spwplugin!
r0 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Got packet",2);
Jeandet Alexis
Working Snapshot
r1 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
First init /!\ outdated spwplugin!
r0 if (stat == TRANSFER_SUCCESS)
{
if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
First init /!\ outdated spwplugin!
r0 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
{
SocExplorerEngine::message(this->plugin,"Got end of packet");
if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
Jeandet Alexis
Working Snapshot
r1 if(properties.len>8)
{
char* packetbuffer = (char*)malloc(properties.len);
memcpy(packetbuffer,buffer,properties.len);
USBSpaceWire_FreeRead(hDevice, pIdentifier);
pIdentifier = NULL;
handleMutex->unlock();
RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
RMAP_AnswersMtx->lock();
RMAP_Answers.append(packet);
RMAP_AnswersMtx->unlock();
RMAP_AnswersSem->release();
}
else //it's a RMAP write response
{
USBSpaceWire_FreeRead(hDevice, pIdentifier);
pIdentifier = NULL;
handleMutex->unlock();
}
First init /!\ outdated spwplugin!
r0 }
else //any non-rmap packet will be pushed to the network
{
USBSpaceWire_FreeRead(hDevice, pIdentifier);
handleMutex->unlock();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
First init /!\ outdated spwplugin!
r0 }
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"No EOP received",2);
First init /!\ outdated spwplugin!
r0 }
}
}
else
{
USBSpaceWire_FreeRead(hDevice, pIdentifier);
handleMutex->unlock();
}
}
else
{
USBSpaceWire_FreeRead(hDevice, pIdentifier);
handleMutex->unlock();
}
}
else
{
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 //do some sanity checks!
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 int list = USBSpaceWire_ListDevices();
if(this->brickList!=list)
{
this->brickList = list;
emit updateAvailableBrickCount(this->brickList);
}
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 sleep(1);
First init /!\ outdated spwplugin!
r0 }
usleep(1000);
}
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
First init /!\ outdated spwplugin!
r0 }
bool stardundeeSPW_USB_Manager::connectBridge()
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 QMutexLocker mlock(this->handleMutex);
First init /!\ outdated spwplugin!
r0 int status;
U32 statusControl;
this->connected = false;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
First init /!\ outdated spwplugin!
r0 return false;
}
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
First init /!\ outdated spwplugin!
r0
USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
// Set the path and return path to the device
CFGSpaceWire_StackClear();
CFGSpaceWire_AddrStackPush(0);
CFGSpaceWire_AddrStackPush(254);
CFGSpaceWire_RetAddrStackPush(254);
// set the base transmit rate to 100 MHz
status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
if (status != CFG_TRANSFER_SUCCESS)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
First init /!\ outdated spwplugin!
r0 return false;
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
First init /!\ outdated spwplugin!
r0 }
// read the link status
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
First init /!\ outdated spwplugin!
r0 return false;
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
First init /!\ outdated spwplugin!
r0
// Set the link status control register properties
CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
CFGSpaceWire_LSEnableStart(&statusControl, 1);
CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
CFGSpaceWire_LSEnableTristate(&statusControl, 0);
CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
// Set the link status control register
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
First init /!\ outdated spwplugin!
r0 return false;
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
First init /!\ outdated spwplugin!
r0 }
}
if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
First init /!\ outdated spwplugin!
r0 return false;
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
First init /!\ outdated spwplugin!
r0 }
USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
USBSpaceWire_SetTimeout(hDevice,1.0);
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
First init /!\ outdated spwplugin!
r0 this->connected = true;
return true;
}
bool stardundeeSPW_USB_Manager::disconnectBridge()
{
this->handleMutex->lock();
USBSpaceWire_Close(hDevice); // Close the device
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
First init /!\ outdated spwplugin!
r0 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
this->handleMutex->unlock();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 this->RMAP_pending_transaction_IDsMtx->lock();
this->RMAP_pending_transaction_IDs.clear();
this->RMAP_pending_transaction_IDsMtx->unlock();
this->RMAP_AnswersMtx->lock();
this->RMAP_Answers.clear();
this->RMAP_AnswersMtx->unlock();
this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
First init /!\ outdated spwplugin!
r0 return true;
}
int stardundeeSPW_USB_Manager::getRMAPtransactionID()
{
this->RMAP_pending_transaction_IDsMtx->lock();
int ID=0;
bool found=true;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 while(ID<511)
First init /!\ outdated spwplugin!
r0 {
for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
{
if(RMAP_pending_transaction_IDs[i]==ID)found=false;
}
if(found==true)break;
ID++;
found = true;
}
if(found)
{
RMAP_pending_transaction_IDs.append(ID);
}
this->RMAP_pending_transaction_IDsMtx->unlock();
return ID;
}
int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 QTime timeout;
First init /!\ outdated spwplugin!
r0 *buffer=NULL;
int count=0;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
timeout.start();
First init /!\ outdated spwplugin!
r0 while (*buffer==NULL)
{
this->RMAP_AnswersMtx->lock();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
SocExplorerEngine::message(this->plugin,QString("%2 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
First init /!\ outdated spwplugin!
r0 for(int i=0;i<RMAP_Answers.count();i++)
{
if(RMAP_Answers[i]->transactionID==transactionID)
{
this->RMAP_pending_transaction_IDsMtx->lock();
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
First init /!\ outdated spwplugin!
r0 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
{
if(RMAP_pending_transaction_IDs[j]==transactionID)
{
RMAP_pending_transaction_IDs.removeAt(j);
}
}
this->RMAP_pending_transaction_IDsMtx->unlock();
*buffer = RMAP_Answers[i]->data;
count = RMAP_Answers[i]->len;
RMAP_Answer* tmp=RMAP_Answers[i];
RMAP_Answers.removeAt(i);
delete tmp;
}
}
this->RMAP_AnswersMtx->unlock();
//if no answer found in the stack wait until a new packet is pushed
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
if(*buffer==NULL)
First init /!\ outdated spwplugin!
r0 {
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 while (0==this->RMAP_AnswersSem->available())
{
SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
if(timeout.elapsed()>=RMAPtimeout)
{
SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
return -1;
}
usleep(1000);
}
First init /!\ outdated spwplugin!
r0 this->RMAP_AnswersSem->acquire();
}
}
return count;
}
bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
{
USB_SPACEWIRE_STATUS result;
USB_SPACEWIRE_ID pIdentifier;
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
First init /!\ outdated spwplugin!
r0 this->handleMutex->lock();
result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
if (result != TRANSFER_SUCCESS)
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
First init /!\ outdated spwplugin!
r0 this->handleMutex->unlock();
return false;
}
else
{
Jeandet Alexis
Added disconnection auto-detection to the spacewire plugin.
r11 SocExplorerEngine::message(this->plugin,"Packet sent",2);
First init /!\ outdated spwplugin!
r0 USBSpaceWire_FreeSend(hDevice, pIdentifier);
}
this->handleMutex->unlock();
return true;
}
void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
{
char* packetbuffer = (char*)malloc(len);
memcpy(packetbuffer,packet,len);
RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
RMAP_AnswersMtx->lock();
RMAP_Answers.append(RMPAPpacket);
RMAP_AnswersMtx->unlock();
}