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

Time variable not initialized in transport_fifo_reset #50

Open
kinimodkoch opened this issue Sep 15, 2023 · 1 comment
Open

Time variable not initialized in transport_fifo_reset #50

kinimodkoch opened this issue Sep 15, 2023 · 1 comment

Comments

@kinimodkoch
Copy link

In min.c, the function transport_fifo_reset uses the now variable, but does not update it first. I suggest to insert a call to min_time_ms().

static void transport_fifo_reset(struct min_context *self)
{
    // Clear down the transmission FIFO queue
    self->transport_fifo.n_frames = 0;
    self->transport_fifo.head_idx = 0;
    self->transport_fifo.tail_idx = 0;
    self->transport_fifo.n_ring_buffer_bytes = 0;
    self->transport_fifo.ring_buffer_tail_offset = 0;
    self->transport_fifo.sn_max = 0;
    self->transport_fifo.sn_min = 0;
    self->transport_fifo.rn = 0;

    // Reset the timers
    now = min_time_ms();  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< I suggest to insert this line
    self->transport_fifo.last_received_anything_ms = now;
    self->transport_fifo.last_sent_ack_time_ms = now;
    self->transport_fifo.last_received_frame_ms = 0;
}
@bojanpotocnik
Copy link
Contributor

Function transport_fifo_reset() is only called from:

  • min_init_context(): usually called once during initialization, when the static uint32_t now; is initialized to 0
  • min_poll() -> rx_byte() -> valid_frame_received(): the value of now is updated in min_poll()
  • min_transport_reset(): usually called in runtime, after calling min_poll()

min_poll() is intended to be called every "tick"/loop iteration, so I think it was meant as a feature to only update now inside this function. This ensures all operations in this processing step will use the same now time, including any later calls to min_transport_reset().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants