Reduce number of watchdog timer resets and rename Makefile target

This commit is contained in:
2024-09-27 14:35:03 +02:00
parent aa0cd89d4e
commit ae329083db
6 changed files with 40 additions and 40 deletions

View File

@@ -8,15 +8,6 @@
# GENERAL SETTINGS # 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 VERBOSE := false
#ARCH := m1284p #ARCH := m1284p
ARCH := m32 ARCH := m32
@@ -32,6 +23,13 @@ AVD := avrdude
MKDIR := mkdir -p MKDIR := mkdir -p
RMR := rm -rf 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) CPPFLAGS := -DF_CPU=$(FREQ) -I$(SRCDIR)
CFLAGS := -mmcu=$(MCU) -Os -std=c99 -Wall -Wextra -Werror CFLAGS := -mmcu=$(MCU) -Os -std=c99 -Wall -Wextra -Werror
OCFLAGS := -j .text -j .data -O ihex OCFLAGS := -j .text -j .data -O ihex
@@ -85,8 +83,8 @@ listen: ./opt/tools/serial-listen.py
$(E) "[PY3] $<" $(E) "[PY3] $<"
$(Q) ./$< $(Q) ./$<
.PHONY: listen-web .PHONY: webgui
listen-web: ./opt/webgui/Makefile webgui: ./opt/webgui/Makefile
$(E) "[MAK] $(<D)" $(E) "[MAK] $(<D)"
$(Q) $(MAKE) -sC $(<D) $(Q) $(MAKE) -sC $(<D)

View File

@@ -26,37 +26,37 @@ build and install the project:
make all make all
If there are any errors during the flashing process you If there are any errors during the flashing process you
should find more information in core.log in the bin/ should find more information in `bin/core.log`. See the
directory. See the Makefile for different settings for Makefile for all build-related settings and make sure
your specific build environment. they are correct for your current build environment.
To remove all build related auxiliary files you may run To remove build related auxiliary files you may use one
these commands: of these commands:
make clean make clean
make distclean make distclean
You can listen on the serial debug interface using the You can listen on the serial debug interface by running
command below (if you have initialized the optional the command below (if you have initialized the optional
submodules as described in the 'Setting a New Target' submodules as described in the section 'Setting a New
section): Target'):
make listen make listen
Alternatively you can spin up a web server on port 443 Alternatively you can spin up a web server on port 443
to interface with the device using the following command. to interface with the device using the following command.
Make sure to read section 'Webinterface Example' for more Make sure to read section 'Webinterface Example' for more
information. information on how to configure the server.
make listen-web make webgui
### Setting a New Target ### Setting a New Target
The script below allows you to send serial commands (you The script below allows you to send serial commands (you
may need to run `git submodule update --init` if the tools/ may need to run `git submodule update --init` first, if
directory is empty): the `opt/tools/` directory is empty):
./opt/tools/serial-send.py <command> <args ...> opt/tools/serial-send.py <command> <args ...>
Issue the SET command to update the target settings: Issue the SET command to update the target settings:
@@ -70,15 +70,15 @@ of digits.
### Webinterface Example ### Webinterface Example
There is an example Python web server utilizing websockets you 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 writing a custom network bridge and integrating the device into
your home automation system. your home automation system.
You must generate a self-signed certificate before you run the You must generate a self-signed certificate before you run the
server. The configuration script will take care of it: 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 and more information. Please be aware that development for the
web server has paused until the core has reached version v1.0. web server has paused until the core has reached version v1.0.

View File

@@ -3,7 +3,6 @@
float Resistance(int adc_raw); float Resistance(int adc_raw);
float SteinhartHart(float res); float SteinhartHart(float res);
float Dewpoint(float t, float rh); float Dewpoint(float t, float rh);
float Temperature(float td, float rh); float Temperature(float td, float rh);
float RelHumidity(float t, float td); float RelHumidity(float t, float td);

View File

@@ -38,6 +38,9 @@ bool CMD_Parse(char ch, cmd_t *out)
if (head < tail - 1) { if (head < tail - 1) {
*head++ = ch; *head++ = ch;
*head = '\0'; *head = '\0';
} else {
// No space left
WDT_Reset();
} }
return false; return false;

View File

@@ -70,8 +70,9 @@ static int Init(void)
// allowing us to detect infinite loops and any // allowing us to detect infinite loops and any
// other error that halts execution. // other error that halts execution.
if (WDT_HasTriggered()) if (WDT_HasTriggered()) {
Info("Unexpected system reset."); Info("Unexpected system reset.");
}
WDT_Enable(); WDT_Enable();
WDT_SetTimeoutFlag(WDT2000); // 2 seconds WDT_SetTimeoutFlag(WDT2000); // 2 seconds
@@ -80,7 +81,7 @@ static int Init(void)
// stored in EEPROM and load them. Some sanity // stored in EEPROM and load them. Some sanity
// checking must be done before using those. // 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("Found persistent configuration in EEPROM!");
Info("Using targets TEMP=%.2fC, DEWP=%.2fC.", Info("Using targets TEMP=%.2fC, DEWP=%.2fC.",
mem.temp, mem.dewp); mem.temp, mem.dewp);
@@ -146,7 +147,6 @@ static void Update(void)
// Parse serial commands // Parse serial commands
while ((ch = USART_Getc()) >= 0) { while ((ch = USART_Getc()) >= 0) {
if (!CMD_Parse(ch, &cmd)) { if (!CMD_Parse(ch, &cmd)) {
WDT_Reset();
continue; continue;
} }
switch(cmd.type) { switch(cmd.type) {
@@ -181,7 +181,7 @@ static void SetTarget(float t, float td)
Info("Setting temperature to %.2fC.", t); Info("Setting temperature to %.2fC.", t);
Info("Setting dewpoint to %.2fC.", td); 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 // of EEPROM write cycles so we should always check
// for redundant values. This could be handled by // for redundant values. This could be handled by
// the underlying memory implementation. // the underlying memory implementation.