Skip to content
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

Add generic byte RingBuffer class #8

Open
wants to merge 22 commits into
base: master
from
Open

Conversation

@facchinm
Copy link
Member

@facchinm facchinm commented Jul 1, 2016

  • cloned from samd core
  • implement addStorage() API to allow static/dynamic size increase
@damellis

This comment has been minimized.

Copy link

@damellis damellis commented on api/RealTimeClock.h in bde41a3 Apr 8, 2016

This is a very minor point, but what about calling this setTimeProvider()?

@PaulStoffregen
Copy link

@PaulStoffregen PaulStoffregen commented Jul 1, 2016

Does this code depend upon SAMD's atomic access to "int" type?

@facchinm
Copy link
Member Author

@facchinm facchinm commented Jul 20, 2016

Hi Paul,
the implementation is clearly not interrupt-safe; I believe we should target 32bit MCU in the future so all the considerations should be based on that fact.
Surrounding everything with noInterrupt or ATOMIC_BLOCK-like functions could have a real impact on performance. Limiting the usage to non-IRQ scenarios will make this library "useless".
Do you have any proposal/idea on this topic?

@PaulStoffregen
Copy link

@PaulStoffregen PaulStoffregen commented Jul 21, 2016

Agreed, disabling interrupts probably adds too much overhead. Using more than 8 bits for the head and tail index probably also slows the code too much on AVR. I'd recommend something like this, and in the documentation mention the maximum total buffer size is limited to 256 bytes on AVR.

class RingBuffer
{
    public:
    uint8_t _aucBuffer[RINGBUFFER_SIZE] ;
#ifdef __AVR__
    uint8_t _iHead ;
    uint8_t _iTail ;
#else
    int _iHead ;
    int _iTail ;
#endif

I do believe this feature will make a lot of people very happy, even if the total size is restricted to 256 bytes on AVR chips.

Any idea what the user-visible API will be in the HardwareSerial class? RingBuffer is meant to remain private, right?

@PaulStoffregen
Copy link

@PaulStoffregen PaulStoffregen commented Jul 21, 2016

On AVR, RingBuffer::addStorage() would also need to check the _size parameter to limit to the maximum.

@PaulStoffregen
Copy link

@PaulStoffregen PaulStoffregen commented Oct 19, 2016

Was any decision or proposal ever made for the public API for sketches? Would addStorage() also be in the HardwareSerial object? Or would it be 2 different function names, one for adding to the read buffer and another for writing?

I'd like to try implementing this. Is that ok? Obviously the last thing I want is to publish anything which needs to be kept confidential, or to end up causing compatibility problems.

@facchinm
Copy link
Member Author

@facchinm facchinm commented Oct 20, 2016

I'd leave a single (generic) function in RingBuffer class while specializing in classes using it (like Serial.increaseTxBuffer and Serial.increaseRxBuffer). However, no public discussion has been made ATM, but I think that proposing in the dev list is a really good idea.
@PaulStoffregen , feel absolutely free to propose / post a PR 😄

@PaulStoffregen
Copy link

@PaulStoffregen PaulStoffregen commented Oct 20, 2016

Perhaps the words "Read" and "Write" would be more consistent than "Tx" and "Rx", with the rest of the Arduino API?

Serial.increaseReadBuffer(array1, size1);
Serial.increaseWriteBuffer(array2, size2);

So it's ok to discuss on the public developer list? This is a private area, so I'm always like to double check before posting anything in public.

@facchinm facchinm force-pushed the arduino:master branch from 141b283 to 8ad0c60 Oct 30, 2018
@aentinger
Copy link
Contributor

@aentinger aentinger commented Oct 7, 2020

@facchinm I believe we can close this one? Looks like ancient history 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.