1 /* 2 * CPower.hh 3 * 4 * Copyright 2014-2018 D. Mitch Bailey cvc at shuharisystem dot com 5 * 6 * This file is part of cvc. 7 * 8 * cvc is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * cvc is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with cvc. If not, see <http://www.gnu.org/licenses/>. 20 * 21 * You can download cvc from https://github.com/d-m-bailey/cvc.git 22 */ 23 24 #ifndef CPOWER_HH_ 25 #define CPOWER_HH_ 26 27 #include "Cvc.hh" 28 #include "CSet.hh" 29 #include "CModel.hh" 30 #include "CFixedText.hh" 31 32 class CCvcDb; 33 class CEventQueue; 34 class CVirtualNetVector; 35 36 // status type bits 37 enum powerType_t : unsigned char { POWER_BIT=0, INPUT_BIT, HIZ_BIT, RESISTOR_BIT, ANALOG_BIT, MIN_CALCULATED_BIT, SIM_CALCULATED_BIT, MAX_CALCULATED_BIT }; 38 enum activeType_t : unsigned char { MIN_ACTIVE=0, MAX_ACTIVE, MIN_IGNORE, MAX_IGNORE }; 39 enum powerPtrType_t : unsigned char { UNKNOWN_POWER_PTR=0, FULL_POWER_PTR, MIN_POWER_PTR, SIM_POWER_PTR, MAX_POWER_PTR }; 40 41 enum calculationType_t : unsigned char { UNKNOWN_CALCULATION=0, NO_CALCULATION, UP_CALCULATION, DOWN_CALCULATION, RESISTOR_CALCULATION, ESTIMATED_CALCULATION }; 42 43 #define IsExternalPower_(power_p) ((power_p)->type[POWER_BIT] || (power_p)->type[INPUT_BIT]) 44 #define IsPriorityPower_(power_p) ((power_p)->type[POWER_BIT] || (power_p)->type[INPUT_BIT] || (power_p)->type[RESISTOR_BIT]) 45 46 class CPowerFamilyMap : public unordered_map<string, CSet> { 47 public: 48 string definition = ""; CPowerFamilyMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)49 CPowerFamilyMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);} 50 void AddFamily(string thePowerString); 51 }; 52 53 class CPowerPtrMap; // forward definition 54 class CPowerPtrVector; // forward definition 55 56 class CExtraPowerData { 57 public: 58 string expectedSim = ""; 59 string expectedMin = ""; 60 string expectedMax = ""; 61 string family = ""; 62 string implicitFamily = ""; 63 CSet relativeSet; 64 text_t powerSignal; // power name from power file (possibly bus or cell level net) must be initialized in constructor 65 text_t powerAlias; // name used to represent this power definition (/VSS -> VSS, /X1/VDDA -> VDDA) must be initialized in constructor 66 voltage_t pullDownVoltage = UNKNOWN_VOLTAGE; 67 voltage_t pullUpVoltage = UNKNOWN_VOLTAGE; 68 69 CExtraPowerData(); 70 }; 71 72 class CPower; // forward declaration 73 74 class CMiniPower { 75 public: 76 static CFixedText powerDefinitionText; 77 78 voltage_t voltage = UNKNOWN_VOLTAGE; 79 netId_t netId = UNKNOWN_NET; // netId for this power definition 80 netId_t defaultNet = UNKNOWN_NET; 81 text_t definition; // must be initialized in constructor 82 // CStatus active; always active 83 84 CMiniPower(); 85 CMiniPower(string thePowerString, CPowerPtrMap & thePowerMacroPtrMap, CModelListMap & theModelListMap); 86 CMiniPower(CPower * thePower_p); 87 CMiniPower(CPower * thePower_p, netId_t theNetId); 88 CMiniPower(netId_t theNetId); 89 CMiniPower(netId_t theNetId, voltage_t theSimVoltage, bool theCreateExtraData = false); 90 CMiniPower(netId_t theNetId, voltage_t theMinVoltage, voltage_t theSimVoltage, voltage_t theMaxVoltage, netId_t theDefaultMinNet, netId_t theDefaultSimNet, netId_t theDefaultMaxNet); 91 ~CMiniPower(); 92 expectedSim()93 string expectedSim() { return (""); }; expectedMin()94 string expectedMin() { return (""); }; expectedMax()95 string expectedMax() { return (""); }; family()96 string family() { return (""); }; implicitFamily()97 string implicitFamily() { return (""); }; pullDownVoltage()98 voltage_t pullDownVoltage() { return (UNKNOWN_VOLTAGE); }; pullUpVoltage()99 voltage_t pullUpVoltage() { return (UNKNOWN_VOLTAGE); }; powerSignal()100 text_t powerSignal() { return (CMiniPower::powerDefinitionText.BlankTextAddress()); }; powerAlias()101 text_t powerAlias() { return (CMiniPower::powerDefinitionText.BlankTextAddress()); }; 102 CPower * GetBasePower(CPowerPtrVector & theNetVoltagePtr_v, CVirtualNetVector & theNet_v); 103 void SetPowerAlias(string thePowerString, size_t theAliasStart); 104 bool IsSamePower(CPower * theMatchPower); 105 bool IsValidSubset(CPower * theMatchPower, voltage_t theThreshold); 106 bool IsRelative(CPower * theTestPower_p, bool theDefault, bool theIsHiZRelative = false); 107 bool IsRelatedPower(CPower * theTestPower_p, CPowerPtrVector & theNetVoltagePtr_v, CVirtualNetVector & theNet_v, CVirtualNetVector & theTestNet_v, 108 bool theDefault, bool isHiZRelated = false); IsInternalOverride()109 inline bool IsInternalOverride() { return(true); }; 110 111 void Print(ostream & theLogFile, string theIndentation = "", string theRealPowerName = ""); 112 string PowerDefinition(); 113 string StandardDefinition(); 114 voltage_t RelativeVoltage(CPowerPtrMap & thePowerMacroPtrMap, netStatus_t theType, CModelListMap & theModelListMap); 115 }; 116 117 class CPower { 118 public: 119 static netId_t powerCount; 120 static CFixedText powerDefinitionText; 121 122 voltage_t minVoltage = UNKNOWN_VOLTAGE; 123 voltage_t simVoltage = UNKNOWN_VOLTAGE; 124 voltage_t maxVoltage = UNKNOWN_VOLTAGE; 125 netId_t powerId; // unique for each power net. used in leak detection 126 netId_t netId = UNKNOWN_NET; // netId for this power definition 127 // default nets are the nets that are used if the calculated voltage is invalid 128 // the base from which voltages have been calculated 129 // not used for min/max defaults to sim values 130 // no default sim for resistance calculations 131 netId_t defaultMinNet = UNKNOWN_NET; 132 netId_t defaultSimNet = UNKNOWN_NET; 133 netId_t defaultMaxNet = UNKNOWN_NET; 134 text_t definition; // must be initialized in constructor 135 CExtraPowerData * extraData = NULL; 136 CStatus type; 137 CStatus active; 138 calculationType_t minCalculationType = UNKNOWN_CALCULATION; 139 calculationType_t simCalculationType = UNKNOWN_CALCULATION; 140 calculationType_t maxCalculationType = UNKNOWN_CALCULATION; 141 bool relativeFriendly = true; 142 bool flagAllShorts = false; 143 144 CPower(); 145 CPower(string thePowerString, CPowerPtrMap & thePowerMacroPtrMap, CModelListMap & theModelListMap); 146 CPower(CPower * thePower_p); 147 CPower(CPower * thePower_p, netId_t theNetId); 148 CPower(netId_t theNetId); 149 CPower(netId_t theNetId, voltage_t theSimVoltage, bool theCreateExtraData = false); 150 CPower(netId_t theNetId, voltage_t theMinVoltage, voltage_t theSimVoltage, voltage_t theMaxVoltage, netId_t theDefaultMinNet, netId_t theDefaultSimNet, netId_t theDefaultMaxNet); 151 ~CPower(); 152 expectedSim()153 string expectedSim() { return (( extraData ) ? extraData->expectedSim : ""); }; expectedMin()154 string expectedMin() { return (( extraData ) ? extraData->expectedMin : ""); }; expectedMax()155 string expectedMax() { return (( extraData ) ? extraData->expectedMax : ""); }; family()156 string family() { return (( extraData ) ? extraData->family : ""); }; implicitFamily()157 string implicitFamily() { return (( extraData ) ? extraData->implicitFamily : ""); }; pullDownVoltage()158 voltage_t pullDownVoltage() { return (( extraData ) ? extraData->pullDownVoltage : UNKNOWN_VOLTAGE); }; pullUpVoltage()159 voltage_t pullUpVoltage() { return (( extraData ) ? extraData->pullDownVoltage : UNKNOWN_VOLTAGE); }; powerSignal()160 text_t powerSignal() { return (( extraData ) ? extraData->powerSignal : CPower::powerDefinitionText.BlankTextAddress()); }; powerAlias()161 text_t powerAlias() { return (( extraData ) ? extraData->powerAlias : CPower::powerDefinitionText.BlankTextAddress()); }; 162 CPower * GetBasePower(CPowerPtrVector & theNetVoltagePtr_v, CVirtualNetVector & theNet_v); 163 void SetPowerAlias(string thePowerString, size_t theAliasStart); 164 bool IsSamePower(CPower * theMatchPower); 165 bool IsValidSubset(CPower * theMatchPower, voltage_t theThreshold); 166 bool IsRelative(CPower * theTestPower_p, bool theDefault, bool theIsHiZRelative = false); 167 bool IsRelatedPower(CPower * theTestPower_p, CPowerPtrVector & theNetVoltagePtr_v, CVirtualNetVector & theNet_v, CVirtualNetVector & theTestNet_v, 168 bool theDefault, bool isHiZRelated = false); IsInternalOverride()169 inline bool IsInternalOverride() {return( ! (type[INPUT_BIT] || type[POWER_BIT]) ); }; 170 171 void Print(ostream & theLogFile, string theIndentation = "", string theRealPowerName = ""); 172 string PowerDefinition(); 173 string StandardDefinition(); 174 voltage_t RelativeVoltage(CPowerPtrMap & thePowerMacroPtrMap, netStatus_t theType, CModelListMap & theModelListMap); 175 }; 176 #define PowerDelimiter_(power_p, BIT) ((power_p == NULL || power_p->type[BIT]) ? "=" : "@") 177 #define IsCalculatedVoltage_(power_p) (power_p && ( power_p->type[MIN_CALCULATED_BIT] || power_p->type[SIM_CALCULATED_BIT] || power_p->type[MAX_CALCULATED_BIT] ) ) 178 #define IsPower_(power_p) (power_p && power_p->type[POWER_BIT]) 179 #define IsInputOrPower_(power_p) (power_p && ( power_p->type[INPUT_BIT] || power_p->type[POWER_BIT] ) ) 180 181 #define IsKnownVoltage_(theVoltage) (theVoltage != UNKNOWN_VOLTAGE) 182 183 class CPowerPtrMap : public unordered_map<string, CPower *> { 184 public: 185 string implicitFamily = ""; CPowerPtrMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)186 CPowerPtrMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);} 187 void Clear(); 188 string CalculateExpectedValue(string theEquation, netStatus_t theType, CModelListMap & theModelListMap); 189 voltage_t CalculateVoltage(string theEquation, netStatus_t theType, CModelListMap & theModelListMap, bool thePermitUndefinedFlag = false, bool theResetImplicitFlag = true); 190 }; 191 192 class CPowerPtrVector; // forward definition 193 194 class CPowerPtrList : public list<CPower *> { 195 public: 196 // CPowerPtrMap calculatedPowerPtrMap; 197 198 void Clear(); 199 void Clear(CPowerPtrVector & theLeakVoltage_v, CPowerPtrVector & theNetVoltage_v, netId_t theNetCount); 200 void SetPowerLimits(voltage_t& theMaxPower, voltage_t& theMinPower); 201 // CPower * FindCalculatedPower(CEventQueue& theEventQueue, CPower * theCurrentPower_p, voltage_t theShortVoltage, string theNetName); 202 // CPower * FindCalculatedPower(CEventQueue& theEventQueue, CPower * theCurrentPower_p, voltage_t theShortVoltage, netId_t theNetId, netId_t theDefaultNetId, CCvcDb * theCvcDb); 203 // CPower * FindCalculatedPower(voltage_t theMinVoltage, voltage_t theSimVoltage, voltage_t theMaxVoltage, netId_t theNetId, CCvcDb * theCvcDb); 204 void SetFamilies(CPowerFamilyMap & thePowerFamilyMap); 205 }; 206 207 union PowerPtr_t { 208 CPower * full; 209 CMiniPower * mini; 210 }; 211 212 class CPowerPtrVector : public vector<PowerPtr_t> { 213 public: 214 vector<powerPtrType_t> powerPtrType_v; 215 216 voltage_t MaxVoltage(netId_t theNetId); 217 voltage_t MinVoltage(netId_t theNetId); 218 voltage_t SimVoltage(netId_t theNetId); 219 void CalculatePower(CEventQueue& theEventQueue, voltage_t theShortVoltage, netId_t theNetId, netId_t theDefaultNetId, CCvcDb * theCvdDb_p, string theCalculation); 220 void ResetPowerPointerVector(size_t theSize); 221 }; 222 223 class CInstancePower { 224 public: 225 string instanceName; 226 string powerFile; 227 list<string> powerList; 228 229 CInstancePower(string theDefinition); 230 }; 231 232 class CInstancePowerPtrList : public list<CInstancePower *> { 233 public: 234 235 }; 236 237 #define IsUnknownMinVoltage_(power_p) ( ! power_p || power_p->minVoltage == UNKNOWN_VOLTAGE || power_p->active[MIN_ACTIVE] == false ) 238 #define IsUnknownMaxVoltage_(power_p) ( ! power_p || power_p->maxVoltage == UNKNOWN_VOLTAGE || power_p->active[MAX_ACTIVE] == false ) 239 240 #endif /* CPOWER_HH_ */ 241