-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.cpp
517 lines (431 loc) · 19.6 KB
/
dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
#include "dialog.h"
#include "ui_dialog.h"
#include "QDebug"
#include <libusb.h>
#include <QMessageBox>
#include <QThread>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
m_ftdi = 0;
ui->m_listDevices->setColumnCount(4);
ui->m_listDevices->setHorizontalHeaderLabels(QStringList()<<"Manufacturer" << "Description" << "Descriptor" << "VID, PID");
ui->m_listDevices->setSelectionMode(QAbstractItemView::SingleSelection);
ui->m_listDevices->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->m_listDevices->setEditTriggers(QAbstractItemView::NoEditTriggers);
if ((m_ftdi = ftdi_new()) == 0) {
qDebug("ftdi_new failed!");
return;
}
ui->m_memoryDump->setData(m_memoryData);
on_m_findAll_clicked();
}
Dialog::~Dialog()
{
delete ui;
ftdi_list_free(&m_devlist);
}
void Dialog::on_m_findAll_clicked()
{
ui->m_listDevices->setRowCount(0);
char manufacturer[128], description[128];
int retval = EXIT_SUCCESS;
if ((retval=ftdi_usb_find_all (m_ftdi,&m_devlist, 0, 0))<0)
{
qDebug("ftdi_usb_find_all failed: %s", ftdi_get_error_string(m_ftdi));
ftdi_free(m_ftdi);
return;
}
qDebug("Number of FTDI devices found: %d\n", retval);
int i = 0;
for (m_curdev = m_devlist; m_curdev != NULL; i++)
{
if (ftdi_usb_get_strings(m_ftdi, m_curdev->dev, manufacturer, sizeof (manufacturer), description, sizeof(description), NULL, 0)<0) {
qDebug("ftdi_usb_get_strings failed: %s\n", ftdi_get_error_string(m_ftdi));
return;
}
qDebug("Manufacturer: %s, Description: %s\n\n", manufacturer, description);
ui->m_listDevices->insertRow(i);
ui->m_listDevices->setItem(i, 0, new QTableWidgetItem(manufacturer));
ui->m_listDevices->setItem(i, 1, new QTableWidgetItem(description));
m_curdev = m_curdev->next;
}
return;
}
void Dialog::on_m_listDevices_cellDoubleClicked(int row, int column)
{
(void) row;
(void) column;
}
void Dialog::on_m_testSPI_clicked()
{
// Now we know that correct address is 0x80000
for (int shift = 0;shift <1;shift++)
{
m_dwNumBytesToSend = 0;
uint32_t addr = (1<<shift);
SPI_TlastDisable();
SPI_CSEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB ;
m_outputBuffer[m_dwNumBytesToSend++] = 0x11; // length low byte, 0x0011 ==> 18dec byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0xa2;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(addr/0x1000000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x10000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x100);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x1);
m_outputBuffer[m_dwNumBytesToSend++] =0x00;
m_outputBuffer[m_dwNumBytesToSend++] =0x0c;
m_outputBuffer[m_dwNumBytesToSend++] =0x11;
m_outputBuffer[m_dwNumBytesToSend++] =0x22;
m_outputBuffer[m_dwNumBytesToSend++] =0x33;
m_outputBuffer[m_dwNumBytesToSend++] =0x44;
m_outputBuffer[m_dwNumBytesToSend++] =0x55;
m_outputBuffer[m_dwNumBytesToSend++] =0x66;
m_outputBuffer[m_dwNumBytesToSend++] =0x77;
m_outputBuffer[m_dwNumBytesToSend++] =0x88;
m_outputBuffer[m_dwNumBytesToSend++] =0x99;
m_outputBuffer[m_dwNumBytesToSend++] =0xaa;
m_outputBuffer[m_dwNumBytesToSend++] =0xbb;
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB ;
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length low byte, 0x0000 ==> 1 byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0xcc;
SPI_CSDisable();
SPI_TlastDisable();
SPI_CSEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x05; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
/* m_outputBuffer[m_dwNumBytesToSend++] =0xff;
m_outputBuffer[m_dwNumBytesToSend++] =0xff;
m_outputBuffer[m_dwNumBytesToSend++] =0xff;
m_outputBuffer[m_dwNumBytesToSend++] =0xff;*/
m_outputBuffer[m_dwNumBytesToSend++] =0xa1;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(addr/0x1000000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x10000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x100);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x1);
m_outputBuffer[m_dwNumBytesToSend++] =0x00;
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x10;
m_outputBuffer[m_dwNumBytesToSend++] = /*MPSSE_DO_WRITE |*/ MPSSE_WRITE_NEG | MPSSE_LSB | MPSSE_DO_READ;
m_outputBuffer[m_dwNumBytesToSend++] = 19; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
SPI_TlastDisable();
SPI_CSDisable();
ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
struct ftdi_transfer_control *tc_read;
tc_read = ftdi_read_data_submit(m_ftdi, m_inputBuffer, 20);
int transfer = ftdi_transfer_data_done(tc_read);
int stop = 0;
}
}
//this routine is used to enable SPI device
void Dialog::SPI_CSEnable() {
//one 0x80 command can keep 0.2us, do 5 times to stay in this situation for 1us
for (int loop = 0; loop < 5; loop++) {
m_outputBuffer[m_dwNumBytesToSend++] = '\x80';//GPIO command for ADBUS
m_outputBuffer[m_dwNumBytesToSend++] = '\x00';//set CS high, MOSI and SCL low
m_outputBuffer[m_dwNumBytesToSend++] = '\x1b';//bit3:CS, bit2:MISO, bit1:MOSI, bit0 : SCK
}
}
//this routine is used to disable SPI device
void Dialog::SPI_CSDisable() {
//one 0x80 command can keep 0.2us, do 5 times to stay in this situation for 1us
for (int loop = 0; loop < 5; loop++) {
m_outputBuffer[m_dwNumBytesToSend++] = '\x80';//GPIO command for ADBUS
m_outputBuffer[m_dwNumBytesToSend++] = '\x08';//set CS, MOSI and SCL low
m_outputBuffer[m_dwNumBytesToSend++] = '\x1b';//bit3:CS, bit2:MISO, bit1:MOSI, bit0 : SCK
}
}
void Dialog::SPI_TlastEnable() {
//one 0x80 command can keep 0.2us, do 5 times to stay in this situation for 1us
m_outputBuffer[m_dwNumBytesToSend++] = '\x80';//GPIO command for ADBUS
m_outputBuffer[m_dwNumBytesToSend++] = '\x10';//set CS high, MOSI and SCL low
m_outputBuffer[m_dwNumBytesToSend++] = '\x1b';//bit3:CS, bit2:MISO, bit1:MOSI, bit0 : SCK
}
//this routine is used to disable SPI device
void Dialog::SPI_TlastDisable() {
//one 0x80 command can keep 0.2us, do 5 times to stay in this situation for 1us
m_outputBuffer[m_dwNumBytesToSend++] = '\x80';//GPIO command for ADBUS
m_outputBuffer[m_dwNumBytesToSend++] = '\x00';//set CS, MOSI and SCL low
m_outputBuffer[m_dwNumBytesToSend++] = '\x1b';//bit3:CS, bit2:MISO, bit1:MOSI, bit0 : SCK
}
void Dialog::SPI_Send(uint8_t data)
{
}
bool Dialog::WishBoneReadMemory(uint32_t addr, uint32_t len, uint8_t* pData)
{
if ((m_ftdi== 0) || (m_ftdi->usb_dev == 0))
{
return false;
}
uint32_t actualAddr = addr/4;
uint32_t actualLen = len + 8;
m_dwNumBytesToSend = 0;
SPI_TlastDisable();
SPI_CSEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x05; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0xa1;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(actualAddr/0x1000000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x10000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x100);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x1);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(len/0x100);
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(len/0x1);
m_outputBuffer[m_dwNumBytesToSend++] = /*MPSSE_DO_WRITE |*/ MPSSE_WRITE_NEG | MPSSE_LSB | MPSSE_DO_READ;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(actualLen/0x1); // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(actualLen/0x100); // length high byte
SPI_TlastDisable();
SPI_CSDisable();
ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
struct ftdi_transfer_control *tc_read;
tc_read = ftdi_read_data_submit(m_ftdi, m_inputBuffer, actualLen+1);
int transfer = ftdi_transfer_data_done(tc_read);
if (m_inputBuffer[0] != (uint8_t)len)
{
return false;
}
memcpy (pData,m_inputBuffer+1,len);
return true;
}
bool Dialog::WishBoneWriteMemory(uint32_t addr, uint32_t len, uint8_t *pData)
{
if ((m_ftdi== 0) || (m_ftdi->usb_dev == 0))
{
return false;
}
uint32_t actualAddr = addr/4;
uint32_t lenOfFirstPart = 0x07 + len - 2;
m_dwNumBytesToSend = 0;
SPI_TlastDisable();
SPI_CSEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(lenOfFirstPart/0x1); // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(lenOfFirstPart/0x100); // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0xa2;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(actualAddr/0x1000000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x10000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x100);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(actualAddr/0x1);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(len/0x100);
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(len/0x1);
for (uint32_t i = 0; i<len-1;i++)
{
m_outputBuffer[m_dwNumBytesToSend++] = pData [i];
}
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x03; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] = pData [len-1];
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
SPI_TlastDisable();
SPI_CSDisable();
// ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
struct ftdi_transfer_control *tc_write;
tc_write = ftdi_write_data_submit(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
int transfer = ftdi_transfer_data_done(tc_write);
return true;
}
namespace Pin {
// enumerate the AD bus for conveniance.
enum bus_t {
SK = 0x01, // ADBUS0, SPI data clock
DO = 0x02, // ADBUS1, SPI data out
DI = 0x04, // ADBUS2, SPI data in
CS = 0x08, // ADBUS3, SPI chip select
L0 = 0x10, // ADBUS4, general-ourpose i/o, GPIOL0
L1 = 0x20, // ADBUS5, general-ourpose i/o, GPIOL1
L2 = 0x40, // ADBUS6, general-ourpose i/o, GPIOL2
l3 = 0x80 // ADBUS7, general-ourpose i/o, GPIOL3
};
}void Dialog::on_pushButton_clicked()
{
// Set these pins high
const unsigned char pinInitialState = Pin::CS|Pin::L0|Pin::L1;
// Use these pins as outputs
const unsigned char pinDirection = Pin::SK|Pin::DO|Pin::CS|Pin::L0|Pin::L1;
int baudrate = 2000000;
auto items = ui->m_listDevices->selectedItems();
if (items.count()==0)
{
QMessageBox::warning(this,"Problem","Please, select any device");
return;
}
int row = items.at(0)->row();
int status;
// Set m_curdev to selected device
m_curdev = m_devlist;
for (int i = 0; i < row; i++ ) {
m_curdev = m_curdev->next;
}
status = ftdi_usb_open_dev(m_ftdi, m_curdev->dev);
if (status <0) {
qDebug("Unable to open device %s", ftdi_get_error_string(m_ftdi));
ui->pushButton->setIcon(QIcon(":/new/icons/Pictures/LedRed.png"));
return;
}
// This code is copied from example
ftdi_usb_reset(m_ftdi);
ftdi_set_interface(m_ftdi, INTERFACE_ANY);
ftdi_set_bitmode(m_ftdi, 0, 0); // reset
ftdi_set_bitmode(m_ftdi, 0, BITMODE_MPSSE); // enable mpsse on all bits
ftdi_usb_purge_buffers(m_ftdi);
QThread::usleep(50000); // sleep 50 ms for setup to complete
m_dwNumBytesToSend = 0;
m_outputBuffer[m_dwNumBytesToSend++] = TCK_DIVISOR; // opcode: set clk divisor
m_outputBuffer[m_dwNumBytesToSend++] = 0x05; // argument: low bit. 60 MHz / (5+1) = 1 MHz
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // argument: high bit.
m_outputBuffer[m_dwNumBytesToSend++] = DIS_ADAPTIVE; // opcode: disable adaptive clocking
m_outputBuffer[m_dwNumBytesToSend++] = DIS_3_PHASE; // opcode: disable 3-phase clocking
m_outputBuffer[m_dwNumBytesToSend++] = SET_BITS_LOW; // opcode: set low bits (ADBUS[0-7])
m_outputBuffer[m_dwNumBytesToSend++] = pinInitialState; // argument: inital pin states
m_outputBuffer[m_dwNumBytesToSend++] = pinDirection; // argument: pin direction
// Write the setup to the chip.
if ( ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend) != m_dwNumBytesToSend ) {
QMessageBox::warning(this,"Problem","Write failed");
return;
}
// zero the buffer for good measure
memset(m_outputBuffer, 0, sizeof(m_outputBuffer));
m_dwNumBytesToSend = 0;
// Now we will write and read 1 byte.
// The DO and DI pins should be physically connected on the breadboard.
// Next three commands sets the GPIOL0 pin low. Pulling CS low.
m_outputBuffer[m_dwNumBytesToSend++] = SET_BITS_LOW;
m_outputBuffer[m_dwNumBytesToSend++] = pinInitialState & ~Pin::CS;
m_outputBuffer[m_dwNumBytesToSend++] = pinDirection;
// commands to write and read one byte in SPI0 (polarity = phase = 0) mode
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_DO_READ;
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length low byte, 0x0000 ==> 1 byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x12; // byte to send
// Next three commands sets the GPIOL0 pin high. Pulling CS high.
m_outputBuffer[m_dwNumBytesToSend++] = SET_BITS_LOW;
m_outputBuffer[m_dwNumBytesToSend++] = pinInitialState | Pin::CS;
m_outputBuffer[m_dwNumBytesToSend++] = pinDirection;
/* std::cout << "Writing: ";
for ( int i = 0; i < m_dwNumBytesToSend; ++i ) {
std::cout << std::hex << (unsigned int)m_outputBuffer[i] << ' ';
}
std::cout << '\n';
// need to purge tx when reading for some etherial reason
ftdi_usb_purge_tx_buffer(&ftdi);
if ( ftdi_write_data(&ftdi, buf, m_dwNumBytesToSend) != m_dwNumBytesToSend ) {
std::cout << "Write failed\n";
}
// zero the buffer for good measure
memset(m_outputBuffer, 0, sizeof(m_outputBuffer));
m_dwNumBytesToSend = 0;
// now get the data we read just read from the chip
unsigned char readm_outputBuffer[256] = {0};
if ( ftdi_read_data(&ftdi, readBuf, 1) != 1 ) std::cout << "Read failed\n";
else std::cout << "Answer: " << std::hex << (unsigned int)readm_outputBuffer[0] << '\n';*/
// to here
/* ftdi_set_baudrate(m_ftdi, baudrate);
if (ftdi_set_bitmode(m_ftdi, 0xFF, BITMODE_MPSSE) < 0) {
qDebug("Can't set mode: %s\n",ftdi_get_error_string(m_ftdi));
ui->pushButton->setIcon(QIcon(":/new/icons/Pictures/LedRed.png"));
return;
}
// Test if MPSSE mode is active
dwNumBytesToSend = 0;
OutputBuffer[m_dwNumBytesToSend++] = '\xAA';
ftdi_write_data(m_ftdi, OutputBuffer, dwNumBytesToSend);
dwNumBytesToSend = 0;*/
ui->pushButton->setIcon(QIcon(":/new/icons/Pictures/LedGreen.png"));
}
void Dialog::on_pushButton_2_clicked()
{
// Now we know that correct address is 0x80000
m_dwNumBytesToSend = 0;
uint32_t addr = 0xf0003000/4;
SPI_TlastDisable();
SPI_CSEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x09; // length low byte, 0x0011 ==> 18dec byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0xa2;
m_outputBuffer[m_dwNumBytesToSend++] = (uint8_t)(addr/0x1000000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x10000);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x100);
m_outputBuffer[m_dwNumBytesToSend++] =(uint8_t)(addr/0x1);
m_outputBuffer[m_dwNumBytesToSend++] =0x00;
m_outputBuffer[m_dwNumBytesToSend++] =0x04;
m_outputBuffer[m_dwNumBytesToSend++] =0x55;
m_outputBuffer[m_dwNumBytesToSend++] =0x55;
m_outputBuffer[m_dwNumBytesToSend++] =0x55;
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length low byte, 0x0000 ==> 1 byte
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] =0x55;
SPI_CSDisable();
SPI_TlastDisable();
ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
int stop = 0;
}
void Dialog::on_m_btnMemoryRead_clicked()
{
int addr = ui->m_editMemoryAddr->text().toULong(nullptr,0);
int len = ui->m_editMemoryCnt->text().toULong(nullptr,0);
m_memoryData.resize(len);
if (WishBoneReadMemory(addr,len,(uint8_t*) m_memoryData.constData()))
{
ui->m_btnMemoryRead->setIcon(QIcon(":/new/icons/Pictures/LedGreen.png"));
} else
{
ui->m_btnMemoryRead->setIcon(QIcon(":/new/icons/Pictures/LedRed.png"));
}
ui->m_memoryDump->setData(m_memoryData);
}
void Dialog::on_m_btnFlushSPI_clicked()
{
if (m_ftdi== 0)
{
return;
}
m_dwNumBytesToSend = 0;
SPI_CSEnable();
SPI_TlastEnable();
m_outputBuffer[m_dwNumBytesToSend++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB /*| MPSSE_DO_READ*/;
m_outputBuffer[m_dwNumBytesToSend++] = 0x05; // length low byte,
m_outputBuffer[m_dwNumBytesToSend++] = 0x00; // length high byte
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
m_outputBuffer[m_dwNumBytesToSend++] = 0xff;
SPI_CSDisable();
SPI_TlastDisable();
ftdi_write_data(m_ftdi, m_outputBuffer, m_dwNumBytesToSend);
}
void Dialog::on_m_btmMemoryWrite_clicked()
{
int addr = ui->m_editMemoryAddr->text().toULong(nullptr,0);
int len = ui->m_editMemoryCnt->text().toULong(nullptr,0);
if (WishBoneWriteMemory(addr,len,(uint8_t*) ui->m_memoryDump->data().constData()))
{
ui->m_btmMemoryWrite->setIcon(QIcon(":/new/icons/Pictures/LedGreen.png"));
} else
{
ui->m_btmMemoryWrite->setIcon(QIcon(":/new/icons/Pictures/LedRed.png"));
}
}