Line data Source code
1 : #include "regmap_manager.hpp" 2 : #include "log.hpp" 3 : #include "util.hpp" 4 : 5 : #include <vector> 6 : #include <algorithm> 7 : 8 1 : RegmapManager::RegmapManager() 9 : { 10 : #if REGMAP_VERSION < 0x0500 11 : std::string regmap_file = "regmap4-symbol.yaml"; 12 : #else 13 1 : std::string regmap_file = "regmap5-symbol.yaml"; 14 : #endif 15 : 16 : // get felix path, remove bin if needed 17 2 : std::filesystem::path executable_path = std::filesystem::canonical("/proc/self/exe").parent_path(); 18 3 : std::filesystem::path felix_path = executable_path.filename() == "bin" ? executable_path.parent_path() : executable_path; 19 5 : std::filesystem::path regmap_path = felix_path / "share" / "felix-star" / regmap_file; 20 1 : LOG_INFO("Reading register map %s", regmap_path.u8string().c_str()); 21 : 22 1 : m_regmap = YAML::LoadFile(regmap_path); 23 3 : } 24 : 25 : 26 7 : bool RegmapManager::has_key(std::string name, std::string key, const std::string& value) { 27 14 : if (!m_regmap["registers"][name]) return false; 28 7 : std::vector<std::string> values = Util::split(m_regmap["registers"][name][key].Scalar(), '|'); 29 7 : return std::find(values.begin(), values.end(), value) != values.end(); 30 7 : } 31 : 32 : 33 0 : bool RegmapManager::has_type(const std::string& name, const std::string& type) { 34 0 : return has_key(name, "type", type); 35 : } 36 : 37 : 38 7 : bool RegmapManager::has_endpoint(const std::string& name, const std::string& endpoint) { 39 7 : return has_key(name, "endpoints", endpoint); 40 : }