Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OLS Improvements #51

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/hardware/openbench-logic-sniffer/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
uint32_t sample;
int num_changroups, offset, j;
int num_changroups, j;
unsigned int i;
unsigned char byte;

Expand Down Expand Up @@ -427,6 +427,8 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
devc->sample[devc->num_bytes++] = byte;
sr_spew("Received byte 0x%.2x.", byte);
if (devc->num_bytes == num_changroups) {
unsigned int samples_to_write;

devc->cnt_samples++;
devc->cnt_samples_rle++;
/*
Expand Down Expand Up @@ -457,13 +459,6 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
return TRUE;
}
}
devc->num_samples += devc->rle_count + 1;
if (devc->num_samples > devc->limit_samples) {
/* Save us from overrunning the buffer. */
devc->rle_count -=
devc->num_samples - devc->limit_samples;
devc->num_samples = devc->limit_samples;
}

if (num_changroups < 4) {
/*
Expand Down Expand Up @@ -495,16 +490,14 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
devc->sample[1], devc->sample[0]);
}

/*
* the OLS sends its sample buffer backwards.
* store it in reverse order here, so we can dump
* this on the session bus later.
*/
offset = (devc->limit_samples - devc->num_samples) * 4;
for (i = 0; i <= devc->rle_count; i++) {
memcpy(devc->raw_sample_buf + offset + (i * 4),
samples_to_write = devc->rle_count + 1;
for (i = 0; i < samples_to_write; i++)
memcpy(devc->raw_sample_buf +
(devc->num_samples + i) * 4,
devc->sample, 4);
}

devc->num_samples += samples_to_write;

memset(devc->sample, 0, 4);
devc->num_bytes = 0;
devc->rle_count = 0;
Expand All @@ -518,6 +511,23 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
sr_dbg("Received %d bytes, %d samples, %d decompressed samples.",
devc->cnt_bytes, devc->cnt_samples,
devc->cnt_samples_rle);

/*
* The OLS sends its sample buffer backwards.
* Flip it back before sending it on the session bus.
*/
for (i = 0; i < devc->num_samples / 2; i++) {
uint8_t temp[4];
memcpy(temp, &devc->raw_sample_buf[4 * i], 4);
memmove(&devc->raw_sample_buf[4 * i],
&devc->raw_sample_buf[4 * (devc->num_samples -
i - 1)],
4);
memcpy(&devc->raw_sample_buf[4 * (devc->num_samples -
i - 1)],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: Putting (i - 1) in a seperate line hurts readability IMHO. I'd rather keep it on one line.
The code looks okay. I think the commit message is a bit vague. We mainly want to introduce 'samples_to_write' here, so we can use it for the dynamic buffer later, or did I miss something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I put it on the same line.

I introduce samples_to_write here for clarity, as it's the number of samples that the current sample is expanded to. I think it's easier to understand than "rle_count + 1". The name is debatable, though.

temp, 4);
}

if (devc->trigger_at_smpl != OLS_NO_TRIGGER) {
/*
* A trigger was set up, so we need to tell the frontend
Expand Down