Buffer from Sam Grove changed to have static instead of dynamic memory allocation. Fixed size to 256B.

Dependents:   BufferedSerialStatic

Fork of Buffer by Sam Grove

Revision:
7:e80960adb2ad
Parent:
6:89564915f2a7
diff -r 89564915f2a7 -r e80960adb2ad MyBuffer.h
--- a/MyBuffer.h	Mon Mar 07 21:10:13 2016 +0000
+++ b/MyBuffer.h	Mon May 28 14:34:02 2018 +0000
@@ -21,47 +21,23 @@
  * limitations under the License.
  */
  
+/**
+ * Modification of original code to implement buffer with static memory 
+ * allocation with size 256. 
+ */
+ 
 #ifndef MYBUFFER_H
 #define MYBUFFER_H
 
 #include <stdint.h>
 #include <string.h>
 
-/** A templated software ring buffer
- *
- * Example:
- * @code
- *  #include "mbed.h"
- *  #include "MyBuffer.h"
- *
- *  MyBuffer <char> buf;
- *
- *  int main()
- *  {
- *      buf = 'a';
- *      buf.put('b');
- *      char *head = buf.head();
- *      puts(head);
- *
- *      char whats_in_there[2] = {0};
- *      int pos = 0;
- *
- *      while(buf.available())
- *      {   
- *          whats_in_there[pos++] = buf;
- *      }
- *      printf("%c %c\n", whats_in_there[0], whats_in_there[1]);
- *      buf.clear();
- *      error("done\n\n\n");
- *  }
- * @endcode
- */
-
 template <typename T>
 class MyBuffer
 {
 private:
-    T   *_buf;
+    const static uint16_t BUFFER_SIZE = 256;
+    T _buf[BUFFER_SIZE];
     volatile uint32_t   _wloc;
     volatile uint32_t   _rloc;
     uint32_t            _size;
@@ -70,7 +46,7 @@
     /** Create a Buffer and allocate memory for it
      *  @param size The size of the buffer
      */
-    MyBuffer(uint32_t size = 0x100);
+    MyBuffer();
     
     /** Get the size of the ring buffer
      * @return the size of the ring buffer