ringbuf: Bugfixes for managing arbitrary sizes of ring buffer
ringbuf: Bugfixes for managing arbitrary sizes of ring buffer

It was observed that if the ring buffer size provided by application
is not a multiple of 4, some checks were failing (as read_ptr and write_ptr
could shoot beyond the ring buffer boundary), thereby causing asserts.
Simply wrapping around the pointers for such cases fixes the issue.

Moreover, because of the logic for maintaining 4-byte boundary,
it was also possible that a wrap-around occurred for some data,
even when the actual size remaining was sufficient for it.
Eg. Buffer available: 34, data size: 34, 4-byte aligned size: 36
Since the logic compares against 36, it writes 34 bytes and does a
wraparound. But since all 34 bytes are already written, there is
nothing to write after wrapping. It is better to just re-set the
write pointer to the dtart of ring buffer in such cases.

Tested send/receive for various arbitrary sizes of data and for
arbitrary sizes of ring buffer.

Alternative Solutions:
1) Allow only sizes which are multiples of 4, and return error otherwise.
Appropriate code and documentation change would be required
2) Allow arbitrary sizes, but internally add upto 3 bytes to make
the total size a multiple of 4

Signed-off-by: Piyush Shah <22b9c231e86e73b6822f10a284ad53e606c09e6d@espressif.com>

empoweredhomes/esp-idf,armada-ai/esp-idf,Hermiedapwdrman/esp-idf,nineisk/esp-idf,empoweredhomes/esp-idf,Hermiedapwdrman/esp-idf,espressif/esp-idf,www220/esp-idf,nineisk/esp-idf,empoweredhomes/esp-idf,MIhanguangyi/esp-idf,www220/esp-idf,MIhanguangyi/esp-idf,empoweredhomes/esp-idf,espressif/esp-idf,espressif/esp-idf,nineisk/esp-idf,MIhanguangyi/esp-idf,mashaoze/esp-idf,mashaoze/esp-idf,armada-ai/esp-idf,mashaoze/esp-idf,nineisk/esp-idf,MIhanguangyi/esp-idf,armada-ai/esp-idf,Hermiedapwdrman/esp-idf,espressif/esp-idf,www220/esp-idf,www220/esp-idf,empoweredhomes/esp-idf,Hermiedapwdrman/esp-idf,Hermiedapwdrman/esp-idf,mashaoze/esp-idf,armada-ai/esp-idf,MIhanguangyi/esp-idf,mashaoze/esp-idf,www220/esp-idf