Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
dast_1961951
Level 4
Level 4
10 likes received First like received

Working in WICED 4.1.0.43 and have noted that, when using a ring buffer (ring_buffer.c), every nth byte is corrupt where n = ring_buffer.size. 

Looks like a long-standing issue that's masked often because the corrupt byte is most often NULL and the buffers are typically used in fault-tolerant protocols.

Exposed as follows:

int cmd_rb_test(int argc, char argv[])

{

    static wiced_ring_buffer_t test_buf;

    unsigned char test_buf_data[999];

    uint8_t in;

    uint8_t out;

    int bytes_read;

    int i;

    memset(test_buf_data, 0, sizeof(test_buf_data));

    ring_buffer_init((wiced_ring_buffer_t*) &test_buf, (uint8_t*) test_buf_data, sizeof(test_buf_data));

    for (i = 0; i < (sizeof(test_buf_data) * 10); ++i)

    {

        in = i & 0xFF;

        out = 0;

        ring_buffer_write(&test_buf, &in, 1);

        ring_buffer_read(&test_buf, &out, 1, &bytes_read);

        if (out != (i & 0xFF))

        {

            printf("ring buffer failure at %d head= %d tail= %d!\n", (unsigned int) out, test_buf.head, test_buf.tail);

            return -1;

        }

    }

    printf("ring buffer passed\n");

    return 0;

}

15 Replies