@@ -3,7 +3,7 | |||||
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <socexplorerplugin.h> |
|
5 | #include <socexplorerplugin.h> | |
6 |
#define RMAP_MAX_XFER_SIZE |
|
6 | #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes | |
7 | #include <spw.h> |
|
7 | #include <spw.h> | |
8 |
|
8 | |||
9 | class abstractSpwBridge : public QObject |
|
9 | class abstractSpwBridge : public QObject |
@@ -27,54 +27,66 int stardundeeSPW_USB::pushRMAPPacket(ch | |||||
27 |
|
27 | |||
28 | unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address) |
|
28 | unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address) | |
29 | { |
|
29 | { | |
30 | //Add transactionID! |
|
30 | char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1]; | |
31 | char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE)+1]; |
|
|||
32 | writeBuffer[0]=1;//Link number |
|
31 | writeBuffer[0]=1;//Link number | |
33 | int transactionID = 0; |
|
32 | int transactionID = 0; | |
34 | int written=0; |
|
33 | int written=0; | |
35 | SocExplorerEngine::message(this->plugin,"Enter Write function"); |
|
34 | SocExplorerEngine::message(this->plugin,"Enter Write function"); | |
|
35 | QProgressBar* progress=NULL; | |||
|
36 | if(count>RMAP_MAX_XFER_SIZE) | |||
|
37 | progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |||
36 | //Quite stupide loop, I guess that I always get the number of byte I asked for! |
|
38 | //Quite stupide loop, I guess that I always get the number of byte I asked for! | |
37 |
|
|
39 | while(count>=RMAP_MAX_XFER_SIZE) | |
38 | { |
|
40 | { | |
39 | for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++) |
|
41 | for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++) | |
40 | { |
|
42 | { | |
41 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char) |
|
43 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); | |
42 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char) |
|
44 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); | |
43 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char) |
|
45 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); | |
44 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char) |
|
46 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); | |
45 | } |
|
47 | } | |
46 | RMAP_build_tx_request_header(254,2,1,transactionID,address+written,RMAP_MAX_XFER_SIZE*4,writeBuffer+1); |
|
48 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1); | |
47 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1); |
|
49 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1); | |
48 | written+=RMAP_MAX_XFER_SIZE; |
|
50 | written+=RMAP_MAX_XFER_SIZE; | |
|
51 | count-=RMAP_MAX_XFER_SIZE; | |||
|
52 | progress->setValue(written); | |||
|
53 | qApp->processEvents(); | |||
49 | } |
|
54 | } | |
50 | if(count>0) |
|
55 | if(count>0) | |
51 | { |
|
56 | { | |
52 | for(int i=0;i<((int)count);i++) |
|
57 | for(int i=0;i<((int)count);i++) | |
53 | { |
|
58 | { | |
54 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char) |
|
59 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); | |
55 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char) |
|
60 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); | |
56 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char) |
|
61 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); | |
57 |
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char) |
|
62 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); | |
58 | } |
|
63 | } | |
59 | RMAP_build_tx_request_header(254,2,1,transactionID,address+written,count*4,writeBuffer+1); |
|
64 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1); | |
60 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1); |
|
65 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1); | |
61 | // QHexEdit* viewer = new QHexEdit(); |
|
|||
62 | // viewer->setData(QByteArray(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4)+1)); |
|
|||
63 | // viewer->show(); |
|
|||
64 | written+=count; |
|
66 | written+=count; | |
|
67 | if(progress!=NULL) | |||
|
68 | { | |||
|
69 | progress->setValue(written); | |||
|
70 | qApp->processEvents(); | |||
|
71 | } | |||
|
72 | } | |||
|
73 | if(progress!=NULL) | |||
|
74 | { | |||
|
75 | SocExplorerEngine::deleteProgressBar(progress); | |||
65 | } |
|
76 | } | |
66 | return written; |
|
77 | return written; | |
67 | } |
|
78 | } | |
68 |
|
79 | |||
69 | unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address) |
|
80 | unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address) | |
70 | { |
|
81 | { | |
71 | //Add transactionID! |
|
|||
72 | char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1]; |
|
82 | char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1]; | |
73 | char* RMAP_AnswerBuffer; |
|
83 | char* RMAP_AnswerBuffer; | |
74 | requestBuffer[0]=1;//Link number |
|
84 | requestBuffer[0]=1;//Link number | |
75 | int transactionID = 0; |
|
85 | int transactionID = 0; | |
76 | int read=0; |
|
86 | int read=0; | |
77 | // SocExplorerEngine::message(this->plugin,"Enter read function"); |
|
87 | QProgressBar* progress=NULL; | |
|
88 | if(count>RMAP_MAX_XFER_SIZE) | |||
|
89 | progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |||
78 | SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE)); |
|
90 | SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE)); | |
79 |
|
91 | |||
80 | //Quite stupide loop, I guess that I always get the number of byte I asked for! |
|
92 | //Quite stupide loop, I guess that I always get the number of byte I asked for! | |
@@ -85,13 +97,18 unsigned int stardundeeSPW_USB::Read(uns | |||||
85 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1); |
|
97 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1); | |
86 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); |
|
98 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); | |
87 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); |
|
99 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); | |
88 | for(int i=0;i<(len/4);i++) |
|
100 | for(int i=0;i<((len-13)/4);i++) | |
89 | { |
|
101 | { | |
90 | Value[read+i]=((unsigned int)(RMAP_AnswerBuffer[i])<<24) + ((unsigned int)(RMAP_AnswerBuffer[i+1])<<16) + ((unsigned int)(RMAP_AnswerBuffer[i+2])<<8) + ((unsigned int)(RMAP_AnswerBuffer[i+3])); |
|
102 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); | |
|
103 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); | |||
|
104 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); | |||
|
105 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); | |||
91 | } |
|
106 | } | |
92 | free(RMAP_AnswerBuffer); |
|
107 | free(RMAP_AnswerBuffer); | |
93 | read+=RMAP_MAX_XFER_SIZE; |
|
108 | read+=RMAP_MAX_XFER_SIZE; | |
94 | count-=RMAP_MAX_XFER_SIZE; |
|
109 | count-=RMAP_MAX_XFER_SIZE; | |
|
110 | progress->setValue(read); | |||
|
111 | qApp->processEvents(); | |||
95 | } |
|
112 | } | |
96 | if((int)count>0) |
|
113 | if((int)count>0) | |
97 | { |
|
114 | { | |
@@ -104,12 +121,24 unsigned int stardundeeSPW_USB::Read(uns | |||||
104 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1); |
|
121 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1); | |
105 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); |
|
122 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); | |
106 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); |
|
123 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); | |
107 | for(int i=0;i<(len/4);i++) |
|
124 | for(int i=0;i<((len-13)/4);i++) | |
108 | { |
|
125 | { | |
109 | Value[read+i]=((unsigned int)(RMAP_AnswerBuffer[i])<<24) + ((unsigned int)(RMAP_AnswerBuffer[i+1])<<16) + ((unsigned int)(RMAP_AnswerBuffer[i+2])<<8) + ((unsigned int)(RMAP_AnswerBuffer[i+3])); |
|
126 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); | |
|
127 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); | |||
|
128 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); | |||
|
129 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); | |||
110 | } |
|
130 | } | |
111 | free(RMAP_AnswerBuffer); |
|
131 | free(RMAP_AnswerBuffer); | |
112 | read+=count; |
|
132 | read+=count; | |
|
133 | if(progress!=NULL) | |||
|
134 | { | |||
|
135 | progress->setValue(read); | |||
|
136 | qApp->processEvents(); | |||
|
137 | } | |||
|
138 | } | |||
|
139 | if(progress!=NULL) | |||
|
140 | { | |||
|
141 | SocExplorerEngine::deleteProgressBar(progress); | |||
113 | } |
|
142 | } | |
114 | return read; |
|
143 | return read; | |
115 | } |
|
144 | } | |
@@ -140,7 +169,7 void stardundeeSPW_USB_Manager::run() | |||||
140 | USB_SPACEWIRE_ID pIdentifier=NULL; |
|
169 | USB_SPACEWIRE_ID pIdentifier=NULL; | |
141 | USB_SPACEWIRE_STATUS stat; |
|
170 | USB_SPACEWIRE_STATUS stat; | |
142 | SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread"); |
|
171 | SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread"); | |
143 | char buffer[RMAP_MAX_XFER_SIZE*4]; |
|
172 | char buffer[(RMAP_MAX_XFER_SIZE*4)+50]; | |
144 | while (!this->isInterruptionRequested()) |
|
173 | while (!this->isInterruptionRequested()) | |
145 | { |
|
174 | { | |
146 | if(this->connected) |
|
175 | if(this->connected) | |
@@ -150,7 +179,7 void stardundeeSPW_USB_Manager::run() | |||||
150 | if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01)) |
|
179 | if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01)) | |
151 | { |
|
180 | { | |
152 | SocExplorerEngine::message(this->plugin,"Got packet"); |
|
181 | SocExplorerEngine::message(this->plugin,"Got packet"); | |
153 | stat = USBSpaceWire_ReadPackets(hDevice, buffer, RMAP_MAX_XFER_SIZE*4,1, 1, &properties, &pIdentifier); |
|
182 | stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier); | |
154 | if (stat == TRANSFER_SUCCESS) |
|
183 | if (stat == TRANSFER_SUCCESS) | |
155 | { |
|
184 | { | |
156 | if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET) |
|
185 | if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET) | |
@@ -163,16 +192,27 void stardundeeSPW_USB_Manager::run() | |||||
163 | { |
|
192 | { | |
164 | SocExplorerEngine::message(this->plugin,"Got RMAP packet"); |
|
193 | SocExplorerEngine::message(this->plugin,"Got RMAP packet"); | |
165 | SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len)); |
|
194 | SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len)); | |
166 |
|
|
195 | if(properties.len>8) | |
167 | memcpy(packetbuffer,buffer+12,properties.len-13); |
|
196 | { | |
168 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
197 | char* packetbuffer = (char*)malloc(properties.len); | |
169 | pIdentifier = NULL; |
|
198 | memcpy(packetbuffer,buffer,properties.len); | |
170 | handleMutex->unlock(); |
|
199 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
171 | RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len); |
|
200 | pIdentifier = NULL; | |
172 |
|
|
201 | handleMutex->unlock(); | |
173 | RMAP_Answers.append(packet); |
|
202 | RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len); | |
174 |
RMAP_AnswersMtx-> |
|
203 | RMAP_AnswersMtx->lock(); | |
175 |
RMAP_Answers |
|
204 | RMAP_Answers.append(packet); | |
|
205 | RMAP_AnswersMtx->unlock(); | |||
|
206 | RMAP_AnswersSem->release(); | |||
|
207 | ||||
|
208 | } | |||
|
209 | else //it's a RMAP write response | |||
|
210 | { | |||
|
211 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |||
|
212 | pIdentifier = NULL; | |||
|
213 | handleMutex->unlock(); | |||
|
214 | } | |||
|
215 | ||||
176 | } |
|
216 | } | |
177 | else //any non-rmap packet will be pushed to the network |
|
217 | else //any non-rmap packet will be pushed to the network | |
178 | { |
|
218 | { |
General Comments 0
You need to be logged in to leave comments.
Login now