summaryrefslogtreecommitdiff
path: root/rtl/core/mmu/mmu.sv
blob: 9d118c109cfc37e53a84fbd6d62fd9ea02750487 (plain)
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
module core_mmu
(
	input  logic clk,

	input  logic bus_ready,
	input  word  bus_data_rd,
	             data_data_wr,
	input  ptr   insn_addr,
	             data_addr,
	input  logic insn_start,
	             data_start,
	             data_write,

	output word  bus_data_wr,
	output ptr   bus_addr,
	output logic bus_start,
	             bus_write,
	             insn_ready,
	             data_ready,
	output word  insn_data_rd,
	             data_data_rd
);

	enum
	{
		INSN,
		DATA
	} master, next_master;

	//TODO
	assign insn_data_rd = bus_data_rd;
	assign data_data_rd = bus_data_rd;

	always_comb begin
		next_master = master;
		if(bus_ready) begin
			if(insn_start)
				next_master = INSN;
			else if(data_start)
				next_master = DATA;
		end

		insn_ready = 0;
		data_ready = 0;

		unique case(master)
			INSN: insn_ready = bus_ready;
			DATA: data_ready = bus_ready;
		endcase

		unique case(next_master)
			INSN: begin
				bus_addr = insn_addr;
				bus_data_wr = {32{1'bx}};
			end

			DATA: begin
				bus_addr = data_addr;
				bus_data_wr = data_data_wr;
			end
		endcase
	end

	always @(posedge clk) begin
		master <= next_master;

		unique case(next_master)
			INSN: begin
				bus_start <= insn_start;
				bus_write <= 0;
			end

			DATA: begin
				bus_start <= data_start;
				bus_write <= data_write;
			end
		endcase
	end

	initial begin
		master = INSN;
		bus_start = 0;
		bus_write = 0;
	end

endmodule