Skip to content

Commit

Permalink
Nodes refactor to c (#94)
Browse files Browse the repository at this point in the history
working state
  • Loading branch information
AnnsAnns authored Jun 3, 2024
2 parents 57bcd26 + b90bdf0 commit f194c36
Show file tree
Hide file tree
Showing 35 changed files with 937 additions and 1,183 deletions.
25 changes: 10 additions & 15 deletions node/code/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APPLICATION = teamagotchi
BOARD = feather-nrf52840-sense
BOARD ?= feather-nrf52840-sense

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/RIOT
Expand All @@ -11,27 +11,23 @@ TEAMAGOTCHI_NODES_BASE = $(CURDIR)
DEVELHELP ?= 1

# Include test_folder example to showcase directories being included
DIR += test_folder
# DIR += test_folder

FEATURES_REQUIRED += cpp
FEATURES_REQUIRED += libstdcpp
FEATURES_REQUIRED += periph_gpio_irq
# FEATURES_REQUIRED += cpp
# FEATURES_REQUIRED += libstdcpp

# Internal Modules
# Teamagotchi MODULES
#USEMODULE += lwm2m_handler
#USEMODULE += io_handler
USEMODULE += io_handler
USEMODULE += display_handler
USEMODULE += lwm2m_handler
# USEMODULE += lwm2m_handler
EXTERNAL_MODULE_DIRS += modules

# External modules
USEMODULE += cpp11-compat
# USEMODULE += cpp11-compat
USEMODULE += ztimer
USEMODULE += ztimer_msec
USEMODULE += shell
USEMODULE += xtimer

# As there is an 'Kconfig' we want to explicitly disable Kconfig by setting
# the variable to empty
#SHOULD_RUN_KCONFIG ?=
Expand All @@ -45,18 +41,18 @@ CFLAGS += -std=c17 -Wall -Wextra

# Set the C++ standard to C++20 [C++23 with all the cool stuff is not yet supported]
# and enable all warnings
CXXEXFLAGS += -std=c++20 -Wall -Wextra
# CXXEXFLAGS += -std=c++20 -Wall -Wextra

# Disable volatile warnings
# C++20 introduced a deprecation for this, which was then
# reverted in C++23 because it wasn't thought through
CXXEXFLAGS += -Wno-volatile
# CXXEXFLAGS += -Wno-volatile

BOARD_BLACKLIST += native64

## DEBUG
CFLAGS += -DDEBUG_ASSERT_VERBOSE

FEATURES_BLACKLIST += tinyusb
##### LWM2M #####
LWM2M_SERVER_SHORT_ID ?= 1
CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE='(3*1024)'
Expand All @@ -79,7 +75,6 @@ endif

include $(RIOTBASE)/Makefile.include


CFLAGS += -DDISPLAY_STACKSIZE=2*1024

# SDL requires more stack
Expand Down
104 changes: 104 additions & 0 deletions node/code/Makefile.bakold
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
APPLICATION = teamagotchi
BOARD = feather-nrf52840-sense

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/RIOT

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1

FEATURES_REQUIRED += cpp
FEATURES_REQUIRED += libstdcpp

# Internal Modules
# Teamagotchi MODULES
#USEMODULE += lwm2m_handler
USEMODULE += io_handler
USEMODULE += display_handler
EXTERNAL_MODULE_DIRS += modules

# External modules
USEMODULE += cpp11-compat
USEMODULE += ztimer
USEMODULE += ztimer_msec
USEMODULE += shell
USEMODULE += xtimer

# As there is an 'Kconfig' we want to explicitly disable Kconfig by setting
# the variable to empty
#SHOULD_RUN_KCONFIG ?=

# Include "inc" directory for the header files
INCLUDES += -I$(CURDIR)/inc

# Set the C standard to C17 [C23 (even experimental) is not yet supported]
# and enable all warnings
CFLAGS += -std=c17 -Wall -Wextra

# Set the C++ standard to C++20 [C++23 with all the cool stuff is not yet supported]
# and enable all warnings
CXXEXFLAGS += -std=c++20 -Wall -Wextra

# Disable volatile warnings
# C++20 introduced a deprecation for this, which was then
# reverted in C++23 because it wasn't thought through
CXXEXFLAGS += -Wno-volatile


#include $(CURDIR)/modules/lwm2m/Makefile.include
include $(RIOTBASE)/Makefile.include


BOARD_BLACKLIST += native64

## DEBUG
CFLAGS += -DDEBUG_ASSERT_VERBOSE

##### LWM2M #####
#SERVER_URI = '"coap://[2001:db8:1::1]:5684"'
LWM2M_SERVER_SHORT_ID ?= 1
CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE='(3*1024)'
# Uncomment to enable Wakaama debug log
#CFLAGS += -DCONFIG_LWM2M_WITH_LOGS=1
# Specific the server URI address (NOTE: Domain names not supported yet)
LWM2M_SERVER_URI ?= '"coap://[fd00:dead:beef::1]:5683"'
# Configure via CFLAGS only if not done via Kconfig
ifndef CONFIG_LWM2M_SERVER_URI
CFLAGS += -DCONFIG_LWM2M_SERVER_URI=$(LWM2M_SERVER_URI)
CFLAGS += -DCONFIG_LWM2M_SERVER_SHORT_ID=$(LWM2M_SERVER_SHORT_ID)
CFLAGS += -DCONFIG_DTLS_PEER_MAX=2
CFLAGS += -DCONFIG_MAX_BUF=1024
# Uncomment to enable Wakaama debug log
CFLAGS += -DCONFIG_LWM2M_WITH_LOGS=1
endif
##### /LWM2M #####


# SDL requires more stack
ifneq (,$(filter native native64,$(BOARD)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=64*1024
else ifneq (,$(filter esp%,$(CPU_FAM)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=4*1024
else
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2*1024
endif


# Note that this will probably only work for me <3
windows: all
@echo "Creating UF2"
@python RIOT/dist/tools/uf2/uf2conv.py -f 0xADA52840 bin/feather-nrf52840-sense/teamagotchi.hex --base 0x1000 -c
@echo "Flashing UF2 via Windows (Make sure your device is actually at D)"
@powershell.exe -command "cp ./flash.uf2 d:/flash.uf2"
@echo "Connecting COM via USBIPD (Make sure you have the USBIPD installed + your device bound to the WSL)"
@sleep 3
@usbipd.exe attach --wsl -i 1209:7d00
@sleep 3
@echo "Connected :D"
@echo "Cleaning up uf2 flash file"
@rm flash.uf2



2 changes: 1 addition & 1 deletion node/code/RIOT
Submodule RIOT updated 41 files
+1 −1 .murdock
+3 −2 Makefile.include
+28 −5 core/include/thread.h
+6 −3 core/thread.c
+1 −0 cpu/cortexm_common/vectors_cortexm.c
+1 −1 cpu/esp_common/freertos/task.c
+3 −4 cpu/esp_common/thread_arch.c
+7 −0 cpu/native/Makefile.include
+1 −1 cpu/native/include/native_internal.h
+12 −9 cpu/native/irq_cpu.c
+23 −15 cpu/native/native_cpu.c
+59 −12 cpu/native/startup.c
+1 −1 cpu/native/syscalls.c
+7 −8 cpu/saml1x/cpu.c
+2 −2 cpu/saml1x/periph/pm.c
+22 −18 cpu/saml21/cpu.c
+2 −2 cpu/saml21/periph/pm.c
+4 −0 dist/tools/tapsetup/tapsetup
+1 −1 examples/rust-gcoap/Cargo.lock
+1 −1 examples/rust-hello-world/Cargo.lock
+1 −2 pkg/flashdb/mtd/fal_mtd_port.c
+6 −0 sys/Makefile.dep
+67 −0 sys/include/net/nanocoap/fs.h
+19 −0 sys/include/net/nanocoap_sock.h
+70 −0 sys/include/net/sock/config.h
+1 −43 sys/include/net/sock/util.h
+34 −22 sys/include/vfs.h
+12 −1 sys/net/application_layer/nanocoap/fileserver.c
+322 −0 sys/net/application_layer/nanocoap/fs.c
+101 −0 sys/net/application_layer/nanocoap/sock.c
+13 −3 sys/net/gnrc/sock/gnrc_sock.c
+1 −1 sys/ps/ps.c
+1 −1 sys/rust_riotmodules_standalone/Cargo.lock
+7 −4 sys/shell/cmds/vfs.c
+1 −1 sys/test_utils/print_stack_usage/print_stack_usage.c
+22 −0 tests/net/nanocoap_fs/Makefile
+38 −0 tests/net/nanocoap_fs/Makefile.ci
+11 −0 tests/net/nanocoap_fs/README.md
+89 −0 tests/net/nanocoap_fs/main.c
+4 −4 tests/periph/hwrng/main.c
+1 −1 tests/rust_minimal/Cargo.lock
32 changes: 0 additions & 32 deletions node/code/dispatcher.cpp

This file was deleted.

33 changes: 33 additions & 0 deletions node/code/events.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "events.h"
#include "event.h"

#define ENABLE_DEBUG 1
#include "debug.h"

#define RCV_QUEUE_SIZE (8)

kernel_pid_t t_events_pid;
static msg_t rcv_queue[RCV_QUEUE_SIZE];

void set_t_events_pid(kernel_pid_t pid){
t_events_pid = pid;
}

void trigger_event(EVENT_T _event){
DEBUG("event input \n");
msg_t msg;
msg.type = _event;
if (msg_try_send(&msg, t_events_pid) == 0) {
printf("Receiver queue full.\n");
}
}


void events_start(void (*fsm_callback)(EVENT_T event)){
msg_t msg;
msg_init_queue(rcv_queue, RCV_QUEUE_SIZE);
while (1) {
msg_receive(&msg);
fsm_callback(msg.type);
}
}
Loading

0 comments on commit f194c36

Please sign in to comment.