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: 2025-12-21 13:07:08 Functions: 0.0 % 12 0

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

Generated by: LCOV version 2.0-1