2010年7月2日 星期五

Image Scalar 4 ESL Flow HW c++ code

延續之前的 Post.

ESL Design Flow

Image Scalar 4 ESL Flow Golden Model

Image Scalar 4 ESL Flow HW Algorithm

底下用 c++ code 來驗證我們的 HW Algorithm, 當然你可以自行插入一些 INFO ("Power Monitor", "Communication Monitor ") HW_scalar.cpp



#include <iostream>

#define LEN 4 

#define FM_BUF_DEP 3 


enum STATUS {
  ST_IDLE      =0,
  ST_PRE_RRDBUF0    =1, //Read From RD_EXT_MEM to LOC RD_BUF_0
  ST_PRE_RRDBUF1_DRDBUF0toWTBUF0  =2, //Read From RD_EXT_MEM to LOC RD_BUF_1 And DO RD_BUF_0 to WT_BUF_0
  ST_REC_WWTBUF0_DRDBUF01toWTBUF1 =3, //Wrtie From WT_BUF_0 to WT_EXT_MEM And Do RD_BUF_0/RD_BUF_1 to WT_BUF_1
  ST_REC_SRDBUF1to0_SWTBUF1to0  =4, //Shift RD_BUF_1 to RD_BUF_0 and WT_BUF_1 to WT_BUF_0
  ST_REC_RRDBUF1     =5,
  ST_REC_WWTBUF0_DRDBUF0toWTBUF1  =6,
  ST_REC_SWTBUF1to0   =7,
  ST_END_WWTBUF0_DRDBUF0toWTBUF1 =8,
  ST_END_SWTBUF1to0   =9,
  ST_END_WWTBUF0   =10,
  ST_END_WWTBUF0_BND   =11,
  ST_DONE    =12,
};

enum BURST {
  BURST_1 =0,
  BURST_4 =1,
  BURST_8 =2,
  BURST_16 =3,
};

using namespace std;


void PRO_ST_IDLE();    
void PRO_ST_PRE_RRDBUF0();    
void PRO_ST_PRE_RRDBUF1_DRDBUF0toWTBUF0();  
void PRO_ST_REC_WWTBUF0_DRDBUF01toWTBUF1(); 
void PRO_ST_REC_SRDBUF1to0_SWTBUF1to0();  
void PRO_ST_REC_RRDBUF1();    
void PRO_ST_REC_WWTBUF0_DRDBUF0toWTBUF1();  
void PRO_ST_REC_SWTBUF1to0();   
void PRO_ST_END_WWTBUF0_DRDBUF0toWTBUF1();  
void PRO_ST_END_SWTBUF1to0();   
void PRO_ST_END_WWTBUF0();    
void PRO_ST_END_WWTBUF0_BND();   
void PRO_ST_DONE();    
void PRO_STATUS_DO();
void HW_SCALAR();


int RD_EXT_MEM[LEN*LEN];
int WT_EXT_MEM[(2*LEN)*(2*LEN)];


int RD_FM_BUF_0[FM_BUF_DEP];
int RD_FM_BUF_1[FM_BUF_DEP];
int BD_FM_BUF[LEN];

int WT_FM_BUF_0[2*FM_BUF_DEP];
int WT_FM_BUF_1[2*FM_BUF_DEP];

int BOUND_COT;
int BOUND_COT_INX_j;

int RD_EXT_MEM_INX_i;
int RD_EXT_MEM_INX_j;

int WT_EXT_MEM_INX_i;
int WT_EXT_MEM_INX_j;

int cur_st;
int nxt_st;


void PRO_ST_IDLE(){
 RD_EXT_MEM_INX_i   =0;
 RD_EXT_MEM_INX_j   =0;
 WT_EXT_MEM_INX_i   =0;
 WT_EXT_MEM_INX_j   =0;
        BOUND_COT_INX_j    =0;
        BOUND_COT          =0;

int BUF_DEP_COT = FM_BUF_DEP;

 while( BUF_DEP_COT < LEN ){
     BUF_DEP_COT += FM_BUF_DEP-1;
     BOUND_COT++;
 }
}

void INI_RD_EXT_MEM(){
int i;
int k=0;
      
  for(i=0; i<LEN*LEN; i++){
     cout<<i<<" : "<<k<<endl;
     RD_EXT_MEM[i] = k++;
  }
}


