Skip to content

Commit e272885

Browse files
authored
Merge pull request #6 from Kev-J/fix-err-management
Fix err line management
2 parents b3726a9 + 5274cac commit e272885

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/main/scala/wbplumbing/wbplumbing.scala

+10-6
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,22 @@ class WbInterconOneMaster(val awbm: WbMaster,
105105
wbs.cyc_i := io.wbm.cyc_o
106106
io.wbm.dat_i := wbs.dat_o
107107
io.wbm.ack_i := wbs.ack_o
108-
if (wbs.feature_err) {
108+
if (io.wbm.feature_err && wbs.feature_err) {
109109
io.wbm.err_i.get := wbs.err_o.get
110110
}
111-
}.otherwise {
112-
if (io.wbm.feature_err) {
113-
io.wbm.err_i.get := true.B
114-
}
115111
}
116112
}
117-
118113
}
114+
119115
val masterAddrMax = 1 << io.wbm.awidth
120116
assert(addrSlave.last <= masterAddrMax,
121117
f"Not enouth address space available for all slaves (0x$masterAddrMax%X)")
118+
119+
if (io.wbm.feature_err && (addrSlave.last < masterAddrMax)) {
120+
when(io.wbm.stb_o === true.B && io.wbm.cyc_o === true.B){
121+
when (io.wbm.adr_o >= addrSlave.last.U) {
122+
io.wbm.err_i.get := true.B
123+
}
124+
}
125+
}
122126
}

src/test/scala/wbplumbing/testwbplumbing.scala

+25-7
Original file line numberDiff line numberDiff line change
@@ -104,38 +104,48 @@ class WbInterconOneMasterSpec extends AnyFlatSpec with Matchers {
104104

105105
it should "raise the err_i line of the master if read address is unmapped" in {
106106
val dataWidth = 16
107-
val wbm = new WbMaster(dataWidth, 3, "Spi2WbMaster", feature_err=true)
107+
val wbm = new WbMaster(dataWidth, 7, "Spi2WbMaster", feature_err=true)
108108
val wbs1 = new WbSlave(dataWidth, 2, "Ksz1")
109+
val wbs2 = new WbSlave(dataWidth, 2, "Ksz2")
109110

110-
simulate(new WbInterconOneMaster(wbm, Seq(wbs1))) { dut =>
111+
simulate(new WbInterconOneMaster(wbm, Seq(wbs1, wbs2))) { dut =>
111112
dut.io.wbm.err_i.get.expect(false.B, "bad init of err_i")
112113

113114
// Read on unmapped address
114-
dut.io.wbm.adr_o.poke(0x4)
115+
dut.io.wbm.adr_o.poke(0x8)
115116
dut.io.wbm.we_o.poke(false.B)
116117
dut.io.wbm.cyc_o.poke(true.B)
117118
dut.io.wbm.stb_o.poke(true.B)
118119
dut.clock.step(1)
119-
dut.io.wbm.err_i.get.expect(true.B, "err_i not raised")
120+
dut.io.wbm.err_i.get.expect(true.B, "err_i not raised on unmapped address read")
120121

121122
// Stop transaction
122123
dut.io.wbm.cyc_o.poke(false.B)
123124
dut.io.wbm.stb_o.poke(false.B)
124125
dut.clock.step(1)
125126
dut.io.wbm.err_i.get.expect(false.B, "err_i not resetted correctly")
127+
128+
// Read on mapped address
129+
dut.io.wbm.adr_o.poke(0x0)
130+
dut.io.wbm.we_o.poke(false.B)
131+
dut.io.wbm.cyc_o.poke(true.B)
132+
dut.io.wbm.stb_o.poke(true.B)
133+
dut.clock.step(1)
134+
dut.io.wbm.err_i.get.expect(false.B, "err_i raised on mapped address read")
126135
}
127136
}
128137

129138
it should "raise the err_i line of the master if write address is unmapped" in {
130139
val dataWidth = 16
131-
val wbm = new WbMaster(dataWidth, 3, "Spi2WbMaster", feature_err=true)
140+
val wbm = new WbMaster(dataWidth, 7, "Spi2WbMaster", feature_err=true)
132141
val wbs1 = new WbSlave(dataWidth, 2, "Ksz1")
142+
val wbs2 = new WbSlave(dataWidth, 2, "Ksz2")
133143

134-
simulate(new WbInterconOneMaster(wbm, Seq(wbs1))) { dut =>
144+
simulate(new WbInterconOneMaster(wbm, Seq(wbs1, wbs2))) { dut =>
135145
dut.io.wbm.err_i.get.expect(false.B, "bad init of err_i")
136146

137147
// Write on unmapped address
138-
dut.io.wbm.adr_o.poke(0x4)
148+
dut.io.wbm.adr_o.poke(0x8)
139149
dut.io.wbm.we_o.poke(true.B)
140150
dut.io.wbm.cyc_o.poke(true.B)
141151
dut.io.wbm.stb_o.poke(true.B)
@@ -148,6 +158,14 @@ class WbInterconOneMasterSpec extends AnyFlatSpec with Matchers {
148158
dut.io.wbm.stb_o.poke(false.B)
149159
dut.clock.step(1)
150160
dut.io.wbm.err_i.get.expect(false.B, "err_i not resetted correctly")
161+
162+
// Write on mapped address
163+
dut.io.wbm.adr_o.poke(0x0)
164+
dut.io.wbm.we_o.poke(true.B)
165+
dut.io.wbm.cyc_o.poke(true.B)
166+
dut.io.wbm.stb_o.poke(true.B)
167+
dut.clock.step(1)
168+
dut.io.wbm.err_i.get.expect(false.B, "err_i raised on mapped address write")
151169
}
152170
}
153171

0 commit comments

Comments
 (0)