min-protocol / min

The MIN protocol specification and reference implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Time variable not initialized in transport_fifo_reset

kinimodkoch opened this issue · comments

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;
}

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().