Writing Traffic Generators in C++ - 2024.1 English

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

Document ID
UG1393
Release Date
2024-07-03
Version
2024.1 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 AMD 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