diff --git a/thread-switch-app/Makefile b/thread-switch-app/Makefile new file mode 100644 index 0000000..9a59ebd --- /dev/null +++ b/thread-switch-app/Makefile @@ -0,0 +1,61 @@ +APPLICATION = thread_switch_app +RIOTBASE ?= /home/hskim/Desktop/rebase/RIOT-OS +BOARD = hamilton + +# System functions +#USEMODULE += random +#USEMODULE += xtimer +USEMODULE += rtt_stdio +CFLAGS += -DRTT_STDIO_DISABLE_STDIN +CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=2048 + +# CPU clock speed +CFLAGS += -DCLOCK_USE_OSCULP32_DFLL=1 + +# Sensors +#USEMODULE += saul_reg # SAUL: sensor/actuator abstraction layer +#USEMODULE += auto_init_saul +#USEMODULE += tmp006 # ambient temperature +#USEMODULE += hdc1000 # humidity and temperature +#USEMODULE += fxos8700 # acceleration and magnetic field +#USEMODULE += apds9007 # illumination +#USEMODULE += ekmb1101111 # pir-based occupancy +#USEMODULE += push_button # simple button + +# Security +#USEMODULE += crypto +#USEMODULE += cipher_modes +#CFLAGS += -DCRYPTO_AES + +#CFLAGS += -DAUTO_CSMA_EN=1 + +# Radio +#USEMODULE += at86rf2xx +#CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=26 + +# Network +#USEMODULE += gnrc_netdev_default +#USEMODULE += auto_init_gnrc_netif +# Duty-cycling +#USEMODULE += gnrc_lasmac +#CFLAGS += -DDUTYCYCLE_SLEEP_INTERVAL=00000UL # If it is ZERO, no duty-cycling for packet reception +#CFLAGS += -DLEAF_NODE=1 # Default is 1 +# Specify the mandatory networking modules for IPv6 and UDP +#USEMODULE += gnrc_ipv6 +#USEMODULE += gnrc_udp +#CFLAGS += -DSOCK_HAS_IPV6 +# Add also the shell, some shell commands +#USEMODULE += netstats_l2 +#USEMODULE += netstats_ipv6 + + +# 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: +# CFLAGS += -DDEVELHELP + +QUIET ?= 1 + +FEATURES_REQUIRED += periph_timer + +include $(RIOTBASE)/Makefile.include diff --git a/thread-switch-app/main.c b/thread-switch-app/main.c new file mode 100644 index 0000000..6594587 --- /dev/null +++ b/thread-switch-app/main.c @@ -0,0 +1,43 @@ +#include "board.h" +#include "thread.h" + +#define ENABLE_DEBUG (1) +#include "debug.h" + +void send_udp(char *addr_str, uint16_t port, uint8_t *data, uint16_t datalen); + +char first_thread_stack[1024]; +char second_thread_stack[1024]; + +#define FIRST_THREAD_PRIO 1 +#define SECOND_THREAD_PRIO 0 + +void* second_thread(void*); + +void* first_thread(void* arg) { + (void) arg; + + kernel_pid_t second_thread_pid = thread_create(second_thread_stack, sizeof(second_thread_stack), SECOND_THREAD_PRIO, THREAD_CREATE_STACKTEST, second_thread, NULL, "second_thread"); + + for (;;) { + LED_ON; + thread_wakeup(second_thread_pid); + } +} + +void* second_thread(void* arg) { + for (;;) { + thread_sleep(); + LED_OFF; + } +} + +int main(void) { + // Disable global interrupts. This will prevent RIOT from functioning + // correctly, but will make the context switch times more accurate. + irq_disable(); + + thread_create(first_thread_stack, sizeof(first_thread_stack), FIRST_THREAD_PRIO, THREAD_CREATE_STACKTEST, first_thread, NULL, "first_thread"); + + return 0; +}