Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CircularArray.cpp
- Revision:
- 1:5036a532fe62
- Parent:
- 0:28766f5a758e
--- a/CircularArray.cpp Tue Feb 11 18:41:26 2014 +0000
+++ b/CircularArray.cpp Wed Feb 12 15:51:51 2014 +0000
@@ -1,51 +1,71 @@
#include "CircularArray.h"
-#include <cstring>
+#include <string.h>
-template <typename T> CircularArray<T>::CircularArray(unsigned int capacity)
+CircularArray::CircularArray(unsigned int capacity)
{
- data = new T[capacity];
- m_capacity=capacity
+ data = new uint8_t[capacity];
+ m_capacity=capacity;
m_full=false;
m_empty=true;
w=0;
r=0;
+ sizeRB=0;
+ sizeWB=0;
+ readerBuffer=0;
+ writerBuffer=0;
}
-template <typename T>CircularArray<T>::~CircularArray()
+CircularArray::~CircularArray()
{
- delete data[];
+ delete[] data;
}
-template <typename T> T * CircularArray<T>::getWritePointer()
+
+
+void volatile_memcpy(volatile uint8_t * dest, volatile uint8_t * src, uint16_t num)
{
- return data+w;
+ for(int i =0; i<num;i++)
+ {
+ dest[i]=src[i];
+ }
}
-template <typename T> T * CircularArray<T>::getReadPointer(T * buffer,unsigned int num)
+uint8_t * CircularArray::getWritePointer()
{
- if(buffer==0 || num <=readable())
+ return (uint8_t *)data+w;
+}
+
+
+uint8_t * CircularArray::getReadPointer(uint16_t num)
+{
+ if(num <=readable())
{
- return data+r;
+ return (uint8_t *)data+r;
}
else
{
- memcpy(buffer,data+r,readable());
- memcpy(buffer+readable(),data,num-readable());
- return buffer;
+ if(sizeRB<num)
+ {
+ if(readerBuffer!=0) delete[] readerBuffer;
+ readerBuffer = new uint8_t[num];
+ }
+ volatile_memcpy(readerBuffer,(uint8_t *)(data+r),readable());
+ volatile_memcpy(readerBuffer+readable(),data,num-readable());
+ return (uint8_t *)readerBuffer;
}
}
-template <typename T> void CircularArray<T>::writeElements(unsigned int num)
+void CircularArray::writeElements(unsigned int num)
{
w=(w+num)%m_capacity;
m_full=r==w;
}
-template <typename T> void CircularArray<T>::readElements(unsigned int num)
+void CircularArray::readElements(unsigned int num)
{
r=(r+num)%m_capacity;
m_empty=r==w;
}
-template <typename T> unsigned int CircularArray<T>::fillCapacity()
+unsigned int CircularArray::fillCapacity()
{
if(w>r || m_empty)
{
@@ -56,7 +76,7 @@
return r-w;
}
}
-template <typename T> unsigned int CircularArray<T>::freeSpace()
+unsigned int CircularArray::freeSpace()
{
if(w>r || m_empty)
{
@@ -68,7 +88,7 @@
}
}
-template <typename T> unsigned int CircularArray<T>::readable()
+unsigned int CircularArray::readable()
{
if(w<r || m_full)
{
@@ -80,7 +100,7 @@
}
}
-template <typename T> unsigned int CircularArray<T>::size()
+unsigned int CircularArray::size()
{
if(w<r || m_full)
{
@@ -92,12 +112,12 @@
}
}
-template <typename T> bool CircularArray<T>::full()
+bool CircularArray::full()
{
return m_full;
}
-template <typename T> bool CircularArray<T>::empty()
+bool CircularArray::empty()
{
return m_empty;
}
\ No newline at end of file