API/Pseudo Code - 2021.2 English

Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393)

Document ID
UG1393
ft:locale
English (United States)
Release Date
2021-12-15
Version
2021.2 English

For API/pseudo code, a single instance of AXI4 memory map transaction is used for the complete transaction. This is in line with how payload is used in the Xilinx SystemC modules. For AXI4 Master, there is a b_transport(aximm_packet) API. After the call, aximm_packet is updated with a response given by AXI4 Slave. For AXI4 Slave, there are sample_transaction() and send_response(aximm_packet) APIs.

The following code snippets show the API usage in the context of C++.

  • Code snippet for C++ Master:
    auto payload = generate_random_transaction(); //Custom Random transaction generator. Users can configure AXI propeties on the payload.
    /* Or User can set the AXI transaction properties as follows
    payload->set_addr(std::rand() * 4);
    payload->set_len(1 + (std::rand() % 255));
    payload->set_size(1 << (std::rand() % 3));
    */
     
    master_uti.b_transport(*payload.get(), std::rand() % 0x10); //A blocking call. Response will be updated in the same payload. Each AXI MM transaction will use same payload for whole transaction
    std::cout << "-----------Transaction Response------------" << std::endl;
    std::cout << *payload << std::endl; //Prints AXI transaction info
  • Code snippet for C++ Slave:
    auto& payload = slave_util.sample_transaction(); // Sample the transaction
     
    //If it is read transaction, give read data
    if(payload.cmd() == xtlm_ipc::aximm_packet_command_READ)
    {
        rd_resp.resize(payload.len()*payload.size());
        std::generate(rd_resp.begin(), rd_resp.end(), []()
        {   return std::rand()%0x100;});
    }
     
    //Set AXI response (for Read & Write)
    payload.set_resp(std::rand()%4);
    slave_util.send_response(payload); //Send the response to the master

The following code snippets show the API usage in the context of Python.

You need to set PYTHONPATH as follows:

  • For example, on C Shell:
    setenv PYTHONPATH $XILINX_VIVADO/data/emulation/hw_em/lib/python: $XILINX_VIVADO/data/emulation/ip_utils/xtlm_ipc/xtlm_ipc_v1_0/python
  • Code snippet of Python Master:
    aximm_payload = xtlm_ipc.aximm_packet()
    random_packet(aximm_payload) # Custom function to set AXI Properties randomly
    #Or user can set AXI properties as required
    #aximm_payload.addr = int(random.randint(0, 1000000)*4)
    #aximm_payload.len = random.randint(1, 64)
    #aximm_payload.size = 4
     
    master_util.b_transport(aximm_payload)
    #After this call aximm_payload will have updated response as set by the AXI Slave.
  • Code snippet of Python Slave:
    aximm_payload = slave_util.sample_transaction()
    aximm_payload.resp = random.randint(0,3)
    if not aximm_payload.cmd: #if it is a read transction set Random data
        tot_bytes = aximm_payload.len * aximm_payload.size
        for i in range(0, int(tot_bytes/SIZE_OF_EACH_DATA_IN_BYTES)):
            aximm_payload.data += bytes(bytearray(struct.pack(">I", random.randint(0,60000)))) # Binary data should be aligned with C struct
             
    slave_util.send_resp(aximm_payload)