LCOV - code coverage report
Current view: top level - uhallibs/test/apps - test-axi4l-if.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 66 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /**
       2              : 
       3              : Low-level ipbus-over-axi4lite test
       4              : 
       5              : Small test application to test low-level ipbus communication over axi4 lite using the
       6              : uhal::Axi4Lite::MappedFile and manually injecting read and write ipbus packets.
       7              : 
       8              : **/
       9              : #include <fcntl.h>
      10              : #include <sys/file.h>
      11              : #include <sys/mman.h>
      12              : #include <unistd.h>
      13              : 
      14              : #include <cstdint>
      15              : #include <cstring>
      16              : #include <iomanip>
      17              : #include <iostream>
      18              : #include <string>
      19              : #include <vector>
      20              : 
      21              : #include "uhal/ClientInterface.hpp"
      22              : #include "uhal/ProtocolIPbus.hpp"
      23              : #include "uhal/log/exception.hpp"
      24              : #include "uhal/log/log.hpp"
      25              : 
      26              : #include "uhallibs/ProtocolAxi4Lite.hpp"
      27              : 
      28              : int
      29            0 : main(int /* argc */, char const* /* argv[] */)
      30              : {
      31              :   /* code */
      32              : 
      33            0 :   std::string lBarFile = "/sys/bus/pci/devices/0000:41:00.0/resource0";
      34              : 
      35            0 :   std::cout << "Starting ipbus-axi4lite test on " << lBarFile << std::endl;
      36              : 
      37            0 :   uint32_t n_pages;
      38            0 :   uint32_t page_size;
      39            0 :   uint32_t next_write_index;
      40            0 :   uint32_t read_counts;
      41              : 
      42            0 :   uhallibs::Axi4Lite::MappedFile f(lBarFile, 0x40, PROT_WRITE);
      43              : 
      44            0 :   std::vector<uint32_t> lStats;
      45            0 :   f.open();
      46            0 :   f.lock();
      47              : 
      48              :   // Inject an ipbus read transation
      49              :   // Read the the status of the transport interface at address 0x0
      50            0 :   std::cout << "--- Stats ---" << std::endl;
      51            0 :   lStats.clear();
      52            0 :   f.read(0, 4, lStats);
      53              : 
      54            0 :   for (uint64_t i(0); i < lStats.size(); ++i) {
      55            0 :     std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << i << "   " << std::setw(8)
      56            0 :               << std::setfill('0') << lStats[i] << std::endl;
      57              :   }
      58              : 
      59            0 :   n_pages = lStats[0];
      60            0 :   page_size = lStats[1];
      61            0 :   next_write_index = lStats[2];
      62            0 :   read_counts = lStats[3];
      63              : 
      64            0 :   std::cout << "n_pages " << n_pages << std::endl;
      65            0 :   std::cout << "page_size " << page_size << std::endl;
      66            0 :   std::cout << "next_write_index " << next_write_index << std::endl;
      67            0 :   std::cout << "read_counts " << read_counts << std::endl;
      68            0 :   std::cout << "-------------" << std::endl;
      69            0 :   f.unlock();
      70            0 :   f.close();
      71              : 
      72              :   // Re-open the interface file
      73            0 :   uint32_t map_size = n_pages * page_size + 4;
      74            0 :   f.setLength(map_size);
      75            0 :   f.open();
      76            0 :   f.lock();
      77              : 
      78            0 :   uint64_t write_base = next_write_index * page_size;
      79            0 :   std::cout << "write base : 0x" << std::hex << std::setw(8) << std::setfill('0') << write_base << std::endl;
      80              : 
      81            0 :   std::vector<uint32_t> lWriteVal = { 0x00010002, 0x200001F0, 0x2001010F, 0x00000001 };
      82              : 
      83            0 :   for (uint64_t i(0); i < lWriteVal.size(); ++i) {
      84            0 :     std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << i + write_base << "   " << std::setw(8)
      85            0 :               << std::setfill('0') << lWriteVal[i] << std::endl;
      86              :   }
      87              : 
      88            0 :   f.write(write_base, lWriteVal);
      89              : 
      90              :   // Read back
      91            0 :   std::cout << "--- Stats ---" << std::endl;
      92            0 :   lStats.clear();
      93            0 :   f.read(0, 4, lStats);
      94              : 
      95            0 :   for (uint64_t i(0); i < lStats.size(); ++i) {
      96            0 :     std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << i << "   " << std::setw(8)
      97            0 :               << std::setfill('0') << lStats[i] << std::endl;
      98              :   }
      99              : 
     100            0 :   n_pages = lStats[0];
     101            0 :   page_size = lStats[1];
     102            0 :   next_write_index = lStats[2];
     103            0 :   read_counts = lStats[3];
     104              : 
     105            0 :   std::cout << "n_pages " << n_pages << std::endl;
     106            0 :   std::cout << "page_size " << page_size << std::endl;
     107            0 :   std::cout << "next_write_index " << next_write_index << std::endl;
     108            0 :   std::cout << "read_counts " << read_counts << std::endl;
     109            0 :   std::cout << "-------------" << std::endl;
     110              : 
     111            0 :   const size_t next_read_index = (next_write_index - 1 + n_pages) % n_pages;
     112            0 :   const size_t read_base = 4 + (next_read_index * page_size);
     113            0 :   std::cout << "read base : 0x" << std::hex << std::setw(8) << std::setfill('0') << read_base << std::endl;
     114              : 
     115            0 :   std::vector<uint32_t> lReadVal;
     116            0 :   f.read(read_base, 8, lReadVal);
     117              : 
     118            0 :   for (uint64_t i(0); i < lReadVal.size(); ++i) {
     119            0 :     std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << i + read_base << "   " << std::setw(8)
     120            0 :               << std::setfill('0') << lReadVal[i] << std::endl;
     121              :   }
     122              : 
     123            0 :   f.unlock();
     124            0 :   f.close();
     125              : 
     126            0 :   return 0;
     127            0 : }
        

Generated by: LCOV version 2.0-1