Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

96 рядки
1.9KB

  1. package Ex0
  2. import chisel3._
  3. import chisel3.experimental._
  4. import chisel3.iotesters.PeekPokeTester
  5. import org.scalatest.{Matchers, FlatSpec}
  6. import TestUtils._
  7. import scala.collection.immutable.{ Vector => _ }
  8. class SVGSNestedSpec extends FlatSpec with Matchers {
  9. behavior of "SumOrSquare"
  10. it should "Make some sweet pngs" in {
  11. wrapTester(
  12. chisel3.iotesters.Driver(() => new SumOrSquare(5, 7)) { c =>
  13. new SumOrSquareTester(c)
  14. } should be(true)
  15. )
  16. }
  17. }
  18. class MyCounter(countTo: Int) extends MultiIOModule {
  19. val io = IO( new Bundle {
  20. val out = Output(UInt(32.W))
  21. })
  22. val debug = IO( new Bundle {
  23. val counterState = Output(UInt(32.W))
  24. })
  25. val reg_a = RegInit(0.U(8.W))
  26. val incremented = reg_a + 1.U
  27. when(incremented === countTo.U){
  28. reg_a := 0.U
  29. }.otherwise{
  30. reg_a := reg_a + 1.U
  31. }
  32. io.out := incremented
  33. debug.counterState := reg_a
  34. }
  35. class SumOrSquare(countToA: Int, countToB: Int) extends MultiIOModule {
  36. val io = IO( new Bundle {
  37. val out = Output(UInt(32.W))
  38. })
  39. val debug = IO( new Bundle {
  40. val counter_a = Output(UInt(32.W))
  41. val counter_b = Output(UInt(32.W))
  42. val square = Output(UInt(32.W))
  43. val sum = Output(UInt(32.W))
  44. })
  45. val counterA = Module(new MyCounter(countToA))
  46. val counterB = Module(new MyCounter(countToB))
  47. val sum = counterA.io.out + counterA.io.out
  48. val square = counterA.io.out * counterA.io.out
  49. when(counterB.io.out % 2.U === 0.U){
  50. io.out := sum
  51. }.otherwise{
  52. io.out := square
  53. }
  54. debug.counter_a := counterA.debug.counterState
  55. debug.counter_b := counterB.debug.counterState
  56. debug.square := square
  57. debug.sum := sum
  58. }
  59. class SumOrSquareTester(c: SumOrSquare) extends PeekPokeTesterLogger(c) {
  60. override def ioLoggers = List(
  61. "" -> c.debug,
  62. "" -> c.io
  63. )
  64. for(ii <- 0 until 10){
  65. step(1)
  66. }
  67. writeLog
  68. }