LCOV - code coverage report
Current view: top level - wibmod/src/WIB1 - AddressTable_IO.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 98 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 12 0

            Line data    Source code
       1              : #include "wibmod/WIB1/AddressTable.hh"
       2              : #include "wibmod/WIB1/AddressTableException.hh"
       3              : #include <boost/algorithm/string/case_conv.hpp> //to_upper
       4              : #include <boost/regex.hpp>                      //regex
       5              : #include <boost/tokenizer.hpp>                  //tokenizer
       6              : #include <fstream>
       7              : #include <stdlib.h> //strtoul & getenv
       8              : 
       9              : uint32_t
      10            0 : AddressTable::Read(uint16_t address)
      11              : {
      12            0 :   return io->Read(address);
      13              : }
      14              : uint32_t
      15            0 : AddressTable::ReadWithRetry(uint16_t address)
      16              : {
      17            0 :   return io->ReadWithRetry(address);
      18              : }
      19              : 
      20              : void
      21            0 : AddressTable::Write(uint16_t address, uint32_t data)
      22              : {
      23            0 :   io->Write(address, data);
      24            0 : }
      25              : void
      26            0 : AddressTable::WriteWithRetry(uint16_t address, uint32_t data)
      27              : {
      28            0 :   io->WriteWithRetry(address, data);
      29            0 : }
      30              : 
      31              : void
      32            0 : AddressTable::Write(uint16_t address, std::vector<uint32_t> const& values)
      33              : {
      34            0 :   io->Write(address, values);
      35            0 : }
      36              : void
      37            0 : AddressTable::Write(uint16_t address, uint32_t const* values, size_t word_count)
      38              : {
      39            0 :   io->Write(address, values, word_count);
      40            0 : }
      41              : 
      42              : uint32_t
      43            0 : AddressTable::Read(std::string registerName)
      44              : {
      45            0 :   std::map<std::string, Item*>::iterator itNameItem = nameItemMap.find(registerName);
      46            0 :   if (itNameItem == nameItemMap.end()) {
      47            0 :     BUException::INVALID_NAME e;
      48            0 :     e.Append("Can't find item with name \"");
      49            0 :     e.Append(registerName.c_str());
      50            0 :     e.Append("\"");
      51            0 :     throw e;
      52            0 :   }
      53            0 :   Item* item = itNameItem->second;
      54            0 :   uint32_t val = io->Read(item->address);
      55            0 :   val &= (item->mask);
      56            0 :   val >>= item->offset;
      57              : 
      58            0 :   return val;
      59              : }
      60              : 
      61              : uint32_t
      62            0 : AddressTable::ReadWithRetry(std::string registerName)
      63              : {
      64            0 :   std::map<std::string, Item*>::iterator itNameItem = nameItemMap.find(registerName);
      65            0 :   if (itNameItem == nameItemMap.end()) {
      66            0 :     BUException::INVALID_NAME e;
      67            0 :     e.Append("Can't find item with name \"");
      68            0 :     e.Append(registerName.c_str());
      69            0 :     e.Append("\"");
      70            0 :     throw e;
      71            0 :   }
      72            0 :   Item* item = itNameItem->second;
      73            0 :   uint32_t val = io->ReadWithRetry(item->address);
      74            0 :   val &= (item->mask);
      75            0 :   val >>= item->offset;
      76              : 
      77            0 :   return val;
      78              : }
      79              : 
      80              : void
      81            0 : AddressTable::Write(std::string registerName, uint32_t val)
      82              : {
      83            0 :   std::map<std::string, Item*>::iterator itNameItem = nameItemMap.find(registerName);
      84            0 :   if (itNameItem == nameItemMap.end()) {
      85            0 :     BUException::INVALID_NAME e;
      86            0 :     e.Append("Can't find item with name \"");
      87            0 :     e.Append(registerName.c_str());
      88            0 :     e.Append("\"");
      89            0 :     throw e;
      90            0 :   }
      91            0 :   Item* item = itNameItem->second;
      92              :   // Check if this entry controls all the bits
      93            0 :   uint32_t buildingVal = 0;
      94            0 :   if (item->mask != 0xFFFFFFFF) {
      95              :     // Since there are bits this register we don't control, we need to see what they currently are
      96            0 :     buildingVal = io->Read(item->address);
      97            0 :     buildingVal &= ~(item->mask);
      98              :   }
      99            0 :   buildingVal |= (item->mask & (val << item->offset));
     100            0 :   io->Write(item->address, buildingVal);
     101            0 : }
     102              : 
     103              : void
     104            0 : AddressTable::WriteWithRetry(std::string registerName, uint32_t val)
     105              : {
     106            0 :   std::map<std::string, Item*>::iterator itNameItem = nameItemMap.find(registerName);
     107            0 :   if (itNameItem == nameItemMap.end()) {
     108            0 :     BUException::INVALID_NAME e;
     109            0 :     e.Append("Can't find item with name \"");
     110            0 :     e.Append(registerName.c_str());
     111            0 :     e.Append("\"");
     112            0 :     throw e;
     113            0 :   }
     114            0 :   Item* item = itNameItem->second;
     115              :   // Check if this entry controls all the bits
     116            0 :   uint32_t buildingVal = 0;
     117            0 :   if (item->mask != 0xFFFFFFFF) {
     118              :     // Since there are bits this register we don't control, we need to see what they currently are
     119            0 :     buildingVal = io->ReadWithRetry(item->address);
     120            0 :     buildingVal &= ~(item->mask);
     121              :   }
     122            0 :   buildingVal |= (item->mask & (val << item->offset));
     123            0 :   io->WriteWithRetry(item->address, buildingVal);
     124            0 : }
     125              : 
     126              : void
     127            0 : AddressTable::Write(std::string registerName, std::vector<uint32_t> const& values)
     128              : {
     129            0 :   Write(registerName, values.data(), values.size());
     130            0 : }
     131              : void
     132            0 : AddressTable::Write(std::string registerName, uint32_t const* values, size_t word_count)
     133              : {
     134            0 :   std::map<std::string, Item*>::iterator itNameItem = nameItemMap.find(registerName);
     135            0 :   if (itNameItem == nameItemMap.end()) {
     136            0 :     BUException::INVALID_NAME e;
     137            0 :     e.Append("Can't find item with name \"");
     138            0 :     e.Append(registerName.c_str());
     139            0 :     e.Append("\"");
     140            0 :     throw e;
     141            0 :   }
     142            0 :   Item* item = itNameItem->second;
     143              :   // Check if this entry controls all the bits
     144            0 :   if (item->mask != 0xFFFFFFFF) {
     145            0 :     BUException::BAD_BLOCK_WRITE e;
     146            0 :     e.Append("Mask is not 0xFFFFFFFF\n");
     147            0 :     throw e;
     148            0 :   }
     149            0 :   io->Write(item->address, values, word_count);
     150            0 : }
        

Generated by: LCOV version 2.0-1