Example #1
0
    def onWriteCmd(self, cmd):
        rsp = Transaction()
        rsp.hid = cmd.hid
        if cmd.addr < (1 << 14):
            rsp.resp = 0
        else:
            rsp.resp = 3

        self.writeRspScoreboard.refPush(rsp, cmd.hid)
Example #2
0
    def onWriteCmd(self,cmd):
        rsp = Transaction()
        rsp.hid = cmd.hid
        if cmd.addr < (1 << 14):
            rsp.resp = 0
        else:
            rsp.resp = 3

        self.writeRspScoreboard.refPush(rsp, cmd.hid)
Example #3
0
    def onReadCmd(self, cmd):
        for i in xrange(cmd.len + 1):
            rsp = Transaction()
            rsp.hid = cmd.hid
            if cmd.addr < (1 << 14):
                rsp.data = cmd.addr + i
                rsp.resp = 0
            else:
                rsp.data = 0
                rsp.resp = 3

            rsp.last = 1 if i == cmd.len else 0
            self.readRspScoreboard.refPush(rsp, cmd.hid)
Example #4
0
    def onReadCmd(self,cmd):
        for i in xrange(cmd.len + 1):
            rsp = Transaction()
            rsp.hid = cmd.hid
            if cmd.addr < (1 << 14):
                rsp.data = cmd.addr + i
                rsp.resp = 0
            else:
                rsp.data = 0
                rsp.resp = 3

            rsp.last = 1 if i == cmd.len else 0
            self.readRspScoreboard.refPush(rsp, cmd.hid)
Example #5
0
    def genWriteRsp(self):
        if len(self.writeCmds) != 0:
            if not self.writeRspIdleRand.get():
                return None
            cmd = self.writeCmds[0]
            beatCount = cmd.len + 1
            if len(self.writeDatas) >= beatCount:
                datas = self.writeDatas[0:beatCount - 1]

                #Check it
                masterWrite = next(write
                                   for write in self.idToWrites[cmd.hid & 0xF]
                                   if write.addr >> 10 == self.hid)
                assertEquals(cmd.addr, masterWrite.addr, "write cmd missmatch")
                assertEquals(cmd.len, masterWrite.len, "write cmd missmatch")
                for data, dataRef in zip(datas, masterWrite.linkedDatas):
                    assertEquals(data.data, dataRef.data,
                                 "write data missmatch")

                #Clean
                self.writeCmds = self.writeCmds[1:]
                self.writeDatas = self.writeDatas[beatCount:]
                self.idToWrites[cmd.hid & 0xF].remove(masterWrite)

                #Answer
                trans = Transaction()
                trans.hid = cmd.hid
                trans.resp = 0
                return trans
        return None
Example #6
0
 def onReadCmd(self,trans):
     if trans.addr < self.base or trans.addr >= self.base + self.size:
         raise TestFailure("WRONG ADDRESS addr=%d base=%d size=%d" %(trans.addr,self.base,self.size))
     for i in xrange(trans.len+1):
         rsp = Transaction()
         rsp.data = trans.addr + i
         rsp.resp = 0
         rsp.hid = trans.hid
         if i == trans.len:
             rsp.last = 1
         else:
             rsp.last = 0
         queue = self.readRspQueues[trans.hid]
         if queue.empty():
             self.nonEmptyReadRspQueues.append(queue)
         queue.put(rsp)
Example #7
0
 def genReadRsp(self):
     tasksQueue = self.getRandTaskList()
     if tasksQueue:
         if self.readRspIdleRand.get():
             task = tasksQueue.queue[0]
             trans = Transaction()
             trans.data = task.addr + task.progress
             trans.resp = 0
             trans.hid = task.hid
             task.progress += 1
             if task.progress == task.len + 1:
                 trans.last = 1
                 tasksQueue.get()
             else:
                 trans.last = 0
             return trans
Example #8
0
 def onReadCmd(self, trans):
     if trans.addr < self.base or trans.addr >= self.base + self.size:
         raise TestFailure("WRONG ADDRESS addr=%d base=%d size=%d" %
                           (trans.addr, self.base, self.size))
     for i in range(trans.len + 1):
         rsp = Transaction()
         rsp.data = trans.addr + i
         rsp.resp = 0
         rsp.hid = trans.hid
         if i == trans.len:
             rsp.last = 1
         else:
             rsp.last = 0
         queue = self.readRspQueues[trans.hid]
         if queue.empty():
             self.nonEmptyReadRspQueues.append(queue)
         queue.put(rsp)
