Applied 0013-Do-not-reuse-the-index-of-a-pending-datagram.patch

This commit is contained in:
Florian Pose 2022-06-23 10:58:57 +02:00
parent 8db3e5abf4
commit d09daadfbb
1 changed files with 22 additions and 1 deletions

View File

@ -989,6 +989,15 @@ void ec_master_queue_datagram_ext(
/*****************************************************************************/ /*****************************************************************************/
static int index_in_use(ec_master_t *master, uint8_t index)
{
ec_datagram_t *datagram;
list_for_each_entry(datagram, &master->datagram_queue, queue)
if (datagram->state == EC_DATAGRAM_SENT && datagram->index == index)
return 1;
return 0;
}
/** Sends the datagrams in the queue for a certain device. /** Sends the datagrams in the queue for a certain device.
* *
*/ */
@ -1008,6 +1017,7 @@ size_t ec_master_send_datagrams(
unsigned int frame_count, more_datagrams_waiting; unsigned int frame_count, more_datagrams_waiting;
struct list_head sent_datagrams; struct list_head sent_datagrams;
size_t sent_bytes = 0; size_t sent_bytes = 0;
uint8_t last_index;
#ifdef EC_HAVE_CYCLES #ifdef EC_HAVE_CYCLES
cycles_start = get_cycles(); cycles_start = get_cycles();
@ -1045,9 +1055,19 @@ size_t ec_master_send_datagrams(
break; break;
} }
list_add_tail(&datagram->sent, &sent_datagrams); // do not reuse the index of a pending datagram to avoid confusion
// in ec_master_receive_datagrams()
last_index = master->datagram_index;
while (index_in_use(master, master->datagram_index)) {
if (++master->datagram_index == last_index) {
EC_MASTER_ERR(master, "No free datagram index, sending delayed\n");
goto break_send;
}
}
datagram->index = master->datagram_index++; datagram->index = master->datagram_index++;
list_add_tail(&datagram->sent, &sent_datagrams);
EC_MASTER_DBG(master, 2, "Adding datagram 0x%02X\n", EC_MASTER_DBG(master, 2, "Adding datagram 0x%02X\n",
datagram->index); datagram->index);
@ -1075,6 +1095,7 @@ size_t ec_master_send_datagrams(
cur_data += EC_DATAGRAM_FOOTER_SIZE; cur_data += EC_DATAGRAM_FOOTER_SIZE;
} }
break_send:
if (list_empty(&sent_datagrams)) { if (list_empty(&sent_datagrams)) {
EC_MASTER_DBG(master, 2, "nothing to send.\n"); EC_MASTER_DBG(master, 2, "nothing to send.\n");
break; break;