@@ -11,14 +11,14 @@ class CPUSingleCycle(
11
11
bitWidth : Int = 32 ,
12
12
instructionMemorySize : Int = 1 * 1024 ,
13
13
dataMemorySize : Int = 1 * 1024 ,
14
- memoryFile : String = " " ,
15
- ramFile : String = " " ,
16
14
numGPIO : Int = 8 ,
17
15
) extends Module {
18
16
val io = IO (new Bundle {
19
- val led0 = Output (Bool ()) // LED 0 is the heartbeat
20
- val GPIO0External = Analog (numGPIO.W ) // GPIO external port
21
- val UART0SerialPort = new UARTSerialPort () // UART0 serial port
17
+ val GPIO0External = Analog (numGPIO.W ) // GPIO external port
18
+
19
+ val UART0Port = Flipped (new UARTPort ()) // UART0 data port
20
+ val instructionMemPort = Flipped (new InstructionMemPort (bitWidth, instructionMemorySize))
21
+ val dataMemPort = Flipped (new MemoryPortDual (bitWidth, dataMemorySize))
22
22
})
23
23
24
24
val stall = WireDefault (false .B )
@@ -49,32 +49,13 @@ class CPUSingleCycle(
49
49
val decoder = Module (new Decoder (bitWidth))
50
50
decoder.io.DecoderPort .op := 0 .U
51
51
52
- // Instantiate and initialize the Instruction memory
53
- val instructionMemory = Module (new InstructionMemory (bitWidth, instructionMemorySize, memoryFile))
54
- instructionMemory.io.memPort.readAddr := 0 .U
55
-
56
- // Instantiate and initialize the Data memory
57
- val dataMemory = Module (new DualPortRAM (bitWidth, dataMemorySize, ramFile))
58
- dataMemory.io.dualPort.writeEnable := false .B
59
- dataMemory.io.dualPort.writeData := 0 .U
60
- dataMemory.io.dualPort.readAddress := 0 .U
61
- dataMemory.io.dualPort.writeAddress := 0 .U
62
- dataMemory.io.dualPort.dataSize := 0 .U
63
- dataMemory.io.dualPort.writeMask := 0 .U
64
-
65
52
// Instantiate and connect GPIO
66
53
val GPIO0 = Module (new GPIO (bitWidth, numGPIO))
67
54
GPIO0 .io.externalPort <> io.GPIO0External
68
55
69
56
// Instantiate and connect the Timer
70
57
val timer0 = Module (new Timer (bitWidth, cpuFrequency))
71
58
72
- // Instantiate and connect the UART
73
- val fifoLength = 128
74
- val rxOverclock = 16
75
- val UART0 = Module (new Uart (fifoLength, rxOverclock))
76
- UART0 .io.serialPort <> io.UART0SerialPort
77
-
78
59
// Instantiate and initialize the Memory IO Manager
79
60
val memoryIOManager = Module (new MemoryIOManager (bitWidth, cpuFrequency, dataMemorySize))
80
61
memoryIOManager.io.MemoryIOPort .readRequest := false .B
@@ -86,10 +67,10 @@ class CPUSingleCycle(
86
67
memoryIOManager.io.MemoryIOPort .writeMask := 0 .U
87
68
88
69
// Connect MMIO to the devices
89
- memoryIOManager.io.DataMemPort <> dataMemory.io.dualPort
90
70
memoryIOManager.io.GPIO0Port <> GPIO0 .io.GPIOPort
91
- memoryIOManager.io.UART0Port <> UART0 .io.dataPort
92
71
memoryIOManager.io.Timer0Port <> timer0.io.timerPort
72
+ memoryIOManager.io.DataMemPort <> io.dataMemPort
73
+ memoryIOManager.io.UART0Port <> io.UART0Port
93
74
94
75
// --------------- CPU Control --------------- //
95
76
@@ -102,10 +83,10 @@ class CPUSingleCycle(
102
83
}
103
84
104
85
// Connect PC output to instruction memory
105
- instructionMemory. io.memPort .readAddr := PC .io.pcPort.PC
86
+ io.instructionMemPort .readAddr := PC .io.pcPort.PC
106
87
107
88
// Connect the instruction memory to the decoder
108
- decoder.io.DecoderPort .op := instructionMemory. io.memPort .readData
89
+ decoder.io.DecoderPort .op := io.instructionMemPort .readData
109
90
110
91
// Connect the decoder output to register bank inputs
111
92
registerBank.io.regPort.regwr_addr := decoder.io.DecoderPort .rd
@@ -143,7 +124,7 @@ class CPUSingleCycle(
143
124
when(ALU .io.ALUPort .x === 1 .U ) {
144
125
PC .io.pcPort.writeEnable := true .B
145
126
PC .io.pcPort.writeAdd := true .B
146
- PC .io.pcPort.dataIn := decoder.io.DecoderPort .imm
127
+ PC .io.pcPort.dataIn := decoder.io.DecoderPort .imm.asUInt()
147
128
}
148
129
}
149
130
@@ -161,12 +142,12 @@ class CPUSingleCycle(
161
142
when(decoder.io.DecoderPort .inst === JAL ) {
162
143
// Set PC to jump address
163
144
PC .io.pcPort.writeAdd := true .B
164
- PC .io.pcPort.dataIn := decoder.io.DecoderPort .imm
145
+ PC .io.pcPort.dataIn := decoder.io.DecoderPort .imm.asUInt()
165
146
}
166
147
when(decoder.io.DecoderPort .inst === JALR ) {
167
148
// Set PC to jump address
168
149
PC .io.pcPort.dataIn := Cat (
169
- (registerBank.io.regPort.rs1 + decoder.io.DecoderPort .imm.asSInt ).asUInt()(31 , 1 ),
150
+ (registerBank.io.regPort.rs1 + decoder.io.DecoderPort .imm).asUInt()(31 , 1 ),
170
151
0 .U ,
171
152
)
172
153
}
@@ -175,18 +156,16 @@ class CPUSingleCycle(
175
156
// LUI
176
157
when(decoder.io.DecoderPort .inst === LUI ) {
177
158
registerBank.io.regPort.writeEnable := true .B
178
- registerBank.io.regPort.regwr_data := Cat ( decoder.io.DecoderPort .imm( 31 , 12 ), Fill ( 12 , 0 . U )).asSInt
159
+ registerBank.io.regPort.regwr_data := decoder.io.DecoderPort .imm
179
160
}
180
161
181
162
// AUIPC
182
163
when(decoder.io.DecoderPort .inst === AUIPC ) {
183
164
registerBank.io.regPort.writeEnable := true .B
184
165
ALU .io.ALUPort .inst := ADD
185
166
ALU .io.ALUPort .a := PC .io.pcPort.PC
186
- ALU .io.ALUPort .b := Cat (
187
- decoder.io.DecoderPort .imm(31 , 12 ),
188
- Fill (12 , 0 .U ),
189
- )
167
+ ALU .io.ALUPort .b :=
168
+ decoder.io.DecoderPort .imm.asUInt()
190
169
registerBank.io.regPort.regwr_data := ALU .io.ALUPort .x.asSInt
191
170
}
192
171
@@ -195,7 +174,7 @@ class CPUSingleCycle(
195
174
// Use the ALU to get the resulting address
196
175
ALU .io.ALUPort .inst := ADD
197
176
ALU .io.ALUPort .a := registerBank.io.regPort.rs1.asUInt
198
- ALU .io.ALUPort .b := decoder.io.DecoderPort .imm
177
+ ALU .io.ALUPort .b := decoder.io.DecoderPort .imm.asUInt()
199
178
200
179
memoryIOManager.io.MemoryIOPort .writeAddr := ALU .io.ALUPort .x
201
180
memoryIOManager.io.MemoryIOPort .readAddr := ALU .io.ALUPort .x
0 commit comments