#include <stdio.h> #include <stdlib.h> #include <iostream> #include <list> using namespace std; #define MAX_NET_NODE 12 #define BEGIN_NODE 0 #define END_NODE 3 enum NETSTATUS{ NET_NXT_OK =0, NET_NXT_FAL =1, NET_TRACE_OK =2, NET_TRACE_FAL =3, }; struct NetPath { int Id; int Weight; //delay } NetPath; struct NeNode { int x; int y; int s; struct NetPath NetPath[MAX_NET_NODE]; }NetNode[MAX_NET_NODE]; void SetInitNetNodeTable(){ // Net_0 set NetNode[0].x=0; NetNode[0].y=0; NetNode[0].NetPath[0].Id =1; NetNode[0].NetPath[0].Weight =3; NetNode[0].NetPath[1].Id =4; NetNode[0].NetPath[1].Weight =5; NetNode[0].s=2; // Net_1 set NetNode[1].x=0; NetNode[1].y=1; NetNode[1].NetPath[0].Id =0; NetNode[1].NetPath[0].Weight =5; NetNode[1].NetPath[1].Id =2; NetNode[1].NetPath[1].Weight =5; NetNode[1].NetPath[2].Id =5; NetNode[1].NetPath[2].Weight =5; NetNode[1].s=3; // Net_2 set NetNode[2].x=0; NetNode[2].y=2; NetNode[2].NetPath[0].Id =1; NetNode[2].NetPath[0].Weight =7; NetNode[2].NetPath[1].Id =3; NetNode[2].NetPath[1].Weight =5; NetNode[2].NetPath[2].Id =6; NetNode[2].NetPath[2].Weight =5; NetNode[2].s=3; // Net_3 set NetNode[3].x=0; NetNode[3].y=3; NetNode[3].NetPath[0].Id =2; NetNode[3].NetPath[0].Weight =4; NetNode[3].NetPath[1].Id =7; NetNode[3].NetPath[1].Weight =3; NetNode[3].s=2; // Net_4 set NetNode[4].x=1; NetNode[4].y=0; NetNode[4].NetPath[0].Id =0; NetNode[4].NetPath[0].Weight =3; NetNode[4].NetPath[1].Id =5; NetNode[4].NetPath[0].Weight =3; NetNode[4].NetPath[2].Id =8; NetNode[4].NetPath[1].Weight =9; NetNode[4].s=3; // Net_5 set NetNode[5].x=1; NetNode[5].y=1; NetNode[5].NetPath[0].Id =1; NetNode[5].NetPath[0].Weight =5; NetNode[5].NetPath[1].Id =4; NetNode[5].NetPath[1].Weight =6; NetNode[5].NetPath[2].Id =6; NetNode[5].NetPath[2].Weight =8; NetNode[5].NetPath[3].Id =9; NetNode[5].NetPath[3].Weight =4; NetNode[5].s=4; // Net_6 set NetNode[6].x=1; NetNode[6].y=2; NetNode[6].NetPath[0].Id =2; NetNode[6].NetPath[0].Weight =5; NetNode[6].NetPath[1].Id =5; NetNode[6].NetPath[1].Weight =5; NetNode[6].NetPath[2].Id =7; NetNode[6].NetPath[2].Weight =5; NetNode[6].NetPath[3].Id =10; NetNode[6].NetPath[3].Weight =5; NetNode[6].s=4; // Net_7 set NetNode[7].x=1; NetNode[7].y=3; NetNode[7].NetPath[0].Id =3; NetNode[7].NetPath[0].Weight =4; NetNode[7].NetPath[1].Id =6; NetNode[7].NetPath[1].Weight =4; NetNode[7].NetPath[2].Id =11; NetNode[7].NetPath[2].Weight =4; NetNode[7].s=3; // Net_8 set NetNode[8].x=2; NetNode[8].y=0; NetNode[8].NetPath[0].Id =4; NetNode[8].NetPath[0].Weight =5; NetNode[8].NetPath[1].Id =9; NetNode[8].NetPath[1].Weight =4; NetNode[8].s=2; // Net_9 set NetNode[9].x=2; NetNode[9].y=1; NetNode[9].NetPath[0].Id =5; NetNode[9].NetPath[0].Weight =5; NetNode[9].NetPath[1].Id =8; NetNode[9].NetPath[1].Weight =7; NetNode[9].NetPath[2].Id =10; NetNode[9].NetPath[2].Weight =6; NetNode[9].s=3; // Net_10 set NetNode[10].x=2; NetNode[10].y=2; NetNode[10].NetPath[0].Id =6; NetNode[10].NetPath[0].Weight =7; NetNode[10].NetPath[1].Id =9; NetNode[10].NetPath[1].Weight =7; NetNode[10].NetPath[2].Id =11; NetNode[10].NetPath[2].Weight =7; NetNode[10].s=3; // Net_11 set NetNode[11].x=2; NetNode[11].y=3; NetNode[11].NetPath[0].Id =6; NetNode[10].NetPath[0].Weight =7; NetNode[11].NetPath[1].Id =11; NetNode[10].NetPath[1].Weight =7; NetNode[11].s=2; } int FindNodeId2xy(int id, int *x, int *y){ switch(id){ case 0 : *x = 0; *y=0; return NET_TRACE_OK; break; case 1 : *x = 0; *y=1; return NET_TRACE_OK; break; case 2 : *x = 0; *y=2; return NET_TRACE_OK; break; case 3 : *x = 0; *y=3; return NET_TRACE_OK; break; case 4 : *x = 1; *y=0; return NET_TRACE_OK; break; case 5 : *x = 1; *y=1; return NET_TRACE_OK; break; case 6 : *x = 1; *y=2; return NET_TRACE_OK; break; case 7 : *x = 1; *y=3; return NET_TRACE_OK; break; case 8 : *x = 2; *y=0; return NET_TRACE_OK; break; case 9 : *x = 2; *y=1; return NET_TRACE_OK; break; case 10: *x = 2; *y=2; return NET_TRACE_OK; break; case 11: *x = 2; *y=3; return NET_TRACE_OK; break; default: return NET_TRACE_FAL; break; } } int xPathCot; int yPathCot; list<int> vistlist; int FindNxtNode(int begin, int end, int xpath, int ypath){ int i; int id; int bx,by; int tx,ty; int ixpath=xpath,iypath=ypath; vistlist.push_back(begin); if( begin==end ){ for(list<int>::iterator it=vistlist.begin(); it!=vistlist.end(); it++){ cout<<*it<<","; } cout<<endl; vistlist.pop_back(); return 0; } if( FindNodeId2xy(begin, &bx, &by) == NET_TRACE_FAL ){ return -1;} for(i=0; i<NetNode[begin].s; i++){ id = NetNode[begin].NetPath[i].Id; if( FindNodeId2xy(id, &tx, &ty) == NET_TRACE_FAL ){ break; return -1;} tx -=bx; ty -=by; if( xpath >0 && tx>0 ){ /*printf("a,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/ FindNxtNode(id,end,ixpath-1,iypath); } else if( xpath <0 && tx<0 ){ /*printf("b,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/ FindNxtNode(id,end,ixpath+1,iypath); } else if( ypath >0 && ty>0 ){ /*printf("c,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/ FindNxtNode(id,end,ixpath ,iypath-1); } else if( ypath <0 && ty<0 ){ /*printf("d,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/ FindNxtNode(id,end,ixpath ,iypath+1); } } vistlist.pop_back(); } int main(int argc,char* argv[]){ SetInitNetNodeTable(); int Beginx,Beginy; int Endx,Endy; if( FindNodeId2xy(BEGIN_NODE,&Beginx,&Beginy)==NET_TRACE_FAL ){ printf("@ Begin Node 2 MapTable Error ...\n"); return -1; } if( FindNodeId2xy(END_NODE, &Endx, &Endy )==NET_TRACE_FAL ){ printf("@ End Node 2 MapTable Error ...\n"); return -1; } xPathCot = Endx-Beginx; yPathCot = Endy-Beginy; FindNxtNode(BEGIN_NODE,END_NODE,xPathCot,yPathCot); return 0; }Refs: Network On Chip
Network-on-Chip @ Google group
有關 network on chip 的學術文章
沒有留言:
張貼留言