void PRO_ST_DONE(){
int i;

  for(i=0; i<(2*LEN)*(2*LEN); i++){
     cout<<i<<" : "<<WT_EXT_MEM[i]<<endl;
  }
}

void PRO_ST_END_WWTBUF0_BND(){
int i;
  // WRITE 
     for(i=0; i<2*FM_BUF_DEP; i++){
         WT_EXT_MEM[ 2*LEN*WT_EXT_MEM_INX_i + 2*BOUND_COT_INX_j +  WT_EXT_MEM_INX_j++ ] = WT_FM_BUF_0[i];
    }
        WT_EXT_MEM_INX_i++;
 WT_EXT_MEM_INX_j=0;

   if( BOUND_COT==1 ){
       BOUND_COT_INX_j = LEN - FM_BUF_DEP;
  }else{
       BOUND_COT_INX_j += FM_BUF_DEP-1;
  }

       BOUND_COT--; 
       RD_EXT_MEM_INX_i=0;
       RD_EXT_MEM_INX_j=0;

       WT_EXT_MEM_INX_i=0;
       WT_EXT_MEM_INX_j=0;

}


void PRO_ST_END_WWTBUF0(){
int i;
  // WRITE 
     for(i=0; i<2*FM_BUF_DEP; i++){
         WT_EXT_MEM[ 2*LEN*WT_EXT_MEM_INX_i + 2*BOUND_COT_INX_j + WT_EXT_MEM_INX_j++ ] = WT_FM_BUF_0[i];
    }
        WT_EXT_MEM_INX_i++;
 WT_EXT_MEM_INX_j=0;

}

void PRO_ST_END_SWTBUF1to0(){
int i;
  //shift
   for(i=0; i<2*FM_BUF_DEP; i++){
        WT_FM_BUF_0[i] = WT_FM_BUF_1[i];
  }

}

void PRO_ST_END_WWTBUF0_DRDBUF0toWTBUF1(){
int i;

 // WRITE 
     for(i=0; i<2*FM_BUF_DEP; i++){
         WT_EXT_MEM[ 2*LEN*WT_EXT_MEM_INX_i + 2*BOUND_COT_INX_j + WT_EXT_MEM_INX_j++ ] = WT_FM_BUF_0[i];
    }
        WT_EXT_MEM_INX_i++;
 WT_EXT_MEM_INX_j=0;

    // DO
   for(i=0; i<FM_BUF_DEP-1; i++){
      WT_FM_BUF_1[2*i]     = (RD_FM_BUF_0[i]);  
      WT_FM_BUF_1[2*i+1]   = (RD_FM_BUF_0[i] + RD_FM_BUF_0[i+1]) >>1;
  }
      WT_FM_BUF_1[2*FM_BUF_DEP-1] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
      WT_FM_BUF_1[2*FM_BUF_DEP-2] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
}


void PRO_ST_REC_SWTBUF1to0(){
int i;
   //Shift
   for(i=0; i<2*FM_BUF_DEP; i++){
        WT_FM_BUF_0[i] = WT_FM_BUF_1[i];
  }

}


void PRO_ST_REC_WWTBUF0_DRDBUF0toWTBUF1(){
 int i; 
     // WRITE 
     for(i=0; i<2*FM_BUF_DEP; i++){
         WT_EXT_MEM[ 2*LEN*WT_EXT_MEM_INX_i + 2*BOUND_COT_INX_j + WT_EXT_MEM_INX_j++ ] = WT_FM_BUF_0[i];
    }
        WT_EXT_MEM_INX_i++;
 WT_EXT_MEM_INX_j=0;

    // DO
   for(i=0; i<FM_BUF_DEP-1; i++){
      WT_FM_BUF_1[2*i]     = (RD_FM_BUF_0[i]);  
      WT_FM_BUF_1[2*i+1]   = (RD_FM_BUF_0[i] + RD_FM_BUF_0[i+1]) >>1;
  }
      WT_FM_BUF_1[2*FM_BUF_DEP-1] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
      WT_FM_BUF_1[2*FM_BUF_DEP-2] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
}


void PRO_ST_REC_RRDBUF1(){
int i;
  // Read
  for(i=0; i<FM_BUF_DEP; i++){
      RD_FM_BUF_1[i] = RD_EXT_MEM[  LEN*RD_EXT_MEM_INX_i + BOUND_COT_INX_j + RD_EXT_MEM_INX_j++];
  }
       RD_EXT_MEM_INX_i++;
 RD_EXT_MEM_INX_j=0;
}

