Skip to content

Commit 7fc0db4

Browse files
committed
ols: Clean up: Rename variables, remove misleading counter
cnt_samples_rle was larger than num_samples in RLE mode. Instead of correcting that, use num_samples instead.
1 parent 72fae1a commit 7fc0db4

File tree

3 files changed

+69
-70
lines changed

3 files changed

+69
-70
lines changed

src/hardware/openbench-logic-sniffer/api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
409409
return SR_ERR;
410410

411411
/* Reset all operational states. */
412-
devc->rle_count = devc->raw_sample_buf_size = 0;
413-
devc->num_samples = devc->num_bytes = 0;
414-
devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0;
415-
memset(devc->sample, 0, 4);
412+
devc->rle_count = devc->sample_buf_size = 0;
413+
devc->cnt_samples = devc->raw_sample_size = 0;
414+
devc->cnt_rx_bytes = devc->cnt_rx_raw_samples = 0;
415+
memset(devc->raw_sample, 0, 4);
416416

417417
std_session_send_df_header(sdi);
418418

src/hardware/openbench-logic-sniffer/protocol.c

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
395395
struct sr_datafeed_packet packet;
396396
struct sr_datafeed_logic logic;
397397
uint32_t sample;
398-
int num_changroups, j;
399-
unsigned int i;
398+
unsigned int i, j, num_changroups;
400399
unsigned char byte;
401400

402401
(void)fd;
@@ -405,7 +404,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
405404
serial = sdi->conn;
406405
devc = sdi->priv;
407406

408-
if (devc->cnt_bytes == 0 && revents == 0) {
407+
if (devc->cnt_rx_bytes == 0 && revents == 0) {
409408
/* Ignore timeouts as long as we haven't received anything */
410409
return TRUE;
411410
}
@@ -420,40 +419,40 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
420419
if (revents == G_IO_IN) {
421420
if (serial_read_nonblocking(serial, &byte, 1) != 1)
422421
return FALSE;
423-
devc->cnt_bytes++;
422+
devc->cnt_rx_bytes++;
424423

425-
devc->sample[devc->num_bytes++] = byte;
424+
devc->raw_sample[devc->raw_sample_size++] = byte;
426425
sr_spew("Received byte 0x%.2x.", byte);
427-
if (devc->num_bytes == num_changroups) {
426+
if (devc->raw_sample_size == num_changroups) {
428427
unsigned int samples_to_write, new_sample_buf_size;
429428

430-
devc->cnt_samples++;
431-
devc->cnt_samples_rle++;
429+
devc->cnt_rx_raw_samples++;
432430
/*
433431
* Got a full sample. Convert from the OLS's little-endian
434432
* sample to the local format.
435433
*/
436-
sample = devc->sample[0] | (devc->sample[1] << 8) |
437-
(devc->sample[2] << 16) |
438-
(devc->sample[3] << 24);
439-
sr_dbg("Received sample 0x%.*x.", devc->num_bytes * 2,
440-
sample);
434+
sample = devc->raw_sample[0] |
435+
(devc->raw_sample[1] << 8) |
436+
(devc->raw_sample[2] << 16) |
437+
(devc->raw_sample[3] << 24);
438+
sr_dbg("Received sample 0x%.*x.",
439+
devc->raw_sample_size * 2, sample);
441440
if (devc->capture_flags & CAPTURE_FLAG_RLE) {
442441
/*
443442
* In RLE mode the high bit of the sample is the
444443
* "count" flag, meaning this sample is the number
445444
* of times the previous sample occurred.
446445
*/
447-
if (devc->sample[devc->num_bytes - 1] & 0x80) {
446+
if (devc->raw_sample[devc->raw_sample_size - 1] &
447+
0x80) {
448448
/* Clear the high bit. */
449-
sample &= ~(0x80 << (devc->num_bytes -
450-
1) * 8);
449+
sample &= ~(0x80
450+
<< (devc->raw_sample_size -
451+
1) * 8);
451452
devc->rle_count = sample;
452-
devc->cnt_samples_rle +=
453-
devc->rle_count;
454453
sr_dbg("RLE count: %u.",
455454
devc->rle_count);
456-
devc->num_bytes = 0;
455+
devc->raw_sample_size = 0;
457456
return TRUE;
458457
}
459458
}
@@ -479,47 +478,47 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
479478
* sample.
480479
*/
481480
tmp_sample[i] =
482-
devc->sample[j++];
481+
devc->raw_sample[j++];
483482
}
484483
}
485-
memcpy(devc->sample, tmp_sample, 4);
484+
memcpy(devc->raw_sample, tmp_sample, 4);
486485
sr_spew("Expanded sample: 0x%.2hhx%.2hhx%.2hhx%.2hhx ",
487-
devc->sample[3], devc->sample[2],
488-
devc->sample[1], devc->sample[0]);
486+
devc->raw_sample[3],
487+
devc->raw_sample[2],
488+
devc->raw_sample[1],
489+
devc->raw_sample[0]);
489490
}
490491

491492
samples_to_write = devc->rle_count + 1;
492493
new_sample_buf_size =
493494
4 * MAX(devc->limit_samples,
494-
devc->num_samples + samples_to_write);
495+
devc->cnt_samples + samples_to_write);
495496

