Skip to content

Commit 3757bff

Browse files
committed
Patmos and s4noc : 7
1 parent 59c00dc commit 3757bff

File tree

11 files changed

+112
-60
lines changed

11 files changed

+112
-60
lines changed

examples/patmos/buildAll.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# set -e
2-
# echo "Building Patmos example"
3-
# ${REACTOR_UC_PATH}/lfc/bin/lfc-dev hello_lf/src/HelloLF.lf
4-
# cmake -Bbuild -DPLATFORM=PATMOS
5-
# make -C build
6-
7-
# echo "Running Patmos example"
8-
# pasim ./bin/hello_lf.elf
9-
10-
111
#!/bin/bash
122

133
set -e
@@ -19,9 +9,9 @@ else
199
for dir in ./*; do
2010
if [ -d $dir ]; then
2111
echo "Entering $dir"
22-
pushd $dir
23-
./build.sh
24-
popd
12+
pushd $dir
13+
./build.sh
14+
popd
2515
fi
2616
done
2717
fi

examples/patmos/hello_lf/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ endif
1111

1212
# ---- Patmos specific configuration ----
1313
include ./src-gen/$(LF_MAIN)/Makefile
14-
include $(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
15-
16-
SOURCES += $(patsubst %, $(SRC_GEN_PATH)/%, $(LFC_GEN_SOURCES) $(LFC_GEN_MAIN))
14+
include $(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
1715

1816
CFLAGS += -DSCHEDULER_DYNAMIC
1917
CFLAGS += -DEVENT_QUEUE_SIZE=$(EVENT_QUEUE_SIZE)

examples/patmos/s4noc_lf/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
REACTOR_UC_PATH ?= $(CURDIR)/../../../
2+
LF_MAIN ?= s4noc
3+
4+
# The name of the LF application inside "./src" to build/run/flash etc.
5+
SRC_GEN_PATH ?= ./src-gen/$(LF_MAIN)
6+
7+
# Execute the LF compiler if build target is "all"
8+
ifeq ($(firstword $(MAKECMDGOALS)),all)
9+
_ := $(shell $(REACTOR_UC_PATH)/lfc/bin/lfc-dev src/$(LF_MAIN).lf)
10+
endif
11+
12+
# ---- Patmos specific configuration ----
13+
include ./src-gen/$(LF_MAIN)/Makefile
14+
include $(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
15+
16+
CFLAGS += -DSCHEDULER_DYNAMIC
17+
CFLAGS += -DEVENT_QUEUE_SIZE=$(EVENT_QUEUE_SIZE)
18+
CFLAGS += -DREACTION_QUEUE_SIZE=$(REACTION_QUEUE_SIZE)
19+
20+
# Output directory
21+
BIN_DIR = $(CURDIR)/bin
22+
OUTPUT = $(BIN_DIR)/$(LF_MAIN)
23+
24+
all: $(OUTPUT)
25+
26+
# Build rule
27+
$(OUTPUT): $(SOURCES)
28+
mkdir -p $(BIN_DIR)
29+
$(CC) $(SOURCES) $(CFLAGS) -o $(OUTPUT)
30+
31+
clean:
32+
rm -rf $(BIN_DIR) ./src-gen
33+
34+
.PHONY: all clean
35+

examples/patmos/s4noc_lf/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
rm -rf bin src-gen
4+
make all
5+
patemu ./bin/s4noc
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
target uC {
2+
platform: PATMOS,
3+
timeout: 1sec
4+
}
5+
6+
reactor Src(id: int = 0) {
7+
output out: int
8+
9+
reaction(startup) -> out{=
10+
printf("Hello from Src!\n");
11+
lf_set(out, self->id);
12+
=}
13+
}
14+
15+
reactor Dst {
16+
input in: int
17+
state check: bool = false
18+
19+
reaction(startup) {=
20+
printf("Hello from Dst!\n");
21+
=}
22+
23+
reaction(in) {=
24+
printf("Received %d from Src\n", in->value);
25+
validate(in->value == 42);
26+
self->check = true;
27+
env->request_shutdown(env);
28+
=}
29+
30+
reaction(shutdown) {=
31+
validate(self->check);
32+
=}
33+
}
34+
35+
main reactor {
36+
@interface_s4noc(core=0)
37+
r1 = new Src(id=42)
38+
39+
@interface_s4noc(core=1)
40+
r2 = new Dst()
41+
42+
@link(left="0", right="1")
43+
r1.out -> r2.in
44+
}

examples/riot/buildAll.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ set -e
66
for dir in ./*; do
77
if [ -d $dir ]; then
88
echo "Entering $dir"
9-
pushd $dir
10-
./build.sh
11-
popd
9+
pushd $dir
10+
./build.sh
11+
popd
1212
fi
1313
done

lfc/core/src/main/java/org/lflang/validation/AttributeSpec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ enum AttrParamType {
286286
List.of(
287287
new AttrParamSpec("name", AttrParamType.STRING, true),
288288
new AttrParamSpec("address", AttrParamType.STRING, true))));
289+
ATTRIBUTE_SPECS_BY_NAME.put(
290+
"interface_s4noc",
291+
new AttributeSpec(List.of(new AttrParamSpec("core", AttrParamType.INT, false))));
289292
ATTRIBUTE_SPECS_BY_NAME.put(
290293
"interface_custom",
291294
new AttributeSpec(
@@ -307,6 +310,8 @@ enum AttrParamType {
307310
ATTRIBUTE_SPECS_BY_NAME.put("platform_riot", new AttributeSpec(null));
308311
// @platform_zephyr
309312
ATTRIBUTE_SPECS_BY_NAME.put("platform_zephyr", new AttributeSpec(null));
313+
// @platform_patmos
314+
ATTRIBUTE_SPECS_BY_NAME.put("platform_patmos", new AttributeSpec(null));
310315
// @platform_native
311316
ATTRIBUTE_SPECS_BY_NAME.put("platform_native", new AttributeSpec(null));
312317
// @clock_sync(grandmaster=true, server_port=1042)

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,7 @@ class UcFederatedTemplateGenerator(
132132
FileUtil.writeToFile(cmake, projectRoot.resolve("CMakeLists.txt"))
133133
}
134134

135-
private fun generateFilesPatmos() {
136-
val make =
137-
"""
138-
|LF_MAIN ?= ${mainDef.name}
139-
|LF_FED ?= ${federate.name}
140-
|
141-
|# Paths
142-
|SRC_DIR = src-gen/${mainDef.name}/${federate.name}
143-
|BUILD_DIR = build
144-
|
145-
|# Source files
146-
|SOURCES = $S(SRC_DIR)/*.c
147-
|
148-
|# Output binary
149-
|OUTPUT = $S(BUILD_DIR)/${federate.name}.elf
150-
|
151-
|all: $S(OUTPUT)
152-
|
153-
|$S(OUTPUT): $S(SOURCES)
154-
| mkdir -p $S(BUILD_DIR)
155-
| $S(CC) $S(CFLAGS) $S(SOURCES) -o $S(OUTPUT)
156-
|
157-
|.PHONY: all clean
158-
|include $S(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
159-
"""
160-
.trimMargin()
161-
FileUtil.writeToFile(make, projectRoot.resolve("Makefile"))
162-
}
135+
private fun generateFilesPatmos() {}
163136

164137
fun generateFiles() {
165138
if (Files.exists(projectRoot)) {

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ object UcNetworkInterfaceFactory {
2424
UcCoapUdpIpInterface.fromAttribute(federate, attr)
2525
},
2626
Pair(CUSTOM) { federate, attr -> UcCustomInterface.fromAttribute(federate, attr) },
27-
Pair(UART) { federate, attr -> UcUARTInterface.fromAttribute(federate, attr) })
27+
Pair(UART) { federate, attr -> UcUARTInterface.fromAttribute(federate, attr) },
28+
Pair(S4NOC) { federate, attr -> UcS4NocInterface.fromAttribute(federate, attr) })
2829

2930
fun createInterfaces(federate: UcFederate): List<UcNetworkInterface> {
3031
val attrs: List<Attribute> = getInterfaceAttributes(federate.inst)
@@ -74,8 +75,7 @@ class UcUARTEndpoint(
7475
class UcCoapUdpIpEndpoint(val ipAddress: IPAddress, iface: UcCoapUdpIpInterface) :
7576
UcNetworkEndpoint(iface) {}
7677

77-
class UcS4NocEndpoint(val s4nocId: Int, val port: Int, iface: UcS4NocInterface) :
78-
UcNetworkEndpoint(iface) {}
78+
class UcS4NocEndpoint(val core: Int, iface: UcS4NocInterface) : UcNetworkEndpoint(iface) {}
7979

8080
class UcCustomEndpoint(iface: UcCustomInterface) : UcNetworkEndpoint(iface) {}
8181

@@ -200,23 +200,26 @@ class UcCoapUdpIpInterface(private val ipAddress: IPAddress, name: String? = nul
200200
}
201201
}
202202

203-
class UcS4NocInterface(val s4nocId: Int, val port: Int, name: String? = null) :
203+
class UcS4NocInterface(val core: Int, name: String? = null) :
204204
UcNetworkInterface(S4NOC, name ?: "s4noc") {
205205
override val includeHeaders: String = ""
206206
override val compileDefs: String = "NETWORK_CHANNEL_S4NOC"
207207

208+
init {
209+
println("UcS4NocInterface created with core=$core and name=${name ?: "s4noc"}")
210+
}
211+
208212
fun createEndpoint(): UcS4NocEndpoint {
209-
val ep = UcS4NocEndpoint(s4nocId, port, this)
213+
val ep = UcS4NocEndpoint(core, this)
210214
endpoints.add(ep)
211215
return ep
212216
}
213217

214218
companion object {
215219
fun fromAttribute(federate: UcFederate, attr: Attribute): UcS4NocInterface {
216-
val s4nocId = attr.getParamInt("s4noc_id") ?: 0
217-
val port = attr.getParamInt("port") ?: 0
220+
val core = attr.getParamInt("core") ?: 0
218221
val name = attr.getParamString("name")
219-
return UcS4NocInterface(s4nocId, port, name)
222+
return UcS4NocInterface(core, name)
220223
}
221224
}
222225
}
@@ -401,10 +404,10 @@ class UcS4NocChannel(
401404
private val destS4Noc = dest
402405

403406
override fun generateChannelCtorSrc() =
404-
"S4NocChannel_ctor(&self->channel, ${if (serverLhs) srcS4Noc.s4nocId else destS4Noc.s4nocId}, ${if (serverLhs) srcS4Noc.port else destS4Noc.port});"
407+
"S4NocChannel_ctor(&self->channel, ${if (serverLhs) srcS4Noc.core else destS4Noc.core});"
405408

406409
override fun generateChannelCtorDest() =
407-
"S4NocChannel_ctor(&self->channel, ${if (serverLhs) srcS4Noc.s4nocId else destS4Noc.s4nocId}, ${if (serverLhs) srcS4Noc.port else destS4Noc.port});"
410+
"S4NocChannel_ctor(&self->channel, ${if (serverLhs) srcS4Noc.core else destS4Noc.core});"
408411

409412
override val codeType: String
410413
get() = "S4NocChannel"

make/patmos/patmos-lfc.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ else
3030
include $(LF_SRC_GEN_PATH)/Makefile
3131

3232
# Include generated c files
33-
SRC += $(patsubst %, $(LF_SRC_GEN_PATH)/%, $(LFC_GEN_SOURCES))
33+
SOURCES += $(patsubst %, $(LF_SRC_GEN_PATH)/%, $(LFC_GEN_SOURCES))
3434

3535
# Include generated main file
36-
SRC += $(LF_SRC_GEN_PATH)/${LFC_GEN_MAIN}
36+
SOURCES += $(LF_SRC_GEN_PATH)/${LFC_GEN_MAIN}
3737

3838
# Include generated h files
3939
CFLAGS += -I$(LF_SRC_GEN_PATH)

0 commit comments

Comments
 (0)