diff CircuitNetlistCreator.c @ 24:b924d86f829e

works in sequential mode
author Sean <seanhalle@yahoo.com>
date Thu, 17 May 2012 20:42:24 +0200
parents c11c48758df3
children 0deed3ee0b02
line diff
     1.1 --- a/CircuitNetlistCreator.c	Tue May 15 06:15:34 2012 -0700
     1.2 +++ b/CircuitNetlistCreator.c	Thu May 17 20:42:24 2012 +0200
     1.3 @@ -9,15 +9,12 @@
     1.4   
     1.5  /* is an expr resolves to an actual commPath struct instance
     1.6   */
     1.7 -#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort,\
     1.8 -                             timeFnPtr, dataPtr)\
     1.9 +#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
    1.10  do{\
    1.11     commPath->idxOfFromElem     = fromElIdx; \
    1.12     commPath->idxOfFromOutPort  = outPort; \
    1.13     commPath->idxOfToElem       = toElIdx; \
    1.14     commPath->idxOfToInPort     = inPort; \
    1.15 -   commPath->commTimeCalcFn     = timeFnPtr;\
    1.16 -   commPath->archSpecCommPathData  = dataPtr; \
    1.17   }while(0); //macro magic for namespace
    1.18  
    1.19  
    1.20 @@ -51,76 +48,85 @@
    1.21     int32 numCommPaths;
    1.22     
    1.23     netlist = malloc( sizeof(HWSimNetlist) );
    1.24 -  	numElems= 2; 
    1.25 +   numElems= 2; 
    1.26     elems = malloc( numElems * sizeof(HWSimElem *) );
    1.27     netlist->numElems = numElems;
    1.28     netlist->elems    = elems;
    1.29     netlist->numActivityTypes = 1;
    1.30     netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
    1.31 -	// Stefan: tocheck valgrind
    1.32 +
    1.33     netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
    1.34  	
    1.35 -   elems[0] = createAPingPongElem( netlist ); //use info from netlist
    1.36 +   elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
    1.37     elems[1] = createAPingPongElem( netlist ); 
    1.38 -      //on one of the elems, make reset trigger an action   
    1.39 -	//Stefan: FIXME
    1.40 +   
    1.41 +      //make reset trigger an action on one of the elements
    1.42     elems[1]->inPorts[-1].triggeredActivityType =
    1.43 -              netlist->activityTypes[PING_PONG_ACTIVITY]; //Connect elems together
    1.44 +              netlist->activityTypes[PING_PONG_ACTIVITY];
    1.45  			  
    1.46 -	/*OutPorts and InPorts may have many commPaths attached.
    1.47 +   /*OutPorts and InPorts may have many commPaths attached.
    1.48      *  but an inPort only     
    1.49 -	 * has one kind of activity that all incoming communications trigger.  That
    1.50 -	 * activity can be zero time and then switch on the type of message then
    1.51 -	 * end with a continuation, where the continuation activity is chosen by the    
    1.52 -	 * switch. 
    1.53 -	 *So, a commPath only connects an out port to an in port
    1.54 -	 *The format is: sending TL-index, out-port, dest TL-index, in-port
    1.55 -	 */
    1.56 +    * has one kind of activity that all incoming communications trigger.  That
    1.57 +    * activity can be zero time and then switch on the type of message then
    1.58 +    * end with a continuation, where the continuation activity is chosen by the    
    1.59 +    * switch. 
    1.60 +    *So, a commPath only connects an out port to an in port
    1.61 +    *The format is: sending elem-index, out-port, dest elem-index, in-port
    1.62 +    */
    1.63     numCommPaths          = 2;
    1.64     commPaths             = malloc( numCommPaths * sizeof(HWSimCommPath *) );
    1.65     netlist->numCommPaths= numCommPaths;
    1.66     netlist->commPaths= commPaths;
    1.67 -      //TL 0, out-port 0 to TL 1, in-port 0
    1.68 -	commPaths[0]= malloc(sizeof(HWSimCommPath));
    1.69 -	setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL); 
    1.70 -      //TL 1, out-port 0 to TL 0, in-port 0
    1.71 -	commPaths[1]= malloc(sizeof(HWSimCommPath));
    1.72 -   setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL);
    1.73 +      //elem 0, out-port 0 to elem 1, in-port 0
    1.74 +   commPaths[0]= malloc(sizeof(HWSimCommPath));
    1.75 +   setCommPathValuesTo(commPaths[0],0,0,1,0);
    1.76 +   commPaths[0]->hasFixedTiming  = TRUE;
    1.77 +   commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.78 +
    1.79 +      //elem 1, out-port 0 to elem 0, in-port 0
    1.80 +   commPaths[1]= malloc(sizeof(HWSimCommPath));
    1.81 +   setCommPathValuesTo(commPaths[1], 1,0,0,0);
    1.82 +   commPaths[1]->hasFixedTiming  = TRUE;
    1.83 +   commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.84     
    1.85 -   //TODO: decide how do in-out bidirectional commPaths -- thinking make it two
    1.86 -   // separate commPaths with guard between in-port and out-port
    1.87 +   //TODO: decide how to do bidirectional commPaths, like connection to a bus
    1.88 +   // thinking make it two separate commPaths with guard between in-port and out-port
    1.89  
    1.90  	return netlist;
    1.91   }
    1.92  
    1.93 +
    1.94 +/*
    1.95 + */
    1.96  void
    1.97  freePingPongNetlist (HWSimNetlist *netlist) 
    1.98 -{
    1.99 -	int i;
   1.100 -	for (i= 0; i<netlist->numCommPaths; i++) {
   1.101 -		free(netlist->commPaths[i]);
   1.102 -	}	
   1.103 -	free(netlist->commPaths);
   1.104 -	for (i= 0; i<netlist->numElems; i++) {
   1.105 -		free(&netlist->elems[i]->inPorts[-1]);
   1.106 -		free(netlist->elems[i]);
   1.107 -	}
   1.108 + { int i;
   1.109 + 
   1.110 +   for( i = 0; i < netlist->numCommPaths; i++ )
   1.111 +    { free(netlist->commPaths[i]);
   1.112 +    }	
   1.113 +   free(netlist->commPaths);
   1.114 +   for( i= 0; i < netlist->numElems; i++ ) 
   1.115 +    { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
   1.116 +      free(netlist->elems[i]->outPorts);
   1.117 +      free(netlist->elems[i]);
   1.118 +    }
   1.119  
   1.120 -	free(netlist->activityTypes);
   1.121 -	free(netlist->elems);
   1.122 -	free(netlist);
   1.123 -}
   1.124 +   free(netlist->activityTypes);
   1.125 +   free(netlist->elems);
   1.126 +   free(netlist);
   1.127 + }
   1.128   
   1.129  HWSimElem *
   1.130  createAPingPongElem( HWSimNetlist *netlist )
   1.131 - { HWSimElem *TL;
   1.132 -   TL = malloc( sizeof(HWSimElem) );
   1.133 -   TL->numInPorts  = 1;
   1.134 -   TL->numOutPorts = 1;
   1.135 -   TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
   1.136 -   TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.137 -   TL->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.138 -	return TL;
   1.139 + { HWSimElem *elem;
   1.140 +   elem = malloc( sizeof(HWSimElem) );
   1.141 +   elem->numInPorts  = 1;
   1.142 +   elem->numOutPorts = 1;
   1.143 +   elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
   1.144 +   elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.145 +   elem->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.146 +	return elem;
   1.147   }
   1.148   
   1.149  HWSimActivityType *
   1.150 @@ -128,9 +134,9 @@
   1.151   { HWSimActivityType *pingPongActivityType;
   1.152     pingPongActivityType = malloc( sizeof(HWSimActivityType) );
   1.153     
   1.154 -   pingPongActivityType->hasBehavior   = true;
   1.155 -   pingPongActivityType->hasTiming     = true;
   1.156 -   pingPongActivityType->timingIsFixed = true;
   1.157 +   pingPongActivityType->hasBehavior   = TRUE;
   1.158 +   pingPongActivityType->hasTiming     = TRUE;
   1.159 +   pingPongActivityType->timingIsFixed = TRUE;
   1.160     pingPongActivityType->fixedTime     = 10;
   1.161     pingPongActivityType->behaviorFn    = &pingPongElem_PingActivity_behavior;
   1.162     return pingPongActivityType;