comparison CircuitNetlistCreator.c @ 25:b1c9d67643f2

fixed DEBUG to DEBUG__printf2
author Some Random Person <seanhalle@yahoo.com>
date Thu, 24 May 2012 08:14:21 -0700
parents c11c48758df3
children 0deed3ee0b02
comparison
equal deleted inserted replaced
11:bd491853056c 12:268bf1aeef4a
7 */ 7 */
8 #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h" 8 #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
9 9
10 /* is an expr resolves to an actual commPath struct instance 10 /* is an expr resolves to an actual commPath struct instance
11 */ 11 */
12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort,\ 12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
13 timeFnPtr, dataPtr)\
14 do{\ 13 do{\
15 commPath->idxOfFromElem = fromElIdx; \ 14 commPath->idxOfFromElem = fromElIdx; \
16 commPath->idxOfFromOutPort = outPort; \ 15 commPath->idxOfFromOutPort = outPort; \
17 commPath->idxOfToElem = toElIdx; \ 16 commPath->idxOfToElem = toElIdx; \
18 commPath->idxOfToInPort = inPort; \ 17 commPath->idxOfToInPort = inPort; \
19 commPath->commTimeCalcFn = timeFnPtr;\
20 commPath->archSpecCommPathData = dataPtr; \
21 }while(0); //macro magic for namespace 18 }while(0); //macro magic for namespace
22 19
23 20
24 21
25 HWSimActivityType* createPingPongActivityType (); 22 HWSimActivityType* createPingPongActivityType ();
49 HWSimElem **elems; 46 HWSimElem **elems;
50 int32 numElems; 47 int32 numElems;
51 int32 numCommPaths; 48 int32 numCommPaths;
52 49
53 netlist = malloc( sizeof(HWSimNetlist) ); 50 netlist = malloc( sizeof(HWSimNetlist) );
54 numElems= 2; 51 numElems= 2;
55 elems = malloc( numElems * sizeof(HWSimElem *) ); 52 elems = malloc( numElems * sizeof(HWSimElem *) );
56 netlist->numElems = numElems; 53 netlist->numElems = numElems;
57 netlist->elems = elems; 54 netlist->elems = elems;
58 netlist->numActivityTypes = 1; 55 netlist->numActivityTypes = 1;
59 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*)); 56 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
60 // Stefan: tocheck valgrind 57
61 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType(); 58 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
62 59
63 elems[0] = createAPingPongElem( netlist ); //use info from netlist 60 elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
64 elems[1] = createAPingPongElem( netlist ); 61 elems[1] = createAPingPongElem( netlist );
65 //on one of the elems, make reset trigger an action 62
66 //Stefan: FIXME 63 //make reset trigger an action on one of the elements
67 elems[1]->inPorts[-1].triggeredActivityType = 64 elems[1]->inPorts[-1].triggeredActivityType =
68 netlist->activityTypes[PING_PONG_ACTIVITY]; //Connect elems together 65 netlist->activityTypes[PING_PONG_ACTIVITY];
69 66
70 /*OutPorts and InPorts may have many commPaths attached. 67 /*OutPorts and InPorts may have many commPaths attached.
71 * but an inPort only 68 * but an inPort only
72 * has one kind of activity that all incoming communications trigger. That 69 * has one kind of activity that all incoming communications trigger. That
73 * activity can be zero time and then switch on the type of message then 70 * activity can be zero time and then switch on the type of message then
74 * end with a continuation, where the continuation activity is chosen by the 71 * end with a continuation, where the continuation activity is chosen by the
75 * switch. 72 * switch.
76 *So, a commPath only connects an out port to an in port 73 *So, a commPath only connects an out port to an in port
77 *The format is: sending TL-index, out-port, dest TL-index, in-port 74 *The format is: sending elem-index, out-port, dest elem-index, in-port
78 */ 75 */
79 numCommPaths = 2; 76 numCommPaths = 2;
80 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) ); 77 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) );
81 netlist->numCommPaths= numCommPaths; 78 netlist->numCommPaths= numCommPaths;
82 netlist->commPaths= commPaths; 79 netlist->commPaths= commPaths;
83 //TL 0, out-port 0 to TL 1, in-port 0 80 //elem 0, out-port 0 to elem 1, in-port 0
84 commPaths[0]= malloc(sizeof(HWSimCommPath)); 81 commPaths[0]= malloc(sizeof(HWSimCommPath));
85 setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL); 82 setCommPathValuesTo(commPaths[0],0,0,1,0);
86 //TL 1, out-port 0 to TL 0, in-port 0 83 commPaths[0]->hasFixedTiming = TRUE;
87 commPaths[1]= malloc(sizeof(HWSimCommPath)); 84 commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
88 setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL); 85
86 //elem 1, out-port 0 to elem 0, in-port 0
87 commPaths[1]= malloc(sizeof(HWSimCommPath));
88 setCommPathValuesTo(commPaths[1], 1,0,0,0);
89 commPaths[1]->hasFixedTiming = TRUE;
90 commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
89 91
90 //TODO: decide how do in-out bidirectional commPaths -- thinking make it two 92 //TODO: decide how to do bidirectional commPaths, like connection to a bus
91 // separate commPaths with guard between in-port and out-port 93 // thinking make it two separate commPaths with guard between in-port and out-port
92 94
93 return netlist; 95 return netlist;
94 } 96 }
95 97
98
99 /*
100 */
96 void 101 void
97 freePingPongNetlist (HWSimNetlist *netlist) 102 freePingPongNetlist (HWSimNetlist *netlist)
98 { 103 { int i;
99 int i; 104
100 for (i= 0; i<netlist->numCommPaths; i++) { 105 for( i = 0; i < netlist->numCommPaths; i++ )
101 free(netlist->commPaths[i]); 106 { free(netlist->commPaths[i]);
102 } 107 }
103 free(netlist->commPaths); 108 free(netlist->commPaths);
104 for (i= 0; i<netlist->numElems; i++) { 109 for( i= 0; i < netlist->numElems; i++ )
105 free(&netlist->elems[i]->inPorts[-1]); 110 { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
106 free(netlist->elems[i]); 111 free(netlist->elems[i]->outPorts);
107 } 112 free(netlist->elems[i]);
113 }
108 114
109 free(netlist->activityTypes); 115 free(netlist->activityTypes);
110 free(netlist->elems); 116 free(netlist->elems);
111 free(netlist); 117 free(netlist);
112 } 118 }
113 119
114 HWSimElem * 120 HWSimElem *
115 createAPingPongElem( HWSimNetlist *netlist ) 121 createAPingPongElem( HWSimNetlist *netlist )
116 { HWSimElem *TL; 122 { HWSimElem *elem;
117 TL = malloc( sizeof(HWSimElem) ); 123 elem = malloc( sizeof(HWSimElem) );
118 TL->numInPorts = 1; 124 elem->numInPorts = 1;
119 TL->numOutPorts = 1; 125 elem->numOutPorts = 1;
120 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts ); 126 elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
121 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port 127 elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
122 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY]; 128 elem->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY];
123 return TL; 129 return elem;
124 } 130 }
125 131
126 HWSimActivityType * 132 HWSimActivityType *
127 createPingPongActivityType( ) 133 createPingPongActivityType( )
128 { HWSimActivityType *pingPongActivityType; 134 { HWSimActivityType *pingPongActivityType;
129 pingPongActivityType = malloc( sizeof(HWSimActivityType) ); 135 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
130 136
131 pingPongActivityType->hasBehavior = true; 137 pingPongActivityType->hasBehavior = TRUE;
132 pingPongActivityType->hasTiming = true; 138 pingPongActivityType->hasTiming = TRUE;
133 pingPongActivityType->timingIsFixed = true; 139 pingPongActivityType->timingIsFixed = TRUE;
134 pingPongActivityType->fixedTime = 10; 140 pingPongActivityType->fixedTime = 10;
135 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior; 141 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
136 return pingPongActivityType; 142 return pingPongActivityType;
137 } 143 }
138 144