Skip to content

Commit

Permalink
store event queue on sd card instead of eeprom #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 18, 2020
1 parent f0d7965 commit 9abbd17
Show file tree
Hide file tree
Showing 29 changed files with 133,817 additions and 133,920 deletions.
Binary file added fonts/RobotoCondensed-Regular.ttf
Binary file not shown.
1,136 changes: 561 additions & 575 deletions modular-psu-firmware.eez-project

Large diffs are not rendered by default.

180 changes: 1 addition & 179 deletions src/eez/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,200 +31,22 @@
#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/datetime.h>

#if OPTION_DISPLAY
#include <eez/gui/gui.h>
#endif

using namespace eez::psu;

namespace eez {
namespace debug {

bool g_stopDebugTraceLog;

static char *g_log = (char *)DEBUG_TRACE_LOG;
static uint32_t g_head;
static uint32_t g_tail;
static bool g_full;

static uint32_t g_numLines;
static uint32_t g_changed;

static uint32_t g_lastLineIndex;
static uint32_t g_lastLineCharPosition;

static uint32_t g_startPosition = 0;
static const uint32_t TRACE_LOG_PAGE_SIZE = 10;

void addCharToLog(char ch) {
#if OPTION_DISPLAY
// wrap line if doesn't fit
static gui::font::Font g_traceLogFont;
static uint16_t lineWidth = 0;
static const uint16_t TRACE_LOG_LINE_WIDTH = 448;
if (ch == 0) {
lineWidth = 0;
} else {
if (!g_traceLogFont.fontData) {
g_traceLogFont.fontData = gui::getFontData(gui::FONT_ID_ROBOTO_CONDENSED_REGULAR);
}
lineWidth += mcu::display::measureGlyph(ch, g_traceLogFont);
if (lineWidth >= TRACE_LOG_LINE_WIDTH) {
addCharToLog(0);
}
}
#endif

*(g_log + g_head) = ch;

// advance pointer
if (g_full) {
g_tail = (g_tail + 1) % DEBUG_TRACE_LOG_SIZE;
}
g_head = (g_head + 1) % DEBUG_TRACE_LOG_SIZE;
g_full = g_head == g_tail;
}

void Trace(const char *format, ...) {
va_list args;
va_start(args, format);

static const size_t BUFFER_SIZE = 128;
static const size_t BUFFER_SIZE = 256;
char buffer[BUFFER_SIZE + 1];

vsnprintf(buffer, BUFFER_SIZE, format, args);
buffer[BUFFER_SIZE] = 0;

va_end(args);

if (g_stopDebugTraceLog) {
return;
}

for (char *p = buffer; *p; p++) {
if (*p == '\r') {
continue;
}
if (*p == '\n') {
addCharToLog(0);
} else if (*p == '\t') {
static const int TAB_SIZE = 4;
for (int i = 0; i < TAB_SIZE; i++) {
addCharToLog(' ');
}
} else {
addCharToLog(*p);
}
}

g_changed = true;

g_lastLineIndex = 0;
g_lastLineCharPosition = g_tail;
}

uint32_t getNumTraceLogLines() {
if (g_changed) {
bool scrollLock = true;
if (g_numLines > TRACE_LOG_PAGE_SIZE) {
scrollLock = g_startPosition == g_numLines - TRACE_LOG_PAGE_SIZE;
}

g_changed = false;

g_numLines = 1;

if (g_full || g_head != g_tail) {
uint32_t from = g_tail;
uint32_t to = g_head > 0 ? g_head - 1 : DEBUG_TRACE_LOG_SIZE - 1;
for (uint32_t i = from; i != to; i = (i + 1) % DEBUG_TRACE_LOG_SIZE) {
if (!g_log[i]) {
g_numLines++;
}
}
}

if (scrollLock) {
if (g_numLines > TRACE_LOG_PAGE_SIZE) {
g_startPosition = g_numLines - TRACE_LOG_PAGE_SIZE;
}
}
}
return g_numLines;
}

const char *getTraceLogLine(uint32_t lineIndex) {
uint32_t lastLineIndex = g_lastLineIndex;
uint32_t lastLineCharPosition = g_lastLineCharPosition;
uint32_t tail = g_tail;

if (lineIndex > lastLineIndex) {
do {
if (g_log[lastLineCharPosition] == 0) {
lastLineIndex++;
}

lastLineCharPosition = (lastLineCharPosition + 1) % DEBUG_TRACE_LOG_SIZE;
} while (lastLineIndex != lineIndex);
} else if (lineIndex < lastLineIndex) {
if (lineIndex == 0) {
lastLineIndex = 0;
lastLineCharPosition = tail;
} else {
lastLineCharPosition = (lastLineCharPosition + DEBUG_TRACE_LOG_SIZE - 2) % DEBUG_TRACE_LOG_SIZE;

do {
if (g_log[lastLineCharPosition] == 0) {
lastLineIndex--;
}

lastLineCharPosition = (lastLineCharPosition + DEBUG_TRACE_LOG_SIZE - 1) % DEBUG_TRACE_LOG_SIZE;
} while (lastLineIndex != lineIndex);

lastLineCharPosition = (lastLineCharPosition + 2) % DEBUG_TRACE_LOG_SIZE;
}
}

return g_log + lastLineCharPosition;
}

uint32_t getTraceLogStartPosition() {
uint32_t position = g_startPosition;
uint32_t count = getNumTraceLogLines();
if (count <= TRACE_LOG_PAGE_SIZE) {
position = 0;
} else if (position > count - TRACE_LOG_PAGE_SIZE) {
position = count - TRACE_LOG_PAGE_SIZE;
}
return position;
}

void setTraceLogStartPosition(uint32_t position) {
g_startPosition = position;
}

void resetTraceLogStartPosition() {
uint32_t count = getNumTraceLogLines();
if (count <= TRACE_LOG_PAGE_SIZE) {
g_startPosition = 0;
} else {
g_startPosition = count - TRACE_LOG_PAGE_SIZE;
}
}

uint32_t getTraceLogPageSize() {
return TRACE_LOG_PAGE_SIZE;
}

void onEncoder(int counter) {
#if defined(EEZ_PLATFORM_SIMULATOR)
counter = -counter;
#endif
int32_t newPosition = getTraceLogStartPosition() + counter;
if (newPosition < 0) {
newPosition = 0;
}
setTraceLogStartPosition(newPosition);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 0 additions & 13 deletions src/eez/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ namespace debug {

void Trace(const char *format, ...);

extern bool g_stopDebugTraceLog;

uint32_t getNumTraceLogLines();
const char *getTraceLogLine(uint32_t lineIndex);

uint32_t getTraceLogStartPosition();
void setTraceLogStartPosition(uint32_t position);
void resetTraceLogStartPosition();

uint32_t getTraceLogPageSize();

void onEncoder(int couter);

} // namespace debug
} // namespace eez

Expand Down
4 changes: 2 additions & 2 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ void boot() {
psu::rtc::init();
psu::datetime::init();

psu::event_queue::init();

mcu::eeprom::init();
mcu::eeprom::test();

Expand Down Expand Up @@ -221,6 +219,8 @@ void boot() {

g_bootTestSuccess &= testMaster();

psu::event_queue::init();

if (!psu::autoRecall()) {
psu::psuReset();
}
Expand Down
9 changes: 0 additions & 9 deletions src/eez/gui/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,6 @@ void action_file_manager_new_file() {
file_manager::newFile();
}

void action_show_debug_trace_log() {
eez::debug::resetTraceLogStartPosition();
pushPage(PAGE_ID_DEBUG_TRACE_LOG);
}

void action_show_sys_settings_mqtt() {
pushPage(PAGE_ID_SYS_SETTINGS_MQTT);
}
Expand Down Expand Up @@ -1294,10 +1289,6 @@ void action_mqtt_edit_period() {
editValue(DATA_ID_MQTT_PERIOD);
}

void action_debug_trace_log_toggle() {
debug::g_stopDebugTraceLog = !debug::g_stopDebugTraceLog;
}

void onFirmwareSelected(const char *filePath) {
int err;
if (!bp3c::flash_slave::start(g_channel->slotIndex, filePath, &err)) {
Expand Down
Loading

0 comments on commit 9abbd17

Please sign in to comment.