From 36598926fd9fbc7a9c66899b402b302f00c0528f Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 14 Feb 2015 21:04:03 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/algo.cpp | 3 +- firmware/controllers/algo/algo.h | 13 +--- firmware/controllers/core/interpolation.cpp | 73 +++++++++++++++++-- firmware/controllers/core/interpolation.h | 3 + firmware/controllers/engine_controller.cpp | 2 +- firmware/rusefi.cpp | 2 +- .../simulator/rusEfiFunctionalTest.cpp | 2 +- 7 files changed, 75 insertions(+), 23 deletions(-) diff --git a/firmware/controllers/algo/algo.cpp b/firmware/controllers/algo/algo.cpp index 3a3fdae145..a723cdff0c 100644 --- a/firmware/controllers/algo/algo.cpp +++ b/firmware/controllers/algo/algo.cpp @@ -35,7 +35,8 @@ void initDataStructures(DECLARE_ENGINE_PARAMETER_F) { initSpeedDensity(engineConfiguration); } -void initAlgo(engine_configuration_s *engineConfiguration) { +void initAlgo(Logging *sharedLogger, engine_configuration_s *engineConfiguration) { + initInterpolation(sharedLogger); #if EFI_PROD_CODE || EFI_SIMULATOR initSettings(engineConfiguration); initSignalExecutor(); diff --git a/firmware/controllers/algo/algo.h b/firmware/controllers/algo/algo.h index 207b9031e6..66167d63df 100644 --- a/firmware/controllers/algo/algo.h +++ b/firmware/controllers/algo/algo.h @@ -8,18 +8,9 @@ #ifndef ALGO_H_ #define ALGO_H_ +#include "main.h" #include "engine_configuration.h" - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - void initDataStructures(DECLARE_ENGINE_PARAMETER_F); -void initAlgo(engine_configuration_s *engineConfiguration); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ +void initAlgo(Logging *sharedLogger, engine_configuration_s *engineConfiguration); #endif /* ALGO_H_ */ diff --git a/firmware/controllers/core/interpolation.cpp b/firmware/controllers/core/interpolation.cpp index b2804ae2b8..5d6bce9bb6 100644 --- a/firmware/controllers/core/interpolation.cpp +++ b/firmware/controllers/core/interpolation.cpp @@ -4,6 +4,7 @@ * * @date Oct 17, 2013 * @author Andrey Belomutskiy, (c) 2012-2015 + * @author Dmitry Sidin, (c) 2015 */ #if DEBUG_FUEL @@ -13,9 +14,58 @@ #include #include "main.h" +#include "efilib2.h" #include "interpolation.h" -int needInterpolationLogging = TRUE; +int needInterpolationLogging = true; + +#define BINARY_PERF true + +Logging * logger; + +#if BINARY_PERF + +#define COUNT 10000 + +float array16[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + +static void testBinary(void) { + const int size16 = 16; + + uint32_t totalOld = 0; + uint32_t totalNew = 0; + + for (int v = 0; v <= 16; v++) { + uint32_t timeOld; + { + uint32_t start = GET_TIMESTAMP(); + int temp = 0; + for (int i = 0; i < COUNT; i++) { + temp += findIndex(array16, size16, v); + } + timeOld = GET_TIMESTAMP() - start; + } + uint32_t timeNew; + { + uint32_t start = GET_TIMESTAMP(); + int temp = 0; + for (int i = 0; i < COUNT; i++) { + temp += findIndex2(array16, size16, v); + } + timeNew = GET_TIMESTAMP() - start; + } + scheduleMsg(logger, "for v=%d old=%d ticks", v, timeOld); + scheduleMsg(logger, "for v=%d new=%d ticks", v, timeNew); + + totalOld += timeOld; + totalNew += timeNew; + } + scheduleMsg(logger, "totalOld=%d ticks", totalOld); + scheduleMsg(logger, "totalNew=%d ticks", totalNew); + +} + +#endif FastInterpolation::FastInterpolation() { init(0, 0, 1, 1); @@ -166,13 +216,13 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int xIndex = findIndex(xBin, xBinSize, x); #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("X index=%d\r\n", xIndex); + printf("X index=%d\r\n", xIndex); #endif int yIndex = findIndex(yBin, yBinSize, y); if (xIndex < 0 && yIndex < 0) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex); + printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex); #endif return map[0][0]; } @@ -180,7 +230,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], if (xIndex < 0) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("X is smaller than smallest cell in table: %dr\n", xIndex); + printf("X is smaller than smallest cell in table: %dr\n", xIndex); #endif // no interpolation should be fine here. return map[0][yIndex]; @@ -189,7 +239,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], if (yIndex < 0) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("Y is smaller than smallest cell in table: %d\r\n", yIndex); + printf("Y is smaller than smallest cell in table: %d\r\n", yIndex); #endif // no interpolation should be fine here. return map[xIndex][0]; @@ -198,7 +248,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex); + printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex); #endif return map[xBinSize - 1][yBinSize - 1]; } @@ -206,7 +256,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], if (xIndex == xBinSize - 1) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex); + printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex); #endif // todo: implement better handling - y interpolation return map[xBinSize - 1][yIndex]; @@ -215,7 +265,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], if (yIndex == yBinSize - 1) { #if DEBUG_INTERPOLATION if (needInterpolationLogging) - printf("Y is larger than largest cell in table: %d\r\n", yIndex); + printf("Y is larger than largest cell in table: %d\r\n", yIndex); #endif // todo: implement better handling - x interpolation return map[xIndex][yBinSize - 1]; @@ -266,3 +316,10 @@ void setTableValue(float bins[], float values[], int size, float key, float valu values[index] = value; } +void initInterpolation(Logging *sharedLogger) { + logger = sharedLogger; +#if BINARY_PERF && ! EFI_UNIT_TEST + addConsoleAction("binarytest", testBinary); +#endif + +} diff --git a/firmware/controllers/core/interpolation.h b/firmware/controllers/core/interpolation.h index 436be02aa9..c397815732 100644 --- a/firmware/controllers/core/interpolation.h +++ b/firmware/controllers/core/interpolation.h @@ -8,6 +8,8 @@ #ifndef INTERPOLATION_3D_H_ #define INTERPOLATION_3D_H_ +#include "datalogging.h" + #define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2)) int findIndex(const float array[], int size, float value); @@ -16,6 +18,7 @@ float interpolate(float x1, float y1, float x2, float y2, float x); float interpolate2d(float value, float bin[], float values[], int size); float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]); void setTableValue(float bins[], float values[], int size, float key, float value); +void initInterpolation(Logging *sharedLogger); class FastInterpolation { public: diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f7f7c2655e..4f52f35e56 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -355,7 +355,7 @@ void initEngineContoller(Logging *sharedLogger, Engine *engine) { initAnalogChart(); #endif /* EFI_ANALOG_CHART */ - initAlgo(engineConfiguration); + initAlgo(sharedLogger, engineConfiguration); #if EFI_WAVE_ANALYZER if (engineConfiguration->isWaveAnalyzerEnabled) { diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 6bcaff2209..3509531ea7 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -258,5 +258,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE == 0) return 1; // this is here to make the compiler happy about the unused array - return 20150213; + return 20150214; } diff --git a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp index 10c5a4a609..328e26ac9f 100644 --- a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp +++ b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp @@ -89,7 +89,7 @@ void rusEfiFunctionalTest(void) { initSensors(PASS_ENGINE_PARAMETER_F); - initAlgo(engineConfiguration); + initAlgo(&sharedLogger, engineConfiguration); initRpmCalculator(engine); #if EFI_ANALOG_CHART