1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 21:35:44 +03:00

Cleanflight sync serial_cli.c // Scheduler CPU instead of load

This commit is contained in:
borisbstyle 2016-02-03 23:44:56 +01:00
parent 27772ba56a
commit 7f5f93a13d
4 changed files with 22 additions and 12 deletions

View file

@ -1160,7 +1160,7 @@ static void cliMotorMix(char *cmdline)
cliMotorMix(""); cliMotorMix("");
} }
} else { } else {
cliShowArgumentRangeError("index", 1, MAX_SUPPORTED_MOTORS); cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
} }
} }
#endif #endif
@ -1734,6 +1734,7 @@ static void cliDump(char *cmdline)
cliPrintf("%s\r\n", ftoa(yaw, buf)); cliPrintf("%s\r\n", ftoa(yaw, buf));
} }
#ifdef USE_SERVOS
// print custom servo mixer if exists // print custom servo mixer if exists
cliPrintf("smix reset\r\n"); cliPrintf("smix reset\r\n");
@ -1754,6 +1755,7 @@ static void cliDump(char *cmdline)
); );
} }
#endif
#endif #endif
cliPrint("\r\n\r\n# feature\r\n"); cliPrint("\r\n\r\n# feature\r\n");
@ -1853,7 +1855,7 @@ void cliEnter(serialPort_t *serialPort)
cliPort = serialPort; cliPort = serialPort;
setPrintfSerialPort(cliPort); setPrintfSerialPort(cliPort);
cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer), cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer),
(bufWrite_t)serialWriteBufShim, serialPort); (bufWrite_t)serialWriteBufShim, serialPort);
cliPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n"); cliPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n");
cliPrompt(); cliPrompt();
@ -1866,6 +1868,7 @@ static void cliExit(char *cmdline)
cliPrint("\r\nLeaving CLI mode, unsaved changes lost.\r\n"); cliPrint("\r\nLeaving CLI mode, unsaved changes lost.\r\n");
bufWriterFlush(cliWriter); bufWriterFlush(cliWriter);
*cliBuffer = '\0'; *cliBuffer = '\0';
bufferIndex = 0; bufferIndex = 0;
cliMode = 0; cliMode = 0;
@ -2068,7 +2071,7 @@ static void cliMotor(char *cmdline)
} }
if (motor_index < 0 || motor_index >= MAX_SUPPORTED_MOTORS) { if (motor_index < 0 || motor_index >= MAX_SUPPORTED_MOTORS) {
cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS); cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
return; return;
} }
@ -2157,6 +2160,7 @@ static void cliRateProfile(char *cmdline)
static void cliReboot(void) { static void cliReboot(void) {
cliPrint("\r\nRebooting"); cliPrint("\r\nRebooting");
bufWriterFlush(cliWriter);
waitForSerialPortToFinishTransmitting(cliPort); waitForSerialPortToFinishTransmitting(cliPort);
stopMotors(); stopMotors();
handleOneshotFeatureChangeOnRestart(); handleOneshotFeatureChangeOnRestart();
@ -2183,8 +2187,8 @@ static void cliDefaults(char *cmdline)
} }
static void cliPrint(const char *str) static void cliPrint(const char *str)
{ {
while (*str) while (*str)
bufWriterAppend(cliWriter, *str++); bufWriterAppend(cliWriter, *str++);
} }
@ -2203,7 +2207,6 @@ static void cliPrintf(const char *fmt, ...)
static void cliWrite(uint8_t ch) static void cliWrite(uint8_t ch)
{ {
serialWrite(cliPort, ch);
bufWriterAppend(cliWriter, ch); bufWriterAppend(cliWriter, ch);
} }
@ -2382,7 +2385,7 @@ static void cliSet(char *cmdline)
cliPrint("Invalid name\r\n"); cliPrint("Invalid name\r\n");
} else { } else {
// no equals, check for matching variables. // no equals, check for matching variables.
cliGet(cmdline); cliGet(cmdline);
} }
} }
@ -2415,8 +2418,13 @@ static void cliStatus(char *cmdline)
{ {
UNUSED(cmdline); UNUSED(cmdline);
cliPrintf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery - %s), System load: %d.%02d\r\n", cliPrintf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery - %s), CPU:%d%%\r\n",
millis() / 1000, vbat, batteryCellCount, getBatteryStateString(), averageWaitingTasks100 / 100, averageWaitingTasks100 % 100); millis() / 1000,
vbat,
batteryCellCount,
getBatteryStateString(),
constrain(averageSystemLoadPercent, 0, 100)
);
cliPrintf("CPU Clock=%dMHz", (SystemCoreClock / 1000000)); cliPrintf("CPU Clock=%dMHz", (SystemCoreClock / 1000000));

View file

@ -311,7 +311,7 @@ void annexCode(void)
DISABLE_ARMING_FLAG(OK_TO_ARM); DISABLE_ARMING_FLAG(OK_TO_ARM);
} }
if (isCalibrating() || (averageWaitingTasks100 > 100)) { if (isCalibrating() || (averageSystemLoadPercent > 100)) {
warningLedFlash(); warningLedFlash();
DISABLE_ARMING_FLAG(OK_TO_ARM); DISABLE_ARMING_FLAG(OK_TO_ARM);
} else { } else {

View file

@ -224,6 +224,8 @@ static cfTask_t cfTasks[TASK_COUNT] = {
#endif #endif
}; };
uint16_t averageSystemLoadPercent = 0;
#define REALTIME_GUARD_INTERVAL_MIN 10 #define REALTIME_GUARD_INTERVAL_MIN 10
#define REALTIME_GUARD_INTERVAL_MAX 300 #define REALTIME_GUARD_INTERVAL_MAX 300
@ -233,7 +235,7 @@ void taskSystem(void)
/* Calculate system load */ /* Calculate system load */
if (totalWaitingTasksSamples > 0) { if (totalWaitingTasksSamples > 0) {
averageWaitingTasks100 = 100 * totalWaitingTasks / totalWaitingTasksSamples; averageSystemLoadPercent = 100 * totalWaitingTasks / totalWaitingTasksSamples;
totalWaitingTasksSamples = 0; totalWaitingTasksSamples = 0;
totalWaitingTasks = 0; totalWaitingTasks = 0;
} }

View file

@ -84,7 +84,7 @@ typedef enum {
} cfTaskId_e; } cfTaskId_e;
extern uint16_t cpuLoad; extern uint16_t cpuLoad;
extern uint16_t averageWaitingTasks100; extern uint16_t averageSystemLoadPercent;
void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo); void getTaskInfo(cfTaskId_e taskId, cfTaskInfo_t * taskInfo);
void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros); void rescheduleTask(cfTaskId_e taskId, uint32_t newPeriodMicros);