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

Skip to content

move ringbuffer definition to header and allow protected access to Hardware serial for subclassing [imported] #947

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

Closed
cmaglie opened this issue Nov 15, 2012 · 1 comment

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 947 moved from a Google Code project.
Added by 2012-06-05T11:32:12.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium

Original description

These changes are suggested to allow for subclassing and access to ringbuffer from subclass methods.

This should to the best of my knowledge be a "Mostly harmless" change, but e.g. projects like (github) ErikZalm/Marlin could stop copying large parts of the Arduino libraries for modifications.

--- HardwareSerial.h Tue Jun 5 13:07:28 2012
+++ HardwareSerial_update.h Tue Jun 5 13:23:29 2012
@@ -26,11 +26,26 @@

#include "Stream.h"

-struct ring_buffer;
+// Define constants and variables for buffering incoming serial data. We're
+// using a ring buffer (I think), in which head is the index of the location
+// to which to write the next incoming character and tail is the index of the
+// location from which to read.
+#if (RAMEND < 1000)

  • #define SERIAL_BUFFER_SIZE 16
    +#else
  • #define SERIAL_BUFFER_SIZE 64
    +#endif

+struct ring_buffer
+{

  • unsigned char buffer[SERIAL_BUFFER_SIZE];
  • volatile unsigned int head;
  • volatile unsigned int tail;
    +};

class HardwareSerial : public Stream
{

  • private:
  • protected:
    ring_buffer *_rx_buffer;
    ring_buffer *_tx_buffer;
    volatile uint8_t *_ubrrh;

$ diff HardwareSerial.cpp HardwareSerial_update.cpp -u
--- HardwareSerial.cpp Tue Jun 5 13:07:28 2012
+++ HardwareSerial_update.cpp Tue Jun 5 13:23:15 2012
@@ -33,23 +33,6 @@

#include "HardwareSerial.h"

-// Define constants and variables for buffering incoming serial data. We're
-// using a ring buffer (I think), in which head is the index of the location
-// to which to write the next incoming character and tail is the index of the
-// location from which to read.
-#if (RAMEND < 1000)

  • #define SERIAL_BUFFER_SIZE 16
    -#else
  • #define SERIAL_BUFFER_SIZE 64
    -#endif

-struct ring_buffer
-{

  • unsigned char buffer[SERIAL_BUFFER_SIZE];
  • volatile unsigned int head;
  • volatile unsigned int tail;
    -};

#if defined(USBCON)
ring_buffer rx_buffer = { { 0 }, 0, 0};
ring_buffer tx_buffer = { { 0 }, 0, 0};

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Apr 19, 2013
This removes the need for doing an extra pointer dereference on every
access to the buffers, shrinking the code by around 100 bytes.

The members for these buffers must be public for now, since the
interrupt handlers also need to access them. These can later be made
private again.

Furthermore, the struct ring_buffer was removed. This allows the all
head and tail pointers to be put into the HardwareSerial struct before
the actual buffers, so the pointers all end up in the first 32 bytes of
the struct that can be accessed using a single instruction (ldd).

References: arduino#947
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Apr 19, 2013
This allows users to create subclasses.

Closes: arduino#947
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Jul 26, 2013
This removes the need for doing an extra pointer dereference on every
access to the buffers, shrinking the code by around 100 bytes.

The members for these buffers must be public for now, since the
interrupt handlers also need to access them. These can later be made
private again.

Furthermore, the struct ring_buffer was removed. This allows the all
head and tail pointers to be put into the HardwareSerial struct before
the actual buffers, so the pointers all end up in the first 32 bytes of
the struct that can be accessed using a single instruction (ldd).

References: arduino#947
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Jul 26, 2013
This allows users to create subclasses.

Closes: arduino#947
cmaglie added a commit to cmaglie/Arduino that referenced this issue Jul 27, 2013
@cmaglie
Copy link
Member Author

cmaglie commented Jul 30, 2013

Done.

@cmaglie cmaglie closed this as completed Jul 30, 2013
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

No branches or pull requests

1 participant