Skip to content

Commit 892b384

Browse files
committed
refactor: rename bitstream_version to bitstream_target
1 parent e168338 commit 892b384

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

armsrc/fpgaloader.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int get_from_fpga_combined_stream(lz4_streamp_t compressed_fpga_stream, u
221221
return *fpga_image_ptr++;
222222
}
223223

224-
static int bitstream_version_to_index(FPGA_config bitstream_version) {
224+
static int bitstream_target_to_index(FPGA_config bitstream_target) {
225225
static int8_t bitstream_index_map[FPGA_BITSTREAM_MAX] = {-1};
226226

227227
// Initialize
@@ -232,17 +232,18 @@ static int bitstream_version_to_index(FPGA_config bitstream_version) {
232232
}
233233
}
234234

235-
return bitstream_index_map[bitstream_version];
235+
return bitstream_index_map[bitstream_target];
236236
}
237237

238238
//----------------------------------------------------------------------------
239239
// Undo the interleaving of several FPGA config files. FPGA config files
240240
// are combined into one big file:
241241
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
242242
//----------------------------------------------------------------------------
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);
245245
while ((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % g_fpga_bitstream_num != bitstream_index) {
246+
// skip undesired data belonging to other bitstream_targets
246247
get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
247248
}
248249

@@ -252,7 +253,7 @@ static int get_from_fpga_stream(int bitstream_version, lz4_streamp_t compressed_
252253
//----------------------------------------------------------------------------
253254
// Initialize decompression of the respective (HF or LF) FPGA stream
254255
//----------------------------------------------------------------------------
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) {
256257
uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE];
257258

258259
uncompressed_bytes_cnt = 0;
@@ -268,7 +269,7 @@ static bool reset_fpga_stream(int bitstream_version, lz4_streamp_t compressed_fp
268269
fpga_image_ptr = output_buffer + FPGA_RING_BUFFER_BYTES;
269270

270271
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);
272273

273274
// Check for a valid .bit file (starts with bitparse_fixed_header)
274275
if (memcmp(bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
@@ -290,7 +291,7 @@ static void DownloadFPGA_byte(uint8_t w) {
290291
}
291292

292293
// 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) {
294295
int i = 0;
295296
#if !defined XC3
296297
AT91C_BASE_PIOA->PIO_OER = GPIO_FPGA_ON;
@@ -368,7 +369,7 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, lz4_streamp_t
368369
#endif
369370

370371
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);
372373
if (b < 0) {
373374
Dbprintf("Error %d during FpgaDownload", b);
374375
break;
@@ -397,14 +398,14 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, lz4_streamp_t
397398
* (big endian), <length> bytes content. Except for section 'e' which has 4 bytes
398399
* length.
399400
*/
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) {
401402

402403
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
403404

404405
int result = 0;
405406
uint16_t numbytes = 0;
406407
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);
408409
numbytes++;
409410
uint32_t current_length = 0;
410411
if (current_name < 'a' || current_name > 'e') {
@@ -415,19 +416,19 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
415416
switch (current_name) {
416417
case 'e':
417418
/* 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;
422423
numbytes += 4;
423424
if (current_length > 300 * 1024) {
424425
/* section e should never exceed about 300KB, if the length is too big limit it but still send the bitstream just in case */
425426
current_length = 300 * 1024;
426427
}
427428
break;
428429
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;
431432
numbytes += 2;
432433
if (current_length > 64) {
433434
/* 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
443444
}
444445

445446
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);
447448
numbytes++;
448449
}
449450
}
@@ -452,12 +453,12 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
452453

453454
//----------------------------------------------------------------------------
454455
// 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
456457
// return true if can change.
457458
// return false if image is unloaded.
458459
//----------------------------------------------------------------------------
459460
#if defined XC3
460-
static bool FpgaConfCurrentMode(int bitstream_version) {
461+
static bool FpgaConfCurrentMode(int bitstream_target) {
461462
// fpga "XC3S100E" image merge
462463
// If fpga image is no init
463464
// We need load hf_lf_allinone.bit
@@ -471,13 +472,13 @@ static bool FpgaConfCurrentMode(int bitstream_version) {
471472
// try to turn off antenna
472473
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
473474

474-
if (bitstream_version == FPGA_BITSTREAM_LF) {
475+
if (bitstream_target == FPGA_BITSTREAM_LF) {
475476
LOW(GPIO_FPGA_SWITCH);
476477
} else {
477478
HIGH(GPIO_FPGA_SWITCH);
478479
}
479480
// update downloaded_bitstream
480-
downloaded_bitstream = bitstream_version;
481+
downloaded_bitstream = bitstream_target;
481482
// turn off antenna
482483
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
483484
return true;
@@ -490,18 +491,18 @@ static bool FpgaConfCurrentMode(int bitstream_version) {
490491
// Check which FPGA image is currently loaded (if any). If necessary
491492
// decompress and load the correct (HF or LF) image to the FPGA
492493
//----------------------------------------------------------------------------
493-
void FpgaDownloadAndGo(int bitstream_version) {
494+
void FpgaDownloadAndGo(int bitstream_target) {
494495

495496
// check whether or not the bitstream is already loaded
496-
if (downloaded_bitstream == bitstream_version) {
497+
if (downloaded_bitstream == bitstream_target) {
497498
FpgaEnableTracing();
498499
return;
499500
}
500501

501502
#if defined XC3
502503
// If we can change image version
503504
// direct return.
504-
if (FpgaConfCurrentMode(bitstream_version)) {
505+
if (FpgaConfCurrentMode(bitstream_target)) {
505506
return;
506507
}
507508
#endif
@@ -520,19 +521,19 @@ void FpgaDownloadAndGo(int bitstream_version) {
520521
compressed_fpga_stream.lz4StreamDecode = &lz4StreamDecode_body;
521522
uint8_t *output_buffer = BigBuf_malloc(FPGA_RING_BUFFER_BYTES);
522523

523-
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer))
524+
if (!reset_fpga_stream(bitstream_target, &compressed_fpga_stream, output_buffer))
524525
return;
525526

526527
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;
530531
}
531532

532533
#if defined XC3
533534
// first download fpga image to hf
534535
// we need to change fpga status to hf
535-
FpgaConfCurrentMode(bitstream_version);
536+
FpgaConfCurrentMode(bitstream_target);
536537
#endif
537538

538539
// turn off antenna

armsrc/fpgaloader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ void FpgaSendCommand(uint16_t cmd, uint16_t v);
165165
void FpgaWriteConfWord(uint16_t v);
166166
void FpgaEnableTracing(void);
167167
void FpgaDisableTracing(void);
168-
void FpgaDownloadAndGo(int bitstream_version);
169-
// void FpgaGatherVersion(int bitstream_version, char *dst, int len);
168+
void FpgaDownloadAndGo(int bitstream_target);
169+
// void FpgaGatherVersion(int bitstream_target, char *dst, int len);
170170
void FpgaSetupSsc(uint16_t fpga_mode);
171171
void SetupSpi(int mode);
172172
bool FpgaSetupSscDma(uint8_t *buf, uint16_t len);

0 commit comments

Comments
 (0)