2010年6月12日 星期六

power monitor part1

Propose : 一般在 Testing 時, 除了 Test Vector (function) 的正確性外, 還要考量 Power 的問題. 如果 Power 過大, 會導致 VDD short 讓電路燒毀, 或者 VDD 供壓不穩造成 function fail. 雖然能透過加大 VDD 的電壓 or 把 Power supply 的 Metal line 變寬... 但總體而言,會浪費不必要的Power消耗. Target : 用簡單的 Power 分析, 在不違背 Test Vector function 正確性下, 大概算出sample 的次數, 之後再帶入 Power model 就可評估出這支 Vector 的 rough Power. Ref: Power Format
Here are the differences between Static and Dynamic Power Analysis:

SPA and DPA

SPA uses average current to calculate IR drop
while DPA uses Peak value of current at any time to calculate the same.
SPA considers Power to Gnd n/w as resistive while DPA considers it as R and C.

Vstatic = I * R

V(t)dyn = I(t) * R + L di/dt

where t- time
    R- resistance
    L - inductance
底下用個簡單的 sample 來測量 Dynamic Power sample的次數. 可得 N(sample counts)*V(t)dyn = total Dynamic Power

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <list>
//#include <util.h>

using namespace std;

enum SIGNALTYPE {
 IN =0,
 OUT =1,
 INOUT =2,
 REG =3,
 FIFO =4,
 BUFF =5,
};



template<class T>
class SignalCss
{
public:
 T PreSignal;
 T CurSignal;
 string Name;
 SIGNALTYPE Type;
};

template<class T>
class TopCss 
{
public:
 SignalCss<T> b;
 list<SignalCss<T> > SignalList;

void SetSignalDef(string n, T pre, T Cur, SIGNALTYPE s);
void DisplaySignal(string n);
int  CalDymPower(string n);

};

//=============================
// insert 2 SignalList
//=============================
template<class T>
void TopCss<T>::SetSignalDef(string n, T pre, T Cur, SIGNALTYPE s){

SignalCss<T> *b = new SignalCss<T>;
b->PreSignal = pre;
b->CurSignal = Cur;
b->Name      = n;
b->Type      = s;
 
SignalList.push_back(*b);
delete b;
}

//===============================
// Display func
//===============================
template<class T>
void TopCss<T>::DisplaySignal(string n){

_List_iterator<SignalCss<T> > it;

for(it=SignalList.begin(); it!=SignalList.end(); it++){
    if( n.compare(it->Name)==0 )
 cout<<"NM::\t"<<it->Name<<"\tTP::\t"<<it->Type<<"\tPre::\t"<<it->PreSignal<<"\tCur::\t"<<it->CurSignal<<endl;
 }

}

//================================
// calculate dynamic power
//================================
template<class T>
int TopCss<T>::CalDymPower(string n){
T c;
int i=0;

_List_iterator<SignalCss<T> > it;
 
for(it=SignalList.begin(); it!=SignalList.end(); it++){
    if( n.compare(it->Name)==0 ){
 c = (it->PreSignal)^(it->CurSignal);
        
 while(c!=0){
  (c % 2 ==0)? i=i : i++;
  c = c>>1;
 }
 return i; 
     }
}
return 0;
}

int main(int argc, char* argv[]){
int8_t a;
TopCss<int> *tp = new TopCss<int>;

tp->SetSignalDef("RX",3,5,IN);
cout<< tp->CalDymPower("RX");

//tp->DisplaySignal("clk");

return 0;
}

PS: 當然也可以寫成 Verilog code 包在 Test bench 下來測. code download: http://sites.google.com/site/funningboy/c/power.cpp?attredirects=0&d=1

沒有留言:

張貼留言