Skip to content

Commit e5afb9f

Browse files
author
schelten
committed
address review
1 parent 5cc13b7 commit e5afb9f

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lib/src/main/scala/spinal/lib/bus/amba4/axi/sim/Axi4Master.scala

+19-16
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ case class Axi4Master(axi: Axi4, clockDomain: ClockDomain, name: String = "unnam
249249
case _ => data.take(bytes)
250250
}
251251
val remaining = data.drop(slice.length)
252-
writeSingle(addr, slice, id, burst, len, size)(handleTransaction(addr, transactionId, remaining))
252+
val thisLen = if (remaining.length == 0) {
253+
((slice.length / bytePerBeat.toFloat).ceil.toInt - 1) min len
254+
} else {
255+
len
256+
}
257+
writeSingle(addr, slice, id, burst, thisLen, size)(handleTransaction(addr, transactionId, remaining))
253258
}
254259

255260
def handleTransaction(addr: BigInt, transactionId: Int, remaining: List[Byte])() = {
@@ -273,40 +278,38 @@ case class Axi4Master(axi: Axi4, clockDomain: ClockDomain, name: String = "unnam
273278
}
274279
assert(len <= 255, s"max burst in one transaction is 256")
275280
val bytePerBeat = 1 << size
276-
val actualLen = ((data.length / bytePerBeat.toFloat).ceil.toInt - 1) min len
277-
val bytes = (actualLen + 1) * bytePerBeat
281+
val bytes = (len + 1) * bytePerBeat
278282
val bytePerBus = 1 << log2Up(busConfig.dataWidth / 8)
279283

280284
val (roundedAddress, padFront, padBack, paddedData) = padData(address, data)
281-
assert(
282-
paddedData.length <= bytes,
283-
s"requested length ${data.length} (${paddedData.length} with padding) could not be completed in one transaction"
284-
)
285+
assert(data.length <= (len + 1) * bytePerBeat, "data is too long and cannot be sent in one transaction")
286+
assert(data.length >= len * bytePerBeat, f"data is too short (${data.length}) for len=$len (would result in erroneous zero transfers)")
287+
assert(paddedData.length <= bytes, s"requested length ${data.length} (${paddedData.length} with padding) could not be completed in one transaction")
285288

286289
awQueue += { aw =>
287290
aw.addr #= roundedAddress
288291
if (busConfig.useId) aw.id #= id
289-
if (busConfig.useLen) aw.len #= actualLen
292+
if (busConfig.useLen) aw.len #= len
290293
if (busConfig.useSize) aw.size #= size
291294
if (busConfig.useBurst) aw.burst #= burst.id
292-
log("AW", f"addr $roundedAddress%#x size $size len $actualLen burst $burst")
295+
log("AW", f"addr $roundedAddress%#x size $size len $len burst $burst")
293296

294-
for (beat <- 0 to actualLen) {
297+
for (beat <- 0 to len) {
295298
wQueue += { w =>
296299
val data = paddedData.slice(beat * bytePerBeat, (beat + 1) * bytePerBeat)
297300
w.data #= data.toArray
298301
val fullStrb = (BigInt(1) << bytePerBeat) - 1
299-
val strb = (if (actualLen == 0) {
302+
val strb = (if (len == 0) {
300303
((BigInt(1) << data.length) - 1) << padFront
301304
} else
302305
beat match {
303-
case 0 => fullStrb << padFront
304-
case `actualLen` => fullStrb >> padBack
305-
case _ => fullStrb
306+
case 0 => fullStrb << padFront
307+
case `len` => fullStrb >> padBack
308+
case _ => fullStrb
306309
}) & fullStrb
307310
if (busConfig.useStrb) w.strb #= strb
308-
if (busConfig.useLast) w.last #= beat == actualLen
309-
log("W", f"data ${data.reverse.bytesToHex} strb $strb%#x last ${beat == actualLen}")
311+
if (busConfig.useLast) w.last #= beat == len
312+
log("W", f"data ${data.reverse.bytesToHex} strb $strb%#x last ${beat == len}")
310313
}
311314
}
312315

0 commit comments

Comments
 (0)