From 9ee6f9b9a3eb5e1d69276a0748be6ab7108e5315 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 23 Mar 2015 08:10:56 -0500 Subject: [PATCH] auto-sync --- .../binary/tunerstudio_configuration.h | 3 +- firmware/rusefi.cpp | 2 +- firmware/util/cyclic_buffer.cpp | 106 +++++++++--------- firmware/util/cyclic_buffer.h | 9 +- 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h index 39905ca820..42557b7097 100644 --- a/firmware/console/binary/tunerstudio_configuration.h +++ b/firmware/console/binary/tunerstudio_configuration.h @@ -91,7 +91,8 @@ typedef struct { float veValue; float maxDelta; float minDelta; - int unused3[18]; + float currentAccelDelta; + int unused3[17]; } TunerStudioOutputChannels; #endif /* TUNERSTUDIO_CONFIGURATION_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 15d017c530..87b0c168f4 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -276,5 +276,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] == 0) return 1; // this is here to make the compiler happy about the unused array - return 20150322; + return 20150323; } diff --git a/firmware/util/cyclic_buffer.cpp b/firmware/util/cyclic_buffer.cpp index 36392b5be0..b364953114 100644 --- a/firmware/util/cyclic_buffer.cpp +++ b/firmware/util/cyclic_buffer.cpp @@ -9,86 +9,82 @@ * @author Daniel Hill - Modified to use C++ - Mar 2, 2014 */ - #include "cyclic_buffer.h" #include -//ctor -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. - currentIndex = 0; - count = 0; +cyclic_buffer::cyclic_buffer() : cyclic_buffer(CB_MAX_SIZE) { +} + +cyclic_buffer::cyclic_buffer(int size) { + currentIndex = 0; + setSize(size); } //cpctor -cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb) -{ - //Deep copy the data - currentIndex = cb.currentIndex; - count = cb.count; - for(int i = 0; i < CB_MAX_SIZE; ++i) - { - elements[i] = cb.elements[i]; - } +cyclic_buffer::cyclic_buffer(const cyclic_buffer& cb) { + //Deep copy the data + currentIndex = cb.currentIndex; + count = cb.count; + size = cb.size; + for (int i = 0; i < size; ++i) { + elements[i] = cb.elements[i]; + } } //dtor -cyclic_buffer::~cyclic_buffer() -{ - //No dynamic allocation - safe to leave +cyclic_buffer::~cyclic_buffer() { + //No dynamic allocation - safe to leave } //overloaded =operator -cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb) -{ - //Deep copy - currentIndex = rhCb.currentIndex; - count = rhCb.count; - for(int i = 0; i < CB_MAX_SIZE; ++i) - { - elements[i] = rhCb.elements[i]; - } - return *this; +cyclic_buffer& cyclic_buffer::operator=(const cyclic_buffer& rhCb) { + //Deep copy + currentIndex = rhCb.currentIndex; + count = rhCb.count; + for (int i = 0; i < size; ++i) { + elements[i] = rhCb.elements[i]; + } + return *this; } -void cyclic_buffer::add(int value) -{ - ++currentIndex; - if(currentIndex == CB_MAX_SIZE) - { - currentIndex = 0; - } - elements[currentIndex] = value; +void cyclic_buffer::add(int value) { + ++currentIndex; + if (currentIndex == size) { + currentIndex = 0; + } + elements[currentIndex] = value; - ++count; + ++count; +} + +void cyclic_buffer::setSize(int size) { + clear(); + this->size = size; } 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; } -int cyclic_buffer::sum(int length) -{ - if(length > count) - { - length = count; - } +int cyclic_buffer::sum(int length) { + if (length > count) { + length = count; + } - int ci = currentIndex; // local copy to increase thread-safety - int result = 0; + int ci = currentIndex; // local copy to increase thread-safety + int result = 0; - for(int i = 0; i < length; ++i) - { - int index = ci - i; - while (index < 0) - { - index += CB_MAX_SIZE; + for (int i = 0; i < length; ++i) { + int index = ci - i; + while (index < 0) { + index += size; } - result += elements[index]; - } + result += elements[index]; + } - return result; + return result; } diff --git a/firmware/util/cyclic_buffer.h b/firmware/util/cyclic_buffer.h index 0a1ba8f4f4..a05df2b95c 100644 --- a/firmware/util/cyclic_buffer.h +++ b/firmware/util/cyclic_buffer.h @@ -10,13 +10,13 @@ #ifndef CYCLIC_BUFFER_H #define CYCLIC_BUFFER_H -static const short CB_MAX_SIZE = 16; +static const short CB_MAX_SIZE = 64; class cyclic_buffer { public: - //ctor - cyclic_buffer(); + cyclic_buffer(); + cyclic_buffer(int size); //cpctor cyclic_buffer(const cyclic_buffer& cb); //dtor @@ -29,13 +29,14 @@ class cyclic_buffer public: void add(int value); int sum(int length); + void setSize(int size); void clear(); - private: volatile int elements[CB_MAX_SIZE]; volatile int currentIndex; volatile int count; + int size; }; #endif //CYCLIC_BUFFER_H