aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-20 12:18:20 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-20 12:18:20 +0200
commit142510b8325b9ef89bd3e22463f36c3caa2815de (patch)
tree0668f163046a43e98e8345c6bf96e97a652341c9
parent407a3ff54a35cbe99ba6ac743376e9b0e9718fc1 (diff)
downloadriscv_cpu-142510b8325b9ef89bd3e22463f36c3caa2815de.tar.gz
riscv_cpu-142510b8325b9ef89bd3e22463f36c3caa2815de.zip
io
-rw-r--r--prog/link.ld8
-rw-r--r--prog/src/main.c8
-rw-r--r--prog/src/startup.s17
-rw-r--r--src/io.v6
-rw-r--r--src/top.v2
5 files changed, 30 insertions, 11 deletions
diff --git a/prog/link.ld b/prog/link.ld
index 7bd11eb..9644d59 100644
--- a/prog/link.ld
+++ b/prog/link.ld
@@ -3,8 +3,8 @@
/* Define memory regions */
MEMORY
{
- ROM (rx) : ORIGIN = 0x00010000, LENGTH = 0x400 /* 1024 bytes for ROM */
- RAM (rwx) : ORIGIN = 0x00100000, LENGTH = 0x400 /* 1024 bytes for RAM */
+ ROM (rx) : ORIGIN = 0x00010000, LENGTH = 0x1000 /* 1024 bytes for ROM */
+ RAM (rwx) : ORIGIN = 0x00100000, LENGTH = 0x1000 /* 1024 bytes for RAM */
}
ENTRY(_start)
@@ -43,7 +43,7 @@ SECTIONS
.stack (NOLOAD) :
{
_stack_start = .;
- . += 0x80; /* Adjust the size as needed */
+ . += 0x100; /* Adjust the size as needed */
_stack_end = .;
} > RAM
@@ -51,7 +51,7 @@ SECTIONS
.heap (NOLOAD) :
{
_heap_start = .;
- . += 0x80; /* Adjust the size as needed */
+ . += 0x100; /* Adjust the size as needed */
_heap_end = .;
} > RAM
}
diff --git a/prog/src/main.c b/prog/src/main.c
index 62b802b..082172d 100644
--- a/prog/src/main.c
+++ b/prog/src/main.c
@@ -1,13 +1,13 @@
#include <stdint.h>
-volatile uint32_t *io_in = (volatile uint32_t *)0x00000000;
-volatile uint32_t *io_out = (volatile uint32_t *)0x00000004;
+//volatile uint32_t *io_in = (volatile uint32_t *)0x00000000;
+//volatile uint32_t *io_out = (volatile uint32_t *)0x00000004;
int main(void) {
- *io_out = 0;
while (1) {
for (int i = 0; i < 32; ++i) {
- *io_out = i;
+ *((volatile uint32_t *)0x00000004) = i;
+ for (int j = 0; j < 1024 * 128; ++j);
}
}
}
diff --git a/prog/src/startup.s b/prog/src/startup.s
index 7adfb5e..963c288 100644
--- a/prog/src/startup.s
+++ b/prog/src/startup.s
@@ -1,6 +1,23 @@
.section .init
.globl _start
_start:
+
+prog:
+/*
+ la t0, 4
+ la t1, 1
+
+ sw t1, 0(t0)
+
+ la t0, 0x00100000
+ li t1, 1
+ sw t1, 0(t0)
+ lw t2, 0(t0)
+
+
+ j halt
+
+*/
/* Set up stack pointer */
la sp, _stack_end
diff --git a/src/io.v b/src/io.v
index f062f31..f53062b 100644
--- a/src/io.v
+++ b/src/io.v
@@ -14,15 +14,17 @@ module io (
`include "include/consts.vh"
-always @ (posedge clk) begin
+always @ (posedge clk or negedge rstn) begin
if (!rstn) begin
io_out <= 32'b0;
end else if (we && addr == 32'h0000_0004) begin
io_out <= wd;
end
+end
+
+always @ (posedge clk) begin
if (addr == 32'h0000_0000) rd <= io_in;
else if (addr == 32'h0000_0004) rd <= io_out;
else rd <= 32'b0;
end
-
endmodule \ No newline at end of file
diff --git a/src/top.v b/src/top.v
index 86f26ce..fc1d9fe 100644
--- a/src/top.v
+++ b/src/top.v
@@ -10,7 +10,7 @@ assign rstn = key;
wire [31:0] io_in;
wire [31:0] io_out;
-clock_divider #(.N(1024 * 1024)) clkdiv (
+clock_divider #(.N(1)) clkdiv (
.clk(clk),
.rstn(rstn),
.clk_div(clk_cpu)