Skip to content

Commit 5bd4aa6

Browse files
LFC: Add RIOT (#156)
* WIP * Add RIOT platform * Fix makefile generation * Move some configuration into riot.mk * Add fallback values * IT WORKS * Move more configuration into riot.mk * Fix old examples * Fix test --------- Co-authored-by: erlingrj <[email protected]>
1 parent 29b0728 commit 5bd4aa6

File tree

9 files changed

+86
-12
lines changed

9 files changed

+86
-12
lines changed

examples/riot/blinky/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# name of your application
22
APPLICATION = lf-test
33

4+
# This has to be the absolute path to the RIOT base directory:
5+
RIOTBASE ?= $(CURDIR)/../../../../RIOT
6+
47
# If no BOARD is found in the environment, use this default:
58
BOARD ?= native
69

@@ -14,7 +17,7 @@ QUIET ?= 1
1417

1518
# Enable reactor-uc features
1619
# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX
17-
CFLAGS += -DEVENT_QUEUE_SIZE=32
18-
CFLAGS += -DREACTION_QUEUE_SIZE=32
20+
REACTION_QUEUE_SIZE = 32
21+
EVENT_QUEUE_SIZE = 32
1922

2023
include $(CURDIR)/../../../make/riot/riot.mk

examples/riot/hello/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# name of your application
22
APPLICATION = lf-test
33

4+
# This has to be the absolute path to the RIOT base directory:
5+
RIOTBASE ?= $(CURDIR)/../../../../RIOT
6+
47
# If no BOARD is found in the environment, use this default:
58
BOARD ?= native
69

@@ -14,7 +17,7 @@ QUIET ?= 1
1417

1518
# Enable reactor-uc features
1619
# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX
17-
CFLAGS += -DEVENT_QUEUE_SIZE=32
18-
CFLAGS += -DREACTION_QUEUE_SIZE=32
20+
REACTION_QUEUE_SIZE = 32
21+
EVENT_QUEUE_SIZE = 32
1922

2023
include $(CURDIR)/../../../make/riot/riot.mk

examples/riot/hello_lf/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# name of your application
2+
APPLICATION = HelloLF
3+
4+
# This has to be the absolute path to the RIOT base directory:
5+
# TODO: In the lingo template this should point to ./RIOT because we plan to include RIOT as a submodule there
6+
RIOTBASE ?= $(CURDIR)/../../../../RIOT
7+
8+
# Path of generated lf c-code
9+
SRC_GEN_PATH = $(CURDIR)/src-gen/$(APPLICATION)
10+
11+
# TODO: Can we call lfc here directly?
12+
13+
# If no BOARD is found in the environment, use this default:
14+
BOARD ?= native
15+
16+
# Comment this out to disable code in RIOT that does safety checking
17+
# which is not needed in a production environment but helps in the
18+
# development process:
19+
DEVELHELP ?= 1
20+
21+
# Change this to 0 show compiler invocation lines by default:
22+
QUIET ?= 1
23+
24+
# Enable reactor-uc features
25+
# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX
26+
27+
include $(SRC_GEN_PATH)/reactor-uc/make/riot/riot.mk

examples/riot/hello_lf/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "lf_main.h"
2+
3+
int main() {
4+
lf_start();
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target uC {
2+
platform: RIOT
3+
}
4+
5+
main reactor {
6+
reaction(startup) {=
7+
printf("Hello from LF my!\n");
8+
=}
9+
}

lfc/core/src/main/java/org/lflang/target/property/type/PlatformType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum Platform {
1818
LINUX("Linux", true),
1919
MAC("Darwin", true),
2020
ZEPHYR("Zephyr", true),
21+
RIOT("RIOT", true),
2122
FLEXPRET("FlexPRET", true),
2223
WINDOWS("Windows", true);
2324

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcMakeGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class UcMakeGenerator(private val main: Reactor, private val targetConfig: Targe
1717
private val S = '$' // a little trick to escape the dollar sign with $S
1818
fun generateMake(sources: List<Path>) = with(PrependOperator) {
1919
"""
20-
| # Makefile genrated for ${fileConfig.name}
20+
| # Makefile generated for ${fileConfig.name}
2121
|LF_SOURCES = \
22-
${" | "..sources.joinWithLn { it.toUnixString() + " \\ "}}
22+
${" | "..sources.joinWithLn { it.toUnixString() + if (it != sources.last()) " \\" else ""}}
2323
|REACTION_QUEUE_SIZE = ${max(main.getReactionQueueSize(), 1)}
2424
|EVENT_QUEUE_SIZE = ${max(main.getEventQueueSize(), 1)}
2525
|

make/riot/riot.mk

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
RIOT_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
22

3-
# This has to be the absolute path to the RIOT base directory:
4-
RIOTBASE ?= $(RIOT_MK_DIR)/../../../RIOT
3+
# Include generated sources and makefiles if SRC_GEN_PATH is defined
4+
ifdef SRC_GEN_PATH
5+
include $(SRC_GEN_PATH)/Makefile
6+
7+
# Include generated c files
8+
SRC += $(patsubst %, $(SRC_GEN_PATH)/%, $(LF_SOURCES)) main.c
9+
10+
# Include generated h files
11+
CFLAGS += -I$(SRC_GEN_PATH)
12+
endif
13+
14+
# Check if required environment variables exist
15+
ifndef RIOTBASE
16+
$(error RIOTBASE is not defined. Please define it!)
17+
endif
18+
19+
ifndef EVENT_QUEUE_SIZE
20+
$(error EVENT_QUEUE_SIZE is not defined. Please define it!)
21+
endif
22+
23+
ifndef REACTION_QUEUE_SIZE
24+
$(error REACTION_QUEUE_SIZE is not defined. Please define it!)
25+
endif
526

627
# Comment this out to disable code in RIOT that does safety checking
728
# which is not needed in a production environment but helps in the
@@ -14,10 +35,12 @@ QUIET ?= 1
1435
# Use a peripheral timer for the delay, if available
1536
FEATURES_OPTIONAL += periph_timer
1637

17-
# External modules
38+
# Include reactor-uc as an external module
1839
EXTERNAL_MODULE_DIRS += $(RIOT_MK_DIR)/external_modules
1940
USEMODULE += reactor-uc
2041

21-
42+
# Apply project reactor-uc configuration variables
43+
CFLAGS += -DEVENT_QUEUE_SIZE=$(EVENT_QUEUE_SIZE)
44+
CFLAGS += -DREACTION_QUEUE_SIZE=$(REACTION_QUEUE_SIZE)
2245

2346
include $(RIOTBASE)/Makefile.include

test/platform/riot/coap_channel_test/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# name of your application
22
APPLICATION = lf-coap-channel-test
33

4+
# This has to be the absolute path to the RIOT base directory:
5+
RIOTBASE ?= $(CURDIR)/../../../../../RIOT
6+
47
# If no BOARD is found in the environment, use this default:
58
BOARD ?= native
69

@@ -20,8 +23,8 @@ USEMODULE += ztimer_sec
2023
# Enable reactor-uc features
2124
# CFLAGS += -DNETWORK_CHANNEL_TCP_POSIX
2225
CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT
23-
CFLAGS += -DEVENT_QUEUE_SIZE=32
24-
CFLAGS += -DREACTION_QUEUE_SIZE=32
26+
REACTION_QUEUE_SIZE = 32
27+
EVENT_QUEUE_SIZE = 32
2528

2629
CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000
2730
CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000

0 commit comments

Comments
 (0)