25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3KB

  1. package Core
  2. import chisel3._
  3. import chisel3.core.Input
  4. import chisel3.util.Counter
  5. /**
  6. DaisyVectors are not indexed. They have no control inputs or outputs, only data.
  7. */
  8. class daisyDot(elements: Int, dataWidth: Int) extends Module{
  9. val io = IO(new Bundle {
  10. val dataInA = Input(UInt(dataWidth.W))
  11. val dataInB = Input(UInt(dataWidth.W))
  12. val dataOut = Output(UInt(dataWidth.W))
  13. val outputValid = Output(Bool())
  14. })
  15. /**
  16. Keep track of how many elements have been accumulated. As the interface has no
  17. indicator that data can be invalid it should always be assumed that data IS valid.
  18. This in turn means that the counter should tick on every cycle
  19. */
  20. val counter = Counter(elements)
  21. val accumulator = RegInit(UInt(dataWidth.W), 0.U)
  22. /**
  23. Your implementation here
  24. */
  25. // Increment the value of the accumulator with the product of data in A and B
  26. // When the counter reaches elements set output valid to true and flush the accumulator
  27. /**
  28. LF
  29. */
  30. val product = io.dataInA * io.dataInB
  31. when(counter.inc()){
  32. io.outputValid := true.B
  33. accumulator := 0.U
  34. }.otherwise{
  35. io.outputValid := false.B
  36. accumulator := accumulator + product
  37. }
  38. io.dataOut := accumulator + product
  39. }