-
Notifications
You must be signed in to change notification settings - Fork 0
/
Otter_wrapper_TC_driver_v1_01.sv
132 lines (111 loc) · 4.12 KB
/
Otter_wrapper_TC_driver_v1_01.sv
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: Ratner Surf Designs
// Engineer: James Ratner
//
// Create Date: 03/08/2020 02:46:31 PM
// Design Name:
// Module Name: OTTER_Wrapper
// Project Name:
// Target Devices:
// Tool Versions:
// Description: Otter Wrapper for timer-counter reference design.
//
// Dependencies:
//
// Revision:
// Revision 1.00 - (03-08-2020) first released version; fully tested
// Revision 1.01 - (07-22-2022) fixed a few typos; added comments
//
// Additional Comments: modified/extended version of Exp 5 Otter Wrapper
// to include instantiation and connections for timer-counter module
//
//////////////////////////////////////////////////////////////////////////////////
module OTTER_Wrapper(
input clk,
input [4:0] buttons,
input [15:0] switches,
output logic [15:0] leds,
output logic [7:0] segs,
output logic [3:0] an );
//- INPUT PORT IDS ---------------------------------------------------------
localparam SWITCHES_PORT_ADDR = 32'h11008000; // 0x1100_8000
localparam BUTTONS_PORT_ADDR = 32'h11008004; // 0x1100_8004
//- timer-counter input support
localparam TMR_CNTR_CNT_OUT = 32'h11008008; // 0x1100_8004
//- OUTPUT PORT IDS --------------------------------------------------------
localparam LEDS_PORT_ADDR = 32'h1100C000; // 0x1100_C000
localparam SEGS_PORT_ADDR = 32'h1100C004; // 0x1100_C004
localparam ANODES_PORT_ADDR = 32'h1100C008; // 0x1100_C008
//- timer-counter output support
localparam TMR_CNTR_CSR_ADDR = 32'h1100D000; // 0x1100_D000
localparam TMR_CNTR_CNT_IN_ADDR = 32'h1100D004; // 0x1100_D004
//- Signals for connecting OTTER_MCU to OTTER_wrapper
logic s_interrupt;
logic s_reset;
logic s_clk = 0;
//- register for dev board output devices ---------------------------------
logic [7:0] r_segs; // register for segments (cathodes)
logic [15:0] r_leds; // register for LEDs
logic [3:0] r_an; // register for display enables (anodes)
logic [7:0] r_tc_csr; // timer-counter count input
logic [31:0] r_tc_cnt_in; // timer-counter count input
logic [31:0] IOBUS_out;
logic [31:0] IOBUS_in;
logic [31:0] IOBUS_addr;
logic IOBUS_wr;
logic [31:0] s_tc_cnt_out;
logic s_tc_intr;
assign s_interrupt = buttons[4];
assign s_reset = buttons[3];
//- Instantiate RISC-V OTTER MCU
OTTER_MCU my_otter(
.RST (s_reset),
.intr (s_tc_intr),
.clk (s_clk),
.iobus_in (IOBUS_in),
.iobus_out (IOBUS_out),
.iobus_addr (IOBUS_addr),
.iobus_wr (IOBUS_wr) );
// instantiate the timer-counter module
timer_counter #(.n(3)) my_tc (
.clk (s_clk),
.tc_cnt_in (r_tc_cnt_in),
.tc_csr (r_tc_csr),
.tc_intr (s_tc_intr),
.tc_cnt_out (s_tc_cnt_out) );
//- Divide clk by 2
always_ff @ (posedge clk)
s_clk <= ~s_clk;
//- Drive dev board output devices with registers
always_ff @ (posedge s_clk)
begin
if (IOBUS_wr == 1)
begin
case(IOBUS_addr)
LEDS_PORT_ADDR: r_leds <= IOBUS_out[15:0];
SEGS_PORT_ADDR: r_segs <= IOBUS_out[7:0];
ANODES_PORT_ADDR: r_an <= IOBUS_out[3:0];
TMR_CNTR_CSR_ADDR: r_tc_csr <= IOBUS_out[7:0];
TMR_CNTR_CNT_IN_ADDR: r_tc_cnt_in <= IOBUS_out[31:0];
default: r_leds <= 0;
endcase
end
end
//- MUX to route input devices to I/O Bus
//- IOBUS_addr is the select signal to the MUX
always_comb
begin
IOBUS_in=32'b0;
case(IOBUS_addr)
SWITCHES_PORT_ADDR: IOBUS_in[15:0] = switches;
BUTTONS_PORT_ADDR: IOBUS_in[4:0] = buttons;
TMR_CNTR_CNT_OUT: IOBUS_in[31:0] = s_tc_cnt_out;
default: IOBUS_in=32'b0;
endcase
end
//- assign registered outputs to actual outputs
assign leds = r_leds;
assign segs = r_segs;
assign an = r_an;
endmodule