From 4026d9857861a79cd059b869f197be2a9fac93c5 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Fri, 19 Nov 2021 15:53:02 +0100 Subject: [PATCH] flow debugger to message non blocking --- scripts/Relay loop test/relay loop test.app | Bin 28049 -> 28010 bytes src/eez/flow/debugger.cpp | 141 ++++++++++++++++---- src/eez/flow/flow.h | 1 + src/eez/memory.h | 7 +- src/eez/tasks.cpp | 4 + src/eez/tasks.h | 1 + 6 files changed, 129 insertions(+), 25 deletions(-) diff --git a/scripts/Relay loop test/relay loop test.app b/scripts/Relay loop test/relay loop test.app index d1af97ceadb1b58e943f3c7cd00f58a5d57570f0..a96f6bdd1f6ed73fa69c251f38ff583e838c8fb4 100644 GIT binary patch delta 1467 zcmXw2e@v8R9DjZt_r7rW5_fJ2cf2pZ>L8>$I+Z~=igQtkR4|4l9oA8=fbH-{xrQDx zTNW*W*Dc&iY0HLFm&HuoP_b5*g#3&{jBewii?eFR7>5a$Z2O1srdbt@m zy*eKs0elYFg47{A*-7n+>OFh*bhOedGvKXzXrQH=dd5967quxwOMpehF7@^Gr4R9`kB%|VMh}(C8k2g?-L~*4N5lqo-bgBM%5b!SUYWxw&th#IqP{r33|T+xq>9TK z`4Za{KXu4LT0$i9y$t(_Lt$k9;NYMW$}B;4)PP<#EbFS3N!c`;Ifn1YaBVqw@StNS zQ6>Lvg6W(5M1}h@LXUy^2l!c#ha&S>{MJC0dz*g2Y9X0ymppdu1dIF%%4%Shf+8b#73_P{nDjmAN4y#@3sGWtl%FR;uMNEp~)GwQ*c7+I~NypX${)knaQeTPn zdSFdYsa?veg4#$Vg}>dX+hbKLVV}c3ITvs2tJeQ2sI*J9*;Q1GMC3zSpQhx+`Q%1A z{iF*FvV2u8^q4{C;9Lo(%l*Y9)59?m)Qm?H>9;itXh(T#8Q)&1ErxS=Lea*tWYU$GFT72K{J>NwTeU4Dbjze~f;b_|IMk`A z;YOH?V8jfrvbvr5tXxIE9ujD@{L&`*#{;z0$1ZfH(KPS1e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4OT9>eDNUXPv7>)OxBwovba!VD@yFwv4dcgdQ&@LExe{hjmYQGor&=;bt9V(>++0o&r@nlhj7=W?W^wORwDO9)#UME-3n|gNlm{>f!GJCbjcK#51A{uFyt1qjAt~;BW8Y;dcr1f z8ySC#t?Q6ch>UY8qa0r{>xg1h*YCU)P@jmAUFxmM?@dS7l{FqW+aqjJwm0Xp((zZC z>$RjtMnpy9KeXg|(i>sY-68T$hA7J(_w4jAzC0&=?J+sh?t1C9d4mRkL11{^$l|)> z9pznlBlC`tTth1g0>n5~)Vx&_An)4&5*d^=3Y-Sc1GB&t;2N+9ECaVQC{O%2L#d}y zAs11WyhJO^Ir3)LkeH*aQfLA|1+WIF$slhS!kEvi_4tHImX%4maLB8LbrZxMd9LFP X-%+9+_?S8xrkHbJ$L<}^JWc-s&P=zK diff --git a/src/eez/flow/debugger.cpp b/src/eez/flow/debugger.cpp index 3d958ea38..5f7e3d3bf 100644 --- a/src/eez/flow/debugger.cpp +++ b/src/eez/flow/debugger.cpp @@ -22,6 +22,8 @@ #include #include +#include +#include #include #include @@ -89,16 +91,61 @@ static unsigned g_inputFromDebuggerPosition; static void processDebuggerInput(char *buffer, uint32_t length); +//////////////////////////////////////////////////////////////////////////////// + +char *g_toDebuggerMessage = (char *)FLOW_TO_DEBUGGER_MESSAGE_BUFFER; +uint32_t g_toDebuggerMessagePosition = 0; + +void startToDebuggerMessage() { +} + +void flushToDebuggerMessageBuffer() { + if (g_toDebuggerMessagePosition != 0) { + sendMessageToLowPriorityThread(FLOW_FLUSH_TO_DEBUGGER_MESSAGE); + + while (g_toDebuggerMessagePosition != 0 && g_debuggerIsConnected) { + osDelay(1); + WATCHDOG_RESET(WATCHDOG_GUI_THREAD); + } + } +} + +void flushToDebuggerMessage() { + eez::mcu::ethernet::writeDebuggerBuffer(g_toDebuggerMessage, g_toDebuggerMessagePosition); + g_toDebuggerMessagePosition = 0; +} + +void writeDebuggerBuffer(const char *buffer, uint32_t length) { + if (g_toDebuggerMessagePosition + length > FLOW_TO_DEBUGGER_MESSAGE_BUFFER_SIZE) { + flushToDebuggerMessageBuffer(); + } + + memcpy(g_toDebuggerMessage + g_toDebuggerMessagePosition, buffer, length); + g_toDebuggerMessagePosition += length; +} + +void finishToDebuggerMessage() { + flushToDebuggerMessageBuffer(); +} + +//////////////////////////////////////////////////////////////////////////////// + static void setDebuggerState(DebuggerState newState) { if (newState != g_debuggerState) { g_debuggerState = newState; - char buffer[100]; - snprintf(buffer, sizeof(buffer), "%d\t%d\n", - MESSAGE_TO_DEBUGGER_STATE_CHANGED, - g_debuggerState - ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + if (g_debuggerIsConnected) { + startToDebuggerMessage(); + + char buffer[100]; + snprintf(buffer, sizeof(buffer), "%d\t%d\n", + MESSAGE_TO_DEBUGGER_STATE_CHANGED, + g_debuggerState + ); + writeDebuggerBuffer(buffer, strlen(buffer)); + + finishToDebuggerMessage(); + } } } @@ -220,13 +267,13 @@ int outputBufferPosition = 0; #define WRITE_TO_OUTPUT_BUFFER(ch) \ outputBuffer[outputBufferPosition++] = ch; \ if (outputBufferPosition == sizeof(outputBuffer)) { \ - eez::mcu::ethernet::writeDebuggerBuffer(outputBuffer, outputBufferPosition); \ + writeDebuggerBuffer(outputBuffer, outputBufferPosition); \ outputBufferPosition = 0; \ } #define FLUSH_OUTPUT_BUFFER() \ if (outputBufferPosition > 0) { \ - eez::mcu::ethernet::writeDebuggerBuffer(outputBuffer, outputBufferPosition); \ + writeDebuggerBuffer(outputBuffer, outputBufferPosition); \ outputBufferPosition = 0; \ } @@ -362,13 +409,15 @@ void writeValue(const Value &value) { stringAppendString(tempStr, sizeof(tempStr), "\n"); - eez::mcu::ethernet::writeDebuggerBuffer(tempStr, strlen(tempStr)); + writeDebuggerBuffer(tempStr, strlen(tempStr)); } //////////////////////////////////////////////////////////////////////////////// void onStarted(Assets *assets) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + auto flowDefinition = assets->flowDefinition.ptr(assets); for (uint32_t i = 0; i < flowDefinition->globalVariables.count; i++) { @@ -380,15 +429,19 @@ void onStarted(Assets *assets) { (int)i, (int)pValue ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeValue(*pValue); } + + finishToDebuggerMessage(); } } void onAddToQueue(FlowState *flowState, int sourceComponentIndex, int sourceOutputIndex, unsigned targetComponentIndex, int targetInputIndex) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\t%d\t%d\n", MESSAGE_TO_DEBUGGER_ADD_TO_QUEUE, @@ -398,35 +451,47 @@ void onAddToQueue(FlowState *flowState, int sourceComponentIndex, int sourceOutp targetComponentIndex, targetInputIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); + + finishToDebuggerMessage(); } } void onRemoveFromQueue() { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\n", MESSAGE_TO_DEBUGGER_REMOVE_FROM_QUEUE ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); + + finishToDebuggerMessage(); } } void onValueChanged(const Value *pValue) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\t", MESSAGE_TO_DEBUGGER_VALUE_CHANGED, (int)pValue ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeValue(*pValue); + + finishToDebuggerMessage(); } } void onFlowStateCreated(FlowState *flowState) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\t%d\n", MESSAGE_TO_DEBUGGER_FLOW_STATE_CREATED, @@ -435,7 +500,7 @@ void onFlowStateCreated(FlowState *flowState) { (int)(flowState->parentFlowState ? flowState->parentFlowState->flowStateIndex : -1), flowState->parentComponentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); auto flow = flowState->flow; @@ -449,7 +514,7 @@ void onFlowStateCreated(FlowState *flowState) { (int)i, (int)pValue ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeValue(*pValue); } @@ -466,35 +531,45 @@ void onFlowStateCreated(FlowState *flowState) { (int)i, (int)pValue ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeValue(*pValue); } } + + finishToDebuggerMessage(); } } void onFlowStateDestroyed(FlowState *flowState) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\n", MESSAGE_TO_DEBUGGER_FLOW_STATE_DESTROYED, (int)flowState->flowStateIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); + + finishToDebuggerMessage(); } } void onFlowError(FlowState *flowState, int componentIndex, const char *errorMessage) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t", MESSAGE_TO_DEBUGGER_FLOW_STATE_ERROR, (int)flowState->flowStateIndex, componentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeString(errorMessage); + + finishToDebuggerMessage(); } } @@ -534,6 +609,8 @@ void writeLogMessage(const char *str, size_t len) { void logInfo(FlowState *flowState, unsigned componentIndex, const char *message) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[256]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\t", MESSAGE_TO_DEBUGGER_LOG, @@ -541,13 +618,17 @@ void logInfo(FlowState *flowState, unsigned componentIndex, const char *message) (int)flowState->flowStateIndex, componentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeLogMessage(message); + + finishToDebuggerMessage(); } } void logScpiCommand(FlowState *flowState, unsigned componentIndex, const char *cmd) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[256]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI COMMAND: ", MESSAGE_TO_DEBUGGER_LOG, @@ -555,13 +636,17 @@ void logScpiCommand(FlowState *flowState, unsigned componentIndex, const char *c (int)flowState->flowStateIndex, componentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeLogMessage(cmd); + + finishToDebuggerMessage(); } } void logScpiQuery(FlowState *flowState, unsigned componentIndex, const char *query) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[256]; snprintf(buffer, sizeof(buffer), "%d\t%d\t%d\t%d\tSCPI QUERY: ", MESSAGE_TO_DEBUGGER_LOG, @@ -569,13 +654,17 @@ void logScpiQuery(FlowState *flowState, unsigned componentIndex, const char *que (int)flowState->flowStateIndex, componentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeLogMessage(query); + + finishToDebuggerMessage(); } } void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const char *resultText, size_t resultTextLen) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[256]; snprintf(buffer, sizeof(buffer) - 1, "%d\t%d\t%d\t%d\tSCPI QUERY RESULT: ", MESSAGE_TO_DEBUGGER_LOG, @@ -583,19 +672,25 @@ void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const cha (int)flowState->flowStateIndex, componentIndex ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); writeLogMessage(resultText, resultTextLen); + + finishToDebuggerMessage(); } } void onPageChanged(int pageId) { if (g_debuggerIsConnected) { + startToDebuggerMessage(); + char buffer[100]; snprintf(buffer, sizeof(buffer), "%d\t%d\n", MESSAGE_TO_DEBUGGER_PAGE_CHANGED, -pageId - 1 ); - eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer)); + writeDebuggerBuffer(buffer, strlen(buffer)); + + finishToDebuggerMessage(); } } diff --git a/src/eez/flow/flow.h b/src/eez/flow/flow.h index b136adaf5..68f1bfcb8 100644 --- a/src/eez/flow/flow.h +++ b/src/eez/flow/flow.h @@ -42,6 +42,7 @@ void onDebuggerClientDisconnected(); void onDebuggerInputAvailable(); void executeScpi(); +void flushToDebuggerMessage(); } // flow } // eez \ No newline at end of file diff --git a/src/eez/memory.h b/src/eez/memory.h index 091d30b3d..940ca4041 100644 --- a/src/eez/memory.h +++ b/src/eez/memory.h @@ -55,9 +55,12 @@ static const uint32_t FILE_VIEW_BUFFER_SIZE = 3 * 512 * 1024; #endif static uint8_t * const ALLOC_BUFFER = FILE_VIEW_BUFFER + FILE_VIEW_BUFFER_SIZE; -static const uint32_t ALLOC_BUFFER_SIZE = 1024 * 1024; +static const uint32_t ALLOC_BUFFER_SIZE = (1024 - 32) * 1024; -static uint8_t * const SOUND_TUNES_MEMORY = ALLOC_BUFFER + ALLOC_BUFFER_SIZE; +static uint8_t * const FLOW_TO_DEBUGGER_MESSAGE_BUFFER = ALLOC_BUFFER + ALLOC_BUFFER_SIZE; +static const uint32_t FLOW_TO_DEBUGGER_MESSAGE_BUFFER_SIZE = 32 * 1024; + +static uint8_t * const SOUND_TUNES_MEMORY = FLOW_TO_DEBUGGER_MESSAGE_BUFFER + FLOW_TO_DEBUGGER_MESSAGE_BUFFER_SIZE; static const uint32_t SOUND_TUNES_MEMORY_SIZE = 32 * 1024; static uint8_t * const FILE_MANAGER_MEMORY = SOUND_TUNES_MEMORY + SOUND_TUNES_MEMORY_SIZE; diff --git a/src/eez/tasks.cpp b/src/eez/tasks.cpp index 18ec22af8..4372b552c 100644 --- a/src/eez/tasks.cpp +++ b/src/eez/tasks.cpp @@ -298,6 +298,10 @@ void lowPriorityThreadOneIter() { flow::executeScpi(); } + else if (type == FLOW_FLUSH_TO_DEBUGGER_MESSAGE) { + flow::flushToDebuggerMessage(); + } + else { if (type == THREAD_MESSAGE_SAVE_LIST) { int err; diff --git a/src/eez/tasks.h b/src/eez/tasks.h index 7724ed48a..4d419821e 100644 --- a/src/eez/tasks.h +++ b/src/eez/tasks.h @@ -88,6 +88,7 @@ enum LowPriorityThreadMessage { MP_LAST_MESSAGE_TYPE, FLOW_EXECUTE_SCPI, + FLOW_FLUSH_TO_DEBUGGER_MESSAGE, THREAD_MESSAGE_SAVE_LIST, THREAD_MESSAGE_SD_DETECT_IRQ,