DataMemory.scala 801 Bytes
Newer Older
1
2
3
// SPDX-FileCopyrightText: 2021 Minyong Li <ml10g20@soton.ac.uk>
// SPDX-License-Identifier: CERN-OHL-W-2.0

Minyong Li's avatar
Minyong Li committed
4
5
6
7
package uk.ac.soton.ecs.can.core

import chisel3._

8
9
10
11
class DataMemory(
    addrWidth: Int,
    dataWidth: Int,
    size: Int,
12
    syncMem: Boolean
13
) extends MultiIOModule {
14
15
16
17
18
19
20
21
22
  val read = IO(
    Vec(
      2,
      new Bundle {
        val addr = Input(UInt(addrWidth.W))
        val data = Output(UInt(dataWidth.W))
      }
    )
  )
23
24
25
26
  val write = IO(new Bundle {
    val en = Input(Bool())
    val addr = Input(UInt(addrWidth.W))
    val data = Input(UInt(dataWidth.W))
Minyong Li's avatar
Minyong Li committed
27
28
  })

29
  private val mem =
30
31
    if (syncMem) SyncReadMem(size, UInt(dataWidth.W))
    else Mem(size, UInt(dataWidth.W))
Minyong Li's avatar
Minyong Li committed
32

33
  read.foreach(p => p.data := mem(p.addr))
Minyong Li's avatar
Minyong Li committed
34

35
36
  when(write.en) {
    mem(write.addr) := write.data
Minyong Li's avatar
Minyong Li committed
37
38
  }
}