auto-sync

This commit is contained in:
rusEfi 2015-03-23 08:10:56 -05:00
parent a0028d3483
commit 9ee6f9b9a3
4 changed files with 59 additions and 61 deletions

View File

@ -91,7 +91,8 @@ typedef struct {
float veValue; float veValue;
float maxDelta; float maxDelta;
float minDelta; float minDelta;
int unused3[18]; float currentAccelDelta;
int unused3[17];
} TunerStudioOutputChannels; } TunerStudioOutputChannels;
#endif /* TUNERSTUDIO_CONFIGURATION_H_ */ #endif /* TUNERSTUDIO_CONFIGURATION_H_ */

View File

@ -276,5 +276,5 @@ int getRusEfiVersion(void) {
return 1; // this is here to make the compiler happy about the unused array return 1; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] == 0) if (UNUSED_CCM_SIZE[0] == 0)
return 1; // this is here to make the compiler happy about the unused array return 1; // this is here to make the compiler happy about the unused array
return 20150322; return 20150323;
} }

View File

@ -9,54 +9,47 @@
* @author Daniel Hill - Modified to use C++ - Mar 2, 2014 * @author Daniel Hill - Modified to use C++ - Mar 2, 2014
*/ */
#include "cyclic_buffer.h" #include "cyclic_buffer.h"
#include <string.h> #include <string.h>
//ctor cyclic_buffer::cyclic_buffer() : cyclic_buffer(CB_MAX_SIZE) {
cyclic_buffer::cyclic_buffer() }
{
memset((void*)elements, 0, sizeof(elements)); // I would usually use static_cast, but due to the elements being volatile we cannot. cyclic_buffer::cyclic_buffer(int size) {
currentIndex = 0; currentIndex = 0;
count = 0; setSize(size);
} }
//cpctor //cpctor
cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb) cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb) {
{
//Deep copy the data //Deep copy the data
currentIndex = cb.currentIndex; currentIndex = cb.currentIndex;
count = cb.count; count = cb.count;
for(int i = 0; i < CB_MAX_SIZE; ++i) size = cb.size;
{ for (int i = 0; i < size; ++i) {
elements[i] = cb.elements[i]; elements[i] = cb.elements[i];
} }
} }
//dtor //dtor
cyclic_buffer::~cyclic_buffer() cyclic_buffer::~cyclic_buffer() {
{
//No dynamic allocation - safe to leave //No dynamic allocation - safe to leave
} }
//overloaded =operator //overloaded =operator
cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb) cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb) {
{
//Deep copy //Deep copy
currentIndex = rhCb.currentIndex; currentIndex = rhCb.currentIndex;
count = rhCb.count; count = rhCb.count;
for(int i = 0; i < CB_MAX_SIZE; ++i) for (int i = 0; i < size; ++i) {
{
elements[i] = rhCb.elements[i]; elements[i] = rhCb.elements[i];
} }
return *this; return *this;
} }
void cyclic_buffer::add(int value) void cyclic_buffer::add(int value) {
{
++currentIndex; ++currentIndex;
if(currentIndex == CB_MAX_SIZE) if (currentIndex == size) {
{
currentIndex = 0; currentIndex = 0;
} }
elements[currentIndex] = value; elements[currentIndex] = value;
@ -64,26 +57,29 @@ void cyclic_buffer::add(int value)
++count; ++count;
} }
void cyclic_buffer::setSize(int size) {
clear();
this->size = size;
}
void cyclic_buffer::clear() { void cyclic_buffer::clear() {
memset((void*) elements, 0, sizeof(elements)); // I would usually use static_cast, but due to the elements being volatile we cannot.
count = 0;
count = 0; count = 0;
} }
int cyclic_buffer::sum(int length) int cyclic_buffer::sum(int length) {
{ if (length > count) {
if(length > count)
{
length = count; length = count;
} }
int ci = currentIndex; // local copy to increase thread-safety int ci = currentIndex; // local copy to increase thread-safety
int result = 0; int result = 0;
for(int i = 0; i < length; ++i) for (int i = 0; i < length; ++i) {
{
int index = ci - i; int index = ci - i;
while (index < 0) while (index < 0) {
{ index += size;
index += CB_MAX_SIZE;
} }
result += elements[index]; result += elements[index];

View File

@ -10,13 +10,13 @@
#ifndef CYCLIC_BUFFER_H #ifndef CYCLIC_BUFFER_H
#define CYCLIC_BUFFER_H #define CYCLIC_BUFFER_H
static const short CB_MAX_SIZE = 16; static const short CB_MAX_SIZE = 64;
class cyclic_buffer class cyclic_buffer
{ {
public: public:
//ctor
cyclic_buffer(); cyclic_buffer();
cyclic_buffer(int size);
//cpctor //cpctor
cyclic_buffer(const cyclic_buffer& cb); cyclic_buffer(const cyclic_buffer& cb);
//dtor //dtor
@ -29,13 +29,14 @@ class cyclic_buffer
public: public:
void add(int value); void add(int value);
int sum(int length); int sum(int length);
void setSize(int size);
void clear(); void clear();
private: private:
volatile int elements[CB_MAX_SIZE]; volatile int elements[CB_MAX_SIZE];
volatile int currentIndex; volatile int currentIndex;
volatile int count; volatile int count;
int size;
}; };
#endif //CYCLIC_BUFFER_H #endif //CYCLIC_BUFFER_H