##// END OF EJS Templates
dsu3plugin: added cacheIsEnable function.
Jeandet Alexis -
r70:a16dfc6c4beb default
parent child
Show More
@@ -1,341 +1,339
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "dsu3plugin.h"
22 #include "dsu3plugin.h"
23 #include <QFileDialog>
23 #include <QFileDialog>
24 #include <QDir>
24 #include <QDir>
25 #include <socexplorerengine.h>
25 #include <socexplorerengine.h>
26
26
27
27
28 struct acceptedMemctrlr_str
28 struct acceptedMemctrlr_str
29 {
29 {
30 int vid;
30 int vid;
31 int pid;
31 int pid;
32 const char* name;
32 const char* name;
33 };
33 };
34
34
35 const struct acceptedMemctrlr_str acceptedMemctrlr[]=
35 const struct acceptedMemctrlr_str acceptedMemctrlr[]=
36 {
36 {
37 {0x04,0x0f,"MCTRL"},
37 {0x04,0x0f,"MCTRL"},
38 {0x01,0x51,"FTSRCTRL"},
38 {0x01,0x51,"FTSRCTRL"},
39 {0x20,0x01,"SRCTRLE_0WS" },
39 {0x20,0x01,"SRCTRLE_0WS" },
40 {0x20,0x02,"SRCTRLE_1WS" }
40 {0x20,0x02,"SRCTRLE_1WS" }
41 };
41 };
42
42
43 #define acceptedMemctrlrCnt 4
43 #define acceptedMemctrlrCnt 4
44
44
45 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
45 dsu3plugin::dsu3plugin(QWidget *parent):socexplorerplugin(parent,false)
46 {
46 {
47 this->UI = new dsu3pluginui();
47 this->UI = new dsu3pluginui();
48 this->setWidget((QWidget*)this->UI);
48 this->setWidget((QWidget*)this->UI);
49 this->elfFile = new ElfFile();
49 this->elfFile = new ElfFile();
50 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
50 connect(this->UI,SIGNAL(openFile()),this,SLOT(openFile()));
51 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
51 connect(this->UI,SIGNAL(flashTarget()),this,SLOT(flashTarget()));
52 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
52 connect(this->UI,SIGNAL(run()),this,SLOT(toggleRun()));
53 connect(this,SIGNAL(updateInfo(ElfFile*)),this->UI,SLOT(updateInfo(ElfFile*)));
53 connect(this,SIGNAL(updateInfo(ElfFile*)),this->UI,SLOT(updateInfo(ElfFile*)));
54 this->running = false;
54 this->running = false;
55 }
55 }
56
56
57
57
58 dsu3plugin::~dsu3plugin()
58 dsu3plugin::~dsu3plugin()
59 {
59 {
60
60
61 }
61 }
62
62
63
63
64 void dsu3plugin::openFile()
64 void dsu3plugin::openFile()
65 {
65 {
66 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
66 QString filename = QFileDialog::getOpenFileName(this,tr("Open elf File"), QDir::homePath(), tr("Elf Files (*)"));
67 if(filename!="")
67 if(filename!="")
68 {
68 {
69 this->openFile(filename);
69 this->openFile(filename);
70 }
70 }
71 }
71 }
72
72
73 void dsu3plugin::openFile(QString fileName)
73 void dsu3plugin::openFile(QString fileName)
74 {
74 {
75 this->elfFile->openFile(fileName);
75 this->elfFile->openFile(fileName);
76 emit this->updateInfo(this->elfFile);
76 emit this->updateInfo(this->elfFile);
77 }
77 }
78
78
79 bool dsu3plugin::configureTarget()
79 bool dsu3plugin::configureTarget()
80 {
80 {
81 int detectedMctrlr=-1;
81 int detectedMctrlr=-1;
82 if(parent==NULL)
82 if(parent==NULL)
83 return false;
83 return false;
84 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
84 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
85 if(DSUBASEADDRESS == (unsigned int)-1)
85 if(DSUBASEADDRESS == (unsigned int)-1)
86 DSUBASEADDRESS = 0x90000000;
86 DSUBASEADDRESS = 0x90000000;
87 unsigned int MCTRLBASEADDRESS =-1;
87 unsigned int MCTRLBASEADDRESS =-1;
88 for(int i=0; i<acceptedMemctrlrCnt;i++)
88 for(int i=0; i<acceptedMemctrlrCnt;i++)
89 {
89 {
90 MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,acceptedMemctrlr[i].vid , acceptedMemctrlr[i].pid,0);
90 MCTRLBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,acceptedMemctrlr[i].vid , acceptedMemctrlr[i].pid,0);
91 if(MCTRLBASEADDRESS != (unsigned int)-1)
91 if(MCTRLBASEADDRESS != (unsigned int)-1)
92 {
92 {
93 SocExplorerEngine::message(this,QString("Found %1 @%2").arg(acceptedMemctrlr[i].name).arg(MCTRLBASEADDRESS,8,16),1);
93 SocExplorerEngine::message(this,QString("Found %1 @%2").arg(acceptedMemctrlr[i].name).arg(MCTRLBASEADDRESS,8,16),1);
94 detectedMctrlr=i;
94 detectedMctrlr=i;
95 break;
95 break;
96 }
96 }
97 }
97 }
98 if(MCTRLBASEADDRESS == (unsigned int)-1)
98 if(MCTRLBASEADDRESS == (unsigned int)-1)
99 {
99 {
100 SocExplorerEngine::message(this,"Can't any compatible memory controller",1);
100 SocExplorerEngine::message(this,"Can't any compatible memory controller",1);
101 return false;
101 return false;
102 }
102 }
103
103
104
104
105 //Force a debug break
105 //Force a debug break
106 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
106 WriteRegs(uIntlist()<<0x0000002f,(unsigned int)DSUBASEADDRESS);
107 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
107 WriteRegs(uIntlist()<<0x0000ffff,(unsigned int)DSUBASEADDRESS+0x20);
108 //Clear time tag counter
108 //Clear time tag counter
109 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
109 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x8);
110
110
111 //Clear ASR registers
111 //Clear ASR registers
112 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
112 WriteRegs(uIntlist()<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400040);
113 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
113 WriteRegs(uIntlist()<<0x2,(unsigned int)DSUBASEADDRESS+0x400024);
114 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
114 WriteRegs(uIntlist()<<0<<0<<0<<0<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
115 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
115 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x48);
116 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
116 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x000004C);
117 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
117 WriteRegs(uIntlist()<<0,(unsigned int)DSUBASEADDRESS+0x400040);
118
118
119 // {0x04,0x0f,"MCTRL"},
119 // {0x04,0x0f,"MCTRL"},
120 // {0x01,0x51,"FTSRCTRL"},
120 // {0x01,0x51,"FTSRCTRL"},
121 // {0x20,0x01,"SRCTRLE_0WS" },
121 // {0x20,0x01,"SRCTRLE_0WS" },
122 // {0x20,0x02,"SRCTRLE_1WS" }
122 // {0x20,0x02,"SRCTRLE_1WS" }
123 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="MCTRL" || QString(acceptedMemctrlr[detectedMctrlr].name)=="FTSRCTRL" )
123 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="MCTRL" || QString(acceptedMemctrlr[detectedMctrlr].name)=="FTSRCTRL" )
124 {
124 {
125 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
125 WriteRegs(uIntlist()<<0x2FF<<0xE60<<0,(unsigned int)MCTRLBASEADDRESS);
126 }
126 }
127 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_0WS" || QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_1WS" )
127 if(QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_0WS" || QString(acceptedMemctrlr[detectedMctrlr].name)=="SRCTRLE_1WS" )
128 {
128 {
129 //let's perform a mem Wash
129 //let's perform a mem Wash
130 unsigned int val = ReadReg(MCTRLBASEADDRESS);
130 unsigned int val = ReadReg(MCTRLBASEADDRESS);
131 val |=1<<31;
131 val |=1<<31;
132 WriteRegs(uIntlist()<<val,(unsigned int)MCTRLBASEADDRESS);
132 WriteRegs(uIntlist()<<val,(unsigned int)MCTRLBASEADDRESS);
133 usleep(1000*1000);
133 usleep(1000*1000);
134 }
134 }
135
135
136
136
137 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
137 WriteRegs(uIntlist()<<0<<0<<0<<0,(unsigned int)DSUBASEADDRESS+0x400060);
138 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
138 WriteRegs(uIntlist()<<0x0000FFFF,(unsigned int)DSUBASEADDRESS+0x24);
139
139
140 memSet(DSUBASEADDRESS+0x300000,0,1567);
140 memSet(DSUBASEADDRESS+0x300000,0,1567);
141 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
141 WriteRegs(uIntlist()<<0<<0xF30000E0<<0x00000002<<0x40000000<<0x40000000<<0x40000004<<0x1000000,(unsigned int)DSUBASEADDRESS+0x400000);
142 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);
142 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);
143 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
143 WriteRegs(uIntlist()<<0x000002EF,(unsigned int)DSUBASEADDRESS);
144
144
145 //Disable interrupts
145 //Disable interrupts
146 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
146 unsigned int APBIRQCTRLRBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x0d,0);
147 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
147 if(APBIRQCTRLRBASEADD == (unsigned int)-1)
148 return false;
148 return false;
149 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
149 WriteRegs(uIntlist()<<0x00000000,APBIRQCTRLRBASEADD+0x040);
150 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
150 WriteRegs(uIntlist()<<0xFFFE0000,APBIRQCTRLRBASEADD+0x080);
151 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
151 WriteRegs(uIntlist()<<0<<0,APBIRQCTRLRBASEADD);
152
152
153 //Set up timer
153 //Set up timer
154 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
154 unsigned int APBTIMERBASEADD = (unsigned int)SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,1,0x11,0);
155 if(APBTIMERBASEADD == (unsigned int)-1)
155 if(APBTIMERBASEADD == (unsigned int)-1)
156 return false;
156 return false;
157 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
157 WriteRegs(uIntlist()<<0xffffffff,APBTIMERBASEADD+0x014);
158 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
158 WriteRegs(uIntlist()<<0x00000018,APBTIMERBASEADD+0x04);
159 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
159 WriteRegs(uIntlist()<<0x00000007,APBTIMERBASEADD+0x018);
160 return true;
160 return true;
161 }
161 }
162
162
163 bool dsu3plugin::cacheDisable()
163 bool dsu3plugin::cacheDisable()
164 {
164 {
165 return setCacheEnable(false);
165 return setCacheEnable(false);
166 }
166 }
167
167
168 bool dsu3plugin::cacheEnable()
168 bool dsu3plugin::cacheEnable()
169 {
169 {
170 return setCacheEnable(true);
170 return setCacheEnable(true);
171 }
171 }
172
172
173 bool dsu3plugin::cacheIsEnable()
174 {
175 if(parent==NULL)
176 return false;
177 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
178 if(DSUBASEADDRESS == (unsigned int)-1)
179 DSUBASEADDRESS = 0x90000000;
180 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
181 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
182 return ((reg&0x0F)==0x0F);
183 }
184
173 bool dsu3plugin::setCacheEnable(bool enabled)
185 bool dsu3plugin::setCacheEnable(bool enabled)
174 {
186 {
175 if(parent==NULL)
187 if(parent==NULL)
176 return false;
188 return false;
177 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
189 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
178 if(DSUBASEADDRESS == (unsigned int)-1)
190 if(DSUBASEADDRESS == (unsigned int)-1)
179 DSUBASEADDRESS = 0x90000000;
191 DSUBASEADDRESS = 0x90000000;
180 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
192 WriteRegs(uIntlist()<<2,DSUBASEADDRESS+0x400024);
181 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
193 unsigned int reg = ReadReg(DSUBASEADDRESS+0x700000);
182 if(enabled)
194 if(enabled)
183 {
195 {
184 WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000);
196 WriteRegs(uIntlist()<<(0x0001000F|reg),DSUBASEADDRESS+0x700000);
185 //flushes cache.
197 //flushes cache.
186 WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000);
198 WriteRegs(uIntlist()<<(0x0061000F|reg),DSUBASEADDRESS+0x700000);
187 }
199 }
188 else
200 else
189 {
201 {
190 WriteRegs(uIntlist()<<((!0x0001000F)&reg),DSUBASEADDRESS+0x700000);
202 WriteRegs(uIntlist()<<((!0x0001000F)&reg),DSUBASEADDRESS+0x700000);
191 WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000);
203 WriteRegs(uIntlist()<<(0x00600000|reg),DSUBASEADDRESS+0x700000);
192 }
204 }
193 return true;
205 return true;
194 }
206 }
195
207
196 bool dsu3plugin::flashTarget()
208 bool dsu3plugin::flashTarget()
197 {
209 {
198 stop();
210 stop();
199 cacheDisable();
211 cacheDisable();
200 configureTarget();
212 configureTarget();
201 /*Write .text*/
213 /*Write .text*/
202 this->writeSection(".text");
214 this->writeSection(".text");
203 /*Write .data*/
215 /*Write .data*/
204 this->writeSection(".data");
216 this->writeSection(".data");
205 return true;
217 return true;
206 }
218 }
207
219
208 void dsu3plugin::run()
220 void dsu3plugin::run()
209 {
221 {
210 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
222 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
211 if(DSUBASEADDRESS == (unsigned int)-1)
223 if(DSUBASEADDRESS == (unsigned int)-1)
212 DSUBASEADDRESS = 0x90000000;
224 DSUBASEADDRESS = 0x90000000;
213 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
225 WriteRegs(uIntlist()<<0,DSUBASEADDRESS+0x020);
214 this->running = true;
226 this->running = true;
215 this->UI->setRunning(true);
227 this->UI->setRunning(true);
216 }
228 }
217
229
218 void dsu3plugin::stop()
230 void dsu3plugin::stop()
219 {
231 {
220 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
232 unsigned int DSUBASEADDRESS = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01 , 0x004,0);
221 if(DSUBASEADDRESS == (unsigned int)-1)
233 if(DSUBASEADDRESS == (unsigned int)-1)
222 DSUBASEADDRESS = 0x90000000;
234 DSUBASEADDRESS = 0x90000000;
223 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
235 WriteRegs(uIntlist()<<0xFFFF,DSUBASEADDRESS+0x020);
224 this->running = false;
236 this->running = false;
225 this->UI->setRunning(false);
237 this->UI->setRunning(false);
226 }
238 }
227
239
228 void dsu3plugin::toggleRun()
240 void dsu3plugin::toggleRun()
229 {
241 {
230 if(this->running)
242 if(this->running)
231 this->stop();
243 this->stop();
232 else
244 else
233 this->run();
245 this->run();
234 }
246 }
235
247
236 bool dsu3plugin::dumpSymbol(const QString &symbolName, QString file, const QString &format)
248 bool dsu3plugin::dumpSymbol(const QString &symbolName, QString file, const QString &format)
237 {
249 {
238 if(this->elfFile->isopened())
250 if(this->elfFile->isopened())
239 {
251 {
240 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
252 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
241 if(symbolIndex!=-1)
253 if(symbolIndex!=-1)
242 return this->dumpMemory(this->elfFile->getSymbolAddress(symbolIndex),this->elfFile->getSymbolSize(symbolIndex)/4,file,format);
254 return this->dumpMemory(this->elfFile->getSymbolAddress(symbolIndex),this->elfFile->getSymbolSize(symbolIndex)/4,file,format);
243 }
255 }
244 return false;
256 return false;
245 }
257 }
246
258
247 QVariantList dsu3plugin::readSymbol(const QString &symbolName)
259 QVariantList dsu3plugin::readSymbol(const QString &symbolName)
248 {
260 {
249 if(this->elfFile->isopened())
261 if(this->elfFile->isopened())
250 {
262 {
251 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
263 int symbolIndex=this->elfFile->getSymbolIndex(symbolName);
252 if(symbolIndex!=-1)
264 if(symbolIndex!=-1)
253 return socexplorerplugin::Read((unsigned int)this->elfFile->getSymbolAddress(symbolIndex),(unsigned int)this->elfFile->getSymbolSize(symbolIndex)/4);
265 return socexplorerplugin::Read((unsigned int)this->elfFile->getSymbolAddress(symbolIndex),(unsigned int)this->elfFile->getSymbolSize(symbolIndex)/4);
254 }
266 }
255 return QVariantList();
267 return QVariantList();
256 }
268 }
257
269
258 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
270 void dsu3plugin::WriteRegs(uIntlist Values, unsigned int address)
259 {
271 {
260 unsigned int* buff;
272 unsigned int* buff;
261 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
273 buff = (unsigned int*)malloc(Values.count()*sizeof(unsigned int));
262 for(int i=0;i<Values.count();i++)
274 for(int i=0;i<Values.count();i++)
263 {
275 {
264 buff[i]=Values.at(i);
276 buff[i]=Values.at(i);
265 }
277 }
266 parent->Write(buff,(unsigned int)Values.count(),address);
278 parent->Write(buff,(unsigned int)Values.count(),address);
267 free(buff);
279 free(buff);
268 }
280 }
269
281
270 unsigned int dsu3plugin::ReadReg(unsigned int address)
282 unsigned int dsu3plugin::ReadReg(unsigned int address)
271 {
283 {
272 unsigned int buff;
284 unsigned int buff;
273 parent->Read(&buff,1,address);
285 parent->Read(&buff,1,address);
274 return buff;
286 return buff;
275 }
287 }
276
288
277 void dsu3plugin::writeSection(int index)
289 void dsu3plugin::writeSection(int index)
278 {
290 {
279 char* buffch=NULL;
291 char* buffch=NULL;
280 unsigned int* buff;
292 unsigned int* buff;
281 int size = this->elfFile->getSectionDatasz(index);
293 int size = this->elfFile->getSectionDatasz(index);
282 int sizeInt = size/4;
294 int sizeInt = size/4;
283 if(parent==NULL)
295 if(parent==NULL)
284 return;
296 return;
285 this->elfFile->getSectionData(index,&buffch);
297 this->elfFile->getSectionData(index,&buffch);
286 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
298 buff = (unsigned int*)malloc(((size/4)+1)*sizeof(unsigned int));
287 for(int i=0;i<sizeInt;i++)
299 for(int i=0;i<sizeInt;i++)
288 {
300 {
289 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
301 buff[i] = 0x0FF & ((unsigned int)buffch[4*i]);
290 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
302 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+1]));
291 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
303 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+2]));
292 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
304 buff[i] = (buff[i]<<8) + (0x0FF & ((unsigned int)buffch[(4*i)+3]));
293 }
305 }
294 if(size%4)
306 if(size%4)
295 {
307 {
296 buff[sizeInt]=0;
308 buff[sizeInt]=0;
297 for(int i=(size%4);i>0;i--)
309 for(int i=(size%4);i>0;i--)
298 {
310 {
299 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
311 buff[sizeInt] = (buff[sizeInt]<<8) + (0x0FF & ((unsigned int)buffch[size-i]));
300 }
312 }
301 sizeInt++;
313 sizeInt++;
302 }
314 }
303 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfFile->getSectionPaddr(index));
315 parent->Write(buff,(unsigned int)sizeInt,(unsigned int)this->elfFile->getSectionPaddr(index));
304 free(buff);
316 free(buff);
305 }
317 }
306
318
307 void dsu3plugin::writeSection(const QString &name)
319 void dsu3plugin::writeSection(const QString &name)
308 {
320 {
309 if(elfFile->isopened())
321 if(elfFile->isopened())
310 {
322 {
311 writeSection(this->elfFile->getSectionIndex(name));
323 writeSection(this->elfFile->getSectionIndex(name));
312 }
324 }
313 }
325 }
314
326
315
327
316 unsigned int dsu3plugin::Write(unsigned int *Value,unsigned int count,unsigned int address)
317 {
318 if(parent!=NULL)
319 return parent->Write(Value,count,address);
320 return 0;
321 }
322
323 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
328 bool dsu3plugin::memSet(unsigned int address,int value, unsigned int count)
324 {
329 {
325 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
330 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
326 if(buffer!=NULL)
331 if(buffer!=NULL)
327 {
332 {
328 memset((void*)buffer,value,count*sizeof(unsigned int));
333 memset((void*)buffer,value,count*sizeof(unsigned int));
329 parent->Write(buffer,count,address);
334 parent->Write(buffer,count,address);
330 free(buffer );
335 free(buffer );
331 return true;
336 return true;
332 }
337 }
333 return false;
338 return false;
334 }
339 }
335
336 unsigned int dsu3plugin::Read(unsigned int *Value,unsigned int count, unsigned int address)
337 {
338 if(parent!=NULL)
339 return parent->Read(Value,count,address);
340 return 0;
341 }
@@ -1,73 +1,72
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef DSU3PLUGIN_H
22 #ifndef DSU3PLUGIN_H
23 #define DSU3PLUGIN_H
23 #define DSU3PLUGIN_H
24 #include "dsu3pluginui.h"
24 #include "dsu3pluginui.h"
25 #include <QMenuBar>
25 #include <QMenuBar>
26 #include <QMenu>
26 #include <QMenu>
27 #include <QAction>
27 #include <QAction>
28 #include <QMainWindow>
28 #include <QMainWindow>
29 #include <QList>
29 #include <QList>
30 #include "elfparser.h"
30 #include "elfparser.h"
31 #include <elffile.h>
31 #include <elffile.h>
32 #include <socexplorerplugin.h>
32 #include <socexplorerplugin.h>
33 #include <socexplorerengine.h>
33 #include <socexplorerengine.h>
34
34
35 typedef QList<unsigned int> uIntlist;
35 typedef QList<unsigned int> uIntlist;
36
36
37 class dsu3plugin : public socexplorerplugin
37 class dsu3plugin : public socexplorerplugin
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40 public:
40 public:
41 explicit dsu3plugin(QWidget *parent = 0);
41 explicit dsu3plugin(QWidget *parent = 0);
42 ~dsu3plugin();
42 ~dsu3plugin();
43 bool memSet(unsigned int address, int value, unsigned int count);
43 bool memSet(unsigned int address, int value, unsigned int count);
44 public slots:
44 public slots:
45 unsigned int Write(unsigned int *Value,unsigned int count,unsigned int address=0);
46 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
47 void openFile();
45 void openFile();
48 void openFile(QString fileName);
46 void openFile(QString fileName);
49 bool configureTarget();
47 bool configureTarget();
50 bool cacheDisable();
48 bool cacheDisable();
51 bool cacheEnable();
49 bool cacheEnable();
50 bool cacheIsEnable();
52 bool setCacheEnable(bool enabled);
51 bool setCacheEnable(bool enabled);
53 bool flashTarget();
52 bool flashTarget();
54 void run();
53 void run();
55 void stop();
54 void stop();
56 void toggleRun();
55 void toggleRun();
57 //added for python backward compatibility
56 //added for python backward compatibility
58 void loadFile(){this->flashTarget();}
57 void loadFile(){this->flashTarget();}
59 bool dumpSymbol(const QString& symbolName,QString file,const QString& format);
58 bool dumpSymbol(const QString& symbolName,QString file,const QString& format);
60 QVariantList readSymbol(const QString& symbolName);
59 QVariantList readSymbol(const QString& symbolName);
61 signals:
60 signals:
62 void updateInfo(ElfFile* elfFile);
61 void updateInfo(ElfFile* elfFile);
63 private:
62 private:
64 void WriteRegs(uIntlist Values, unsigned int address);
63 void WriteRegs(uIntlist Values, unsigned int address);
65 unsigned int ReadReg(unsigned int address);
64 unsigned int ReadReg(unsigned int address);
66 void writeSection(int index);
65 void writeSection(int index);
67 void writeSection(const QString& name);
66 void writeSection(const QString& name);
68 dsu3pluginui* UI;
67 dsu3pluginui* UI;
69 ElfFile* elfFile;
68 ElfFile* elfFile;
70 bool running;
69 bool running;
71 };
70 };
72
71
73 #endif // DSU3PLUGIN_H
72 #endif // DSU3PLUGIN_H
@@ -1,1108 +1,1108
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22
22
23 #include "stardundeespw_usb.h"
23 #include "stardundeespw_usb.h"
24 #include "fakestardundeespwusb_lib.h"
24 #include "fakestardundeespwusb_lib.h"
25 #include <socexplorerengine.h>
25 #include <socexplorerengine.h>
26 #include <qhexedit.h>
26 #include <qhexedit.h>
27
27
28 QString dwLinkStatusQString[6] = {
28 const QString dwLinkStatusQString[6] = {
29 "CFG_SPACEWIRE_ERROR_RESET",
29 "CFG_SPACEWIRE_ERROR_RESET",
30 "CFG_SPACEWIRE_ERROR_WAIT",
30 "CFG_SPACEWIRE_ERROR_WAIT",
31 "CFG_SPACEWIRE_READY",
31 "CFG_SPACEWIRE_READY",
32 "CFG_SPACEWIRE_STARTED",
32 "CFG_SPACEWIRE_STARTED",
33 "CFG_SPACEWIRE_CONNECTING",
33 "CFG_SPACEWIRE_CONNECTING",
34 "CFG_SPACEWIRE_RUN"
34 "CFG_SPACEWIRE_RUN"
35 };
35 };
36
36
37 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
37 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
38 abstractSpwBridge(parent)
38 abstractSpwBridge(parent)
39 {
39 {
40 Q_UNUSED(parent)
40 Q_UNUSED(parent)
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
42 makeGUI(parent);
42 makeGUI(parent);
43 this->manager->start();
43 this->manager->start();
44 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
44 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
45 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
45 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
46 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
46 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
47 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
47 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
48 }
48 }
49
49
50 stardundeeSPW_USB::~stardundeeSPW_USB()
50 stardundeeSPW_USB::~stardundeeSPW_USB()
51 {
51 {
52 this->manager->requestInterruption();
52 this->manager->requestInterruption();
53 while(this->manager->isRunning());
53 while(this->manager->isRunning());
54 }
54 }
55
55
56 void stardundeeSPW_USB::toggleBridgeConnection()
56 void stardundeeSPW_USB::toggleBridgeConnection()
57 {
57 {
58 if(this->plugin->isConnected())
58 if(this->plugin->isConnected())
59 {
59 {
60 this->disconnectBridge();
60 this->disconnectBridge();
61 }
61 }
62 else
62 else
63 {
63 {
64 this->connectBridge();
64 this->connectBridge();
65 }
65 }
66 }
66 }
67
67
68 bool stardundeeSPW_USB::connectBridge()
68 bool stardundeeSPW_USB::connectBridge()
69 {
69 {
70 if(this->manager->connectBridge())
70 if(this->manager->connectBridge())
71 {
71 {
72 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
72 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
73 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
73 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
74 ((StarDundeeGUI*)this->p_GUI)->lock(true);
74 ((StarDundeeGUI*)this->p_GUI)->lock(true);
75 emit setConnected(true);
75 emit setConnected(true);
76 return true;
76 return true;
77 }
77 }
78 return false;
78 return false;
79 }
79 }
80
80
81 bool stardundeeSPW_USB::disconnectBridge()
81 bool stardundeeSPW_USB::disconnectBridge()
82 {
82 {
83 if(this->manager->disconnectBridge())
83 if(this->manager->disconnectBridge())
84 {
84 {
85 ((StarDundeeGUI*)this->p_GUI)->lock(false);
85 ((StarDundeeGUI*)this->p_GUI)->lock(false);
86 emit setConnected(false);
86 emit setConnected(false);
87 return true;
87 return true;
88 }
88 }
89 return false;
89 return false;
90 }
90 }
91
91
92 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
92 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
93 {
93 {
94 return this->manager->sendPacket(packet,size);
94 return this->manager->sendPacket(packet,size);
95 }
95 }
96
96
97 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
97 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
98 {
98 {
99 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
99 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
100 char *RMAPAckBuff;
100 char *RMAPAckBuff;
101 writeBuffer[0]=this->manager->linkNumber;//Link number
101 writeBuffer[0]=this->manager->linkNumber;//Link number
102 int transactionID = 0;
102 int transactionID = 0;
103 int written=0;
103 int written=0;
104 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
104 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
105 QProgressBar* progress=NULL;
105 QProgressBar* progress=NULL;
106 SocExplorerAutoProgressBar autopb;
106 SocExplorerAutoProgressBar autopb;
107 if(count>RMAP_MAX_XFER_SIZE)
107 if(count>RMAP_MAX_XFER_SIZE)
108 {
108 {
109 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
109 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
110 autopb.setProgressBar(progress);
110 autopb.setProgressBar(progress);
111 }
111 }
112 //Quite stupide loop, I guess that I always get the number of byte I asked for!
112 //Quite stupide loop, I guess that I always get the number of byte I asked for!
113 while(count>=RMAP_MAX_XFER_SIZE)
113 while(count>=RMAP_MAX_XFER_SIZE)
114 {
114 {
115 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
115 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
116 {
116 {
117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
120 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
120 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
121 }
121 }
122 transactionID=manager->getRMAPtransactionID();
122 transactionID=manager->getRMAPtransactionID();
123 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
123 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
124 RMAP_build_tx_request_header(
124 RMAP_build_tx_request_header(
125 this->manager->destinationLogicalAddress,
125 this->manager->destinationLogicalAddress,
126 this->manager->destinationKey,
126 this->manager->destinationKey,
127 this->manager->sourceLogicalAddress,
127 this->manager->sourceLogicalAddress,
128 transactionID,
128 transactionID,
129 address+(written*4),
129 address+(written*4),
130 RMAP_MAX_XFER_SIZE*4,
130 RMAP_MAX_XFER_SIZE*4,
131 writeBuffer+1);
131 writeBuffer+1);
132 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
132 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
133 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
133 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
134 free(RMAPAckBuff);
134 free(RMAPAckBuff);
135 written+=RMAP_MAX_XFER_SIZE;
135 written+=RMAP_MAX_XFER_SIZE;
136 count-=RMAP_MAX_XFER_SIZE;
136 count-=RMAP_MAX_XFER_SIZE;
137 progress->setValue(written);
137 progress->setValue(written);
138 qApp->processEvents();
138 qApp->processEvents();
139 }
139 }
140 if(count>0)
140 if(count>0)
141 {
141 {
142 for(int i=0;i<((int)count);i++)
142 for(int i=0;i<((int)count);i++)
143 {
143 {
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
147 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
147 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
148 }
148 }
149 transactionID=manager->getRMAPtransactionID();
149 transactionID=manager->getRMAPtransactionID();
150 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
150 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
151 RMAP_build_tx_request_header(
151 RMAP_build_tx_request_header(
152 this->manager->destinationLogicalAddress,
152 this->manager->destinationLogicalAddress,
153 this->manager->destinationKey,
153 this->manager->destinationKey,
154 this->manager->sourceLogicalAddress,
154 this->manager->sourceLogicalAddress,
155 transactionID,
155 transactionID,
156 address+(written*4),
156 address+(written*4),
157 count*4,
157 count*4,
158 writeBuffer+1);
158 writeBuffer+1);
159 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
159 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
160 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
160 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
161 free(RMAPAckBuff);
161 free(RMAPAckBuff);
162 written+=count;
162 written+=count;
163 if(progress!=NULL)
163 if(progress!=NULL)
164 {
164 {
165 progress->setValue(written);
165 progress->setValue(written);
166 qApp->processEvents();
166 qApp->processEvents();
167 }
167 }
168 }
168 }
169 return written;
169 return written;
170 }
170 }
171
171
172 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
172 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
173 {
173 {
174 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
174 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
175 char* RMAP_AnswerBuffer;
175 char* RMAP_AnswerBuffer;
176 requestBuffer[0]=this->manager->linkNumber;//Link number
176 requestBuffer[0]=this->manager->linkNumber;//Link number
177 int transactionID = 0;
177 int transactionID = 0;
178 int read=0;
178 int read=0;
179 QProgressBar* progress=NULL;
179 QProgressBar* progress=NULL;
180 SocExplorerAutoProgressBar autopb;
180 SocExplorerAutoProgressBar autopb;
181 if(count>RMAP_MAX_XFER_SIZE)
181 if(count>RMAP_MAX_XFER_SIZE)
182 {
182 {
183 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
183 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
184 autopb.setProgressBar(progress);
184 autopb.setProgressBar(progress);
185 }
185 }
186 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
186 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
187
187
188 //Quite stupide loop, I guess that I always get the number of byte I asked for!
188 //Quite stupide loop, I guess that I always get the number of byte I asked for!
189 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
189 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
190 {
190 {
191 transactionID = manager->getRMAPtransactionID();
191 transactionID = manager->getRMAPtransactionID();
192 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
192 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
193 RMAP_build_rx_request_header(
193 RMAP_build_rx_request_header(
194 this->manager->destinationLogicalAddress,
194 this->manager->destinationLogicalAddress,
195 this->manager->destinationKey,
195 this->manager->destinationKey,
196 this->manager->sourceLogicalAddress,
196 this->manager->sourceLogicalAddress,
197 transactionID,
197 transactionID,
198 address+(read*4),
198 address+(read*4),
199 RMAP_MAX_XFER_SIZE*4,
199 RMAP_MAX_XFER_SIZE*4,
200 requestBuffer+1);
200 requestBuffer+1);
201 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
201 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
202 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
202 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
203 if(len==-1)
203 if(len==-1)
204 {
204 {
205 this->toggleBridgeConnection();
205 this->toggleBridgeConnection();
206 return 0;
206 return 0;
207 }
207 }
208 for(int i=0;i<((len-13)/4);i++)
208 for(int i=0;i<((len-13)/4);i++)
209 {
209 {
210 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
210 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
213 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
213 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
214 }
214 }
215 free(RMAP_AnswerBuffer);
215 free(RMAP_AnswerBuffer);
216 read+=RMAP_MAX_XFER_SIZE;
216 read+=RMAP_MAX_XFER_SIZE;
217 count-=RMAP_MAX_XFER_SIZE;
217 count-=RMAP_MAX_XFER_SIZE;
218 progress->setValue(read);
218 progress->setValue(read);
219 qApp->processEvents();
219 qApp->processEvents();
220 }
220 }
221 if((int)count>0)
221 if((int)count>0)
222 {
222 {
223 transactionID = manager->getRMAPtransactionID();
223 transactionID = manager->getRMAPtransactionID();
224 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
224 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
225 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
225 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
226 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
226 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
227 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
227 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
228 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
228 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
229 RMAP_build_rx_request_header(
229 RMAP_build_rx_request_header(
230 this->manager->destinationLogicalAddress,
230 this->manager->destinationLogicalAddress,
231 this->manager->destinationKey,
231 this->manager->destinationKey,
232 this->manager->sourceLogicalAddress,
232 this->manager->sourceLogicalAddress,
233 transactionID,
233 transactionID,
234 address+(read*4),
234 address+(read*4),
235 count*4,
235 count*4,
236 requestBuffer+1);
236 requestBuffer+1);
237 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
237 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
238 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
238 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
239 if(len==-1)
239 if(len==-1)
240 {
240 {
241 this->toggleBridgeConnection();
241 this->toggleBridgeConnection();
242 return 0;
242 return 0;
243 }
243 }
244 for(int i=0;i<((len-13)/4);i++)
244 for(int i=0;i<((len-13)/4);i++)
245 {
245 {
246 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
246 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
247 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
247 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
248 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
248 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
249 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
249 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
250 }
250 }
251 free(RMAP_AnswerBuffer);
251 free(RMAP_AnswerBuffer);
252 read+=count;
252 read+=count;
253 if(progress!=NULL)
253 if(progress!=NULL)
254 {
254 {
255 progress->setValue(read);
255 progress->setValue(read);
256 qApp->processEvents();
256 qApp->processEvents();
257 }
257 }
258 }
258 }
259 return read;
259 return read;
260 }
260 }
261
261
262 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
262 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
263 {
263 {
264 this->manager->selectedBrick = brickIndex-1;
264 this->manager->selectedBrick = brickIndex-1;
265 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
265 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
266 }
266 }
267
267
268 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
268 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
269 {
269 {
270 this->manager->linkNumber = linkIndex + 1;
270 this->manager->linkNumber = linkIndex + 1;
271 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
271 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
272 }
272 }
273
273
274 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
274 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
275 {
275 {
276 this->manager->linkSpeed = linkSpeed.toInt();
276 this->manager->linkSpeed = linkSpeed.toInt();
277
277
278 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
278 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
279 }
279 }
280
280
281 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
281 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
282 {
282 {
283 this->manager->sourceLogicalAddress = sourceAddress.toInt();
283 this->manager->sourceLogicalAddress = sourceAddress.toInt();
284 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
284 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
285 }
285 }
286
286
287 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
287 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
288 {
288 {
289 this->manager->destinationLogicalAddress = rmapaddress.toInt();
289 this->manager->destinationLogicalAddress = rmapaddress.toInt();
290 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
290 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
291 }
291 }
292
292
293 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
293 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
294 {
294 {
295 this->manager->destinationKey = key.toInt();
295 this->manager->destinationKey = key.toInt();
296 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
296 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
297 }
297 }
298
298
299 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
299 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
300 {
300 {
301 this->manager->interfaceMode = interfaceMode;
301 this->manager->interfaceMode = interfaceMode;
302 }
302 }
303
303
304 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
304 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
305 {
305 {
306 this->manager->timecodeFrequency = frequency.toDouble();
306 this->manager->timecodeFrequency = frequency.toDouble();
307 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
307 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
308 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
308 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
309 }
309 }
310
310
311 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
311 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
312 {
312 {
313 this->manager->sendTimecodePeriodically( onOff );
313 this->manager->sendTimecodePeriodically( onOff );
314 }
314 }
315
315
316 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
316 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
317 {
317 {
318 int tim=timeout.toInt();
318 int tim=timeout.toInt();
319 if(tim<50)
319 if(tim<50)
320 {
320 {
321 tim = 50;
321 tim = 50;
322 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
322 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
323 }
323 }
324 this->manager->RMAPtimeout = tim;
324 this->manager->RMAPtimeout = tim;
325 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
325 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
326 }
326 }
327
327
328 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
328 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
329 {
329 {
330 Q_UNUSED(parent)
330 Q_UNUSED(parent)
331 this->p_GUI = new StarDundeeGUI();
331 this->p_GUI = new StarDundeeGUI();
332 // this->mainLayout = new QGridLayout(this->p_GUI);
332 // this->mainLayout = new QGridLayout(this->p_GUI);
333 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
333 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
334 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
334 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
344 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
344 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
345
345
346 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
346 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
347 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
347 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
348 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
348 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
349 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
349 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
350 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
350 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
351 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
351 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
352 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
352 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
353 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
353 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
354
354
355 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
355 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
356 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
356 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
357 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
357 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
358 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
358 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
359 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
359 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
360 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
360 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
361 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
361 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
362 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
362 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
363 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
363 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
364 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
364 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
365 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
365 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
366 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
366 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
367 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
367 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
368 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
368 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
369 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
369 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
370 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
370 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
371 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
371 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
372 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
372 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
373
373
374 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
374 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
375 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
375 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
376 }
376 }
377
377
378 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
378 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
379 {
379 {
380 char* data;
380 char* data;
381 int i;
381 int i;
382
382
383 data = (char *) malloc( size + 5 );
383 data = (char *) malloc( size + 5 );
384
384
385 data[0] = this->manager->linkNumber;
385 data[0] = this->manager->linkNumber;
386 data[1] = this->manager->destinationLogicalAddress; // target logical address
386 data[1] = this->manager->destinationLogicalAddress; // target logical address
387 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
387 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
388 data[3] = 0x00; // reserved
388 data[3] = 0x00; // reserved
389 data[4] = 0x00; // user application
389 data[4] = 0x00; // user application
390
390
391 for ( i=0; i<size; i++ )
391 for ( i=0; i<size; i++ )
392 {
392 {
393 data[i+5] = packet[i];
393 data[i+5] = packet[i];
394 }
394 }
395
395
396 this->manager->sendPacket( data, size + 5);
396 this->manager->sendPacket( data, size + 5);
397
397
398 free(data);
398 free(data);
399 free(packet);
399 free(packet);
400 }
400 }
401
401
402 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
402 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
403 :QThread((QObject*)parent)
403 :QThread((QObject*)parent)
404 {
404 {
405 this->RMAPtimeout = 2000;
405 this->RMAPtimeout = 2000;
406 this->handleMutex = new QMutex(QMutex::NonRecursive);
406 this->handleMutex = new QMutex(QMutex::NonRecursive);
407 // this->handleMutex = new QMutex(QMutex::Recursive);
407 // this->handleMutex = new QMutex(QMutex::Recursive);
408 this->RMAP_AnswersSem = new QSemaphore(0);
408 this->RMAP_AnswersSem = new QSemaphore(0);
409 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
409 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
410 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
410 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
411 this->plugin = plugin;
411 this->plugin = plugin;
412 connected = false;
412 connected = false;
413 // TODO remove this crap!
413 // TODO remove this crap!
414 this->initDialog();
414 this->initDialog();
415 // this->moveToThread(this);
415 // this->moveToThread(this);
416 }
416 }
417
417
418 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
418 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
419 {
419 {
420 this->terminate();
420 this->terminate();
421 while (!this->isFinished()) {
421 while (!this->isFinished()) {
422 this->usleep(1000);
422 this->usleep(1000);
423 }
423 }
424 }
424 }
425
425
426 void stardundeeSPW_USB_Manager::run()
426 void stardundeeSPW_USB_Manager::run()
427 {
427 {
428 USB_SPACEWIRE_PACKET_PROPERTIES properties;
428 USB_SPACEWIRE_PACKET_PROPERTIES properties;
429 USB_SPACEWIRE_ID pIdentifier=NULL;
429 USB_SPACEWIRE_ID pIdentifier=NULL;
430 USB_SPACEWIRE_STATUS stat;
430 USB_SPACEWIRE_STATUS stat;
431 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
431 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
432 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
432 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
433 while (!this->isInterruptionRequested())
433 while (!this->isInterruptionRequested())
434 {
434 {
435 if(this->connected)
435 if(this->connected)
436 {
436 {
437 this->handleMutex->lock();
437 this->handleMutex->lock();
438 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
438 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
439 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
439 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
440 {
440 {
441 SocExplorerEngine::message(this->plugin,"Got packet",2);
441 SocExplorerEngine::message(this->plugin,"Got packet",2);
442 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
442 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
443 if (stat == TRANSFER_SUCCESS)
443 if (stat == TRANSFER_SUCCESS)
444 {
444 {
445 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
445 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
446 {
446 {
447 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
447 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
448 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
448 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
449 {
449 {
450 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
450 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
451 emit bytesReceivedFromSpw( properties.len );
451 emit bytesReceivedFromSpw( properties.len );
452 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
452 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
453 {
453 {
454 RMAP_Answer* packet;
454 RMAP_Answer* packet;
455 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
455 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
456 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
456 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
457 char* packetbuffer = (char*)malloc(properties.len);
457 char* packetbuffer = (char*)malloc(properties.len);
458 memcpy(packetbuffer,buffer,properties.len);
458 memcpy(packetbuffer,buffer,properties.len);
459 USBSpaceWire_FreeRead(hDevice, pIdentifier);
459 USBSpaceWire_FreeRead(hDevice, pIdentifier);
460 pIdentifier = NULL;
460 pIdentifier = NULL;
461 this->handleMutex->unlock();
461 this->handleMutex->unlock();
462 if(properties.len==8)
462 if(properties.len==8)
463 {
463 {
464 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
464 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
465 }
465 }
466 else
466 else
467 {
467 {
468 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
468 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
469 }
469 }
470 RMAP_AnswersMtx->lock();
470 RMAP_AnswersMtx->lock();
471 RMAP_Answers.append(packet);
471 RMAP_Answers.append(packet);
472 RMAP_AnswersMtx->unlock();
472 RMAP_AnswersMtx->unlock();
473 RMAP_AnswersSem->release();
473 RMAP_AnswersSem->release();
474 }
474 }
475 else //any non-rmap packet will be pushed to the network
475 else //any non-rmap packet will be pushed to the network
476 {
476 {
477 char* packetbuffer = (char*)malloc(properties.len);
477 char* packetbuffer = (char*)malloc(properties.len);
478 memcpy(packetbuffer,buffer,properties.len);
478 memcpy(packetbuffer,buffer,properties.len);
479 emit emitPacket(packetbuffer,properties.len);
479 emit emitPacket(packetbuffer,properties.len);
480 USBSpaceWire_FreeRead(hDevice, pIdentifier);
480 USBSpaceWire_FreeRead(hDevice, pIdentifier);
481 this->handleMutex->unlock();
481 this->handleMutex->unlock();
482 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
482 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
483 }
483 }
484 }
484 }
485 else
485 else
486 {
486 {
487 SocExplorerEngine::message(this->plugin,"No EOP received",2);
487 SocExplorerEngine::message(this->plugin,"No EOP received",2);
488 this->handleMutex->unlock();
488 this->handleMutex->unlock();
489 }
489 }
490 }
490 }
491
491
492 }
492 }
493 else
493 else
494 {
494 {
495 USBSpaceWire_FreeRead(hDevice, pIdentifier);
495 USBSpaceWire_FreeRead(hDevice, pIdentifier);
496 this->handleMutex->unlock();
496 this->handleMutex->unlock();
497 }
497 }
498 }
498 }
499 else
499 else
500 {
500 {
501 USBSpaceWire_FreeRead(hDevice, pIdentifier);
501 USBSpaceWire_FreeRead(hDevice, pIdentifier);
502 this->handleMutex->unlock();
502 this->handleMutex->unlock();
503 }
503 }
504 }
504 }
505 else
505 else
506 {
506 {
507 //do some sanity checks!
507 //do some sanity checks!
508 int list = USBSpaceWire_ListDevices();
508 int list = USBSpaceWire_ListDevices();
509 if(this->brickList!=list)
509 if(this->brickList!=list)
510 {
510 {
511 this->brickList = list;
511 this->brickList = list;
512 emit updateAvailableBrickCount(this->brickList);
512 emit updateAvailableBrickCount(this->brickList);
513 }
513 }
514 usleep(RMAPtimeout/2);
514 usleep(RMAPtimeout/2);
515 }
515 }
516 usleep(1000);
516 usleep(1000);
517 }
517 }
518 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
518 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
519 }
519 }
520
520
521 bool stardundeeSPW_USB_Manager::connectBridge()
521 bool stardundeeSPW_USB_Manager::connectBridge()
522 {
522 {
523 bool ret;
523 bool ret;
524
524
525 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
525 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
526 {
526 {
527 ret = connectBridgeAsInterface();
527 ret = connectBridgeAsInterface();
528 }
528 }
529 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
529 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
530 {
530 {
531 ret = connectBridgeAsRouter();
531 ret = connectBridgeAsRouter();
532 }
532 }
533 else
533 else
534 {
534 {
535 ret = false;
535 ret = false;
536 }
536 }
537
537
538 return ret;
538 return ret;
539 }
539 }
540
540
541 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
541 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
542 {
542 {
543 this->handleMutex->lock();
543 this->handleMutex->lock();
544 int status;
544 int status;
545 U32 statusControl;
545 U32 statusControl;
546 this->connected = false;
546 this->connected = false;
547 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
547 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
548 {
548 {
549 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
549 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
550 this->handleMutex->unlock();
550 this->handleMutex->unlock();
551 return false;
551 return false;
552 }
552 }
553 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
553 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
554
554
555 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
555 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
556 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
556 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
557 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
557 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
558
558
559 // Set the path and return path to the device
559 // Set the path and return path to the device
560 CFGSpaceWire_StackClear();
560 CFGSpaceWire_StackClear();
561 CFGSpaceWire_AddrStackPush(0);
561 CFGSpaceWire_AddrStackPush(0);
562 CFGSpaceWire_AddrStackPush(254);
562 CFGSpaceWire_AddrStackPush(254);
563 CFGSpaceWire_RetAddrStackPush(254);
563 CFGSpaceWire_RetAddrStackPush(254);
564 // set the base transmit rate to 100 MHz
564 // set the base transmit rate to 100 MHz
565 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
565 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
566 if (status != CFG_TRANSFER_SUCCESS)
566 if (status != CFG_TRANSFER_SUCCESS)
567 {
567 {
568 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
568 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
569 this->handleMutex->unlock();
569 this->handleMutex->unlock();
570 return false;
570 return false;
571 }
571 }
572 else
572 else
573 {
573 {
574 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
574 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
575 }
575 }
576
576
577 // read the link status
577 // read the link status
578 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
578 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
579 {
579 {
580 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
580 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
581 this->handleMutex->unlock();
581 this->handleMutex->unlock();
582 return false;
582 return false;
583 }
583 }
584 else
584 else
585 {
585 {
586 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
586 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
587
587
588 // Set the link status control register properties
588 // Set the link status control register properties
589 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
589 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
590 CFGSpaceWire_LSEnableStart(&statusControl, 1);
590 CFGSpaceWire_LSEnableStart(&statusControl, 1);
591 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
591 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
592 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
592 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
593 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
593 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
594
594
595 // Set the link status control register
595 // Set the link status control register
596 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
596 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
597 {
597 {
598 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
598 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
599 this->handleMutex->unlock();
599 this->handleMutex->unlock();
600 return false;
600 return false;
601 }
601 }
602 else
602 else
603 {
603 {
604 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
604 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
605 }
605 }
606 }
606 }
607
607
608 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
608 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
609 {
609 {
610 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
610 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
611 this->handleMutex->unlock();
611 this->handleMutex->unlock();
612 return false;
612 return false;
613 }
613 }
614 else
614 else
615 {
615 {
616 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
616 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
617 }
617 }
618
618
619 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
619 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
620 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
620 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
621 USBSpaceWire_SetTimeout(hDevice,1.0);
621 USBSpaceWire_SetTimeout(hDevice,1.0);
622 this->handleMutex->unlock();
622 this->handleMutex->unlock();
623 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
623 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
624 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
624 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
625 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
625 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
626 this->connected = true;
626 this->connected = true;
627 return true;
627 return true;
628 }
628 }
629
629
630 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
630 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
631 {
631 {
632 // QMutexLocker mlock(&this->handleMutex);
632 // QMutexLocker mlock(&this->handleMutex);
633 this->handleMutex->lock();
633 this->handleMutex->lock();
634 int status;
634 int status;
635 U32 statusControl;
635 U32 statusControl;
636 unsigned int linkStatus1;
636 unsigned int linkStatus1;
637 unsigned int linkStatus2;
637 unsigned int linkStatus2;
638 unsigned char linkNumber;
638 unsigned char linkNumber;
639 unsigned char deviceIsAnInterface;
639 unsigned char deviceIsAnInterface;
640
640
641 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
641 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
642 {
642 {
643 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
643 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
644 this->handleMutex->unlock();
644 this->handleMutex->unlock();
645 return false;
645 return false;
646 }
646 }
647 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
647 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
648 + QString::number(this->selectedBrick));
648 + QString::number(this->selectedBrick));
649
649
650 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
650 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
651 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
651 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
652 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
652 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
653
653
654 // Set the path and return path to the device
654 // Set the path and return path to the device
655 // This affects just the operations performed by the Configuration Library and does not affect the packets
655 // This affects just the operations performed by the Configuration Library and does not affect the packets
656 // sent and received using the driver API.
656 // sent and received using the driver API.
657 CFGSpaceWire_StackClear();
657 CFGSpaceWire_StackClear();
658 CFGSpaceWire_AddrStackPush(0);
658 CFGSpaceWire_AddrStackPush(0);
659 CFGSpaceWire_AddrStackPush(254);
659 CFGSpaceWire_AddrStackPush(254);
660 CFGSpaceWire_RetAddrStackPush(254);
660 CFGSpaceWire_RetAddrStackPush(254);
661
661
662 // set the base transmit rate to 100 MHz
662 // set the base transmit rate to 100 MHz
663 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
663 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
664 if (status != CFG_TRANSFER_SUCCESS)
664 if (status != CFG_TRANSFER_SUCCESS)
665 {
665 {
666 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
666 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
667 }
667 }
668 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
668 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
669
669
670 //*********************
670 //*********************
671 // LINK 1 CONFIGURATION
671 // LINK 1 CONFIGURATION
672 linkNumber = 1;
672 linkNumber = 1;
673 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
673 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
674 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
674 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
675 else
675 else
676 {
676 {
677 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
677 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
678
678
679 // Set the link status control register properties
679 // Set the link status control register properties
680 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
680 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
681 CFGSpaceWire_LSEnableStart(&statusControl, 1);
681 CFGSpaceWire_LSEnableStart(&statusControl, 1);
682 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
682 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
683 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
683 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
684 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
684 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
685
685
686 // Set the link status control register
686 // Set the link status control register
687 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
687 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
688 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
688 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
689 else
689 else
690 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
690 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
691 }
691 }
692
692
693 //*********************
693 //*********************
694 // LINK 2 CONFIGURATION
694 // LINK 2 CONFIGURATION
695 linkNumber = 2;
695 linkNumber = 2;
696 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
696 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
697 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
697 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
698 else
698 else
699 {
699 {
700 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
700 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
701
701
702 // Set the link status control register properties
702 // Set the link status control register properties
703 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
703 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
704 CFGSpaceWire_LSEnableStart(&statusControl, 1);
704 CFGSpaceWire_LSEnableStart(&statusControl, 1);
705 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
705 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
706 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
706 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
707 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
707 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
708
708
709 // Set the link status control register
709 // Set the link status control register
710 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
710 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
711 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
711 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
712 else
712 else
713 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
713 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
714 }
714 }
715
715
716 //***************************
716 //***************************
717 // SET THE DEVICE AS A ROUTER
717 // SET THE DEVICE AS A ROUTER
718 deviceIsAnInterface = 0; // 0 = router, 1 = interface
718 deviceIsAnInterface = 0; // 0 = router, 1 = interface
719 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
719 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
720 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
720 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
721 else
721 else
722 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
722 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
723
723
724 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
724 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
725 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
725 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
726
726
727 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
727 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
728 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
728 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
729
729
730 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
730 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
731 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
731 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
732 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
732 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
733
733
734 //************
734 //************
735 // test Link 1 and Link 2
735 // test Link 1 and Link 2
736 linkStatus1 = getLinkStatus(0x01);
736 linkStatus1 = getLinkStatus(0x01);
737 linkStatus2 = getLinkStatus(0x02);
737 linkStatus2 = getLinkStatus(0x02);
738 this->handleMutex->unlock();
738 this->handleMutex->unlock();
739
739
740 if ((linkStatus1==1) || (linkStatus2==1))
740 if ((linkStatus1==1) || (linkStatus2==1))
741 {
741 {
742 initializeTimecodeGeneration();
742 initializeTimecodeGeneration();
743 this->connected=true;
743 this->connected=true;
744 return true;
744 return true;
745 }
745 }
746 else
746 else
747 {
747 {
748 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
748 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
749 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
749 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
750 starDundeeStatusQueryDialog->exec();
750 starDundeeStatusQueryDialog->exec();
751 this->connected = false;
751 this->connected = false;
752 return false;
752 return false;
753 }
753 }
754 }
754 }
755
755
756 void stardundeeSPW_USB_Manager::initDialog( void )
756 void stardundeeSPW_USB_Manager::initDialog( void )
757 {
757 {
758 // STAR DUNDEE STATUS QUERY DIALOG
758 // STAR DUNDEE STATUS QUERY DIALOG
759 starDundeeStatusQueryDialog = new QDialog;
759 starDundeeStatusQueryDialog = new QDialog;
760 starDundeeStatusQueryDialogLayout = new QGridLayout;
760 starDundeeStatusQueryDialogLayout = new QGridLayout;
761 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
761 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
762 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
762 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
763 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
763 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
764 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
764 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
765 statusLink1 = new QLabel(tr("Link 1 status code: -"));
765 statusLink1 = new QLabel(tr("Link 1 status code: -"));
766 statusLink2 = new QLabel(tr("Link 2 status code: -"));
766 statusLink2 = new QLabel(tr("Link 2 status code: -"));
767
767
768 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
768 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
769 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
769 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
770 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
770 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
771 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
771 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
772 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
772 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
773 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
773 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
774 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
774 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
775 }
775 }
776
776
777 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
777 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
778 {
778 {
779 U32 routingTableEntry;
779 U32 routingTableEntry;
780 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
780 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
781 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
781 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
782 {
782 {
783 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
783 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
784 }
784 }
785 // Build the routing table entry
785 // Build the routing table entry
786 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
786 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
787 dwOutputPorts, // route out of port dwOutputPorts
787 dwOutputPorts, // route out of port dwOutputPorts
788 bDelHead, // header deletion is enabled [1] or disabled [0]
788 bDelHead, // header deletion is enabled [1] or disabled [0]
789 0); // priority normal
789 0); // priority normal
790 // Set the routing table entry for logical address tableEntry
790 // Set the routing table entry for logical address tableEntry
791 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
791 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
792 {
792 {
793 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
793 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
794 }
794 }
795 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
795 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
796 return 1;
796 return 1;
797 }
797 }
798
798
799 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
799 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
800 {
800 {
801 U32 routingTableEntry, outputPorts;
801 U32 routingTableEntry, outputPorts;
802 char enabled, delHead, priority;
802 char enabled, delHead, priority;
803 int portNum;
803 int portNum;
804
804
805 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
805 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
806 // Read the routing table entry
806 // Read the routing table entry
807 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
807 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
808 {
808 {
809 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
809 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
810 }
810 }
811 else
811 else
812 {
812 {
813 // Display the routing table entry properties
813 // Display the routing table entry properties
814 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
814 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
815 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
815 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
816 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
816 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
817 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
817 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
818 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
818 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
819 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
819 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
820 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
820 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
821 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
821 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
822 for (portNum = 0; portNum < 32; portNum++)
822 for (portNum = 0; portNum < 32; portNum++)
823 {
823 {
824 if (outputPorts & (1 << portNum))
824 if (outputPorts & (1 << portNum))
825 {
825 {
826 SocExplorerEngine::message(this->plugin,QString::number(portNum));
826 SocExplorerEngine::message(this->plugin,QString::number(portNum));
827 }
827 }
828 }
828 }
829 }
829 }
830
830
831 return 1;
831 return 1;
832 }
832 }
833
833
834 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
834 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
835 {
835 {
836 U32 dwTickEnableStatus;
836 U32 dwTickEnableStatus;
837 U32 rtr_clk_freq;
837 U32 rtr_clk_freq;
838
838
839 // (1) RESET
839 // (1) RESET
840 if (!USBSpaceWire_TC_Reset(hDevice))
840 if (!USBSpaceWire_TC_Reset(hDevice))
841 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
841 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
842
842
843 // (2) Clear the tick enable register
843 // (2) Clear the tick enable register
844 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
844 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
845 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
845 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
846 else
846 else
847 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
847 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
848
848
849 // (3) get the tick status
849 // (3) get the tick status
850 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
850 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
851 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
851 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
852
852
853 // (4) enable external timecode selection
853 // (4) enable external timecode selection
854 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
854 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
855 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
855 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
856
856
857 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
857 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
858
858
859 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
859 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
860
860
861 //**************************************************
861 //**************************************************
862 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
862 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
863 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
863 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
864 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
864 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
865 }
865 }
866
866
867 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
867 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
868 {
868 {
869 U32 statusControl, errorStatus, portType;
869 U32 statusControl, errorStatus, portType;
870 U32 linkStatus, operatingSpeed, outputPortConnection;
870 U32 linkStatus, operatingSpeed, outputPortConnection;
871 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
871 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
872
872
873 // Read the link status control register
873 // Read the link status control register
874 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
874 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
875 {
875 {
876 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
876 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
877 }
877 }
878 else
878 else
879 {
879 {
880 // Display the link status control register properties
880 // Display the link status control register properties
881 CFGSpaceWire_LSPortType(statusControl, &portType);
881 CFGSpaceWire_LSPortType(statusControl, &portType);
882 if (portType == CFG_CONFIGURATION_PORT)
882 if (portType == CFG_CONFIGURATION_PORT)
883 {
883 {
884 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
884 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
885 }
885 }
886 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
886 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
887 {
887 {
888 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
888 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
889 }
889 }
890 else
890 else
891 {
891 {
892 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
892 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
893 }
893 }
894 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
894 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
895 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
895 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
896 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
896 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
897 CFGSpaceWire_LSIsStart(statusControl, &isStart);
897 CFGSpaceWire_LSIsStart(statusControl, &isStart);
898 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
898 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
899 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
899 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
900 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
900 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
901 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
901 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
902 }
902 }
903 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
903 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
904 +" is " + dwLinkStatusQString[linkStatus]);
904 +" is " + dwLinkStatusQString[linkStatus]);
905 if (linkStatus == 5)
905 if (linkStatus == 5)
906 {
906 {
907 return 1;
907 return 1;
908 }
908 }
909 else return 0;
909 else return 0;
910 }
910 }
911
911
912 bool stardundeeSPW_USB_Manager::disconnectBridge()
912 bool stardundeeSPW_USB_Manager::disconnectBridge()
913 {
913 {
914 this->handleMutex->lock();
914 this->handleMutex->lock();
915 USBSpaceWire_Close(hDevice); // Close the device
915 USBSpaceWire_Close(hDevice); // Close the device
916 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
916 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
917 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
917 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
918 this->handleMutex->unlock();
918 this->handleMutex->unlock();
919 this->RMAP_pending_transaction_IDsMtx->lock();
919 this->RMAP_pending_transaction_IDsMtx->lock();
920 this->RMAP_pending_transaction_IDs.clear();
920 this->RMAP_pending_transaction_IDs.clear();
921 this->RMAP_pending_transaction_IDsMtx->unlock();
921 this->RMAP_pending_transaction_IDsMtx->unlock();
922 this->RMAP_AnswersMtx->lock();
922 this->RMAP_AnswersMtx->lock();
923 this->RMAP_Answers.clear();
923 this->RMAP_Answers.clear();
924 this->RMAP_AnswersMtx->unlock();
924 this->RMAP_AnswersMtx->unlock();
925 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
925 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
926 return true;
926 return true;
927 }
927 }
928
928
929 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
929 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
930 {
930 {
931 this->RMAP_pending_transaction_IDsMtx->lock();
931 this->RMAP_pending_transaction_IDsMtx->lock();
932 int ID=0;
932 int ID=0;
933 bool found=true;
933 bool found=true;
934 while(ID<511)
934 while(ID<511)
935 {
935 {
936 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
936 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
937 {
937 {
938 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
938 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
939 }
939 }
940 if(found==true)break;
940 if(found==true)break;
941 ID++;
941 ID++;
942 found = true;
942 found = true;
943 }
943 }
944 if(found)
944 if(found)
945 {
945 {
946 RMAP_pending_transaction_IDs.append(ID);
946 RMAP_pending_transaction_IDs.append(ID);
947 }
947 }
948 this->RMAP_pending_transaction_IDsMtx->unlock();
948 this->RMAP_pending_transaction_IDsMtx->unlock();
949 return ID;
949 return ID;
950 }
950 }
951
951
952 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
952 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
953 {
953 {
954 QTime timeout;
954 QTime timeout;
955 *buffer=NULL;
955 *buffer=NULL;
956 int count=0;
956 int count=0;
957 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
957 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
958 timeout.start();
958 timeout.start();
959 while (*buffer==NULL)
959 while (*buffer==NULL)
960 {
960 {
961 this->RMAP_AnswersMtx->lock();
961 this->RMAP_AnswersMtx->lock();
962 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
962 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
963 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
963 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
964 for(int i=0;i<RMAP_Answers.count();i++)
964 for(int i=0;i<RMAP_Answers.count();i++)
965 {
965 {
966 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
966 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
967 if(RMAP_Answers[i]->transactionID==transactionID)
967 if(RMAP_Answers[i]->transactionID==transactionID)
968 {
968 {
969 this->RMAP_pending_transaction_IDsMtx->lock();
969 this->RMAP_pending_transaction_IDsMtx->lock();
970 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
970 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
971 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
971 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
972 {
972 {
973 if(RMAP_pending_transaction_IDs[j]==transactionID)
973 if(RMAP_pending_transaction_IDs[j]==transactionID)
974 {
974 {
975 RMAP_pending_transaction_IDs.removeAt(j);
975 RMAP_pending_transaction_IDs.removeAt(j);
976 }
976 }
977 }
977 }
978 this->RMAP_pending_transaction_IDsMtx->unlock();
978 this->RMAP_pending_transaction_IDsMtx->unlock();
979 *buffer = RMAP_Answers[i]->data;
979 *buffer = RMAP_Answers[i]->data;
980 count = RMAP_Answers[i]->len;
980 count = RMAP_Answers[i]->len;
981 RMAP_Answer* tmp=RMAP_Answers[i];
981 RMAP_Answer* tmp=RMAP_Answers[i];
982 RMAP_Answers.removeAt(i);
982 RMAP_Answers.removeAt(i);
983 delete tmp;
983 delete tmp;
984 }
984 }
985 }
985 }
986 this->RMAP_AnswersMtx->unlock();
986 this->RMAP_AnswersMtx->unlock();
987 //if no answer found in the stack wait until a new packet is pushed
987 //if no answer found in the stack wait until a new packet is pushed
988 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
988 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
989 if(*buffer==NULL)
989 if(*buffer==NULL)
990 {
990 {
991 while (0==this->RMAP_AnswersSem->available())
991 while (0==this->RMAP_AnswersSem->available())
992 {
992 {
993 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
993 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
994 if(timeout.elapsed()>=RMAPtimeout)
994 if(timeout.elapsed()>=RMAPtimeout)
995 {
995 {
996 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
996 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
997 return -1;
997 return -1;
998 }
998 }
999 usleep(1000);
999 usleep(1000);
1000 }
1000 }
1001 this->RMAP_AnswersSem->acquire();
1001 this->RMAP_AnswersSem->acquire();
1002 }
1002 }
1003 }
1003 }
1004 return count;
1004 return count;
1005 }
1005 }
1006
1006
1007 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
1007 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
1008 {
1008 {
1009 char protocoleIdentifier;
1009 char protocoleIdentifier;
1010 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
1010 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
1011 USB_SPACEWIRE_ID pIdentifier;
1011 USB_SPACEWIRE_ID pIdentifier;
1012 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
1012 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
1013 this->handleMutex->lock();
1013 this->handleMutex->lock();
1014 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
1014 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
1015 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1015 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1016 this->handleMutex->unlock();
1016 this->handleMutex->unlock();
1017 if (result != TRANSFER_SUCCESS)
1017 if (result != TRANSFER_SUCCESS)
1018 {
1018 {
1019 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
1019 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
1020 return false;
1020 return false;
1021 }
1021 }
1022 else
1022 else
1023 {
1023 {
1024 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1024 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1025 // read the protocole identifier
1025 // read the protocole identifier
1026 protocoleIdentifier = packet[2];
1026 protocoleIdentifier = packet[2];
1027 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1027 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1028 emit ccsdsPacketTransmittedToSpw();
1028 emit ccsdsPacketTransmittedToSpw();
1029
1029
1030 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1030 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1031 }
1031 }
1032 return true;
1032 return true;
1033 }
1033 }
1034
1034
1035 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1035 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1036 {
1036 {
1037 char* packetbuffer = (char*)malloc(len);
1037 char* packetbuffer = (char*)malloc(len);
1038 memcpy(packetbuffer,packet,len);
1038 memcpy(packetbuffer,packet,len);
1039 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1039 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1040 RMAP_AnswersMtx->lock();
1040 RMAP_AnswersMtx->lock();
1041 RMAP_Answers.append(RMPAPpacket);
1041 RMAP_Answers.append(RMPAPpacket);
1042 RMAP_AnswersMtx->unlock();
1042 RMAP_AnswersMtx->unlock();
1043 }
1043 }
1044
1044
1045 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1045 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1046 {
1046 {
1047 this->handleMutex->lock();
1047 this->handleMutex->lock();
1048 if (onOff == true)
1048 if (onOff == true)
1049 {
1049 {
1050 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
1050 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
1051 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
1051 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
1052 }
1052 }
1053 else
1053 else
1054 {
1054 {
1055 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
1055 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
1056 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
1056 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
1057 }
1057 }
1058 this->handleMutex->unlock();
1058 this->handleMutex->unlock();
1059 }
1059 }
1060
1060
1061 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1061 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1062 {
1062 {
1063 return this->linkNumber;
1063 return this->linkNumber;
1064 }
1064 }
1065
1065
1066 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1066 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1067 {
1067 {
1068 U32 rtr_clk_freq=0;
1068 U32 rtr_clk_freq=0;
1069 U32 freqCount=0;
1069 U32 freqCount=0;
1070 double freqCountInDouble=0.0;
1070 double freqCountInDouble=0.0;
1071 double currentFrequency=0.0;
1071 double currentFrequency=0.0;
1072
1072
1073 this->handleMutex->lock();
1073 this->handleMutex->lock();
1074 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
1074 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
1075 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
1075 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
1076 freqCount = (unsigned int) freqCountInDouble;
1076 freqCount = (unsigned int) freqCountInDouble;
1077
1077
1078 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
1078 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
1079
1079
1080 //**************************************************
1080 //**************************************************
1081 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
1081 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
1082 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
1082 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
1083 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
1083 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
1084 else
1084 else
1085 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
1085 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
1086 + " (freqCount set to " + QString::number(freqCount) + ")" );
1086 + " (freqCount set to " + QString::number(freqCount) + ")" );
1087 this->handleMutex->unlock();
1087 this->handleMutex->unlock();
1088 }
1088 }
1089
1089
1090 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
1090 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
1091 {
1091 {
1092 this->handleMutex->lock();
1092 this->handleMutex->lock();
1093 // enable external timecode selection
1093 // enable external timecode selection
1094 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
1094 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
1095 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
1095 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
1096
1096
1097 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1097 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1098 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1098 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1099 else
1099 else
1100 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1100 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1101
1101
1102 // disable external timecode selection
1102 // disable external timecode selection
1103 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1103 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1104 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1104 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1105 this->handleMutex->unlock();
1105 this->handleMutex->unlock();
1106 }
1106 }
1107
1107
1108
1108
General Comments 0
You need to be logged in to leave comments. Login now