Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduced ringbuf_init to perform static buffer initialisation #5813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 10, 2022

Conversation

EmergReanimator
Copy link

@EmergReanimator EmergReanimator commented Jan 5, 2022

In some use cases like debugging over UART, if DEBUG_TX/DEBUG_RX are defined, the static buffer is provided by serial_early_init with the call of common_hal_busio_uart_construct.

Mircopython originally recommended to use list of initialisers instead of calling ringbuf_alloc in case the buffer cannot be allocated from heap internally and static buffer must be provided by user code.

// Static initialization:
// byte buf_array[N];
// ringbuf_t buf = {buf_array, sizeof(buf_array)};

In the meantime the ring buffer interface has been modified in micropython project.

This approach can be error prone because the user code relies on certain order of structure members.
Initialising the structure with designators addresses this issue but then the names of structure members are exposed.

Using dedicated function is cleaner and more portable way of initialisation.
The overhead is single bool structure member.
Appending this member to the structure preserves the backward compatibility with initialiser list approach.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I agree ringbuf_init is an improvement. One comment that I think points out a bug. Otherwise this looks good.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you!

@tannewt tannewt merged commit 838a007 into adafruit:main Jan 10, 2022
@EmergReanimator EmergReanimator deleted the code_improvements branch February 5, 2022 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants