From c6f417c7754f9af89080e0c5cbb09828e0dbdae9 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 3 Mar 2023 16:06:45 +0100 Subject: [PATCH 01/13] Fix docs --- README.md | 4 ++-- env.fish | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 968ef0f..1bae5e9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ InterPRET is a multicore FlexPRET architecture that uses a time-predictable Netw ### Prerequisites 1. Verilator 2. SBT -3. RISCV 32-bit toolchain +3. RISCV toolchain on the PATH. Download prebuild [rv32i-4.0.0](https://github.com/stnolting/riscv-gcc-prebuilt) ### Clone repo and set up ``` @@ -19,7 +19,7 @@ source env.bash ### Build and run tests ``` -make tests +make test ``` The final tests, which consist of bootloading an application over serial might take a few minutes to complete. diff --git a/env.fish b/env.fish index cdd3f87..4c5dc98 100644 --- a/env.fish +++ b/env.fish @@ -1,6 +1,5 @@ set -Ux FP_ROOT (pwd) -set PATH $PATH:/opt/riscv32/bin set PATH $PATH:$FP_ROOT/flexpret/scripts/c set PATH $PATH:$FP_ROOT/emulator set PATH $PATH:$FP_ROOT/programs/scripts \ No newline at end of file From 6df560b29211beeeb6a1b50dcc8a77ce5dc3218e Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 9 Mar 2023 18:35:13 +0100 Subject: [PATCH 02/13] Initial commit for the libinterpret --- lib/Makefile | 0 lib/include/interpret_noc.h | 109 +++++++++++++++++++++++++++++++++++ lib/include/interpret_uart.h | 32 ++++++++++ lib/include/interpret_wb.h | 28 +++++++++ lib/interpret_noc.c | 0 lib/interpret_uart.c | 0 lib/interpret_wb.c | 0 7 files changed, 169 insertions(+) create mode 100644 lib/Makefile create mode 100644 lib/include/interpret_noc.h create mode 100644 lib/include/interpret_uart.h create mode 100644 lib/include/interpret_wb.h create mode 100644 lib/interpret_noc.c create mode 100644 lib/interpret_uart.c create mode 100644 lib/interpret_wb.c diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/lib/include/interpret_noc.h b/lib/include/interpret_noc.h new file mode 100644 index 0000000..916627b --- /dev/null +++ b/lib/include/interpret_noc.h @@ -0,0 +1,109 @@ +#ifndef FLEXPRET_NOC_H +#define FLEXPRET_NOC_H + +#include +#include +#include + +#define NOC_BASE 0x40000020UL +#define NOC_CSR (*( (volatile uint32_t *) (NOC_BASE + 0x0UL))) +#define NOC_DATA (*( (volatile uint32_t *) (NOC_BASE + 0x4UL))) +#define NOC_SOURCE (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) +#define NOC_DEST (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) + +// Macros for parsing the CSR register value +#define NOC_TX_READY(val) (val & 0x01) +#define NOC_DATA_AVAILABLE(val) (val & 0x02) + +/** + * @brief Send a word over the NoC. Depending on the value of the timeout, the + * function will exhibit a different behavior: + * * Blocking send is performed if timeout value is TIMEOUT_FOREVER, + * * Non blocking send is performed if the timeout value is TIMEOUT_NEVER, + * * And send within the given timeout, otherwise. + * + * @param addr: id of the core to send to + * @param data: The data value to send + * @param timeout: the timeout in ns + * + * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise + **/ +static fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout) { + if (timeout == TIMEOUT_FOREVER) { + while (!NOC_TX_READY(NOC_CSR)); + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } + if (timeout == TIMEOUT_NEVER) { + if (NOC_TX_READY(NOC_CSR)) { + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } else { + return FP_FAILURE; + } + } + timeout_t time = rdtime() + timeout; + while (rdtime() < time) { + if (NOC_TX_READY(NOC_CSR)) { + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } + } + return FP_FAILURE; +} + +/** + * @brief Blocking send of an array of words over the NoC. + * + * @param addr: id of the core to send to + * @param data: pointer to start of the array + * @param length: length of the array + * + * @return fp_ret_t: FP_SUCCESS, if sending is successful + **/ +static fp_ret_t noc_send_arr(uint32_t addr, uint32_t *data, int length) { + for (int i = 0; i < length; i++) + noc_send(addr, data[i], TIMEOUT_FOREVER); + return FP_SUCCESS; +} + +/** + * Receive a word over the NoC. Depending on the value of the timeout, the function + * will exhibit a different behavior: + * * Blocking receive is performed if timeout value is TIMEOUT_FOREVER, + * * Non blocking receive is performed if the timeout value is TIMEOUT_NEVER, + * * And receive within the given timeout, otherwise. + * + * @param data: pointer to where the data will be written, if any + * @param timeout: the timeout in ns + * FIXME: Should the data type be passed as well? + * + * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise + **/ +static fp_ret_t noc_receive(uint32_t* data, timeout_t timeout) { + if (timeout == TIMEOUT_FOREVER) { + while (!NOC_DATA_AVAILABLE(NOC_CSR)); + *data = NOC_DATA; + return FP_SUCCESS; + } + if (timeout == TIMEOUT_NEVER) { + if (NOC_DATA_AVAILABLE(NOC_CSR)) { + *data = NOC_DATA; + return FP_SUCCESS; + } + return FP_FAILURE; + } + uint32_t time = rdtime() + timeout; + while (rdtime() < time) { + if (NOC_DATA_AVAILABLE(NOC_CSR)) { + *data = NOC_DATA; + return FP_SUCCESS; + } + } + return FP_FAILURE; +} + +#endif diff --git a/lib/include/interpret_uart.h b/lib/include/interpret_uart.h new file mode 100644 index 0000000..f50ca3d --- /dev/null +++ b/lib/include/interpret_uart.h @@ -0,0 +1,32 @@ + +#ifndef FLEXPRET_NOC_H +#define FLEXPRET_NOC_H + +#include +#include "interpret_wb.h" + +// Addresses on the NOC wishbone device +#define UART_TXD 0x0UL +#define UART_RXD 0x4UL +#define UART_CSR 0x8UL + +// Macros for parsing the CSR register value +#define UART_DATA_READY(val) (val & 0x01) +#define UART_TX_FULL(val) (val & 0x02) +#define UART_FAULT(val) (val & 0x04) + + + +// Blocking send word +static void uart_send(uint8_t data) { + while (UART_TX_FULL(wb_read(UART_CSR))) {} + wb_write(UART_TXD, data); +} + +// Blocking read word +static uint8_t uart_receive() { + while(!UART_DATA_READY(wb_read(UART_CSR))) {} + return wb_read(UART_RXD); +} + +#endif diff --git a/lib/include/interpret_wb.h b/lib/include/interpret_wb.h new file mode 100644 index 0000000..9efe510 --- /dev/null +++ b/lib/include/interpret_wb.h @@ -0,0 +1,28 @@ +#ifndef WISHBONE_H +#define WISHBONE_H + +#include + + +#define WB_BASE 0x40000000UL +#define WB_READ_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x0UL))) +#define WB_WRITE_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x4UL))) +#define WB_WRITE_DATA (*( (volatile uint32_t *) (WB_BASE + 0x8UL))) +#define WB_READ_DATA (*( (volatile uint32_t *) (WB_BASE + 0xCUL))) +#define WB_STATUS (*( (volatile uint32_t *) (WB_BASE + 0x10UL))) + +// Write and block until it was successful +// FIXME: Instead we could block until ready, then write? +static void wb_write(uint32_t addr, uint32_t data) { + WB_WRITE_DATA = data; + WB_WRITE_ADDR = addr; + while(!WB_STATUS) {} +} + +static uint32_t wb_read(uint32_t addr) { + WB_READ_ADDR = addr; + while(!WB_STATUS) {} + return WB_READ_DATA; +} + +#endif \ No newline at end of file diff --git a/lib/interpret_noc.c b/lib/interpret_noc.c new file mode 100644 index 0000000..e69de29 diff --git a/lib/interpret_uart.c b/lib/interpret_uart.c new file mode 100644 index 0000000..e69de29 diff --git a/lib/interpret_wb.c b/lib/interpret_wb.c new file mode 100644 index 0000000..e69de29 From a327b445a54c3285ee79ebc10a455c84e7e0d060 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 14:39:30 +0100 Subject: [PATCH 03/13] update envs build.sb and gitignore --- .gitignore | 4 +++- build.sbt | 25 +++++++++++++------------ env.bash | 10 +++------- env.fish | 7 +++---- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 6b52f5b..cec47a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,14 @@ .bsp/ .metals/ +.idea/ .vscode/ project/ target/ build/ emulator/*.v emulator/obj_dir +emulator/ip-emu +emulator/ip-verilator .bloop # Generated files @@ -17,7 +20,6 @@ emulator/obj_dir **/*.map **/*.orig **/*.dump -**/fp-emu **/*.fir **/*.app **/*.binary.txt diff --git a/build.sbt b/build.sbt index 784e4dc..7571e70 100644 --- a/build.sbt +++ b/build.sbt @@ -1,23 +1,24 @@ +ThisBuild / scalaVersion := "2.12.10" +ThisBuild / version := "0.1.0" +ThisBuild / organization := "PRETIS" - -val chiselVersion = "3.5.5" +val chiselVersion = "3.5.6" lazy val interpret = (project in file(".")) .settings( name := "interpret", libraryDependencies ++= Seq( "edu.berkeley.cs" %% "chisel3" % chiselVersion, - "edu.berkeley.cs" %% "chiseltest" % "0.5.5", + "edu.berkeley.cs" %% "chiseltest" % "0.5.6" % "test" + ), + scalacOptions ++= Seq( + "-language:reflectiveCalls", + "-deprecation", + "-feature", + "-Xcheckinit", + "-P:chiselplugin:genBundleElements", ), -scalaVersion := "2.12.10", // Issue on scalamacros:paradise -scalacOptions ++= Seq( - "-deprecation", - "-feature", - "-unchecked", - "-language:reflectiveCalls", -), -addCompilerPlugin("edu.berkeley.cs" %% "chisel3-plugin" % chiselVersion cross CrossVersion.full), -addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full) + addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full), ).dependsOn(flexpret,soc_comm) // Import flexpret diff --git a/env.bash b/env.bash index 59c340b..3b24a3d 100644 --- a/env.bash +++ b/env.bash @@ -1,9 +1,5 @@ -export FP_ROOT=$(pwd) +export INTERPRET_ROOT_DIR=$(pwd) +export FLEXPRET_ROOT_DIR=$(IP_ROOT)/flexpret -# Put riscv gcc compiler on the path -# export PATH="$PATH:/opt/riscv32/bin" - -# Put riscv_compile.sh and riscv_clean.sh on the path -export PATH="$PATH:$FP_ROOT/flexpret/scripts/c" # Put the generated emulator on the path -export PATH="$PATH:$FP_ROOT/emulator" \ No newline at end of file +export PATH="$PATH:$IP_ROOT/emulator" \ No newline at end of file diff --git a/env.fish b/env.fish index 4c5dc98..6cfc9f9 100644 --- a/env.fish +++ b/env.fish @@ -1,5 +1,4 @@ -set -Ux FP_ROOT (pwd) +set -Ux INTERPRET_ROOT_DIR (pwd) +set -Ux FLEXPRET_ROOT_DIR $INTERPRET_ROOT_DIR/flexpret -set PATH $PATH:$FP_ROOT/flexpret/scripts/c -set PATH $PATH:$FP_ROOT/emulator -set PATH $PATH:$FP_ROOT/programs/scripts \ No newline at end of file +set PATH $PATH:$INTERPRET_ROOT_DIR/emulator \ No newline at end of file From 22f5a7eee6facbabc9bf95f83d48ba064e40507f Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 14:40:25 +0100 Subject: [PATCH 04/13] Create the InterPRET lib --- lib/Makefrag | 14 ++++ lib/include/interpret.h | 10 +++ lib/{Makefile => include/interpret_config.h} | 0 lib/include/interpret_noc.h | 78 +------------------- lib/include/interpret_stdio.h | 9 +++ lib/include/interpret_uart.h | 25 +------ lib/include/interpret_wb.h | 26 +------ lib/interpret_noc.c | 64 ++++++++++++++++ lib/interpret_stdio.c | 40 ++++++++++ lib/interpret_uart.c | 25 +++++++ lib/interpret_wb.c | 22 ++++++ 11 files changed, 196 insertions(+), 117 deletions(-) create mode 100644 lib/Makefrag create mode 100644 lib/include/interpret.h rename lib/{Makefile => include/interpret_config.h} (100%) create mode 100644 lib/include/interpret_stdio.h create mode 100644 lib/interpret_stdio.c diff --git a/lib/Makefrag b/lib/Makefrag new file mode 100644 index 0000000..7a4299b --- /dev/null +++ b/lib/Makefrag @@ -0,0 +1,14 @@ + +IP_LIB_DIR=$(INTERPRET_ROOT_DIR)/lib +ifdef BOOTLOADER +LIB_SOURCES += \ + $(IP_LIB_DIR)/interpret_uart.c \ + $(IP_LIB_DIR)/interpret_wb.c +else +LIB_SOURCES += \ + $(IP_LIB_DIR)/interpret_noc.c \ + $(IP_LIB_DIR)/interpret_uart.c \ + $(IP_LIB_DIR)/interpret_wb.c \ + $(IP_LIB_DIR)/interpret_stdio.c +endif +LIB_INCS += -I$(IP_LIB_DIR)/include diff --git a/lib/include/interpret.h b/lib/include/interpret.h new file mode 100644 index 0000000..a610d1c --- /dev/null +++ b/lib/include/interpret.h @@ -0,0 +1,10 @@ +#ifndef INTERPRET_H +#define INTERPRET_H + +#include "flexpret.h" +#include "interpret_wb.h" +#include "interpret_uart.h" +#include "interpret_stdio.h" +#include "interpret_noc.h" + +#endif diff --git a/lib/Makefile b/lib/include/interpret_config.h similarity index 100% rename from lib/Makefile rename to lib/include/interpret_config.h diff --git a/lib/include/interpret_noc.h b/lib/include/interpret_noc.h index 916627b..2b4b6a9 100644 --- a/lib/include/interpret_noc.h +++ b/lib/include/interpret_noc.h @@ -1,19 +1,9 @@ -#ifndef FLEXPRET_NOC_H -#define FLEXPRET_NOC_H +#ifndef INTERPRET_NOC_H +#define INTERPRET_NOC_H #include -#include #include -#define NOC_BASE 0x40000020UL -#define NOC_CSR (*( (volatile uint32_t *) (NOC_BASE + 0x0UL))) -#define NOC_DATA (*( (volatile uint32_t *) (NOC_BASE + 0x4UL))) -#define NOC_SOURCE (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) -#define NOC_DEST (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) - -// Macros for parsing the CSR register value -#define NOC_TX_READY(val) (val & 0x01) -#define NOC_DATA_AVAILABLE(val) (val & 0x02) /** * @brief Send a word over the NoC. Depending on the value of the timeout, the @@ -28,47 +18,8 @@ * * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise **/ -static fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout) { - if (timeout == TIMEOUT_FOREVER) { - while (!NOC_TX_READY(NOC_CSR)); - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } - if (timeout == TIMEOUT_NEVER) { - if (NOC_TX_READY(NOC_CSR)) { - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } else { - return FP_FAILURE; - } - } - timeout_t time = rdtime() + timeout; - while (rdtime() < time) { - if (NOC_TX_READY(NOC_CSR)) { - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } - } - return FP_FAILURE; -} +fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout); -/** - * @brief Blocking send of an array of words over the NoC. - * - * @param addr: id of the core to send to - * @param data: pointer to start of the array - * @param length: length of the array - * - * @return fp_ret_t: FP_SUCCESS, if sending is successful - **/ -static fp_ret_t noc_send_arr(uint32_t addr, uint32_t *data, int length) { - for (int i = 0; i < length; i++) - noc_send(addr, data[i], TIMEOUT_FOREVER); - return FP_SUCCESS; -} /** * Receive a word over the NoC. Depending on the value of the timeout, the function @@ -83,27 +34,6 @@ static fp_ret_t noc_send_arr(uint32_t addr, uint32_t *data, int length) { * * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise **/ -static fp_ret_t noc_receive(uint32_t* data, timeout_t timeout) { - if (timeout == TIMEOUT_FOREVER) { - while (!NOC_DATA_AVAILABLE(NOC_CSR)); - *data = NOC_DATA; - return FP_SUCCESS; - } - if (timeout == TIMEOUT_NEVER) { - if (NOC_DATA_AVAILABLE(NOC_CSR)) { - *data = NOC_DATA; - return FP_SUCCESS; - } - return FP_FAILURE; - } - uint32_t time = rdtime() + timeout; - while (rdtime() < time) { - if (NOC_DATA_AVAILABLE(NOC_CSR)) { - *data = NOC_DATA; - return FP_SUCCESS; - } - } - return FP_FAILURE; -} +fp_ret_t noc_receive(uint32_t* data, timeout_t timeout); #endif diff --git a/lib/include/interpret_stdio.h b/lib/include/interpret_stdio.h new file mode 100644 index 0000000..b7dcc38 --- /dev/null +++ b/lib/include/interpret_stdio.h @@ -0,0 +1,9 @@ +#ifndef INTERPRET_STDIO_H +#define INTERPRET_STDIO_H + +void print_str(const char *str); + +void print_int(int val); + +#endif + diff --git a/lib/include/interpret_uart.h b/lib/include/interpret_uart.h index f50ca3d..78689c5 100644 --- a/lib/include/interpret_uart.h +++ b/lib/include/interpret_uart.h @@ -1,32 +1,15 @@ -#ifndef FLEXPRET_NOC_H -#define FLEXPRET_NOC_H +#ifndef INTERPRET_UART_H +#define INTERPRET_UART_H #include #include "interpret_wb.h" -// Addresses on the NOC wishbone device -#define UART_TXD 0x0UL -#define UART_RXD 0x4UL -#define UART_CSR 0x8UL - -// Macros for parsing the CSR register value -#define UART_DATA_READY(val) (val & 0x01) -#define UART_TX_FULL(val) (val & 0x02) -#define UART_FAULT(val) (val & 0x04) - - // Blocking send word -static void uart_send(uint8_t data) { - while (UART_TX_FULL(wb_read(UART_CSR))) {} - wb_write(UART_TXD, data); -} +void uart_send(uint8_t data); // Blocking read word -static uint8_t uart_receive() { - while(!UART_DATA_READY(wb_read(UART_CSR))) {} - return wb_read(UART_RXD); -} +uint8_t uart_receive(); #endif diff --git a/lib/include/interpret_wb.h b/lib/include/interpret_wb.h index 9efe510..22ff452 100644 --- a/lib/include/interpret_wb.h +++ b/lib/include/interpret_wb.h @@ -1,28 +1,10 @@ -#ifndef WISHBONE_H -#define WISHBONE_H +#ifndef INTERPRET_WB_H +#define INTERPRET_WB_H #include +void wb_write(uint32_t addr, uint32_t data); -#define WB_BASE 0x40000000UL -#define WB_READ_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x0UL))) -#define WB_WRITE_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x4UL))) -#define WB_WRITE_DATA (*( (volatile uint32_t *) (WB_BASE + 0x8UL))) -#define WB_READ_DATA (*( (volatile uint32_t *) (WB_BASE + 0xCUL))) -#define WB_STATUS (*( (volatile uint32_t *) (WB_BASE + 0x10UL))) - -// Write and block until it was successful -// FIXME: Instead we could block until ready, then write? -static void wb_write(uint32_t addr, uint32_t data) { - WB_WRITE_DATA = data; - WB_WRITE_ADDR = addr; - while(!WB_STATUS) {} -} - -static uint32_t wb_read(uint32_t addr) { - WB_READ_ADDR = addr; - while(!WB_STATUS) {} - return WB_READ_DATA; -} +uint32_t wb_read(uint32_t addr); #endif \ No newline at end of file diff --git a/lib/interpret_noc.c b/lib/interpret_noc.c index e69de29..4e70d0e 100644 --- a/lib/interpret_noc.c +++ b/lib/interpret_noc.c @@ -0,0 +1,64 @@ +#include "interpret_noc.h" +#include +#include "flexpret.h" + +#define NOC_BASE 0x40000020UL +#define NOC_CSR (*( (volatile uint32_t *) (NOC_BASE + 0x0UL))) +#define NOC_DATA (*( (volatile uint32_t *) (NOC_BASE + 0x4UL))) +#define NOC_SOURCE (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) +#define NOC_DEST (*( (volatile uint32_t *) (NOC_BASE + 0x8UL))) + +// Macros for parsing the CSR register value +#define NOC_TX_READY(val) (val & 0x01) +#define NOC_DATA_AVAILABLE(val) (val & 0x02) + +fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout) { + if (timeout == TIMEOUT_FOREVER) { + while (!NOC_TX_READY(NOC_CSR)); + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } + if (timeout == TIMEOUT_NEVER) { + if (NOC_TX_READY(NOC_CSR)) { + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } else { + return FP_FAILURE; + } + } + timeout_t time = rdtime() + timeout; + while (rdtime() < time) { + if (NOC_TX_READY(NOC_CSR)) { + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; + } + } + return FP_FAILURE; +} + + +fp_ret_t noc_receive(uint32_t* data, timeout_t timeout) { + if (timeout == TIMEOUT_FOREVER) { + while (!NOC_DATA_AVAILABLE(NOC_CSR)); + *data = NOC_DATA; + return FP_SUCCESS; + } + if (timeout == TIMEOUT_NEVER) { + if (NOC_DATA_AVAILABLE(NOC_CSR)) { + *data = NOC_DATA; + return FP_SUCCESS; + } + return FP_FAILURE; + } + uint32_t time = rdtime() + timeout; + while (rdtime() < time) { + if (NOC_DATA_AVAILABLE(NOC_CSR)) { + *data = NOC_DATA; + return FP_SUCCESS; + } + } + return FP_FAILURE; +} \ No newline at end of file diff --git a/lib/interpret_stdio.c b/lib/interpret_stdio.c new file mode 100644 index 0000000..fab9f6c --- /dev/null +++ b/lib/interpret_stdio.c @@ -0,0 +1,40 @@ +#include "flexpret_lock.h" +#include "interpret_stdio.h" +#include "interpret_uart.h" + +#define STDIO_MAX_DIGITS 32 + +lock_t lock = {.locked = false}; + +void print_str(const char *str) { + lock_acquire(&lock); + while (*str != '\0') { + uart_send(*str); + str++; + } + + lock_release(&lock); +} + +void print_int(int val) { + lock_acquire(&lock); + + char buf[STDIO_MAX_DIGITS]; + int n_digits = 0; + if (val == 0) { + buf[n_digits++] = '0'; + } + + while (val && n_digits < STDIO_MAX_DIGITS) { + char digit = '0' + (val % 10); + buf[n_digits++] = digit; + val = val / 10; + } + + for (int i = n_digits - 1; i >= 0; i--) { + uart_send(buf[i]); + } + // Print newline + uart_send('\n'); + lock_release(&lock); +} \ No newline at end of file diff --git a/lib/interpret_uart.c b/lib/interpret_uart.c index e69de29..e0118fa 100644 --- a/lib/interpret_uart.c +++ b/lib/interpret_uart.c @@ -0,0 +1,25 @@ +#include "interpret_uart.h" +#include "flexpret.h" + +// Addresses on the NOC wishbone device +#define UART_TXD 0x0UL +#define UART_RXD 0x4UL +#define UART_CSR 0x8UL + +// Macros for parsing the CSR register value +#define UART_DATA_READY(val) (val & 0x01) +#define UART_TX_FULL(val) (val & 0x02) +#define UART_FAULT(val) (val & 0x04) + +// Send a single character. This function will NOT block, it will +// enqueue it to the UART FIFO and return. +void uart_send(uint8_t data) { + while (UART_TX_FULL(wb_read(UART_CSR))) {} + wb_write(UART_TXD, data); +} + +// Blocking read word +uint8_t uart_receive() { + while(!UART_DATA_READY(wb_read(UART_CSR))) {} + return wb_read(UART_RXD); +} \ No newline at end of file diff --git a/lib/interpret_wb.c b/lib/interpret_wb.c index e69de29..882fcfd 100644 --- a/lib/interpret_wb.c +++ b/lib/interpret_wb.c @@ -0,0 +1,22 @@ +#include "interpret_wb.h" + +#define WB_BASE 0x40000000UL +#define WB_READ_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x0UL))) +#define WB_WRITE_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x4UL))) +#define WB_WRITE_DATA (*( (volatile uint32_t *) (WB_BASE + 0x8UL))) +#define WB_READ_DATA (*( (volatile uint32_t *) (WB_BASE + 0xCUL))) +#define WB_STATUS (*( (volatile uint32_t *) (WB_BASE + 0x10UL))) + +// Write and block until it was successful +// FIXME: Instead we could block until ready, then write? +void wb_write(uint32_t addr, uint32_t data) { + WB_WRITE_DATA = data; + WB_WRITE_ADDR = addr; + while(!WB_STATUS) {} +} + +uint32_t wb_read(uint32_t addr) { + WB_READ_ADDR = addr; + while(!WB_STATUS) {} + return WB_READ_DATA; +} \ No newline at end of file From 8de505a455c5c12d76db260ba34b7582f0f95520 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 14:40:53 +0100 Subject: [PATCH 05/13] Bring tests and examples up to date with new Make-based build --- Makefile | 2 - Makefrag | 23 +++++++++ emulator/emulator.mk | 21 ++------ emulator/main.cpp | 68 ++++++++++++++++++++++++-- flexpret | 2 +- programs/blinky/Makefile | 5 ++ programs/bootloader/Makefile | 36 +++----------- programs/bootloader/bootloader.c | 19 +++---- programs/counter/Makefile | 5 ++ programs/counter/counter.c | 7 +-- programs/delayUntil/Makefile | 13 ++--- programs/delayUntil/delay.c | 5 +- programs/helloWorld/Makefile | 5 ++ programs/integration-tests.mk | 15 +++--- programs/interruptExpire/Makefile | 13 ++--- programs/lib/include/flexpret_config.h | 37 ++++++++++++++ programs/lib/linker/flexpret_config.ld | 16 ++++++ programs/noc/HelloWorld/Makefile | 13 ++--- programs/noc/HelloWorld/hello_noc.c | 6 +-- programs/noc/PingPong/Makefile | 13 ++--- programs/noc/PingPong/ping_pong_noc.c | 5 +- programs/print/Makefile | 13 ++--- programs/print/print.c | 8 +-- programs/scripts/test_result_parse.sh | 3 +- programs/softwareUart/Makefile | 5 ++ programs/threaded/Makefile | 14 ++---- programs/threaded/mt.c | 9 +--- programs/uart/rx/Makefile | 5 ++ programs/uart/rx/uart_rx.c | 7 ++- programs/uart/tx/Makefile | 5 ++ programs/uart/tx/uart_tx.c | 6 +-- src/main/scala/Top.scala | 3 ++ src/main/scala/WishboneUart.scala | 3 -- tests/devices/wishbone.h | 14 ++++++ tests/devices/wishbone_master.c | 25 ++++++++++ 35 files changed, 277 insertions(+), 172 deletions(-) create mode 100644 Makefrag create mode 100644 programs/blinky/Makefile create mode 100644 programs/counter/Makefile create mode 100644 programs/helloWorld/Makefile create mode 100644 programs/lib/include/flexpret_config.h create mode 100644 programs/lib/linker/flexpret_config.ld create mode 100644 programs/softwareUart/Makefile create mode 100644 programs/uart/rx/Makefile create mode 100644 programs/uart/tx/Makefile create mode 100644 tests/devices/wishbone.h create mode 100644 tests/devices/wishbone_master.c diff --git a/Makefile b/Makefile index 921f7d3..a11dbdf 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,6 @@ SCRIPTS_DIR = flexpret/scripts BUILD_DIR = build RESOURCE_DIR = flexpret/src/main/resources - - # Compiler options. CXX = g++ CXXFLAGS = -g -O2 diff --git a/Makefrag b/Makefrag new file mode 100644 index 0000000..63f6ae5 --- /dev/null +++ b/Makefrag @@ -0,0 +1,23 @@ +ifndef FLEXPRET_ROOT_DIR +$(error FLEXPRET_ROOT_DIR is not set. Please source env.bash) +endif + +ifndef INTERPRET_ROOT_DIR +$(error INTERPRET_ROOT_DIR is not set. Please source env.bash) +endif + +EMU:=$(INTERPRET_ROOT_DIR)/emulator/ip-emu + +ifdef BOOTLOADER +LINKER_SCRIPT := $(FLEXPRET_ROOT_DIR)/programs/lib/linker/flexpret_btl.ld +endif + +ifdef APP +LINKER_SCRIPT := $(FLEXPRET_ROOT_DIR)/programs/lib/linker/flexpret_app.ld +endif + +include $(INTERPRET_ROOT_DIR)/lib/Makefrag + + +app: compile + $(INTERPRET_ROOT_DIR)/programs/scripts/serialize_app.py $(NAME).mem $(NAME).app \ No newline at end of file diff --git a/emulator/emulator.mk b/emulator/emulator.mk index 039e74b..6b10486 100644 --- a/emulator/emulator.mk +++ b/emulator/emulator.mk @@ -3,25 +3,10 @@ # Edward Wang # Shaokai Lin -EMULATOR_BIN = $(EMULATOR_DIR)/fp-emu -HDL_SCRIPTS = $(SCRIPTS_DIR)/hdl -TRACE ?= 0 +EMULATOR_BIN = $(EMULATOR_DIR)/ip-verilator -$(EMULATOR_BIN): $(VERILOG_RAW) $(EMULATOR_DIR)/main.cpp $(EMULATOR_DIR)/uartsim.cpp $(HDL_SCRIPTS)/simify_verilog.py - # Inject the right simulation constructs - # FIXME: Remove this alltogether, currently only used for enabling tracing +$(EMULATOR_BIN): $(VERILOG_RAW) $(EMULATOR_DIR)/main.cpp $(EMULATOR_DIR)/uartsim.cpp cp $(RESOURCE_DIR)/DualPortBram.v $(EMULATOR_DIR)/DualPortBram.v -ifeq ($(TRACE),1) - @echo "Enabling tracing on Verilator" - $(HDL_SCRIPTS)/simify_verilog.py $(VERILOG_RAW) > $(EMULATOR_DIR)/$(MODULE).sim.v - (cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --trace --build main.cpp uartsim.cpp) -else - @echo "Disabling tracing on Verilator" cp $(VERILOG_RAW) $(EMULATOR_DIR)/$(MODULE).sim.v - (cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --build main.cpp uartsim.cpp) -endif - - + (cd $(EMULATOR_DIR) && verilator --cc $(MODULE).sim.v --timescale 1ns/1ns --exe --trace --build main.cpp uartsim.cpp) cp $(EMULATOR_DIR)/obj_dir/V$(MODULE) $(EMULATOR_BIN) - - echo "Emulator usage: Run '$(EMULATOR_BIN)'. The emulator expects to find the program for each core stored in the directory it is invoked from with the names 'core1.mem', 'core2.mem', 'coreN.mem' etc. The programs can be built using 'scripts/c/riscv_build.sh coreN '. The emulation will generate a VCD called 'trace.vcd'. Use flexpret_io.h to print or to terminate simulation." diff --git a/emulator/main.cpp b/emulator/main.cpp index cde5be4..40f9d15 100644 --- a/emulator/main.cpp +++ b/emulator/main.cpp @@ -6,6 +6,8 @@ */ #include "VTop.h" #include "verilated.h" +#include "verilated_vcd_c.h" +#include #include "uartsim.h" uint64_t timestamp = 0; @@ -16,13 +18,56 @@ double sc_time_stamp() { int main(int argc, char* argv[]) { Verilated::commandArgs(argc, argv); - Verilated::traceEverOn(true); + bool trace_enabled = false; + bool uart_file = false; + int uart_file_argv = 0; + + // We accept 2 optional command line args, in arbitrary order + // A) `--trace` to turn on VCD tracing + // B) file_path.bin to a binary file which will be read into the uart rx pin of the InterPRET + + if (argc == 2) { + if (!strcmp(argv[1], "--trace")) { + std::cout << "Tracing enabled" << std::endl; + trace_enabled = true; + Verilated::traceEverOn(true); + } else { + uart_file = true; + uart_file_argv = 1; + } + } + + if (argc == 3) { + uart_file = true; + if (!strcmp(argv[1], "--trace")) { + std::cout << "Tracing enabled" << std::endl; + trace_enabled = true; + Verilated::traceEverOn(true); + uart_file_argv = 2; + } else if (argv[2], "--trace") { + std::cout << "Tracing enabled" << std::endl; + trace_enabled = true; + Verilated::traceEverOn(true); + uart_file_argv = 1; + } else { + std::cout << "Dont recognize command line arguments:" <trace(trace, 99); + trace->open("trace.vcd"); + } - if (argc == 2) { - uartsim_init(argv[1]); + if (uart_file) { + std::cout <<"Passing in uart_file: `" <clock = 1; top->eval(); timestamp+=1; + + if (trace_enabled) { + trace->dump(10*timestamp); + } + if (timestamp > 10) { - uartsim_print_rx( (int *) &top->io_gpio_out_1, 0); + uartsim_print_rx( (int *) &top->io_uart_tx, 0); uartsim_write(&top->io_uart_rx); } top->clock = 0; top->eval(); timestamp+=1; + + if (trace_enabled) { + trace->dump(10*timestamp); + trace->flush(); + } + } + + if (trace_enabled) { + trace->close(); + delete trace; } delete top; diff --git a/flexpret b/flexpret index 8f2b9a1..ade1475 160000 --- a/flexpret +++ b/flexpret @@ -1 +1 @@ -Subproject commit 8f2b9a12bef896138e60ec6d43ea29a7a1fac6be +Subproject commit ade1475b052193eed1428f3497b5ad241445f67e diff --git a/programs/blinky/Makefile b/programs/blinky/Makefile new file mode 100644 index 0000000..8b199e4 --- /dev/null +++ b/programs/blinky/Makefile @@ -0,0 +1,5 @@ +NAME := blinky +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/bootloader/Makefile b/programs/bootloader/Makefile index 627f21b..3491a95 100644 --- a/programs/bootloader/Makefile +++ b/programs/bootloader/Makefile @@ -1,32 +1,8 @@ -SRCS=bootloader.c -LINKER_SCRIPT=$(FP_ROOT)/programs/linker/flexpret_btl.ld -CC=riscv32-unknown-elf-gcc -OBJDUMP=riscv32-unknown-elf-objdump -OBJCOPY=riscv32-unknown-elf-objcopy -LIB_DIR=$(FP_ROOT)/flexpret/programs/lib +NAME := bootloader +APP_SOURCES = bootloader.c +APP_DEFS := -DBOOTLOADER +BOOTLOADER := true -build: btl.mem - -btl.mem: btl.binary.txt - xxd -c 4 -e btl.binary.txt | cut -c11-18 > btl.mem - xxd -c 4 -e btl.binary.txt > btl.mem.orig - cp btl.mem ispm.mem - - -btl.binary.txt: btl.riscv - $(OBJCOPY) -O binary btl.riscv btl.binary.txt - $(OBJDUMP) -S -d btl.riscv > btl.dump - - -btl.riscv: bootloader.c - $(CC) -I$(LIB_DIR)/include -T $(LINKER_SCRIPT) -DBOOTLOADER=1 -DNUM_THREADS=4 -DCPU_FREQ=50000000 -Xlinker -Map=output.map -g -static -O0 -march=rv32i -mabi=ilp32 -nostartfiles --specs=nosys.specs -o btl.riscv $(LIB_DIR)/start.S $(LIB_DIR)/syscalls.c $(LIB_DIR)/startup.c bootloader.c - - -clean: - riscv_clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/bootloader/bootloader.c b/programs/bootloader/bootloader.c index 5ac6cef..75bb844 100644 --- a/programs/bootloader/bootloader.c +++ b/programs/bootloader/bootloader.c @@ -1,21 +1,15 @@ -#include - -#include "flexpret_io.h" -#include "flexpret_stdio.h" -#include "flexpret_uart.h" -#include +#include "interpret.h" #define SYNC_ID_LEN 2 #define LEN_FIELD_LEN 2 -#define APP_START 0x00001000 -// #define DBG +#define APP_START ISPM_APP_START #ifdef DBG #define DBG_PRINT(x) do {_fp_print(x);} while(0) #else #define DBG_PRINT(x) do {} while(0) #endif -void (*application)(void) = (void (*)())APP_START; +void (*application)(void) = (void (*)()) APP_START; int bootloader(void); typedef enum { @@ -98,7 +92,10 @@ int bootloader(void) { DBG_PRINT(recv); recv_buffer[idx++] = recv; if (idx == LEN_FIELD_LEN) { - len = recv_buffer[1] << 8 | recv_buffer[0]; + len = recv_buffer[1] << 8 | recv_buffer[0]; + DBG_PRINT(66); + DBG_PRINT(len); + DBG_PRINT(66); app_recv_state = RECV_DATA; idx = 0; gpo_clear(0, 2); @@ -112,7 +109,7 @@ int bootloader(void) { instr = instr | (((unsigned int) recv) << 8*byte_idx); if (byte_idx-- == 0) { DBG_PRINT(3); - DBG_PRINT(app_ptr); + DBG_PRINT((uint32_t) app_ptr); DBG_PRINT(instr); *(app_ptr++) = instr; instr = 0; diff --git a/programs/counter/Makefile b/programs/counter/Makefile new file mode 100644 index 0000000..b76a2aa --- /dev/null +++ b/programs/counter/Makefile @@ -0,0 +1,5 @@ +NAME := counter +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/counter/counter.c b/programs/counter/counter.c index 6f16565..d542be0 100644 --- a/programs/counter/counter.c +++ b/programs/counter/counter.c @@ -1,11 +1,8 @@ -#include -#include -#include -#include - +#include "interpret.h" void main(void) { int core_id = read_coreid(); + print_str("Hello world!"); int cnt = 0; if (core_id == 0) { while(1) { diff --git a/programs/delayUntil/Makefile b/programs/delayUntil/Makefile index 2afc565..64aa083 100644 --- a/programs/delayUntil/Makefile +++ b/programs/delayUntil/Makefile @@ -1,10 +1,5 @@ -build: - riscv-compile.sh 1 ispm delay.c +NAME := delay +APP_SOURCES = *.c -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/delayUntil/delay.c b/programs/delayUntil/delay.c index b029d97..7328c08 100644 --- a/programs/delayUntil/delay.c +++ b/programs/delayUntil/delay.c @@ -1,7 +1,4 @@ -#include -#include -#include -#include +#include "interpret.h" int main() { _fp_print(1); diff --git a/programs/helloWorld/Makefile b/programs/helloWorld/Makefile new file mode 100644 index 0000000..a833630 --- /dev/null +++ b/programs/helloWorld/Makefile @@ -0,0 +1,5 @@ +NAME := helloworld +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/integration-tests.mk b/programs/integration-tests.mk index c2307e9..87b8f07 100644 --- a/programs/integration-tests.mk +++ b/programs/integration-tests.mk @@ -12,6 +12,8 @@ TEST_SRCS= \ TEST_RESULTS = $(patsubst $(TEST_DIR)/%,$(TEST_DIR)/%/test_res.txt,$(TEST_SRCS)) +RES_PARSER := $(INTERPRET_ROOT_DIR)/programs/scripts/test_result_parse.sh + .PHONY: integration-tests integration-tests: $(TEST_RESULTS) bootloader-test @echo FINISHED @@ -20,14 +22,15 @@ integration-tests: $(TEST_RESULTS) bootloader-test # run the emulator on it (so env.bash must be called). And parse results $(TEST_DIR)/%/test_res.txt: $(TEST_DIR)/% @echo Executing $^ - @cd $^; make rebuild - @cd $^; if ! (fp-emu > test_res.txt 2>&1); then continue; fi - @test_result_parse.sh $@ + @cd $^; make recompile + @cd $^; if ! (make run > test_res.txt 2>&1); then continue; fi + @$(RES_PARSER) $@ bootloader-test: - @cd programs/bootloader; riscv-clean.sh; make; compile_app.sh 1 hello hello.c - @cd programs/bootloader; if ! (fp-emu hello.app > test_res.txt 2>&1); then continue; fi - @cd programs/bootloader; test_result_parse.sh test_res.txt + @cd programs/helloWorld; make clean; make app; + @cd programs/bootloader; make recompile; + @cd programs/bootloader; if ! (ip-emu bootloader.mem ../helloWorld/helloworld.app > test_res.txt 2>&1); then continue; fi + @cd programs/bootloader; $(RES_PARSER) test_res.txt .PHONY: integration-clean # Loop through all the test dirs and do `make clean` which should remove all diff --git a/programs/interruptExpire/Makefile b/programs/interruptExpire/Makefile index 9ee7c71..5a2ba31 100644 --- a/programs/interruptExpire/Makefile +++ b/programs/interruptExpire/Makefile @@ -1,10 +1,5 @@ -build: - riscv-compile.sh 1 ispm ie.c +NAME := interrupt +APP_SOURCES = *.c -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/lib/include/flexpret_config.h b/programs/lib/include/flexpret_config.h new file mode 100644 index 0000000..434e11b --- /dev/null +++ b/programs/lib/include/flexpret_config.h @@ -0,0 +1,37 @@ + +/** + * This flexpret core config file is auto-generated, and based on the + * configuration used to build the flexpret emulator. + * + * Do not edit. + * + */ +#ifndef FLEXPRET_CONFIG_H +#define FLEXPRET_CONFIG_H + +/* Memory ranges */ +#define ISPM_START 0x00000000 +#define ISPM_END 0x8000 +#define ISPM_SIZE_KB 24 +#define DSPM_START 0x20000000 +#define DSPM_END 0x20000000 + 0x8000 +#define DSPM_SIZE_KB 24 +#define BUS_START 0x40000000 +#define BUS_END 0x40000000 + 0x400 + +/* Scheduling */ +#define SCHED_ROUND_ROBIN +#define NUM_THREADS 4 + +/* Timing */ +#define CLOCK_PERIOD_NS 10 +#define TIME_BITS 32 + +/* IO */ +#define NUM_GPIS 4 +#define GPI_SIZES {1,1,1,1} +#define NUM_GPOS 4 +#define GPO_SIZES {2,2,2,2} + +#endif + \ No newline at end of file diff --git a/programs/lib/linker/flexpret_config.ld b/programs/lib/linker/flexpret_config.ld new file mode 100644 index 0000000..2c53c8f --- /dev/null +++ b/programs/lib/linker/flexpret_config.ld @@ -0,0 +1,16 @@ + +/** +* This flexpret core config file is auto-generated, and based on the +* configuration used to build the flexpret emulator. +* +* Do not edit. +* +*/ +ISPM_START = 0x00000000 ; +ISPM_END = 0x8000 ; +DSPM_START = 0x20000000 ; +DSPM_END = 0x20000000 + 0x8000 ; +DSPM_SIZE_KB = 24 ; +BUS_START = 0x40000000 ; +BUS_END = 0x40000000 + 0x400 ; + \ No newline at end of file diff --git a/programs/noc/HelloWorld/Makefile b/programs/noc/HelloWorld/Makefile index ebe95cd..2c8a440 100644 --- a/programs/noc/HelloWorld/Makefile +++ b/programs/noc/HelloWorld/Makefile @@ -1,10 +1,5 @@ -build: - riscv-compile.sh 4 ispm hello_noc.c +NAME := hello_noc +APP_SOURCES = *.c -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/noc/HelloWorld/hello_noc.c b/programs/noc/HelloWorld/hello_noc.c index ad175e6..5e2e7d0 100644 --- a/programs/noc/HelloWorld/hello_noc.c +++ b/programs/noc/HelloWorld/hello_noc.c @@ -1,8 +1,4 @@ -#include -#include -#include -#include -#include +#include "interpret.h" int main0(); int main1(); diff --git a/programs/noc/PingPong/Makefile b/programs/noc/PingPong/Makefile index 21278ee..383e3dc 100644 --- a/programs/noc/PingPong/Makefile +++ b/programs/noc/PingPong/Makefile @@ -1,10 +1,5 @@ -build: - riscv-compile.sh 4 ispm ping_pong_noc.c +NAME := pingpong +APP_SOURCES = *.c -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/noc/PingPong/ping_pong_noc.c b/programs/noc/PingPong/ping_pong_noc.c index 74687cc..768db11 100644 --- a/programs/noc/PingPong/ping_pong_noc.c +++ b/programs/noc/PingPong/ping_pong_noc.c @@ -1,7 +1,4 @@ -#include -#include -#include -#include +#include "interpret.h" #define PING_PONG_LIMIT 10 diff --git a/programs/print/Makefile b/programs/print/Makefile index 78f808e..3ac61be 100644 --- a/programs/print/Makefile +++ b/programs/print/Makefile @@ -1,10 +1,5 @@ -build: - riscv-compile.sh 4 ispm print.c +NAME := print +APP_SOURCES = print.c -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/print/print.c b/programs/print/print.c index 177901d..e536834 100644 --- a/programs/print/print.c +++ b/programs/print/print.c @@ -1,10 +1,4 @@ -#include -#include -#include -#include -#include -#include - +#include "interpret.h" void *t1(void *arg) { print_str("Hello from t1\n"); diff --git a/programs/scripts/test_result_parse.sh b/programs/scripts/test_result_parse.sh index 14cd1e4..25314d6 100755 --- a/programs/scripts/test_result_parse.sh +++ b/programs/scripts/test_result_parse.sh @@ -3,8 +3,7 @@ # Verify that the program started echo "Parsing results from test: $1" -if ! grep --quiet "Assertion failed: Program terminated sucessfully -" $1; then +if ! grep --quiet "Assertion failed: Program terminated sucessfully" $1; then echo "ERROR: Test program did not terminate properly" exit -1 fi diff --git a/programs/softwareUart/Makefile b/programs/softwareUart/Makefile new file mode 100644 index 0000000..8b199e4 --- /dev/null +++ b/programs/softwareUart/Makefile @@ -0,0 +1,5 @@ +NAME := blinky +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/threaded/Makefile b/programs/threaded/Makefile index 2d2d052..49fc0a9 100644 --- a/programs/threaded/Makefile +++ b/programs/threaded/Makefile @@ -1,11 +1,5 @@ +NAME := threaded +APP_SOURCES = *.c -build: - riscv-compile.sh 4 ispm mt.c - -clean: - riscv-clean.sh - - -rebuild: clean build - -PHONY: build clean rebuild \ No newline at end of file +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/threaded/mt.c b/programs/threaded/mt.c index f839c28..28e7676 100644 --- a/programs/threaded/mt.c +++ b/programs/threaded/mt.c @@ -1,11 +1,5 @@ -#include -#include -#include -#include +#include "interpret.h" -#include -#include -#include void* t1(void *) { print_str("Hello from t1\n"); @@ -48,6 +42,7 @@ int main() { thread_join(tid3, &etid3); print_str("t3 done\n"); + delay_for(MSEC(1)); return 0; } } diff --git a/programs/uart/rx/Makefile b/programs/uart/rx/Makefile new file mode 100644 index 0000000..bb10173 --- /dev/null +++ b/programs/uart/rx/Makefile @@ -0,0 +1,5 @@ +NAME := uart_rx +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/uart/rx/uart_rx.c b/programs/uart/rx/uart_rx.c index 7d863b4..58da02d 100644 --- a/programs/uart/rx/uart_rx.c +++ b/programs/uart/rx/uart_rx.c @@ -1,6 +1,5 @@ -#include -#include -#include +#include "interpret.h" + int main() { int core_id = read_csr(CSR_COREID); @@ -8,6 +7,6 @@ int main() { uint8_t recv; while (1) { recv=uart_receive(); - gpo_write(0, recv); + print_int(recv); } } \ No newline at end of file diff --git a/programs/uart/tx/Makefile b/programs/uart/tx/Makefile new file mode 100644 index 0000000..430e86d --- /dev/null +++ b/programs/uart/tx/Makefile @@ -0,0 +1,5 @@ +NAME := uart_tx +APP_SOURCES = *.c + +include $(INTERPRET_ROOT_DIR)/Makefrag +include $(FLEXPRET_ROOT_DIR)/Makefrag \ No newline at end of file diff --git a/programs/uart/tx/uart_tx.c b/programs/uart/tx/uart_tx.c index 70e9cfc..3a23eb0 100644 --- a/programs/uart/tx/uart_tx.c +++ b/programs/uart/tx/uart_tx.c @@ -1,6 +1,4 @@ -#include -#include -#include +#include "interpret.h" int main() { int core_id = read_csr(CSR_COREID); @@ -8,6 +6,6 @@ int main() { if (core_id == 0) { uart_send(42); } - while(1) {} + delay_for(MSEC(2)); } diff --git a/src/main/scala/Top.scala b/src/main/scala/Top.scala index df69796..13cc7b2 100644 --- a/src/main/scala/Top.scala +++ b/src/main/scala/Top.scala @@ -25,6 +25,9 @@ class TopIO(topCfg: TopConfig) extends Bundle { } class Top(topCfg: TopConfig) extends Module { + // Write flexpret_config.h and flexpret_config.ld to file + topCfg.coreCfgs(0).writeConfigHeaderToFile("flexpret/programs/lib/include/flexpret_config.h") + topCfg.coreCfgs(0).writeLinkerConfigToFile("flexpret/programs/lib/linker/flexpret_config.ld") val io = IO(new TopIO(topCfg)) // Flexpret cores val cores = for (i <- 0 until topCfg.nCores) yield Module(new Core(topCfg.coreCfgs(i))) diff --git a/src/main/scala/WishboneUart.scala b/src/main/scala/WishboneUart.scala index 6ae5c24..e63a763 100644 --- a/src/main/scala/WishboneUart.scala +++ b/src/main/scala/WishboneUart.scala @@ -32,9 +32,6 @@ class WishboneUart(implicit cfg: TopConfig) extends WishboneDevice(4) { ioUart.tx := tx.txd rx.rxd := ioUart.rx - - // FIXME: Use Martins FIFO - // MS: Queue is fine as well val rxFifo = Module(new Queue(UInt(8.W), 8)).io val txFifo = Module(new Queue(UInt(8.W), 8)).io rx.channel <> rxFifo.enq diff --git a/tests/devices/wishbone.h b/tests/devices/wishbone.h new file mode 100644 index 0000000..c0078b7 --- /dev/null +++ b/tests/devices/wishbone.h @@ -0,0 +1,14 @@ +#ifndef WISHBONE_H +#define WISHBONE_H + +#define WB_BASE 0x40000000UL +#define WB_READ_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x0UL))) +#define WB_WRITE_ADDR (*( (volatile uint32_t *) (WB_BASE + 0x4UL))) +#define WB_WRITE_DATA (*( (volatile uint32_t *) (WB_BASE + 0x8UL))) +#define WB_READ_DATA (*( (volatile uint32_t *) (WB_BASE + 0xCUL))) +#define WB_STATUS (*( (volatile uint32_t *) (WB_BASE + 0x10UL))) + + + + +#endif \ No newline at end of file diff --git a/tests/devices/wishbone_master.c b/tests/devices/wishbone_master.c new file mode 100644 index 0000000..c80e6ec --- /dev/null +++ b/tests/devices/wishbone_master.c @@ -0,0 +1,25 @@ + +#include +#include +#include "wishbone.h" + + +void wb_write(uint32_t addr, uint32_t data) { + WB_WRITE_DATA = data; + WB_WRITE_ADDR = addr; + while(!WB_STATUS) {} +} + +uint32_t wb_read(uint32_t addr) { + WB_READ_ADDR = addr; + while(!WB_STATUS) {} + return WB_READ_DATA; +} + +int main() { + uint32_t read; + wb_write(1, 42); + read = wb_read(1); + _fp_print(read); + return 0; +} From 801f59c940c1a1392fb308e6ef53f17d3d178f91 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 15:49:28 +0100 Subject: [PATCH 06/13] Fix bash.env --- env.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/env.bash b/env.bash index 3b24a3d..4f164d7 100644 --- a/env.bash +++ b/env.bash @@ -1,5 +1,5 @@ export INTERPRET_ROOT_DIR=$(pwd) -export FLEXPRET_ROOT_DIR=$(IP_ROOT)/flexpret +export FLEXPRET_ROOT_DIR=$INTERPRET_ROOT_DIR/flexpret # Put the generated emulator on the path -export PATH="$PATH:$IP_ROOT/emulator" \ No newline at end of file +export PATH="$PATH:$INTERPRET_ROOT_DIR/emulator" \ No newline at end of file From a6115b5db3416b767c40dc758b5625057b180271 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 15:56:10 +0100 Subject: [PATCH 07/13] Fix CI. Also test FlexPRET --- .github/workflows/ci.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79618db..4ac5394 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,13 +25,18 @@ jobs: sudo mkdir /opt/riscv sudo tar -xzf riscv32-unknown-elf.gcc-12.1.0.tar.gz -C /opt/riscv/ rm riscv32-unknown-elf.gcc-12.1.0.tar.gz + root=$(pwd) echo "PATH=$PATH:/opt/riscv/bin" >> $GITHUB_ENV + echo "FLEXPRET_ROOT_DIR=$root/flexpret" >> $GITHUB_ENV + echo "INTERPRET_ROOT_DIR=$root" >> $GITHUB_ENV + - name: Build and test FlexPRET + run : | + cd $(FLEXPRET_ROOT_DIR) + make clean && make emulator + make test - name: Build InterPRET run: | make emulator N_CORES=4 THREADS=4 FLEX=false TRACE=0 - root=$(pwd) - echo "PATH=$PATH:$root/flexpret/scripts/c:$root/emulator:$root/programs/scripts" >> $GITHUB_ENV - echo "FP_ROOT=$root" >> $GITHUB_ENV - name: Run unit-tests run: make unit-tests - name: Run integration tests From 4ced9e2934ccb11c54e20dc720e6749631b9a20f Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 17 Mar 2023 21:10:56 +0100 Subject: [PATCH 08/13] CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ac5394..dced13c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: echo "INTERPRET_ROOT_DIR=$root" >> $GITHUB_ENV - name: Build and test FlexPRET run : | - cd $(FLEXPRET_ROOT_DIR) + cd $FLEXPRET_ROOT_DIR make clean && make emulator make test - name: Build InterPRET From 7b483a625fcc2f4050316938453e325739647e21 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Sat, 18 Mar 2023 12:05:01 +0100 Subject: [PATCH 09/13] CI --- programs/integration-tests.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/programs/integration-tests.mk b/programs/integration-tests.mk index 87b8f07..ce52fbd 100644 --- a/programs/integration-tests.mk +++ b/programs/integration-tests.mk @@ -13,6 +13,7 @@ TEST_SRCS= \ TEST_RESULTS = $(patsubst $(TEST_DIR)/%,$(TEST_DIR)/%/test_res.txt,$(TEST_SRCS)) RES_PARSER := $(INTERPRET_ROOT_DIR)/programs/scripts/test_result_parse.sh +IP_EMU := $(INTERPRET_ROOT_DIR)/emulator/ip-emu .PHONY: integration-tests integration-tests: $(TEST_RESULTS) bootloader-test @@ -23,13 +24,13 @@ integration-tests: $(TEST_RESULTS) bootloader-test $(TEST_DIR)/%/test_res.txt: $(TEST_DIR)/% @echo Executing $^ @cd $^; make recompile - @cd $^; if ! (make run > test_res.txt 2>&1); then continue; fi + @cd $^; if ! (make run | tee test_res.txt); then continue; fi @$(RES_PARSER) $@ bootloader-test: @cd programs/helloWorld; make clean; make app; @cd programs/bootloader; make recompile; - @cd programs/bootloader; if ! (ip-emu bootloader.mem ../helloWorld/helloworld.app > test_res.txt 2>&1); then continue; fi + @cd programs/bootloader; if ! ($(IP_EMU) bootloader.mem ../helloWorld/helloworld.app | test_res.txt ); then continue; fi @cd programs/bootloader; $(RES_PARSER) test_res.txt .PHONY: integration-clean From df12f9f8d144527f412c3c36e5b434b1f4911c39 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 31 Mar 2023 16:54:31 +0200 Subject: [PATCH 10/13] Update --- Makefile | 2 +- emulator/main.cpp | 5 +++++ programs/integration-tests.mk | 4 ++-- programs/scripts/test_result_parse.sh | 2 +- src/main/scala/Main.scala | 15 +++++++++------ src/main/scala/Top.scala | 13 +++++++++++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index a11dbdf..3563532 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ verilog_raw: $(VERILOG_RAW) # --no-dedup flag is to make it possible to load programs directly into the ISpms $(VERILOG_RAW): - sbt 'run $(CORE_CONFIG) $(SOC_CONFIG) --no-dedup --target-dir $(BUILD_DIR)' + sbt 'run verilator $(CORE_CONFIG) $(SOC_CONFIG) --no-dedup --target-dir $(BUILD_DIR)' # FPGA Verilog generation # FPGA_SRC_DIR = $(FPGA_DIR)/generated-$(CORE_CONFIG) diff --git a/emulator/main.cpp b/emulator/main.cpp index 40f9d15..a2fe369 100644 --- a/emulator/main.cpp +++ b/emulator/main.cpp @@ -97,6 +97,11 @@ int main(int argc, char* argv[]) { trace->dump(10*timestamp); trace->flush(); } + + if (top->io_stop) { + std::cout <<"Verilator received stop signal from InterPRET" <= 2) + assert(args.length >= 3) + + val targetVerilator = (args(0) == "verilator") // Parse second parameter which is the number of cores - val nCores = args(1).toInt + val nCores = args(2).toInt // Parse the coreCfg string passed as a command line argument val coreCfgs = for (i <- 0 until nCores) yield { - FlexpretConfiguration.parseString(confString=args(0), coreId=i) + FlexpretConfiguration.parseString(confString=args(1), coreId=i) } println(s"Building $nCores-core SoC") // Extract arguments to pass further to the chisel scala compiler - val chiselArgs = if (args.length > 2) { - args.slice(2,args.length) + val chiselArgs = if (args.length > 3) { + args.slice(3,args.length) } else { Array("") } @@ -28,7 +30,8 @@ object Main { val topConfig = TopConfig( coreCfgs = coreCfgs, nCores = nCores, - freq = 50000000 // Xilinx board runs with 50 MHz + freq = 50000000, // Xilinx board runs with 50 MHz + emulation = targetVerilator ) // Pass configuration to FlexPRET processor. diff --git a/src/main/scala/Top.scala b/src/main/scala/Top.scala index 13cc7b2..1b59e9e 100644 --- a/src/main/scala/Top.scala +++ b/src/main/scala/Top.scala @@ -11,7 +11,8 @@ import s4noc.{Config, S4NoCTop} case class TopConfig( coreCfgs : Seq[FlexpretConfiguration], nCores : Int, - freq : Int + freq : Int, + emulation: Boolean, ){ } @@ -22,6 +23,8 @@ class TopIO(topCfg: TopConfig) extends Bundle { val rx = Input(Bool()) val tx = Output(Bool()) } + + val stop = if (topCfg.emulation) Some((Output(Bool()))) else None } class Top(topCfg: TopConfig) extends Module { @@ -66,6 +69,10 @@ class Top(topCfg: TopConfig) extends Module { val regCoreDone = RegInit(VecInit(Seq.fill(topCfg.nCores)(false.B))) val regCorePrintNext = RegInit(VecInit(Seq.fill(topCfg.nCores)(false.B))) + if (topCfg.emulation) { + io.stop.get := false.B + } + for (i <- 0 until topCfg.nCores) { // Drove core IO to defaults cores(i).io.dmem.driveDefaultsFlipped() @@ -126,6 +133,8 @@ class Top(topCfg: TopConfig) extends Module { // Wait until all cores are done when(regCoreDone.asUInt.andR) { printf("All cores are done terminating\n") - assert(false.B, "Program terminated sucessfully") + if (topCfg.emulation) { + io.stop.get := true.B + } } } From da0439df8685f05b56ad9b29b0f63c28f0c0b6f2 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 31 Mar 2023 17:00:12 +0200 Subject: [PATCH 11/13] CI --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dced13c..2bb6152 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,8 @@ jobs: cd $FLEXPRET_ROOT_DIR make clean && make emulator make test - - name: Build InterPRET + - name: Build and test InterPRET run: | make emulator N_CORES=4 THREADS=4 FLEX=false TRACE=0 - - name: Run unit-tests - run: make unit-tests - - name: Run integration tests - run: make integration-tests \ No newline at end of file + make unit-tests + make integration-tests \ No newline at end of file From cfea15629d1087f0698d3b93b3eff78aace01059 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 31 Mar 2023 18:04:41 +0200 Subject: [PATCH 12/13] Fix the noc implementation --- lib/include/interpret_noc.h | 15 +++++++- lib/interpret_noc.c | 55 +++++---------------------- programs/noc/HelloWorld/hello_noc.c | 8 ++-- programs/noc/PingPong/ping_pong_noc.c | 4 +- src/main/scala/Top.scala | 6 +-- 5 files changed, 31 insertions(+), 57 deletions(-) diff --git a/lib/include/interpret_noc.h b/lib/include/interpret_noc.h index 2b4b6a9..d710371 100644 --- a/lib/include/interpret_noc.h +++ b/lib/include/interpret_noc.h @@ -4,6 +4,16 @@ #include #include +// A 32 bit header which is always sent first +struct noc_header { + unsigned int write : 1; + unsigned int port : 14; // 14 bits for the package type + unsigned int length : 14; // 14 bits for the package length + unsigned int flags : 3; // 3 bits for package flags +}; + +#define NOC_HEADER_INIT(write, port, length, flags) { .write=write, .port=port, .length=length, .flags=flags } + /** * @brief Send a word over the NoC. Depending on the value of the timeout, the @@ -18,7 +28,7 @@ * * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise **/ -fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout); +fp_ret_t noc_send(uint32_t addr, uint32_t data); /** @@ -34,6 +44,7 @@ fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout); * * @return fp_ret_t: FP_SUCCESS, if sending is successful, FP_FAILIURE otherwise **/ -fp_ret_t noc_receive(uint32_t* data, timeout_t timeout); +fp_ret_t noc_receive(uint32_t* data); + #endif diff --git a/lib/interpret_noc.c b/lib/interpret_noc.c index 4e70d0e..9e529bb 100644 --- a/lib/interpret_noc.c +++ b/lib/interpret_noc.c @@ -12,53 +12,16 @@ #define NOC_TX_READY(val) (val & 0x01) #define NOC_DATA_AVAILABLE(val) (val & 0x02) -fp_ret_t noc_send(uint32_t addr, uint32_t data, timeout_t timeout) { - if (timeout == TIMEOUT_FOREVER) { - while (!NOC_TX_READY(NOC_CSR)); - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } - if (timeout == TIMEOUT_NEVER) { - if (NOC_TX_READY(NOC_CSR)) { - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } else { - return FP_FAILURE; - } - } - timeout_t time = rdtime() + timeout; - while (rdtime() < time) { - if (NOC_TX_READY(NOC_CSR)) { - NOC_DEST = addr; - NOC_DATA = data; - return FP_SUCCESS; - } - } - return FP_FAILURE; +fp_ret_t noc_send(uint32_t addr, uint32_t data) { + while (!NOC_TX_READY(NOC_CSR)); + NOC_DEST = addr; + NOC_DATA = data; + return FP_SUCCESS; } -fp_ret_t noc_receive(uint32_t* data, timeout_t timeout) { - if (timeout == TIMEOUT_FOREVER) { - while (!NOC_DATA_AVAILABLE(NOC_CSR)); - *data = NOC_DATA; - return FP_SUCCESS; - } - if (timeout == TIMEOUT_NEVER) { - if (NOC_DATA_AVAILABLE(NOC_CSR)) { - *data = NOC_DATA; - return FP_SUCCESS; - } - return FP_FAILURE; - } - uint32_t time = rdtime() + timeout; - while (rdtime() < time) { - if (NOC_DATA_AVAILABLE(NOC_CSR)) { - *data = NOC_DATA; - return FP_SUCCESS; - } - } - return FP_FAILURE; +fp_ret_t noc_receive(uint32_t* data) { + while (!NOC_DATA_AVAILABLE(NOC_CSR)); + *data = NOC_DATA; + return FP_SUCCESS; } \ No newline at end of file diff --git a/programs/noc/HelloWorld/hello_noc.c b/programs/noc/HelloWorld/hello_noc.c index 5e2e7d0..5e35127 100644 --- a/programs/noc/HelloWorld/hello_noc.c +++ b/programs/noc/HelloWorld/hello_noc.c @@ -24,7 +24,7 @@ uint32_t send_values0[] = {1,2,3,4,5,6,7,8,9,10}; int main0() { // Send values to listener for (int i = 0; i<10; i++) { - noc_send(2, send_values0[i], TIMEOUT_FOREVER); + noc_send(2, send_values0[i]); } } @@ -32,7 +32,7 @@ uint32_t send_values1[] = {10,20,30,40,50,60,70,80,90,100}; int main1() { // Send values to listener for (int i = 0; i<10; i++) { - noc_send(3, send_values1[i], TIMEOUT_FOREVER); + noc_send(3, send_values1[i]); } } @@ -40,7 +40,7 @@ int main2() { uint32_t read; fp_ret_t ret; for (int i=0; i<10; i++) { - ret = noc_receive(&read, TIMEOUT_FOREVER); + ret = noc_receive(&read); assert(read == send_values0[i]); } } @@ -49,7 +49,7 @@ int main3() { uint32_t read; fp_ret_t ret; for (int i=0; i<10; i++) { - ret = noc_receive(&read, TIMEOUT_FOREVER); + ret = noc_receive(&read); assert(read == send_values1[i]); } } \ No newline at end of file diff --git a/programs/noc/PingPong/ping_pong_noc.c b/programs/noc/PingPong/ping_pong_noc.c index 768db11..b55af1f 100644 --- a/programs/noc/PingPong/ping_pong_noc.c +++ b/programs/noc/PingPong/ping_pong_noc.c @@ -21,10 +21,10 @@ int main() { ping_pong_count += 1; // core_id sent and incremented ping_pong_count to partner_core_id - noc_send(partner_core_id, ping_pong_count, TIMEOUT_FOREVER); + noc_send(partner_core_id, ping_pong_count); } else { // core_id received ping_pong_count from partner_core_id - fp_ret_t ret = noc_receive(&ping_pong_count, TIMEOUT_FOREVER); + fp_ret_t ret = noc_receive(&ping_pong_count); _fp_print(ping_pong_count); } } diff --git a/src/main/scala/Top.scala b/src/main/scala/Top.scala index 1b59e9e..27124ea 100644 --- a/src/main/scala/Top.scala +++ b/src/main/scala/Top.scala @@ -10,9 +10,9 @@ import s4noc.{Config, S4NoCTop} case class TopConfig( coreCfgs : Seq[FlexpretConfiguration], - nCores : Int, - freq : Int, - emulation: Boolean, + nCores : Int = 4, + freq : Int = 50000000, + emulation: Boolean = true, ){ } From 4fd27afc56b42db10d66f2fe61278776a7e40342 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 31 Mar 2023 18:14:00 +0200 Subject: [PATCH 13/13] Add ip-emu script --- emulator/ip-emu | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 emulator/ip-emu diff --git a/emulator/ip-emu b/emulator/ip-emu new file mode 100755 index 0000000..a3d54ae --- /dev/null +++ b/emulator/ip-emu @@ -0,0 +1,39 @@ +#!/bin/bash +# Simple wrapper around the ip-verilator emulation + +# Get the directory of the script and the verilator emulation +script_dir=$(dirname "$0") +script_name=$(basename "$0") +emu="$script_dir/ip-verilator" +working_dir=$(pwd) + +echo "Running InterPRET emulator:" + +# Check if exactly one argument is provided +if [ $# -lt 1 ]; then + echo "Usage: $script_name ispm-file [uart_file] [--trace]" + exit 1 +fi + +# Check if the file exists +if [ ! -f "$1" ]; then + echo "File not found: $1" + exit 1 +fi + +# Check if the file exists +if [ ! -f "$emu" ]; then + echo "Did not find verilator emulator at: $emu" + exit 1 +fi + +# Get the filename from the path +filename=$(basename "$1") + +# Copy the file to the current directory +cp "$1" "$working_dir/ispm.mem" + +# Excute the verilator emulation +echo "${@:2}" +"$script_dir/ip-verilator" "${@:2}" +