#ifndef CPSW_YAML_H #define CPSW_YAML_H #include #include /* Template specializations to convert YAML nodes to CPSW entries * (ByteOrder, IIntField::Mode, Field, MMIODev, etc.) */ namespace YAML { template<> struct convert { static bool decode(const Node& node, ByteOrder& rhs) { if (!node.IsScalar()) return false; std::string str = node.Scalar(); if( str.compare( "LE" ) == 0 ) rhs = LE; else if (str.compare( "BE" ) == 0 ) rhs = BE; else rhs = UNKNOWN; return true; } }; template<> struct convert { static bool decode(const Node& node, IField::Cacheable& rhs) { if (!node.IsScalar()) return false; std::string str = node.Scalar(); if( str.compare( "NOT_CACHEABLE" ) == 0 ) rhs = IField::NOT_CACHEABLE; else if (str.compare( "WT_CACHEABLE" ) == 0 ) rhs = IField::WT_CACHEABLE; else if (str.compare( "WB_CACHEABLE" ) == 0 ) rhs = IField::WB_CACHEABLE; else rhs = IField::UNKNOWN_CACHEABLE; return true; } }; template<> struct convert { static bool decode(const Node& node, INoSsiDev::ProtocolVersion& rhs) { if (!node.IsScalar()) return false; std::string str = node.Scalar(); if( str.compare( "SRP_UDP_V1" ) == 0 ) rhs = INoSsiDev::SRP_UDP_V1; else if (str.compare( "SRP_UDP_V2" ) == 0 ) rhs = INoSsiDev::SRP_UDP_V2; else return false; return true; } }; template<> struct convert { static bool decode(const Node& node, IIntField::Mode& rhs) { if (!node.IsScalar()) return false; std::string str = node.Scalar(); if( str.compare( "RO" ) == 0 ) rhs = IIntField::RO; else if (str.compare( "WO" ) == 0 ) rhs = IIntField::WO; else if (str.compare( "RW" ) == 0 ) rhs = IIntField::RW; else return false; return true; } }; template<> struct convert { static bool decode(const Node& node, IntField& rhs) { // if(!node.IsMap() || node.size() >= 3) { // return false; // } IIntField::Builder bldr = IIntField::IBuilder::create(); std::string name; int val; IIntField::Mode mode; name = node["name"].as(); bldr->name( name.c_str() ); if( node["size"] ) { val = node["size"].as(); bldr->sizeBits( val ); } if( node["isSigned"] ) { val = node["isSigned"].as(); bldr->isSigned( (bool) val ); } if( node["lsBit"] ) { val = node["lsBit"].as(); bldr->lsBit( val ); } if( node["mode"] ) { mode = node["mode"].as(); bldr->mode( mode ); } if( node["wordSwap"] ) { val = node["wordSwap"].as(); bldr->wordSwap( val ); } rhs = bldr->build(); return true; } }; template<> struct convert { static bool decode(const Node& node, MMIODev& rhs) { std::string name = node["name"].as(); int size = node["size"].as(); rhs = IMMIODev::create( name.c_str(), size ); Field f; // This device contains registers if ( node["registers"] ) { const YAML::Node& registers = node["registers"]; for( unsigned i = 0; i < registers.size(); i++ ) { int address = registers[i]["address"].as(); int nelms = registers[i]["nelms"] ? \ registers[i]["nelms"].as() : \ 1; uint64_t stride =registers[i]["stride"] ? registers[i]["stride"].as() : IMMIODev::STRIDE_AUTO; ByteOrder byteOrder = registers[i]["ByteOrder"] ? registers[i]["ByteOrder"].as() : UNKNOWN; std::string desc = registers[i]["description"].as(); IField::Cacheable cacheable = registers[i]["cacheable"] ? \ registers[i]["cacheable"].as() : \ IField::UNKNOWN_CACHEABLE; f = registers[i].as(); f->setDescription( desc ); rhs->addAtAddress( f, address, nelms, stride, byteOrder ); } } // This device contains other peripherals const YAML::Node& peripherals = node["peripherals"]; if ( node["peripherals"] ) { const YAML::Node& peripherals = node["peripherals"]; for( unsigned i = 0; i < peripherals.size(); i++ ) { int address = peripherals[i]["address"].as(); int nelms = peripherals[i]["nelms"] ? peripherals[i]["nelms"].as() : 1; f = peripherals[i].as(); rhs->addAtAddress( f, address, nelms ); } } return true; } }; } #endif