DataMemory.scala 785 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
package uk.ac.soton.ecs.can.core

import chisel3._
Minyong Li's avatar
Minyong Li committed
7
import chisel3.util.log2Ceil
8
import uk.ac.soton.ecs.can.types._
Minyong Li's avatar
Minyong Li committed
9
10
11
12
import uk.ac.soton.ecs.can.config.CanCoreConfiguration

class DataMemory(implicit cfg: CanCoreConfiguration) extends MultiIOModule {
  private val addrWidth = log2Ceil(cfg.dataMemoryWords)
Minyong Li's avatar
Minyong Li committed
13

14
15
  val read = IO(new MemoryReadIO(addrWidth, 512))
  val write = IO(new MemoryWriteIO(addrWidth, 512))
Minyong Li's avatar
Minyong Li committed
16

17
  private val mem =
Minyong Li's avatar
Minyong Li committed
18
19
20
21
    if (cfg.syncReadMemory)
      SyncReadMem(cfg.dataMemoryWords, UInt(512.W))
    else
      Mem(cfg.dataMemoryWords, UInt(512.W))
Minyong Li's avatar
Minyong Li committed
22

23
24
25
  when(read.en) {
    read.data := mem(read.addr)
  }
Minyong Li's avatar
Minyong Li committed
26

27
28
  when(write.en) {
    mem(write.addr) := write.data
Minyong Li's avatar
Minyong Li committed
29
30
  }
}