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
33 changes: 21 additions & 12 deletions src/hardware/openbench-logic-sniffer/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
devc->rle_count = 0;
}
} else {
unsigned int num_pre_trigger_samples;

/*
* This is the main loop telling us a timeout was reached, or
* we've acquired all the samples we asked for -- we're done.
Expand Down Expand Up @@ -541,7 +543,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
* A trigger was set up, so we need to tell the frontend
* about it.
*/
if (devc->trigger_at_smpl > 0) {
if (devc->trigger_at_smpl > 0 &&
(unsigned int)devc->trigger_at_smpl <=
devc->num_samples) {
/* There are pre-trigger samples, send those first. */
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
Expand All @@ -556,17 +560,22 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
}

/* Send post-trigger / all captured samples. */
int num_pre_trigger_samples = devc->trigger_at_smpl ==
OLS_NO_TRIGGER ?
0 :
devc->trigger_at_smpl;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
logic.length =
(devc->num_samples - num_pre_trigger_samples) * 4;
logic.unitsize = 4;
logic.data = devc->raw_sample_buf + num_pre_trigger_samples * 4;
sr_session_send(sdi, &packet);
num_pre_trigger_samples =
devc->trigger_at_smpl == OLS_NO_TRIGGER ?
0 :
MIN((unsigned int)devc->trigger_at_smpl,
devc->num_samples);
if (devc->num_samples > num_pre_trigger_samples) {
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
logic.length =
(devc->num_samples - num_pre_trigger_samples) *
4;
logic.unitsize = 4;
logic.data = devc->raw_sample_buf +
num_pre_trigger_samples * 4;
sr_session_send(sdi, &packet);
}

Choose a reason for hiding this comment

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

Looks good. Maybe commit message could state what non-desired behaviour happened with the old code?

Copy link
Author

Choose a reason for hiding this comment

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

I honestly don't remember what happened when we send garbage via sr_session_send (trigger in the future). I guess it is some unrecoverable state, like a crash, otherwise I think I wouldn't have fixed it.


g_free(devc->raw_sample_buf);
devc->raw_sample_buf = 0;
Expand Down