void PRO_ST_REC_SRDBUF1to0_SWTBUF1to0(){
int i; 
   // Shift
   for(i=0; i<FM_BUF_DEP; i++){
         RD_FM_BUF_0[i] = RD_FM_BUF_1[i];
    }
   // Shift   
   for(i=0; i<2*FM_BUF_DEP; i++){
        WT_FM_BUF_0[i] = WT_FM_BUF_1[i];
  }

}

void PRO_ST_REC_WWTBUF0_DRDBUF01toWTBUF1(){
int i; 
     // WRITE 
     for(i=0; i<2*FM_BUF_DEP; i++){
         WT_EXT_MEM[ 2*LEN*WT_EXT_MEM_INX_i + 2*BOUND_COT_INX_j + WT_EXT_MEM_INX_j++ ] = WT_FM_BUF_0[i];
    }
        WT_EXT_MEM_INX_i++;
 WT_EXT_MEM_INX_j=0;
    
     //DO
     for(i=0; i<FM_BUF_DEP-1; i++){
        WT_FM_BUF_1[2*i]    = (RD_FM_BUF_0[i] + RD_FM_BUF_1[i]) >>1;
 WT_FM_BUF_1[2*i+1]  = (RD_FM_BUF_0[i] + RD_FM_BUF_1[i] + RD_FM_BUF_0[i+1] + RD_FM_BUF_1[i+1])>>2;
  }

         WT_FM_BUF_1[2*FM_BUF_DEP-1]    = (RD_FM_BUF_0[FM_BUF_DEP-1] + RD_FM_BUF_1[FM_BUF_DEP-1]) >>1;
         WT_FM_BUF_1[2*FM_BUF_DEP-2]    = (RD_FM_BUF_0[FM_BUF_DEP-1] + RD_FM_BUF_1[FM_BUF_DEP-1]) >>1;
}

void PRO_ST_PRE_RRDBUF1_DRDBUF0toWTBUF0(){
int i;
    // READ 
   for(i=0; i<FM_BUF_DEP; i++){
      RD_FM_BUF_1[i] = RD_EXT_MEM[  LEN*RD_EXT_MEM_INX_i + BOUND_COT_INX_j + RD_EXT_MEM_INX_j++];
    }
      RD_EXT_MEM_INX_i++;
      RD_EXT_MEM_INX_j=0;
  
   // DO
   for(i=0; i<FM_BUF_DEP-1; i++){
      WT_FM_BUF_0[2*i]     = (RD_FM_BUF_0[i]);  
      WT_FM_BUF_0[2*i+1]   = (RD_FM_BUF_0[i] + RD_FM_BUF_0[i+1]) >>1;
  }

      WT_FM_BUF_0[2*FM_BUF_DEP-1] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
      WT_FM_BUF_0[2*FM_BUF_DEP-2] = (RD_FM_BUF_0[FM_BUF_DEP-1]);  
}


void PRO_ST_PRE_RRDBUF0(){
int i;

   for(i=0; i<FM_BUF_DEP; i++){
      RD_FM_BUF_0[i] = RD_EXT_MEM[  LEN*RD_EXT_MEM_INX_i + BOUND_COT_INX_j + RD_EXT_MEM_INX_j++];
    }
      RD_EXT_MEM_INX_i++;
      RD_EXT_MEM_INX_j=0;
}


void PRO_DEBUG_INFO(){
    cout<<"cur_st           :: "<<cur_st<<endl;
    cout<<"RD_EXT_MEM_INX_i :: "<<RD_EXT_MEM_INX_i<<endl;
    cout<<"RD_EXT_MEM_INX_j :: "<<RD_EXT_MEM_INX_j<<endl;
    cout<<"WT_EXT_MEM_INX_i :: "<<WT_EXT_MEM_INX_i<<endl;
    cout<<"WT_EXT_MEM_INX_j :: "<<WT_EXT_MEM_INX_j<<endl;
    cout<<"BOUND_COT_INX_j  :: "<<BOUND_COT_INX_j<<endl;
    cout<<"BOUND_COT        :: "<<BOUND_COT<<endl;

    cout<<endl;
    cout<<endl;
 
}

