Skip to content
Snippets Groups Projects
Select Git revision
  • master
1 result

fp-info-cache

Blame
  • adp_cocotb_driver.py 2.80 KiB
    #-----------------------------------------------------------------------------
    # SoCLabs ADP Cocotb Drivers
    # Contributors
    #
    # David Mapstone (d.a.mapstone@soton.ac.uk)
    #
    # Copyright 2021-3, SoC Labs (www.soclabs.org)
    #-----------------------------------------------------------------------------
    import cocotb
    import os
    
    # Class for ADP AXI Stream Interface
    class ADP():
        def __init__(self, dut, send, recieve):
            self.dut      = dut
            # Send Stream to NanoSoC
            self.send    = send
            # Send Recieve to NanoSoC
            self.recieve = recieve
            self.monitor_mode = False
        
        # Read Block from ADP
        @cocotb.coroutine
        async def read(self, length):
            read_str = ""
            for i in range(length):
                data = await self.recieve.read()
                read_str += chr(data[0])
            return read_str  
                    
        # Read ADP String
        @cocotb.coroutine
        async def readLine(self):
            read_str = ""
            while True:
                # Read Bytes from ADP AXI Stream
                data = await self.recieve.read()
                curr_char = chr(data[0])
                # Combine Bytes into String
                if (curr_char != '\n'):
                    read_str += curr_char
                else:
                    return read_str.strip()
                                  
        # Write ADP String
        @cocotb.coroutine
        async def write8(self, val):
            await self.send.write([val])
            
        # Write ADP String
        @cocotb.coroutine
        async def write(self, string):
            for i in string:      
                await self.send.write([ord(i)])
            await self.send.write([0x0a])
            read_str = await self.readLine()
            self.dut.log.info(read_str)
        
        # Enter Monitor Mode
        @cocotb.coroutine
        async def monitorModeEnter(self):
            self.dut.log.info("Entering ADP Monitor Mode")
            await self.send.write([0x1b])
            self.monitor_mode = True
            
        # Exit Monitor Mode
        @cocotb.coroutine
        async def monitorModeExit(self):
            self.dut.log.info("Exiting ADP Monitor Mode")
            await self.send.write([0x04])
            self.monitor_mode = False
        
        # Write Hex File into System
        @cocotb.coroutine
        async def writeHex(self, file_name, address=0x20000000):
            self.dut.log.info(f"Writing {file_name} to {hex(address)}")
            file_stats = os.stat(file_name)
            file_len_in_bytes = round(file_stats.st_size/3)
            bytecount_hex=hex(file_len_in_bytes)
            await self.write(f'A {str(hex(address))}\n')
            await self.write(f'U {str(bytecount_hex)}\n')
            count = file_len_in_bytes
            with open(file_name, mode='r') as file:
                for i in range(count) :
                    b=file.readline()
                    await self.write8(int(str.strip(b),16))
            await self.write8(0x0a)
            self.dut.log.info("Finished Send Code")