496-
if (devc->raw_sample_buf_size < new_sample_buf_size) {
497-
unsigned int old_size =
498-
devc->raw_sample_buf_size;
497+
if (devc->sample_buf_size < new_sample_buf_size) {
498+
unsigned int old_size = devc->sample_buf_size;
499499
new_sample_buf_size *= 2;
500-
devc->raw_sample_buf =
501-
g_try_realloc(devc->raw_sample_buf,
502-
new_sample_buf_size);
503-
devc->raw_sample_buf_size = new_sample_buf_size;
500+
devc->sample_buf = g_try_realloc(
501+
devc->sample_buf, new_sample_buf_size);
502+
devc->sample_buf_size = new_sample_buf_size;
504503

505-
if (!devc->raw_sample_buf) {
504+
if (!devc->sample_buf) {
506505
sr_err("Sample buffer malloc failed.");
507506
return FALSE;
508507
}
509508
/* fill with 1010... for debugging */
510-
memset(devc->raw_sample_buf + old_size, 0x82,
509+
memset(devc->sample_buf + old_size, 0x82,
511510
new_sample_buf_size - old_size);
512511
}
513512

514513
for (i = 0; i < samples_to_write; i++)
515-
memcpy(devc->raw_sample_buf +
516-
(devc->num_samples + i) * 4,
517-
devc->sample, 4);
514+
memcpy(devc->sample_buf +
515+
(devc->cnt_samples + i) * 4,
516+
devc->raw_sample, 4);
518517

519-
devc->num_samples += samples_to_write;
518+
devc->cnt_samples += samples_to_write;
520519

521-
memset(devc->sample, 0, 4);
522-
devc->num_bytes = 0;
520+
memset(devc->raw_sample, 0, 4);
521+
devc->raw_sample_size = 0;
523522
devc->rle_count = 0;
524523
}
525524
} else {
@@ -530,23 +529,23 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
530529
* we've acquired all the samples we asked for -- we're done.
531530
* Send the (properly-ordered) buffer to the frontend.
532531
*/
533-
sr_dbg("Received %d bytes, %d samples, %d decompressed samples.",
534-
devc->cnt_bytes, devc->cnt_samples,
535-
devc->cnt_samples_rle);
532+
sr_dbg("Received %d bytes, %d raw samples, %d decompressed samples.",
533+
devc->cnt_rx_bytes, devc->cnt_rx_raw_samples,
534+
devc->cnt_samples);
536535

537536
/*
538537
* The OLS sends its sample buffer backwards.
539538
* Flip it back before sending it on the session bus.
540539
*/
541-
for (i = 0; i < devc->num_samples / 2; i++) {
540+
for (i = 0; i < devc->cnt_samples / 2; i++) {
542541
uint8_t temp[4];
543-
memcpy(temp, &devc->raw_sample_buf[4 * i], 4);
544-
memmove(&devc->raw_sample_buf[4 * i],
545-
&devc->raw_sample_buf[4 * (devc->num_samples -
546-
i - 1)],
542+
memcpy(temp, &devc->sample_buf[4 * i], 4);
543+
memmove(&devc->sample_buf[4 * i],
544+
&devc->sample_buf[4 *
545+
(devc->cnt_samples - i - 1)],
547546
4);
548-
memcpy(&devc->raw_sample_buf[4 * (devc->num_samples -
549-
i - 1)],
547+
memcpy(&devc->sample_buf[4 *
548+
(devc->cnt_samples - i - 1)],
550549
temp, 4);
551550
}
552551

@@ -557,13 +556,13 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
557556
*/
558557
if (devc->trigger_at_smpl > 0 &&
559558
(unsigned int)devc->trigger_at_smpl <=
560-
devc->num_samples) {
559+
devc->cnt_samples) {
561560
/* There are pre-trigger samples, send those first. */
562561
packet.type = SR_DF_LOGIC;
563562
packet.payload = &logic;
564563
logic.length = devc->trigger_at_smpl * 4;
565564
logic.unitsize = 4;
566-
logic.data = devc->raw_sample_buf;
565+
logic.data = devc->sample_buf;
567566
sr_session_send(sdi, &packet);
568567
}
569568

@@ -576,21 +575,21 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
576575
devc->trigger_at_smpl == OLS_NO_TRIGGER ?
577576
0 :
578577
MIN((unsigned int)devc->trigger_at_smpl,
579-
devc->num_samples);
580-
if (devc->num_samples > num_pre_trigger_samples) {
578+
devc->cnt_samples);
579+
if (devc->cnt_samples > num_pre_trigger_samples) {
581580
packet.type = SR_DF_LOGIC;
582581
packet.payload = &logic;
583582
logic.length =
584-
(devc->num_samples - num_pre_trigger_samples) *
583+
(devc->cnt_samples - num_pre_trigger_samples) *
585584
4;
586585
logic.unitsize = 4;
587-
logic.data = devc->raw_sample_buf +
588-
num_pre_trigger_samples * 4;
586+
logic.data =
587+
devc->sample_buf + num_pre_trigger_samples * 4;
589588
sr_session_send(sdi, &packet);
590589
}
591590

592-
g_free(devc->raw_sample_buf);
593-
devc->raw_sample_buf = 0;
591+
g_free(devc->sample_buf);
592+
devc->sample_buf = 0;
594593

595594
serial_flush(serial);
596595
abort_acquisition(sdi);

src/hardware/openbench-logic-sniffer/protocol.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ struct dev_context {
114114
int trigger_at_smpl;
115115
uint16_t capture_flags;
116116

117-
unsigned int num_samples;
118-
int num_bytes;
119-
int cnt_bytes;
120-
int cnt_samples;
121-
int cnt_samples_rle;
117+
unsigned int cnt_rx_bytes; /* number of bytes received */
118+
unsigned int raw_sample_size; /* valid bytes in sample[4] */
119+
unsigned char
120+
raw_sample[4]; /* raw sample, assembled from received bytes */
121+
unsigned int cnt_rx_raw_samples; /* number of raw samples received */
122122

123123
unsigned int rle_count;
124-
unsigned char sample[4];
125-
unsigned char *raw_sample_buf;
126-
unsigned int raw_sample_buf_size;
124+
unsigned char *sample_buf;
125+
unsigned int sample_buf_size;
126+
unsigned int cnt_samples; /* number of final samples in sample_buf */
127127
};
128128

129129
SR_PRIV extern const char *ols_channel_names[];

0 commit comments

Comments
 (0)