Merge remote-tracking branch 'origin/master' into master
This commit is contained in:
commit
68eb50332c
|
@ -40,7 +40,7 @@ endif
|
|||
|
||||
# Compiler options here.
|
||||
ifeq ($(USE_OPT),)
|
||||
USE_OPT = $(EXTRA_PARAMS) $(DEBUG_LEVEL_OPT) $(RFLAGS) -fomit-frame-pointer -falign-functions=16
|
||||
USE_OPT = $(EXTRA_PARAMS) $(DEBUG_LEVEL_OPT) $(RFLAGS) -fomit-frame-pointer -falign-functions=16 -fsingle-precision-constant
|
||||
endif
|
||||
|
||||
USE_OPT += $(RUSEFI_OPT)
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include "periodic_thread_controller.h"
|
||||
#include "cdm_ion_sense.h"
|
||||
#include "binary_logging.h"
|
||||
#include "buffered_writer.h"
|
||||
|
||||
extern bool main_loop_started;
|
||||
|
||||
|
@ -142,7 +143,7 @@ static float getAirFlowGauge(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
return hasMafSensor() ? getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) : engine->engineState.airFlow;
|
||||
}
|
||||
|
||||
void writeLogLine() {
|
||||
void writeLogLine(Writer& buffer) {
|
||||
#if EFI_FILE_LOGGING
|
||||
if (!main_loop_started)
|
||||
return;
|
||||
|
@ -157,7 +158,7 @@ void writeLogLine() {
|
|||
|
||||
efiAssertVoid(OBD_PCM_Processor_Fault, length <= efi::size(sdLogBuffer), "SD log buffer overflow");
|
||||
|
||||
appendToLog(sdLogBuffer, length);
|
||||
buffer.write(sdLogBuffer, length);
|
||||
|
||||
binaryLogCount++;
|
||||
#endif /* EFI_FILE_LOGGING */
|
||||
|
|
|
@ -13,5 +13,7 @@ void updateDevConsoleState(void);
|
|||
void prepareTunerStudioOutputs(void);
|
||||
void startStatusThreads(void);
|
||||
void initStatusLoop(void);
|
||||
void writeLogLine(void);
|
||||
|
||||
struct Writer;
|
||||
void writeLogLine(Writer& buffer);
|
||||
void printOverallStatus(systime_t nowSeconds);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#pragma once
|
||||
#define VCS_DATE 20201012
|
||||
#define VCS_DATE 20201014
|
||||
|
|
|
@ -707,7 +707,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
|
|||
* UNUSED_SIZE constants.
|
||||
*/
|
||||
#ifndef RAM_UNUSED_SIZE
|
||||
#define RAM_UNUSED_SIZE 2850
|
||||
#define RAM_UNUSED_SIZE 2350
|
||||
#endif
|
||||
#ifndef CCM_UNUSED_SIZE
|
||||
#define CCM_UNUSED_SIZE 2900
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "engine_configuration.h"
|
||||
#include "status_loop.h"
|
||||
#include "usb_msd_cfg.h"
|
||||
#include "buffered_writer.h"
|
||||
|
||||
#include "rtc_helper.h"
|
||||
|
||||
|
@ -304,49 +305,6 @@ static void listDirectory(const char *path) {
|
|||
UNLOCK_SD_SPI;
|
||||
}
|
||||
|
||||
static int errorReported = FALSE; // this is used to report the error only once
|
||||
|
||||
#if 0
|
||||
void readLogFileContent(char *buffer, short fileId, short offset, short length) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Appends specified line to the current log file
|
||||
*/
|
||||
void appendToLog(const char *line, size_t lineLength) {
|
||||
UINT bytesWritten;
|
||||
|
||||
if (!isSdCardAlive()) {
|
||||
if (!errorReported)
|
||||
scheduleMsg(&logger, "appendToLog Error: No File system is mounted");
|
||||
errorReported = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
totalLoggedBytes += lineLength;
|
||||
LOCK_SD_SPI;
|
||||
FRESULT err = f_write(&FDLogFile, line, lineLength, &bytesWritten);
|
||||
if (bytesWritten < lineLength) {
|
||||
printError("write error or disk full", err); // error or disk full
|
||||
mmcUnMount();
|
||||
} else {
|
||||
writeCounter++;
|
||||
totalWritesCounter++;
|
||||
if (writeCounter >= F_SYNC_FREQUENCY) {
|
||||
/**
|
||||
* Performance optimization: not f_sync after each line, f_sync is probably a heavy operation
|
||||
* todo: one day someone should actually measure the relative cost of f_sync
|
||||
*/
|
||||
f_sync(&FDLogFile);
|
||||
totalSyncCounter++;
|
||||
writeCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
UNLOCK_SD_SPI;
|
||||
}
|
||||
|
||||
/*
|
||||
* MMC card un-mount.
|
||||
*/
|
||||
|
@ -439,6 +397,39 @@ static void MMCmount(void) {
|
|||
}
|
||||
}
|
||||
|
||||
class SdLogBufferWriter final : public BufferedWriter<512> {
|
||||
size_t writeInternal(const char* buffer, size_t count) override {
|
||||
size_t bytesWritten;
|
||||
|
||||
totalLoggedBytes += count;
|
||||
|
||||
LOCK_SD_SPI;
|
||||
FRESULT err = f_write(&FDLogFile, buffer, count, &bytesWritten);
|
||||
|
||||
if (bytesWritten != count) {
|
||||
printError("write error or disk full", err); // error or disk full
|
||||
mmcUnMount();
|
||||
} else {
|
||||
writeCounter++;
|
||||
totalWritesCounter++;
|
||||
if (writeCounter >= F_SYNC_FREQUENCY) {
|
||||
/**
|
||||
* Performance optimization: not f_sync after each line, f_sync is probably a heavy operation
|
||||
* todo: one day someone should actually measure the relative cost of f_sync
|
||||
*/
|
||||
f_sync(&FDLogFile);
|
||||
totalSyncCounter++;
|
||||
writeCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
UNLOCK_SD_SPI;
|
||||
return bytesWritten;
|
||||
}
|
||||
};
|
||||
|
||||
static SdLogBufferWriter logBuffer MAIN_RAM;
|
||||
|
||||
static THD_FUNCTION(MMCmonThread, arg) {
|
||||
(void)arg;
|
||||
chRegSetThreadName("MMC_Monitor");
|
||||
|
@ -462,7 +453,7 @@ static THD_FUNCTION(MMCmonThread, arg) {
|
|||
}
|
||||
|
||||
if (isSdCardAlive()) {
|
||||
writeLogLine();
|
||||
writeLogLine(logBuffer);
|
||||
} else {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
@ -501,9 +492,6 @@ void initMmcCard(void) {
|
|||
chThdCreateStatic(mmcThreadStack, sizeof(mmcThreadStack), LOWPRIO, (tfunc_t)(void*) MMCmonThread, NULL);
|
||||
|
||||
addConsoleAction("mountsd", MMCmount);
|
||||
addConsoleActionS("appendtolog", [](const char* str) {
|
||||
appendToLog(str, strlen(str));
|
||||
});
|
||||
addConsoleAction("umountsd", mmcUnMount);
|
||||
addConsoleActionS("ls", listDirectory);
|
||||
addConsoleActionS("del", removeFile);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
bool isLogFile(const char *fileName);
|
||||
void initMmcCard(void);
|
||||
bool isSdCardAlive(void);
|
||||
void appendToLog(const char *line, size_t length);
|
||||
|
||||
void readLogFileContent(char *buffer, short fileId, short offset, short length);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ ifeq ($(USE_OPT),)
|
|||
USE_OPT += -fprofile-arcs -ftest-coverage
|
||||
USE_OPT += -Werror=missing-field-initializers
|
||||
USE_OPT += -Wno-unused-parameter -Wno-unused-function
|
||||
USE_OPT += -fsingle-precision-constant
|
||||
endif
|
||||
|
||||
|
||||
|
|
|
@ -23,21 +23,21 @@ TEST(util, pid) {
|
|||
|
||||
Pid pid(&pidS);
|
||||
|
||||
ASSERT_EQ( 90, pid.getOutput(14, 12, 0.1)) << "getValue#90";
|
||||
ASSERT_FLOAT_EQ( 90, pid.getOutput(14, 12, 0.1)) << "getValue#90";
|
||||
|
||||
|
||||
ASSERT_EQ( 10, pid.getOutput(14, 16, 0.1)) << "getValue#10";
|
||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
ASSERT_FLOAT_EQ( 10, pid.getOutput(14, 16, 0.1)) << "getValue#10";
|
||||
ASSERT_FLOAT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
|
||||
pid.updateFactors(29, 0, 0);
|
||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_EQ(68, pid.getIntegration());
|
||||
ASSERT_FLOAT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_FLOAT_EQ(68, pid.getIntegration());
|
||||
|
||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_EQ(0, pid.getIntegration());
|
||||
ASSERT_FLOAT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_FLOAT_EQ(0, pid.getIntegration());
|
||||
|
||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_EQ(68, pid.getIntegration());
|
||||
ASSERT_FLOAT_EQ(10, pid.getOutput(14, 16, 1));
|
||||
// ASSERT_FLOAT_EQ(68, pid.getIntegration());
|
||||
|
||||
|
||||
|
||||
|
@ -51,17 +51,17 @@ TEST(util, pid) {
|
|||
|
||||
pid.reset();
|
||||
|
||||
ASSERT_EQ( 50, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0";
|
||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=0 iTerm";
|
||||
ASSERT_FLOAT_EQ( 50, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0";
|
||||
ASSERT_FLOAT_EQ( 0, pid.iTerm) << "target=50, input=0 iTerm";
|
||||
|
||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70";
|
||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm";
|
||||
ASSERT_FLOAT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70";
|
||||
ASSERT_FLOAT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm";
|
||||
|
||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70 #2";
|
||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm #2";
|
||||
ASSERT_FLOAT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70 #2";
|
||||
ASSERT_FLOAT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm #2";
|
||||
|
||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50";
|
||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm";
|
||||
ASSERT_FLOAT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50";
|
||||
ASSERT_FLOAT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm";
|
||||
}
|
||||
|
||||
static void commonPidTestParameters(pid_s * pidS) {
|
||||
|
@ -77,15 +77,15 @@ static void commonPidTestParameters(pid_s * pidS) {
|
|||
static void commonPidTest(Pid *pid) {
|
||||
pid->iTermMax = 45;
|
||||
|
||||
ASSERT_EQ( 12.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #0";
|
||||
ASSERT_EQ( 12.5, pid->getIntegration());
|
||||
ASSERT_EQ( 25 , pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #1";
|
||||
ASSERT_FLOAT_EQ( 12.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #0";
|
||||
ASSERT_FLOAT_EQ( 12.5, pid->getIntegration());
|
||||
ASSERT_FLOAT_EQ( 25 , pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #1";
|
||||
|
||||
ASSERT_EQ( 37.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #2";
|
||||
ASSERT_EQ( 37.5, pid->getIntegration());
|
||||
ASSERT_FLOAT_EQ( 37.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #2";
|
||||
ASSERT_FLOAT_EQ( 37.5, pid->getIntegration());
|
||||
|
||||
ASSERT_EQ( 40.0, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #3";
|
||||
ASSERT_EQ( 45, pid->getIntegration());
|
||||
ASSERT_FLOAT_EQ( 40.0, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #3";
|
||||
ASSERT_FLOAT_EQ( 45, pid->getIntegration());
|
||||
}
|
||||
|
||||
TEST(util, parallelPidLimits) {
|
||||
|
@ -126,12 +126,12 @@ TEST(util, pidIndustrial) {
|
|||
|
||||
float industValue = pid.getOutput(/*target*/1, /*input*/0);
|
||||
// check if the first output is clamped because of large deviative
|
||||
ASSERT_EQ(100.0, industValue);
|
||||
ASSERT_FLOAT_EQ(100.0, industValue);
|
||||
|
||||
// check if all output of the 'zeroed' PidIndustrial (w/o new features) is the same as our "normal" Pid
|
||||
for (int i = 0; i < 10; i++) {
|
||||
float normalValue = pid0.getOutput(1, 0);
|
||||
ASSERT_EQ(normalValue, industValue) << "[" << i << "]";
|
||||
ASSERT_FLOAT_EQ(normalValue, industValue) << "[" << i << "]";
|
||||
industValue = pid.getOutput(1, 0);
|
||||
}
|
||||
|
||||
|
@ -141,11 +141,11 @@ TEST(util, pidIndustrial) {
|
|||
pid.derivativeFilterLoss = 0.01;
|
||||
|
||||
// now the first value is less (and not clipped!) due to the derivative filtering
|
||||
ASSERT_EQ(67.671669f, pid.getOutput(1, 0));
|
||||
ASSERT_FLOAT_EQ(67.671669f, pid.getOutput(1, 0));
|
||||
// here we still have some leftovers of the initial D-term
|
||||
ASSERT_EQ(45.4544487f, pid.getOutput(1, 0));
|
||||
ASSERT_FLOAT_EQ(45.4544487f, pid.getOutput(1, 0));
|
||||
// but the value is quickly fading
|
||||
ASSERT_EQ(30.6446342f, pid.getOutput(1, 0));
|
||||
ASSERT_FLOAT_EQ(30.6446342f, pid.getOutput(1, 0));
|
||||
|
||||
pid.reset();
|
||||
|
||||
|
@ -166,7 +166,7 @@ TEST(util, pidIndustrial) {
|
|||
pid.antiwindupFreq = 0.1;
|
||||
|
||||
// the first value is clipped, and that's when the anti-windup comes into effect
|
||||
ASSERT_EQ(100.0f, pid.getOutput(1, 0));
|
||||
ASSERT_FLOAT_EQ(100.0f, pid.getOutput(1, 0));
|
||||
// it stores a small negative offset in the I-term to avoid it's saturation!
|
||||
ASSERT_NEAR(-0.0455025025f, pid.getIntegration(), EPS4D);
|
||||
// and that's why the second output is smaller then that of normal PID (=1.00999999)
|
||||
|
|
Loading…
Reference in New Issue