Skip to content

Change Wire Rx/Tx buffers managements #152

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 4 commits into from
Nov 16, 2017
Merged

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Nov 15, 2017

Rx/Tx Buffers are now dynamically allocated (min size: BUFFER_LENGTH)
TwoWire::write(const uint8_t *data, size_t quantity) avoid copy byte/byte in the buffer

Replace #131 to solve issue #124

fpr added 3 commits November 10, 2017 11:36
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Buffers are now dynamically allocated (min size: BUFFER_LENGTH)

Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
@fpistm fpistm added the enhancement New feature or request label Nov 15, 2017
@fpistm fpistm added this to the Next release milestone Nov 15, 2017
@fpistm fpistm self-assigned this Nov 15, 2017
@fpistm fpistm requested review from LMESTM and a user November 15, 2017 16:09
Copy link
Member

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

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

Minor comments and question - concept and overall implementation is good to go for me

/* Reset rx buffer when no more data available */
/*if(rxBufferIndex == rxBufferLength) {
resetRxBuffer();
}*/
}
Copy link
Member

Choose a reason for hiding this comment

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

Why keeping commented source code ?

Copy link
Member Author

@fpistm fpistm Nov 15, 2017

Choose a reason for hiding this comment

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

Just to show it is possible to reset the Rx buffer here. But thought it is not required.

}
return buffer;
}

Copy link
Member

Choose a reason for hiding this comment

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

why moving to .h file ? maybe you can simply move it up in the C file ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Move it as inline function in the class to avoid function call

Copy link
Member

Choose a reason for hiding this comment

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

inline is fine - but why not keep it in wire.cpp file ?

uint8_t *allocateBuffer(uint8_t *buffer, size_t length);
uint8_t *resetBuffer(uint8_t *buffer);
inline void allocateRxBuffer(size_t length){ if(rxBufferAllocated < length) {
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
Copy link
Member

Choose a reason for hiding this comment

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

missing return lines

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a choice but I can add one.

inline void allocateRxBuffer(size_t length){ if(rxBufferAllocated < length) {
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
if(length < BUFFER_LENGTH) { length = BUFFER_LENGTH; }
rxBuffer = (uint8_t *)realloc(rxBuffer, length * sizeof(uint8_t));
Copy link
Member

Choose a reason for hiding this comment

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

should't you check for a MAX SIZE somewhere to report an error rather than allocating all the available heap memory ?

Copy link
Member Author

@fpistm fpistm Nov 15, 2017

Choose a reason for hiding this comment

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

I thought about it but I would not add more check.
If all heap is used then buffer will be at nullptr then an error will be raised.

- Do not call realloc each time, only if needed
- Assume that user will use more than one time the same buffer
size so avoid the call to realloc to decrease size
- write: avoid copy byte/byte in the buffer

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
@fpistm fpistm merged commit 19930bf into stm32duino:master Nov 16, 2017
@fpistm fpistm deleted the pr/131 branch November 16, 2017 09:48
benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
Change Wire Rx/Tx buffers managements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants