diff --git a/utils/regtools/headergen_v2.cpp b/utils/regtools/headergen_v2.cpp index eeb297a773..778135e018 100644 --- a/utils/regtools/headergen_v2.cpp +++ b/utils/regtools/headergen_v2.cpp @@ -2414,6 +2414,166 @@ class cortex_m_generator : public common_generator } }; +/** + * Generator: st + */ + +class st_generator : public common_generator +{ + bool has_support_macros() const + { + return true; + } + + bool has_selectors() const + { + return m_soc.size() >= 2; + } + + bool has_offsets() const + { + return true; + } + + std::string selector_soc_dir(const soc_ref_t& ref) const + { + return ref.get()->name; + } + + std::string selector_include_header() const + { + return "select.h"; + } + + std::string selector_soc_macro(const soc_ref_t& ref) const + { + return toupper(ref.get()->name) + "_INCLUDE"; + } + + std::string register_header(const node_inst_t& inst) const + { + /* one register header per top-level block */ + if(inst.is_root()) + return ""; + if(inst.parent().is_root()) + return tolower(inst.node().name()) + ".h"; + else + return register_header(inst.parent()); + } + + std::string macro_name(macro_name_t macro, bool relative) const + { + switch(macro) + { + case MN_REG_READ: return relative ? "st_readl" : "st_read"; + case MN_FIELD_READ: return relative ? "st_readlf" : "st_readf"; + case MN_FIELD_READX: return "st_vreadf"; + case MN_REG_WRITE: return relative ? "st_writel" : "st_write"; + case MN_FIELD_WRITE: return relative ? "st_writelf" : "st_writef"; + case MN_FIELD_OVERWRITE: return relative ? "st_overwritelf" : "st_overwritef"; + case MN_FIELD_WRITEX: return "st_vwritef"; + case MN_FIELD_SET: return relative ? "st_setlf" : "st_setf"; + case MN_FIELD_CLEAR: return relative ? "st_clrlf" : "st_clrf"; + case MN_FIELD_OR: return "st_orf"; + case MN_FIELD_OR_MASK: return "__st_orfm"; // internal macro + case MN_MASK_OR: return "st_orm"; + case MN_GET_VARIANT: return "__st_variant"; // internal macro + case MN_VARIABLE: return relative ? "st_regl" : "st_reg"; + default: return ""; + } + } + + std::string macro_header() const + { + return "macro.h"; + } + + bool register_flag(const node_inst_t& inst, register_flag_t flag) const + { + /* make everything parametrized */ + switch(flag) + { + case RF_GENERATE_ALL_INST: return false; + case RF_GENERATE_PARAM_INST: return true; + default: return false; + } + } + + std::string type_xfix(macro_type_t type, bool prefix) const + { + switch(type) + { + case MT_NODE_ADDR: /* fallthrough */ + case MT_REG_ADDR: return prefix ? "STA_" : ""; + case MT_REG_OFFSET: return prefix ? "STO_" : ""; + case MT_REG_TYPE: return prefix ? "STT_" : ""; + case MT_REG_NAME: return prefix ? "STN_" : ""; + case MT_REG_VAR: return prefix ? "REG_" : ""; + case MT_FIELD_BP: return prefix ? "BP_" : ""; + case MT_FIELD_BM: return prefix ? "BM_" : ""; + case MT_FIELD_BV: return prefix ? "BV_" : ""; + case MT_FIELD_BF: return prefix ? "BF_" : ""; + case MT_FIELD_BFM: return prefix ? "BFM_" : ""; + case MT_FIELD_BFV: return prefix ? "BF_" : "_V"; + case MT_FIELD_BFMV: return prefix ? "BFM_" : "_V"; + case MT_IO_TYPE: return prefix ? "STIO_" : ""; + default: return ""; + } + } + + std::string variant_xfix(const std::string& variant, bool prefix) const + { + /* variant X -> reg_X */ + if(prefix) + return ""; + else + return "_" + toupper(variant); + } + + std::string inst_prefix(const node_inst_t& inst) const + { + /* separate blocks with _: block_reg */ + return "_"; + } + + std::string field_prefix() const + { + /* separate fields with _: block_reg_field */ + return "_"; + } + + std::string enum_prefix() const + { + /* separate enums with __: block_reg_field__enum */ + return "__"; + } + + std::string enum_name(const enum_ref_t& enum_) const + { + return enum_.get()->name; + } + + access_type_t register_access(const std::string& variant, access_t access) const + { + if(access == WRITE_ONLY) + return AT_WO; + else if(access == READ_ONLY) + return AT_RO; + else + return AT_RW; + } + + bool has_sct() const + { + return false; + } + + std::string sct_variant(macro_name_t name) const + { + return ""; + } +}; + /** * Driver */ @@ -2428,6 +2588,8 @@ abstract_generator *get_generator(const std::string& name) return new atj_generator(); else if(name == "cortex_m") return new cortex_m_generator(); + else if(name == "st") + return new st_generator(); else return 0; }