Skip to content

Commit 59c00dc

Browse files
committed
Patmos and s4noc support: 6
1 parent 1729aa4 commit 59c00dc

File tree

18 files changed

+57
-258
lines changed

18 files changed

+57
-258
lines changed

examples/patmos/hello_lf/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ endif
1111

1212
# ---- Patmos specific configuration ----
1313
include ./src-gen/$(LF_MAIN)/Makefile
14+
include $(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
1415

15-
SRC = $(REACTOR_UC_PATH)/src/*.c
16-
SRC += $(patsubst %, $(SRC_GEN_PATH)/%, $(LFC_GEN_SOURCES) $(LFC_GEN_MAIN))
16+
SOURCES += $(patsubst %, $(SRC_GEN_PATH)/%, $(LFC_GEN_SOURCES) $(LFC_GEN_MAIN))
1717

18-
INC = -I$(REACTOR_UC_PATH)/include -I$(REACTOR_UC_PATH)/external -I$(SRC_GEN_PATH)
19-
FLG = -DPLATFORM_PATMOS -DSCHEDULER_DYNAMIC -DEVENT_QUEUE_SIZE=$(EVENT_QUEUE_SIZE) -DREACTION_QUEUE_SIZE=$(REACTION_QUEUE_SIZE) -O2
18+
CFLAGS += -DSCHEDULER_DYNAMIC
19+
CFLAGS += -DEVENT_QUEUE_SIZE=$(EVENT_QUEUE_SIZE)
20+
CFLAGS += -DREACTION_QUEUE_SIZE=$(REACTION_QUEUE_SIZE)
2021

2122
# Output directory
2223
BIN_DIR = $(CURDIR)/bin
@@ -25,9 +26,9 @@ OUTPUT = $(BIN_DIR)/$(LF_MAIN)
2526
all: $(OUTPUT)
2627

2728
# Build rule
28-
$(OUTPUT): $(SRC)
29+
$(OUTPUT): $(SOURCES)
2930
mkdir -p $(BIN_DIR)
30-
patmos-clang $(SRC) $(INC) $(FLG) -o $(OUTPUT) -Wno-everything
31+
$(CC) $(SOURCES) $(CFLAGS) -o $(OUTPUT)
3132

3233
clean:
3334
rm -rf $(BIN_DIR) ./src-gen

include/reactor-uc/event.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include <stdbool.h>
88

99
#define EVENT_INIT(Tag, Trigger, Payload) \
10-
{.super.type = EVENT, .super.tag = Tag, .intended_tag = Tag, .trigger = Trigger, .super.payload = Payload}
10+
{ .super.type = EVENT, .super.tag = Tag, .intended_tag = Tag, .trigger = Trigger, .super.payload = Payload }
1111

1212
#define SYSTEM_EVENT_INIT(Tag, Handler, Payload) \
13-
{.super.type = SYSTEM_EVENT, .super.tag = Tag, .super.payload = Payload, .handler = Handler}
13+
{ .super.type = SYSTEM_EVENT, .super.tag = Tag, .super.payload = Payload, .handler = Handler }
1414

1515
typedef struct Trigger Trigger;
1616
typedef struct SystemEventHandler SystemEventHandler;

include/reactor-uc/platform/patmos/s4noc_channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct S4NOCPollChannel {
3232

3333
FederatedConnectionBundle *federated_connection;
3434
void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message);
35-
pthread_t worker_thread;
35+
pthread_t worker_thread;
3636
};
3737

3838
void S4NOCPollChannel_ctor(S4NOCPollChannel *self, Environment *env, unsigned int destination_core);

include/reactor-uc/tag.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@
4040
.time = NEVER, .microstep = NEVER_MICROSTEP \
4141
}
4242
// Need a separate initializer expression to comply with some C compilers
43-
#define NEVER_TAG_INITIALIZER {NEVER, NEVER_MICROSTEP}
43+
#define NEVER_TAG_INITIALIZER \
44+
{ NEVER, NEVER_MICROSTEP }
4445
#define FOREVER_TAG \
4546
(tag_t) { \
4647
.time = FOREVER, .microstep = FOREVER_MICROSTEP \
4748
}
4849
// Need a separate initializer expression to comply with some C compilers
49-
#define FOREVER_TAG_INITIALIZER {FOREVER, FOREVER_MICROSTEP}
50-
#define ZERO_TAG (tag_t){.time = 0LL, .microstep = 0u}
50+
#define FOREVER_TAG_INITIALIZER \
51+
{ FOREVER, FOREVER_MICROSTEP }
52+
#define ZERO_TAG \
53+
(tag_t) { \
54+
.time = 0LL, .microstep = 0u \
55+
}
5156

5257
// Returns true if timeout has elapsed.
5358
#define CHECK_TIMEOUT(start, duration) (lf_time_physical() > ((start) + (duration)))

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class UcFederatedTemplateGenerator(
135135
private fun generateFilesPatmos() {
136136
val make =
137137
"""
138-
|# Compiler and tools for PATMOS
139-
|CC = patmos-clang
138+
|LF_MAIN ?= ${mainDef.name}
139+
|LF_FED ?= ${federate.name}
140140
|
141141
|# Paths
142142
|SRC_DIR = src-gen/${mainDef.name}/${federate.name}
@@ -145,9 +145,6 @@ class UcFederatedTemplateGenerator(
145145
|# Source files
146146
|SOURCES = $S(SRC_DIR)/*.c
147147
|
148-
|# Compiler flags
149-
|CFLAGS = -O2 -Wall -Wextra -Werror
150-
|
151148
|# Output binary
152149
|OUTPUT = $S(BUILD_DIR)/${federate.name}.elf
153150
|
@@ -157,10 +154,8 @@ class UcFederatedTemplateGenerator(
157154
| mkdir -p $S(BUILD_DIR)
158155
| $S(CC) $S(CFLAGS) $S(SOURCES) -o $S(OUTPUT)
159156
|
160-
|clean:
161-
| rm -rf $S(BUILD_DIR)
162-
|
163157
|.PHONY: all clean
158+
|include $S(REACTOR_UC_PATH)/make/patmos/patmos-lfc.mk
164159
"""
165160
.trimMargin()
166161
FileUtil.writeToFile(make, projectRoot.resolve("Makefile"))

make/patmos/patmos-lfc.mk

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ ifndef LF_MAIN
55
$(error LF_MAIN is not defined. Please define it!)
66
endif
77

8-
# ifndef RIOTBASE
9-
# $(error RIOTBASE is not defined. Please define it!)
10-
# endif
11-
128
# Check if this is a federated program
139
ifdef LF_FED
1410
# Name of your application
@@ -29,8 +25,6 @@ endif
2925
ifeq ($(firstword $(MAKECMDGOALS)),clean)
3026
# Delete src-gen folder if build target is "clean"
3127
_ := $(shell rm -rf $(LF_SRC_GEN_PATH))
32-
33-
# include $(RIOTBASE)/Makefile.include
3428
else
3529
# Include the Makefile of the generated target application
3630
include $(LF_SRC_GEN_PATH)/Makefile

make/patmos/patmos.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# This Makefile is used to build the Patmos platform for the Reactor-UC project.
33
# It includes the necessary paths, sources, and compiler flags for the Patmos architecture.
44

5+
# Compiler and tools for PATMOS
6+
CC = patmos-clang
7+
58
# Includes
69
CFLAGS += -I$(REACTOR_UC_PATH)/
710
CFLAGS += -I$(REACTOR_UC_PATH)/include
@@ -26,3 +29,8 @@ SOURCES += $(wildcard $(REACTOR_UC_PATH)/src/*.c)
2629

2730
SOURCES += $(wildcard $(REACTOR_UC_PATH)/external/nanopb/*.c)
2831
SOURCES += $(REACTOR_UC_PATH)/external/proto/message.pb.c
32+
33+
CFLAGS += -O2
34+
CFLAGS += -Wall -Wextra
35+
CFLAGS += -DPLATFORM_PATMOS
36+

src/platform/patmos/patmos.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ instant_t PlatformPatmos_get_physical_time(Platform *super) {
2121
lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *super, instant_t wakeup_time) {
2222
PlatformPatmos *self = (PlatformPatmos *)super;
2323
self->async_event = false;
24-
//super->leave_critical_section(super); // turing on interrupts
2524

2625
instant_t now = super->get_physical_time(super);
2726

@@ -30,8 +29,6 @@ lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *super, instant_t wake
3029
now = super->get_physical_time(super);
3130
} while ((now < wakeup_time) && !self->async_event);
3231

33-
//super->enter_critical_section(super);
34-
3532
if (self->async_event) {
3633
self->async_event = false;
3734
return LF_ERR;
@@ -44,8 +41,6 @@ lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *super, instant_t wake
4441
return LF_OK;
4542
}
4643

47-
//super->leave_critical_section(super);
48-
4944
return LF_OK;
5045
}
5146

@@ -131,5 +126,5 @@ void Mutex_ctor(Mutex *super) {
131126
MutexPatmos *self = (MutexPatmos *)super;
132127
super->lock = MutexPatmos_lock;
133128
super->unlock = MutexPatmos_unlock;
134-
//critical_section_init(&self->crit_sec);
135-
}
129+
// critical_section_init(&self->crit_sec);
130+
}

src/platform/patmos/s4noc_channel.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static lf_ret_t S4NOCPollChannel_send_blocking(NetworkChannel *untyped_self, con
4040

4141
if (self->state == NETWORK_CHANNEL_STATE_CONNECTED) {
4242
int message_size = serialize_to_protobuf(message, self->write_buffer + 4, S4NOC_CHANNEL_BUFFERSIZE - 4);
43-
43+
4444
*((int *)self->write_buffer) = message_size;
4545

4646
int total_size = message_size + 4;
@@ -83,31 +83,31 @@ void S4NOCPollChannel_poll(NetworkChannel *untyped_self) {
8383

8484
int value = *s4noc_data;
8585
int source = *s4noc_source;
86-
S4NOC_CHANNEL_INFO("S4NOCPollChannel_poll: Received value 0x%08x (%c%c%c%c) from source %d", value,
87-
((char *)&value)[0], ((char *)&value)[1], ((char *)&value)[2], ((char *)&value)[3], source);
88-
S4NOCPollChannel *receive_channel = s4noc_global_state.core_channels[source][get_cpuid()]; // Get the receive channel for the source core
86+
S4NOC_CHANNEL_INFO("S4NOCPollChannel_poll: Received value 0x%08x (%c%c%c%c) from source %d", value,
87+
((char *)&value)[0], ((char *)&value)[1], ((char *)&value)[2], ((char *)&value)[3], source);
88+
S4NOCPollChannel *receive_channel =
89+
s4noc_global_state.core_channels[source][get_cpuid()]; // Get the receive channel for the source core
8990

9091
((int *)receive_channel->receive_buffer)[receive_channel->receive_buffer_index / 4] = value;
9192
receive_channel->receive_buffer_index += 4;
9293
S4NOC_CHANNEL_DEBUG("receive_buffer_index %d", receive_channel->receive_buffer_index);
9394
unsigned int expected_message_size = *((int *)receive_channel->receive_buffer);
9495
S4NOC_CHANNEL_DEBUG("Expected message size: %d", expected_message_size);
9596
if (receive_channel->receive_buffer_index >= expected_message_size + 4) {
96-
int bytes_left = deserialize_from_protobuf(
97-
&receive_channel->output,
98-
receive_channel->receive_buffer + 4, // skip the 4-byte size header
99-
expected_message_size // only the message payload
97+
int bytes_left = deserialize_from_protobuf(&receive_channel->output,
98+
receive_channel->receive_buffer + 4, // skip the 4-byte size header
99+
expected_message_size // only the message payload
100100
);
101101
S4NOC_CHANNEL_DEBUG("Bytes Left after attempted to deserialize: %d", bytes_left);
102102

103103
if (bytes_left >= 0) {
104-
receive_channel->receive_buffer_index = bytes_left;
105-
if (receive_channel->receive_callback != NULL) {
106-
S4NOC_CHANNEL_DEBUG("calling user callback at %p!", receive_channel->receive_callback);
107-
receive_channel->receive_callback(self->federated_connection, &receive_channel->output);
108-
} else {
109-
S4NOC_CHANNEL_WARN("No receive callback registered, dropping message");
110-
}
104+
receive_channel->receive_buffer_index = bytes_left;
105+
if (receive_channel->receive_callback != NULL) {
106+
S4NOC_CHANNEL_DEBUG("calling user callback at %p!", receive_channel->receive_callback);
107+
receive_channel->receive_callback(self->federated_connection, &receive_channel->output);
108+
} else {
109+
S4NOC_CHANNEL_WARN("No receive callback registered, dropping message");
110+
}
111111
}
112112
}
113113
}
@@ -132,5 +132,5 @@ void S4NOCPollChannel_ctor(S4NOCPollChannel *self, Environment *env, unsigned in
132132
self->receive_callback = NULL;
133133
self->federated_connection = NULL;
134134
self->state = NETWORK_CHANNEL_STATE_CONNECTED;
135-
self->destination_core = destination_core;
135+
self->destination_core = destination_core;
136136
}

src/platform/pico/uart_channel.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
#define UART_CHANNEL_INFO(fmt, ...) LF_INFO(NET, "UartPolledChannel: " fmt, ##__VA_ARGS__)
1010
#define UART_CHANNEL_DEBUG(fmt, ...) LF_DEBUG(NET, "UartPolledChannel: " fmt, ##__VA_ARGS__)
1111

12-
#define UART_OPEN_MESSAGE_REQUEST {0xC0, 0x18, 0x11, 0xC0, 0xDD}
13-
#define UART_OPEN_MESSAGE_RESPONSE {0xC0, 0xFF, 0x31, 0xC0, 0xDD}
14-
#define UART_MESSAGE_PREFIX {0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
15-
#define UART_MESSAGE_POSTFIX {0xBB, 0xBB, 0xBB, 0xBB, 0xBD}
12+
#define UART_OPEN_MESSAGE_REQUEST \
13+
{ 0xC0, 0x18, 0x11, 0xC0, 0xDD }
14+
#define UART_OPEN_MESSAGE_RESPONSE \
15+
{ 0xC0, 0xFF, 0x31, 0xC0, 0xDD }
16+
#define UART_MESSAGE_PREFIX \
17+
{ 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }
18+
#define UART_MESSAGE_POSTFIX \
19+
{ 0xBB, 0xBB, 0xBB, 0xBB, 0xBD }
1620
#define UART_CLOSE_MESSAGE {0x2, 0xF, 0x6, 0xC, 0x2};
1721
#define MINIMUM_MESSAGE_SIZE 10
1822
#define UART_CHANNEL_EXPECTED_CONNECT_DURATION MSEC(2500)

0 commit comments

Comments
 (0)