This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCU-PLUS-SDK-AM273X: LwIP socket API not being blocking

Part Number: MCU-PLUS-SDK-AM273X
Other Parts Discussed in Thread: AM2732

Tool/software:

Hello,
LwIP describes socket API as part of "Sequential-style APIs, blocking functions. More overhead, but can be called from any thread except TCPIP thread.".
I'm trying to stream RTP using UDP on my AM2732 but noticed that many of the packets going out were corrupted.
I'm aware that a cache invalidate needs to be performed on the send buffer before sending, and that the send buffer should be a multiple of the cache size:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define R5F_CACHE_LINE_SIZE (32)
#define UTILS_ALIGN(x, align) ((((x) + ((align)-1)) / (align)) * (align))
static u8_t rtp_send_packet[UTILS_ALIGN(RTP_PACKET_SIZE, R5F_CACHE_LINE_SIZE)] __attribute__ ((aligned(R5F_CACHE_LINE_SIZE), section(".bss:UDP_SND_BUF")));
/*...*/
do {
/*...*/
CacheP_wbInv(rtp_send_packet, sizeof(rtp_send_packet), CacheP_TYPE_ALLD);
if (lwip_sendto(sock, rtp_send_packet, sizeof(struct rtp_hdr) + rtp_payload_size, 0, (struct sockaddr *)to, sizeof(struct sockaddr)) >= 0)
{
/*...*/
} while (rtp_data_index < sizeof(rtp_data));
/*...*/
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Adding a simple sleep or some debug prints fixes the issue, so I started investigating the lower level functions using DMA.
Please correct me if I'm wrong, but I noticed that everything works using queues, so the lwip_sendto returns as early as enqueuing is done, and then inside the interrupt function EnetCpdma_txIsr the queue is processed and actually sent.

Adding a SemaphoreP_post inside this DMA function and doing SemaphoreP_pend right after the lwip_sendto fixes the corruptions, but noticeably reduces throughput.

Is this the expected solution to this problem? If not, what would be the correct approach to ensure data integrity without significantly impacting performance?

Thank you