void HW_SCALAR(){

cur_st = ST_IDLE; 

  while( cur_st != ST_DONE ){
      switch(cur_st){
        case  ST_IDLE           : nxt_st = ST_PRE_RRDBUF0;    break; 
        case  ST_PRE_RRDBUF0   : nxt_st = ST_PRE_RRDBUF1_DRDBUF0toWTBUF0; break;
        case  ST_PRE_RRDBUF1_DRDBUF0toWTBUF0  : nxt_st = ST_REC_WWTBUF0_DRDBUF01toWTBUF1; break;
        case  ST_REC_WWTBUF0_DRDBUF01toWTBUF1 : nxt_st = ST_REC_SRDBUF1to0_SWTBUF1to0;    break;
        case  ST_REC_SRDBUF1to0_SWTBUF1to0 : nxt_st = ( RD_EXT_MEM_INX_i == LEN )? ST_END_WWTBUF0_DRDBUF0toWTBUF1 :
                     ST_REC_RRDBUF1;
            break;   
        case  ST_REC_RRDBUF1            : nxt_st = ST_REC_WWTBUF0_DRDBUF0toWTBUF1; break;  
        case  ST_REC_WWTBUF0_DRDBUF0toWTBUF1  : nxt_st = ST_REC_SWTBUF1to0;   break;
        case  ST_REC_SWTBUF1to0   : nxt_st = ST_REC_WWTBUF0_DRDBUF01toWTBUF1;  break;
        case  ST_END_WWTBUF0_DRDBUF0toWTBUF1  : nxt_st = ST_END_SWTBUF1to0;   break; 
        case  ST_END_SWTBUF1to0   : nxt_st = ST_END_WWTBUF0;   break; 
        case  ST_END_WWTBUF0   : nxt_st = ST_END_WWTBUF0_BND;   break; 
        case  ST_END_WWTBUF0_BND  : nxt_st = ( BOUND_COT ==0 )? ST_DONE : 
                      ST_PRE_RRDBUF0;
            break;
        case  ST_DONE    :      break; 
       }
         
         PRO_STATUS_DO();

         PRO_DEBUG_INFO();    

         cur_st = nxt_st;
   }
}

void PRO_STATUS_DO(){

   switch(cur_st){ 
        case  ST_IDLE       : PRO_ST_IDLE();    break;       
        case  ST_PRE_RRDBUF0   : PRO_ST_PRE_RRDBUF0();    break;
        case  ST_PRE_RRDBUF1_DRDBUF0toWTBUF0  : PRO_ST_PRE_RRDBUF1_DRDBUF0toWTBUF0();  break;
        case  ST_REC_WWTBUF0_DRDBUF01toWTBUF1 : PRO_ST_REC_WWTBUF0_DRDBUF01toWTBUF1(); break;
        case  ST_REC_SRDBUF1to0_SWTBUF1to0 : PRO_ST_REC_SRDBUF1to0_SWTBUF1to0();  break;
        case  ST_REC_RRDBUF1            : PRO_ST_REC_RRDBUF1();    break;
        case  ST_REC_WWTBUF0_DRDBUF0toWTBUF1   : PRO_ST_REC_WWTBUF0_DRDBUF0toWTBUF1();  break; 
        case  ST_REC_SWTBUF1to0   : PRO_ST_REC_SWTBUF1to0();   break;
        case  ST_END_WWTBUF0_DRDBUF0toWTBUF1    : PRO_ST_END_WWTBUF0_DRDBUF0toWTBUF1();  break;
        case  ST_END_SWTBUF1to0          : PRO_ST_END_SWTBUF1to0();   break;
        case  ST_END_WWTBUF0   : PRO_ST_END_WWTBUF0();    break;
        case  ST_END_WWTBUF0_BND  : PRO_ST_END_WWTBUF0_BND();   break; 
  case  ST_DONE    : PRO_ST_DONE();    break; 
 }
}




int main(int argc,char *argv[]){
  if( FM_BUF_DEP <=1 ){    cout<< "HW Not Support Buf Dep <=1 case"<<endl; return -1; }
   
 INI_RD_EXT_MEM();
 HW_SCALAR();
 PRO_ST_DONE();

return 0;
}
Total Download: http://sites.google.com/site/funningboy/c/ESL_Scalar.tar.gz?attredirects=0&d=1

1 則留言:

  1. Open source logic analyzer software

    http://logicanalyzer.sourceforge.net/

    回覆刪除