-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsoc.v
151 lines (116 loc) · 3.49 KB
/
soc.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* pipelineZ.v
* femtorv32-tordboyau
* Configurable 5-stages pipelined RV32IM
* Bruno Levy, Sept 2022
*/
/****************************************************************************/
`ifndef BOARD
`define ARTY
`ifndef BOARD_FREQ
`define BOARD_FREQ 100
`endif
// Uncomment to change CPU freq
// If undefined, the 100MHz clock of
// the board is used.
`ifndef CPU_FREQ
`define CPU_FREQ 140
`endif
`endif
/****************************************************************************/
`define CONFIG_PC_PREDICT // enables D -> F path (needed by RAS and GSHARE)
`define CONFIG_RAS // return address stack
`define CONFIG_GSHARE // gshare branch prediction (or BTFNT if not set)
`define CONFIG_RV32M // RV32M instruction set (MUL,DIV,REM)
//`define CONFIG_DEBUG // debug mode, displays execution
// See "debugger" section in source
// to define breakpoints
`define CONFIG_INITIALIZE // initialize register file and BHT table
// (required by Icarus/iverilog
// and by some synth tools)
/******************************************************************************/
`ifndef CPU_FREQ
`define CPU_FREQ 100
`define PASSTHROUGH_PLL
`endif
`ifdef BENCH
`undef BOARD_FREQ
`undef CPU_FREQ
`define BOARD_FREQ 10
`define CPU_FREQ 10
`ifndef PASSTHROUGH_PLL
`define PASSTHROUGH_PLL
`endif
`endif
/******************************************************************************/
`default_nettype none
`include "clockworks.v"
`include "emitter_uart.v"
`include "TordBoyau5.v"
// replaces TordBoyau with a 5-state core to identify bottlenecks
//`include "TordBoyau5_sequential.v"
module SOC (
input wire CLK, // system clock
input wire RESET,// reset button
output reg [3:0] LEDS, // system LEDs
output wire TXD // UART transmit
);
wire clk;
wire resetn;
wire [31:0] IO_mem_addr;
wire [31:0] IO_mem_rdata;
wire [31:0] IO_mem_wdata;
wire IO_mem_wr;
Processor CPU(
.clk(clk),
.resetn(resetn),
.IO_mem_addr(IO_mem_addr),
.IO_mem_rdata(IO_mem_rdata),
.IO_mem_wdata(IO_mem_wdata),
.IO_mem_wr(IO_mem_wr)
);
wire [13:0] IO_wordaddr = IO_mem_addr[15:2];
// Memory-mapped IO in IO page, 1-hot addressing in word address.
localparam IO_LEDS_bit = 0; // W four leds
localparam IO_UART_DAT_bit = 1; // W data to send (8 bits)
localparam IO_UART_CNTL_bit = 2; // R status. bit 9: busy sending
always @(posedge clk) begin
if(IO_mem_wr & IO_wordaddr[IO_LEDS_bit]) begin
LEDS <= IO_mem_wdata[3:0];
end
end
wire uart_valid = IO_mem_wr & IO_wordaddr[IO_UART_DAT_bit];
wire uart_ready;
corescore_emitter_uart #(
.clk_freq_hz(`CPU_FREQ*1000000),
.baud_rate(1000000)
) UART(
.i_clk(clk),
.i_data(IO_mem_wdata[7:0]),
.i_valid(uart_valid),
.o_ready(uart_ready),
.o_uart_tx(TXD)
);
assign IO_mem_rdata =
IO_wordaddr[IO_UART_CNTL_bit] ? { 22'b0, !uart_ready, 9'b0}
: 32'b0;
`ifdef BENCH
always @(posedge clk) begin
if(uart_valid) begin
`ifdef CONFIG_DEBUG
$display("UART: %c", IO_mem_wdata[7:0]);
`else
$write("%c", IO_mem_wdata[7:0] );
$fflush(32'h8000_0001);
`endif
end
end
`endif
// Gearbox and reset circuitry.
Clockworks CW(
.CLK(CLK),
.RESET(RESET),
.clk(clk),
.resetn(resetn)
);
endmodule