Skip to content

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

Closed
@cmaglie

Description

@cmaglie

This is Issue 947 moved from a Google Code project.
Added by 2012-06-05T11:32:12.000Z by l...@soerup.org.
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};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions