@@ -221,7 +221,7 @@ static int get_from_fpga_combined_stream(lz4_streamp_t compressed_fpga_stream, u
221
221
return * fpga_image_ptr ++ ;
222
222
}
223
223
224
- static int bitstream_version_to_index (FPGA_config bitstream_version ) {
224
+ static int bitstream_target_to_index (FPGA_config bitstream_target ) {
225
225
static int8_t bitstream_index_map [FPGA_BITSTREAM_MAX ] = {-1 };
226
226
227
227
// Initialize
@@ -232,17 +232,18 @@ static int bitstream_version_to_index(FPGA_config bitstream_version) {
232
232
}
233
233
}
234
234
235
- return bitstream_index_map [bitstream_version ];
235
+ return bitstream_index_map [bitstream_target ];
236
236
}
237
237
238
238
//----------------------------------------------------------------------------
239
239
// Undo the interleaving of several FPGA config files. FPGA config files
240
240
// are combined into one big file:
241
241
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
242
242
//----------------------------------------------------------------------------
243
- static int get_from_fpga_stream (int bitstream_version , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
244
- int bitstream_index = bitstream_version_to_index ( bitstream_version );
243
+ static int get_from_fpga_stream (int bitstream_target , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
244
+ int bitstream_index = bitstream_target_to_index ( bitstream_target );
245
245
while ((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE ) % g_fpga_bitstream_num != bitstream_index ) {
246
+ // skip undesired data belonging to other bitstream_targets
246
247
get_from_fpga_combined_stream (compressed_fpga_stream , output_buffer );
247
248
}
248
249
@@ -252,7 +253,7 @@ static int get_from_fpga_stream(int bitstream_version, lz4_streamp_t compressed_
252
253
//----------------------------------------------------------------------------
253
254
// Initialize decompression of the respective (HF or LF) FPGA stream
254
255
//----------------------------------------------------------------------------
255
- static bool reset_fpga_stream (int bitstream_version , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
256
+ static bool reset_fpga_stream (int bitstream_target , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
256
257
uint8_t header [FPGA_BITSTREAM_FIXED_HEADER_SIZE ];
257
258
258
259
uncompressed_bytes_cnt = 0 ;
@@ -268,7 +269,7 @@ static bool reset_fpga_stream(int bitstream_version, lz4_streamp_t compressed_fp
268
269
fpga_image_ptr = output_buffer + FPGA_RING_BUFFER_BYTES ;
269
270
270
271
for (uint16_t i = 0 ; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE ; i ++ )
271
- header [i ] = get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer );
272
+ header [i ] = get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer );
272
273
273
274
// Check for a valid .bit file (starts with bitparse_fixed_header)
274
275
if (memcmp (bitparse_fixed_header , header , FPGA_BITSTREAM_FIXED_HEADER_SIZE ) == 0 )
@@ -290,7 +291,7 @@ static void DownloadFPGA_byte(uint8_t w) {
290
291
}
291
292
292
293
// Download the fpga image starting at current stream position with length FpgaImageLen bytes
293
- static void DownloadFPGA (int bitstream_version , int FpgaImageLen , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
294
+ static void DownloadFPGA (int bitstream_target , int FpgaImageLen , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
294
295
int i = 0 ;
295
296
#if !defined XC3
296
297
AT91C_BASE_PIOA -> PIO_OER = GPIO_FPGA_ON ;
@@ -368,7 +369,7 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, lz4_streamp_t
368
369
#endif
369
370
370
371
for (i = 0 ; i < FpgaImageLen ; i ++ ) {
371
- int b = get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer );
372
+ int b = get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer );
372
373
if (b < 0 ) {
373
374
Dbprintf ("Error %d during FpgaDownload" , b );
374
375
break ;
@@ -397,14 +398,14 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, lz4_streamp_t
397
398
* (big endian), <length> bytes content. Except for section 'e' which has 4 bytes
398
399
* length.
399
400
*/
400
- static int bitparse_find_section (int bitstream_version , char section_name , uint32_t * section_length , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
401
+ static int bitparse_find_section (int bitstream_target , char section_name , uint32_t * section_length , lz4_streamp_t compressed_fpga_stream , uint8_t * output_buffer ) {
401
402
402
403
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
403
404
404
405
int result = 0 ;
405
406
uint16_t numbytes = 0 ;
406
407
while (numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH ) {
407
- char current_name = get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer );
408
+ char current_name = get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer );
408
409
numbytes ++ ;
409
410
uint32_t current_length = 0 ;
410
411
if (current_name < 'a' || current_name > 'e' ) {
@@ -415,19 +416,19 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
415
416
switch (current_name ) {
416
417
case 'e' :
417
418
/* Four byte length field */
418
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 24 ;
419
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 16 ;
420
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 8 ;
421
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 0 ;
419
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 24 ;
420
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 16 ;
421
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 8 ;
422
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 0 ;
422
423
numbytes += 4 ;
423
424
if (current_length > 300 * 1024 ) {
424
425
/* section e should never exceed about 300KB, if the length is too big limit it but still send the bitstream just in case */
425
426
current_length = 300 * 1024 ;
426
427
}
427
428
break ;
428
429
default : /* Two byte length field */
429
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 8 ;
430
- current_length += get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer ) << 0 ;
430
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 8 ;
431
+ current_length += get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer ) << 0 ;
431
432
numbytes += 2 ;
432
433
if (current_length > 64 ) {
433
434
/* if text field is too long, keep it but truncate it */
@@ -443,7 +444,7 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
443
444
}
444
445
445
446
for (uint32_t i = 0 ; i < current_length && numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH ; i ++ ) {
446
- get_from_fpga_stream (bitstream_version , compressed_fpga_stream , output_buffer );
447
+ get_from_fpga_stream (bitstream_target , compressed_fpga_stream , output_buffer );
447
448
numbytes ++ ;
448
449
}
449
450
}
@@ -452,12 +453,12 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
452
453
453
454
//----------------------------------------------------------------------------
454
455
// Change FPGA image status, if image loaded.
455
- // bitstream_version is your new fpga image version
456
+ // bitstream_target is your new fpga image version
456
457
// return true if can change.
457
458
// return false if image is unloaded.
458
459
//----------------------------------------------------------------------------
459
460
#if defined XC3
460
- static bool FpgaConfCurrentMode (int bitstream_version ) {
461
+ static bool FpgaConfCurrentMode (int bitstream_target ) {
461
462
// fpga "XC3S100E" image merge
462
463
// If fpga image is no init
463
464
// We need load hf_lf_allinone.bit
@@ -471,13 +472,13 @@ static bool FpgaConfCurrentMode(int bitstream_version) {
471
472
// try to turn off antenna
472
473
FpgaWriteConfWord (FPGA_MAJOR_MODE_OFF );
473
474
474
- if (bitstream_version == FPGA_BITSTREAM_LF ) {
475
+ if (bitstream_target == FPGA_BITSTREAM_LF ) {
475
476
LOW (GPIO_FPGA_SWITCH );
476
477
} else {
477
478
HIGH (GPIO_FPGA_SWITCH );
478
479
}
479
480
// update downloaded_bitstream
480
- downloaded_bitstream = bitstream_version ;
481
+ downloaded_bitstream = bitstream_target ;
481
482
// turn off antenna
482
483
FpgaWriteConfWord (FPGA_MAJOR_MODE_OFF );
483
484
return true;
@@ -490,18 +491,18 @@ static bool FpgaConfCurrentMode(int bitstream_version) {
490
491
// Check which FPGA image is currently loaded (if any). If necessary
491
492
// decompress and load the correct (HF or LF) image to the FPGA
492
493
//----------------------------------------------------------------------------
493
- void FpgaDownloadAndGo (int bitstream_version ) {
494
+ void FpgaDownloadAndGo (int bitstream_target ) {
494
495
495
496
// check whether or not the bitstream is already loaded
496
- if (downloaded_bitstream == bitstream_version ) {
497
+ if (downloaded_bitstream == bitstream_target ) {
497
498
FpgaEnableTracing ();
498
499
return ;
499
500
}
500
501
501
502
#if defined XC3
502
503
// If we can change image version
503
504
// direct return.
504
- if (FpgaConfCurrentMode (bitstream_version )) {
505
+ if (FpgaConfCurrentMode (bitstream_target )) {
505
506
return ;
506
507
}
507
508
#endif
@@ -520,19 +521,19 @@ void FpgaDownloadAndGo(int bitstream_version) {
520
521
compressed_fpga_stream .lz4StreamDecode = & lz4StreamDecode_body ;
521
522
uint8_t * output_buffer = BigBuf_malloc (FPGA_RING_BUFFER_BYTES );
522
523
523
- if (!reset_fpga_stream (bitstream_version , & compressed_fpga_stream , output_buffer ))
524
+ if (!reset_fpga_stream (bitstream_target , & compressed_fpga_stream , output_buffer ))
524
525
return ;
525
526
526
527
uint32_t bitstream_length ;
527
- if (bitparse_find_section (bitstream_version , 'e' , & bitstream_length , & compressed_fpga_stream , output_buffer )) {
528
- DownloadFPGA (bitstream_version , bitstream_length , & compressed_fpga_stream , output_buffer );
529
- downloaded_bitstream = bitstream_version ;
528
+ if (bitparse_find_section (bitstream_target , 'e' , & bitstream_length , & compressed_fpga_stream , output_buffer )) {
529
+ DownloadFPGA (bitstream_target , bitstream_length , & compressed_fpga_stream , output_buffer );
530
+ downloaded_bitstream = bitstream_target ;
530
531
}
531
532
532
533
#if defined XC3
533
534
// first download fpga image to hf
534
535
// we need to change fpga status to hf
535
- FpgaConfCurrentMode (bitstream_version );
536
+ FpgaConfCurrentMode (bitstream_target );
536
537
#endif
537
538
538
539
// turn off antenna
0 commit comments