My current thing do is about using a Ring Buffer.
Code: Select all
void fSendSerialToBrain( void *pvParameters )
{
CAN_frame_t rx_frame;
xSemaphoreGive ( sema_SendSerialToBrain );
bool PassTwo = false;
for (;;)
{
xEventGroupWaitBits (eg, evtSendSerialToBrain, pdTRUE, pdTRUE, portMAX_DELAY);
size_t item_size;
for (int i = 0; i < RingBufferTriggerSize; i++)
{
int *item = (int *)xRingbufferReceive(h_buf_LIDAR_INFO, &item_size, pdMS_TO_TICKS(0)); // reterive item from ring buffer, no wait
if (item != NULL)
{
vRingbufferReturnItem(h_buf_LIDAR_INFO, (void *)item); // remove item from ring buffer
// prep item for sending over CAN buss
if (!PassTwo)
{
rx_frame.FIR.B.FF = CAN_frame_std;
rx_frame.MsgID = 1;
rx_frame.FIR.B.DLC = 8;
rx_frame.data.u8[0] = *item & 0xFF;
rx_frame.data.u8[1] = (*item >> 8) & 0xFF;
rx_frame.data.u8[2] = (*item >> 16) & 0xFF;
rx_frame.data.u8[3] = (*item >> 24) & 0xFF;
PassTwo = true;
} else {
rx_frame.data.u8[4] = *item & 0xFF;;
rx_frame.data.u8[5] = (*item >> 8) & 0xFF;
rx_frame.data.u8[6] = (*item >> 16) & 0xFF;
rx_frame.data.u8[7] = (*item >> 24) & 0xFF;
ESP32Can.CANWriteFrame(&rx_frame); // send items over CAN buss
PassTwo = false;
}
}
}
}
vTaskDelete( NULL );
} // void fSendSerialToBrain( void *pvParameters )
What I'd like to do, if possible, is to read the entire contents of the ring buffer but only remove the first item, instead of removing all the items. I am under the impression that each retrieve requires a vRingbufferReturnItem. It makes sense to me that if I just do a vRingbufferReturnItem on the first item that the first item can be replaced leaving the other items in place but still able to be read?