Added display() to Peripheral

This commit is contained in:
Łukasz Czyż 2019-11-15 11:48:38 +01:00
parent f645188b8d
commit 5fa14dbc99
2 changed files with 51 additions and 5 deletions

View file

@ -11,15 +11,27 @@ enum class EAccess{
Read_Write Read_Write
}; };
struct Field{ struct IDisplay{
virtual void display() = 0;
};
struct Field : public IDisplay{
std::string name; std::string name;
std::string description; std::string description;
unsigned int bitOffset; unsigned int bitOffset;
unsigned int bitWidth; unsigned int bitWidth;
EAccess fieldAccess; EAccess fieldAccess;
void display() final{
std::cout << std::endl
<< "\t\tname: " << name << std::endl
<< "\t\tdescription: " << description << std::endl
<< "\t\tbitOffset: " << bitOffset << std::endl
<< "\t\tbitWidth: " << bitWidth << std::endl
<< "\t\tfieldAccess: " << (int)fieldAccess << std::endl;
}
}; };
struct Register{ struct Register : public IDisplay{
std::string name; std::string name;
std::string description; std::string description;
unsigned int addressOffset; unsigned int addressOffset;
@ -27,20 +39,53 @@ struct Register{
EAccess registerAccess; EAccess registerAccess;
unsigned int resetValue; unsigned int resetValue;
std::vector<Field> fields; std::vector<Field> fields;
void display() final{
std::cout << std::endl
<< "\tname: " << name << std::endl
<< "\tdescription: " << description << std::endl
<< "\taddressOffset: " << addressOffset << std::endl
<< "\tsize: " << size << std::endl
<< "\tregisterAccess: " << (int)registerAccess << std::endl
<< "\tresetValue: " << resetValue << std::endl;
std::cout << std::endl << "\tfields: " << std::endl;
for(auto& i : fields){
i.display();
}
}
}; };
struct AddressBlock{ struct AddressBlock : public IDisplay{
unsigned int offset; unsigned int offset;
unsigned int size; unsigned int size;
void display() final{
std::cout << std::endl
<< "\toffset: " << offset << std::endl
<< "\tsize: " << size << std::endl;
}
}; };
struct Peripheral{ struct Peripheral : public IDisplay{
std::string name; std::string name;
std::string description; std::string description;
std::string groupName; std::string groupName;
unsigned int baseAddress; unsigned int baseAddress;
AddressBlock addressBlock; AddressBlock addressBlock;
std::vector<Register> registers; std::vector<Register> registers;
void display() final{
std::cout << std::endl
<< "name: " << name << std::endl
<< "description: " << description << std::endl
<< "groupName: " << groupName << std::endl
<< "baseAddress: " << baseAddress << std::endl
<< "addressBlock: ";
addressBlock.display();
std::cout << std::endl << "registers: " << std::endl;
for(auto& i : registers){
i.display();
}
}
}; };
#endif #endif

View file

@ -76,7 +76,6 @@ Peripheral XmlParser::parsePeripheral(tinyxml2::XMLElement* peripheralRoot){
setDeviceInfoAttrib(peripheralRoot, "description", peripheral.description); setDeviceInfoAttrib(peripheralRoot, "description", peripheral.description);
setDeviceInfoAttrib(peripheralRoot, "groupName", peripheral.groupName); setDeviceInfoAttrib(peripheralRoot, "groupName", peripheral.groupName);
setDeviceInfoAttrib(peripheralRoot, "baseAddress", peripheral.baseAddress); setDeviceInfoAttrib(peripheralRoot, "baseAddress", peripheral.baseAddress);
peripheral.addressBlock = parseAddressBlock(peripheralRoot->FirstChildElement("addressBlock")); peripheral.addressBlock = parseAddressBlock(peripheralRoot->FirstChildElement("addressBlock"));
//Iterate over all registers and append them to peripheral //Iterate over all registers and append them to peripheral
@ -93,6 +92,7 @@ Peripheral XmlParser::parsePeripheral(tinyxml2::XMLElement* peripheralRoot){
peripheral.registers.push_back(parseRegister(registerRoot->ToElement())); peripheral.registers.push_back(parseRegister(registerRoot->ToElement()));
} }
} }
peripheral.display();
return peripheral; return peripheral;
} }
@ -104,6 +104,7 @@ AddressBlock XmlParser::parseAddressBlock(tinyxml2::XMLElement* addressBlockRoot
} }
else else
std::cout << "parseAddressBlock is nullptr!" << std::endl; std::cout << "parseAddressBlock is nullptr!" << std::endl;
1 / 0;
return addressBlock; return addressBlock;
} }