From ae329083dbaa71b240858d10fc63f8eecc27bb89 Mon Sep 17 00:00:00 2001 From: Leon Krieg Date: Fri, 27 Sep 2024 14:35:03 +0200 Subject: [PATCH] Reduce number of watchdog timer resets and rename Makefile target --- Makefile | 20 +++++++++----------- docs/README.md | 34 +++++++++++++++++----------------- src/common/common.c | 4 ++-- src/common/math.h | 11 +++++------ src/common/parser.c | 3 +++ src/main.c | 8 ++++---- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index cced8de..806af32 100644 --- a/Makefile +++ b/Makefile @@ -8,15 +8,6 @@ # GENERAL SETTINGS # ============================================================================== -# NOTE: System clock frequency should be a multiple of 1.8432MHz for USART. - -SRCDIR := src -BINDIR := bin -TMPDIR := $(BINDIR)/build -TARGET := $(BINDIR)/core.hex -ELFFILE := $(BINDIR)/core.elf -LOGFILE := $(BINDIR)/core.log - VERBOSE := false #ARCH := m1284p ARCH := m32 @@ -32,6 +23,13 @@ AVD := avrdude MKDIR := mkdir -p RMR := rm -rf +SRCDIR := src +BINDIR := bin +TMPDIR := $(BINDIR)/build +TARGET := $(BINDIR)/core.hex +ELFFILE := $(BINDIR)/core.elf +LOGFILE := $(BINDIR)/core.log + CPPFLAGS := -DF_CPU=$(FREQ) -I$(SRCDIR) CFLAGS := -mmcu=$(MCU) -Os -std=c99 -Wall -Wextra -Werror OCFLAGS := -j .text -j .data -O ihex @@ -85,8 +83,8 @@ listen: ./opt/tools/serial-listen.py $(E) "[PY3] $<" $(Q) ./$< -.PHONY: listen-web -listen-web: ./opt/webgui/Makefile +.PHONY: webgui +webgui: ./opt/webgui/Makefile $(E) "[MAK] $( + opt/tools/serial-send.py Issue the SET command to update the target settings: @@ -70,15 +70,15 @@ of digits. ### Webinterface Example There is an example Python web server utilizing websockets you -can check out in `opt/webgui`. It should give you a basis for +can check out in `opt/webgui/`. It should give you a basis for writing a custom network bridge and integrating the device into your home automation system. You must generate a self-signed certificate before you run the server. The configuration script will take care of it: - ./opt/webgui/configure + opt/webgui/configure -See the README file in the webgui/ directory for prerequisites +See the README file in the server directory for prerequisites and more information. Please be aware that development for the web server has paused until the core has reached version v1.0. diff --git a/src/common/common.c b/src/common/common.c index 700242d..b1aaa3a 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -3,8 +3,8 @@ #include -static void Puts(const char *str); -static void PrintArgs(const char *fmt, va_list ap); +static void Puts(const char *str); +static void PrintArgs(const char *fmt, va_list ap); void Print(const char *fmt, ...) { diff --git a/src/common/math.h b/src/common/math.h index 43f09ff..5303638 100644 --- a/src/common/math.h +++ b/src/common/math.h @@ -1,11 +1,10 @@ #ifndef MAD_CORE_COMMON_MATH_H #define MAD_CORE_COMMON_MATH_H -float Resistance(int adc_raw); -float SteinhartHart(float res); - -float Dewpoint(float t, float rh); -float Temperature(float td, float rh); -float RelHumidity(float t, float td); +float Resistance(int adc_raw); +float SteinhartHart(float res); +float Dewpoint(float t, float rh); +float Temperature(float td, float rh); +float RelHumidity(float t, float td); #endif // MAD_CORE_COMMON_MATH_H diff --git a/src/common/parser.c b/src/common/parser.c index 4e2f516..3202817 100644 --- a/src/common/parser.c +++ b/src/common/parser.c @@ -38,6 +38,9 @@ bool CMD_Parse(char ch, cmd_t *out) if (head < tail - 1) { *head++ = ch; *head = '\0'; + } else { + // No space left + WDT_Reset(); } return false; diff --git a/src/main.c b/src/main.c index 4f36a12..18ffd34 100644 --- a/src/main.c +++ b/src/main.c @@ -70,8 +70,9 @@ static int Init(void) // allowing us to detect infinite loops and any // other error that halts execution. - if (WDT_HasTriggered()) + if (WDT_HasTriggered()) { Info("Unexpected system reset."); + } WDT_Enable(); WDT_SetTimeoutFlag(WDT2000); // 2 seconds @@ -80,7 +81,7 @@ static int Init(void) // stored in EEPROM and load them. Some sanity // checking must be done before using those. - if (MEM_Read(&mem)) { // Any valid blocks found? + if (MEM_Read(&mem)) { // Any valid block found? Info("Found persistent configuration in EEPROM!"); Info("Using targets TEMP=%.2fC, DEWP=%.2fC.", mem.temp, mem.dewp); @@ -146,7 +147,6 @@ static void Update(void) // Parse serial commands while ((ch = USART_Getc()) >= 0) { if (!CMD_Parse(ch, &cmd)) { - WDT_Reset(); continue; } switch(cmd.type) { @@ -181,7 +181,7 @@ static void SetTarget(float t, float td) Info("Setting temperature to %.2fC.", t); Info("Setting dewpoint to %.2fC.", td); - // Even with level wearing there is a finite number + // Even with wear leveling there is a finite number // of EEPROM write cycles so we should always check // for redundant values. This could be handled by // the underlying memory implementation.