Example #9
0
    def managePendingWrites(self):
        if len(self.writeCmds) != 0:
            cmd = self.writeCmds[0]
            beatCount = cmd.len + 1
            if len(self.writeDatas) >= beatCount:
                datas = self.writeDatas[0:beatCount - 1]

                # Clean
                self.writeCmds = self.writeCmds[1:]
                self.writeDatas = self.writeDatas[beatCount:]

                # Rsp
                rsp = Transaction()
                rsp.hid = cmd.hid
                rsp.resp = 0

                queue = self.writeRspQueues[cmd.hid]
                if queue.empty():
                    self.nonEmptyWriteRspQueues.append(queue)
                queue.put(rsp)
Example #10
0
    def managePendingWrites(self):
        if len(self.writeCmds) != 0:
            cmd = self.writeCmds[0]
            beatCount = cmd.len + 1
            if len(self.writeDatas) >= beatCount:
                datas = self.writeDatas[0:beatCount - 1]

                # Clean
                self.writeCmds = self.writeCmds[1:]
                self.writeDatas = self.writeDatas[beatCount:]

                # Rsp
                rsp = Transaction()
                rsp.hid = cmd.hid
                rsp.resp = 0

                queue = self.writeRspQueues[cmd.hid]
                if queue.empty():
                    self.nonEmptyWriteRspQueues.append(queue)
                queue.put(rsp)
Example #11
0
    def genNewCmd(self):
        cmd = Transaction()
        cmd.hid = randBits(self.idWidth)  # Each master can use 4 id
        cmd.region = randBits(4)
        cmd.len = randBits(4)
        cmd.size = random.randint(0, self.maxDataBytes)
        cmd.burst = random.randint(0, 2)
        if cmd.burst == 2:
            cmd.len = random.choice([2, 4, 8, 16]) - 1
        else:
            cmd.len = randBits(4) + (16 if random.random() < 0.1 else
                                     0) + (32 if random.random() < 0.02 else 0)
        cmd.lock = randBits(1)
        cmd.cache = randBits(4)
        cmd.qos = randBits(4)
        cmd.prot = randBits(3)

        byteCount = (1 << cmd.size) * (cmd.len + 1)
        while (True):
            cmd.addr = self.genRandomeAddress() & ~((1 << cmd.size) - 1)
            if cmd.burst == 1:
                if cmd.addr + byteCount >= (1 << self.addressWidth):
                    continue
            if cmd.burst == 0:
                start = cmd.addr
                end = start + cmd.size

            if cmd.burst == 1:
                start = cmd.addr
                end = start + byteCount

            if cmd.burst == 2:
                start = cmd.addr & ~(byteCount - 1)
                end = start + byteCount

            if self.isAddressRangeBusy(start, end):
                continue
            break

        if self.readWriteRand.get():
            cmd.write = 1
            beatAddr = cmd.addr
            for i in range(cmd.len + 1):
                dataTrans = Transaction()
                dataTrans.data = randBits(self.dataWidth)
                dataTrans.strb = randBits(self.maxDataBytes)
                dataTrans.last = 1 if cmd.len == i else 0
                self.writeTasks.put(dataTrans)

                for s in range(self.maxDataBytes):
                    if (dataTrans.strb >> s) & 1 == 1:
                        self.ram[(beatAddr & ~(self.maxDataBytes - 1)) +
                                 s] = (dataTrans.data >> (s * 8)) & 0xFF
                beatAddr = Axi4AddrIncr(beatAddr, cmd.burst, cmd.len, cmd.size)

            writeRsp = Transaction()
            writeRsp.resp = 0
            writeRsp.hid = cmd.hid

            self.reservedAddresses[writeRsp] = [start, end]
            self.writeRspScoreboard.refPush(writeRsp, writeRsp.hid)
        else:
            cmd.write = 0

            beatAddr = cmd.addr
            for s in range(cmd.len + 1):
                readRsp = Transaction()
                addrBase = beatAddr & ~(self.maxDataBytes - 1)
                readRsp.data = 0
                for i in range(self.maxDataBytes):
                    readRsp.data |= self.ram[addrBase + i] << (i * 8)
                readRsp.resp = 0
                readRsp.last = 1 if cmd.len == s else 0
                readRsp.hid = cmd.hid
                if readRsp.last == 1:
                    self.reservedAddresses[readRsp] = [start, end]
                self.readRspScoreboard.refPush(readRsp, readRsp.hid)
                beatAddr = Axi4AddrIncr(beatAddr, cmd.burst, cmd.len, cmd.size)

        self.cmdTasks.put(cmd)