Skip to content

Commit 1729aa4

Browse files
committed
Patmos and s4noc support
1 parent f6f5e65 commit 1729aa4

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

src/platform/patmos/s4noc_channel.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static lf_ret_t S4NOCPollChannel_send_blocking(NetworkChannel *untyped_self, con
4444
*((int *)self->write_buffer) = message_size;
4545

4646
int total_size = message_size + 4;
47+
*s4noc_dest = self->destination_core;
4748
int bytes_send = 0;
4849
while (bytes_send < total_size) {
4950
*s4noc_data = ((int *)self->write_buffer)[bytes_send / 4];
@@ -69,20 +70,20 @@ static void S4NOCPollChannel_register_receive_callback(NetworkChannel *untyped_s
6970

7071
void S4NOCPollChannel_poll(NetworkChannel *untyped_self) {
7172
S4NOCPollChannel *self = (S4NOCPollChannel *)untyped_self;
72-
LF_INFO(NET, "S4NOCPollChannel_poll called");
73+
S4NOC_CHANNEL_INFO("S4NOCPollChannel_poll called");
7374

7475
volatile _IODEV int *s4noc_status = (volatile _IODEV int *)PATMOS_IO_S4NOC;
7576
volatile _IODEV int *s4noc_data = (volatile _IODEV int *)(PATMOS_IO_S4NOC + 4);
7677
volatile _IODEV int *s4noc_source = (volatile _IODEV int *)(PATMOS_IO_S4NOC + 8);
7778

7879
if (((*s4noc_status) & 0x02) == 0) {
79-
LF_INFO(NET, "S4NOCPollChannel_poll: No data available");
80+
S4NOC_CHANNEL_INFO("S4NOCPollChannel_poll: No data available");
8081
return;
8182
}
8283

8384
int value = *s4noc_data;
8485
int source = *s4noc_source;
85-
LF_INFO(NET, "S4NOCPollChannel_poll: Received value 0x%08x (%c%c%c%c) from source %d", value,
86+
S4NOC_CHANNEL_INFO("S4NOCPollChannel_poll: Received value 0x%08x (%c%c%c%c) from source %d", value,
8687
((char *)&value)[0], ((char *)&value)[1], ((char *)&value)[2], ((char *)&value)[3], source);
8788
S4NOCPollChannel *receive_channel = s4noc_global_state.core_channels[source][get_cpuid()]; // Get the receive channel for the source core
8889

test/platform/patmos/s4noc_channel_test/main.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#define MESSAGE_CONTENT "Hello S4NOC"
88
#define MESSAGE_CONNECTION_ID 42
99
#define SOURCE_CORE 1
10-
#define DESTINATION_CORE 0
10+
#define DESTINATION_CORE 2
11+
#define MAX_TRIES 10
1112

1213
Reactor parent;
1314
FederatedEnvironment fed_env;
@@ -34,6 +35,7 @@ void setUp(void) {
3435
FederatedConnectionBundle_ctor(&receiver_bundle, &parent, receiver, NULL, NULL, 0, NULL, NULL, 0, 0);
3536

3637
s4noc_global_state.core_channels[SOURCE_CORE][DESTINATION_CORE] = &receiver_channel;
38+
s4noc_global_state.core_channels[DESTINATION_CORE][SOURCE_CORE] = &sender_channel;
3739

3840
}
3941

@@ -63,30 +65,41 @@ void send_message(void) {
6365
const char *message = MESSAGE_CONTENT;
6466
memcpy(port_message->payload.bytes, message, sizeof(MESSAGE_CONTENT)); // NOLINT
6567
port_message->payload.size = sizeof(MESSAGE_CONTENT);
66-
LF_INFO(NET, "Sender: Sending message with connection number %i and content %s\n", port_message->conn_id,
67-
(char *)port_message->payload.bytes);
68+
LF_INFO(NET, "Sender: Sending message with connection number %i and content %s\n", port_message->conn_id, (char *)port_message->payload.bytes);
6869
TEST_ASSERT_OK(sender->send_blocking(sender, &msg));
6970
}
7071

72+
void receive_message(void) {
73+
int tries = 0;
74+
do {
75+
LF_WARN(NET, "Receiver: Polling for messages, tries: %i\n", tries);
76+
tries++;
77+
((PolledNetworkChannel *)&receiver_channel.super)->poll((PolledNetworkChannel *)&receiver_channel.super);
78+
} while (receiver_callback_called == false && tries < MAX_TRIES);
79+
}
80+
7181
void test_sender_send_and_receiver_recv(void) {
7282
TEST_ASSERT_OK(sender->open_connection(sender));
7383
TEST_ASSERT_OK(receiver->open_connection(receiver));
7484

7585
receiver->register_receive_callback(receiver, receiver_callback_handler, NULL);
7686

7787
if(pthread_create(&sender_channel.worker_thread, NULL, send_message, NULL)) {
78-
LF_INFO(NET,"Error creating thread\n");
88+
LF_ERR(NET,"Error creating thread\n");
89+
return;
90+
}
91+
if(pthread_create(&receiver_channel.worker_thread, NULL, receive_message, NULL)) {
92+
LF_ERR(NET,"Error creating thread\n");
7993
return;
8094
}
8195
if (pthread_join(sender_channel.worker_thread, NULL)) {
82-
LF_INFO(NET,"Error joining thread\n");
96+
LF_ERR(NET,"Error joining thread\n");
97+
return;
98+
}
99+
if (pthread_join(receiver_channel.worker_thread, NULL)) {
100+
LF_ERR(NET,"Error joining thread\n");
83101
return;
84102
}
85-
86-
do {
87-
LF_INFO(NET, "Receiver: Waiting for callback to be called\n");
88-
((PolledNetworkChannel *)&receiver_channel.super)->poll((PolledNetworkChannel *)&receiver_channel.super);
89-
} while(!receiver_callback_called);
90103

91104
TEST_ASSERT_TRUE(receiver_callback_called);
92105
}
@@ -95,4 +108,4 @@ int main(void) {
95108
UNITY_BEGIN();
96109
RUN_TEST(test_sender_send_and_receiver_recv);
97110
return UNITY_END();
98-
}
111+
}

test/platform/patmos/s4noc_test/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <machine/rtc.h>
66
#include <pthread.h>
77

8+
#define SOURCE_CORE 1
9+
#define DESTINATION_CORE 2
10+
811
typedef int64_t instant_t;
912
typedef int64_t interval_t;
1013

@@ -54,7 +57,7 @@ void sender_function() {
5457
volatile _IODEV int *s4noc_data = (volatile _IODEV int *) (PATMOS_IO_S4NOC + 4);
5558
volatile _IODEV int *s4noc_dest = (volatile _IODEV int *) (PATMOS_IO_S4NOC + 8);
5659

57-
*s4noc_dest = 2;
60+
*s4noc_dest = DESTINATION_CORE;
5861
for (int i = 0; i < MAX_ITER; i++) {
5962
int status = (*s4noc_status) & 0x01;
6063
while (status == 0) {

0 commit comments

Comments
 (0)