2019-11-22 11:57:17 +00:00
|
|
|
#include <Builders.hpp>
|
2019-11-22 14:22:52 +00:00
|
|
|
#include <iostream>
|
2019-11-22 11:57:17 +00:00
|
|
|
|
2019-11-22 14:22:52 +00:00
|
|
|
|
|
|
|
void ZeroPointerBuilder::build(std::stringstream& ss) const{
|
2019-11-22 11:57:17 +00:00
|
|
|
ss << "template <unsigned int zero = 0>\n"
|
|
|
|
"constexpr unsigned int *zeroVal = reinterpret_cast<unsigned int *>(zero);\n";
|
|
|
|
}
|
|
|
|
|
2019-11-22 14:22:52 +00:00
|
|
|
void PeripheralBuilder::build(std::stringstream& ss) const{
|
|
|
|
ss << "namespace " << peripheral.name << "{\n";
|
2019-11-22 11:57:17 +00:00
|
|
|
for(auto& registe : peripheral.registers){
|
2019-11-22 14:22:52 +00:00
|
|
|
RegisterBuilder(registe, peripheral.baseAddress).build(ss);
|
2019-11-22 11:57:17 +00:00
|
|
|
}
|
|
|
|
ss << "}\n";
|
|
|
|
}
|
|
|
|
|
2019-11-22 14:22:52 +00:00
|
|
|
void RegisterBuilder::build(std::stringstream& ss) const{
|
2019-11-22 11:57:17 +00:00
|
|
|
ss << " "
|
2019-11-22 14:22:52 +00:00
|
|
|
<< "namespace " << registe.name << "{\n";
|
2019-11-22 11:57:17 +00:00
|
|
|
for(auto& field : registe.fields){
|
2019-11-22 14:22:52 +00:00
|
|
|
FieldBuilder(field, getRegisterAddress()).build(ss);
|
2019-11-22 11:57:17 +00:00
|
|
|
}
|
|
|
|
ss << " " << "}\n";
|
|
|
|
}
|
|
|
|
|
2019-11-22 14:22:52 +00:00
|
|
|
unsigned int RegisterBuilder::getRegisterAddress() const{
|
|
|
|
return baseAddress + registe.addressOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FieldBuilder::build(std::stringstream& ss) const{
|
|
|
|
ss << " " << "struct " << field.name << "{\n";
|
2019-11-22 11:57:17 +00:00
|
|
|
|
|
|
|
ss << " " << " " << "constexpr static inline unsigned int bitOffset(){"
|
2019-11-22 14:22:52 +00:00
|
|
|
<< "return " << field.bitOffset << ";}\n";
|
|
|
|
|
2019-11-22 11:57:17 +00:00
|
|
|
ss << " " << " " << "constexpr static inline unsigned int bitMask(){"
|
2019-11-22 14:22:52 +00:00
|
|
|
<< "return " << field.bitWidth << ";}\n";
|
|
|
|
|
|
|
|
ss << " " << " " << "constexpr static inline unsigned int* address(){"
|
|
|
|
<< "return zeroVal<> + " << getAddress() << ";}\n";
|
|
|
|
ss << " };\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string FieldBuilder::getAddress() const{
|
|
|
|
return std::to_string(registerAddress);
|
|
|
|
}
|