diff CircuitNetlistCreator.c @ 26:0deed3ee0b02

update comments for public viewing
author kshalle
date Wed, 25 Feb 2015 15:20:16 -0800
parents b924d86f829e
children
line diff
     1.1 --- a/CircuitNetlistCreator.c	Thu May 24 08:14:21 2012 -0700
     1.2 +++ b/CircuitNetlistCreator.c	Wed Feb 25 15:20:16 2015 -0800
     1.3 @@ -1,144 +1,165 @@
     1.4 -/*
     1.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     1.6 - *  Licensed under GNU General Public License version 2
     1.7 - *
     1.8 - * Author: seanhalle@yahoo.com
     1.9 - *
    1.10 - */
    1.11 -#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
    1.12 - 
    1.13 -/* is an expr resolves to an actual commPath struct instance
    1.14 - */
    1.15 -#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
    1.16 -do{\
    1.17 -   commPath->idxOfFromElem     = fromElIdx; \
    1.18 -   commPath->idxOfFromOutPort  = outPort; \
    1.19 -   commPath->idxOfToElem       = toElIdx; \
    1.20 -   commPath->idxOfToInPort     = inPort; \
    1.21 - }while(0); //macro magic for namespace
    1.22 -
    1.23 -
    1.24 -
    1.25 -HWSimActivityType* createPingPongActivityType (); 
    1.26 -
    1.27 -HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
    1.28 -
    1.29 -/*This file constructs the netlist for the Hello World circuit, which is
    1.30 - * used during design and implementation of the HWSim language
    1.31 - *
    1.32 - *It has two elements, each with one input port and one output port, and
    1.33 - * a single activity-type.
    1.34 - *
    1.35 - *The elements are cross-coupled, so output port of one connects to input
    1.36 - * port of the other.  The input port has a single trigger, which fires
    1.37 - * the one activity-type.
    1.38 - *
    1.39 - *The activity does nothing, except send a NULL message on the output port.
    1.40 - *The activity-sim-time and communication-sim-time are both constants.
    1.41 - *
    1.42 - *Note that elements are generic.  They are specialized by declaring
    1.43 - * inports and outports, and by registering triggers that fire particular
    1.44 - * activity-types.
    1.45 - */
    1.46 -HWSimNetlist *createPingPongNetlist()
    1.47 - { HWSimNetlist   *netlist;
    1.48 -   HWSimCommPath  **commPaths;
    1.49 -   HWSimElem **elems;
    1.50 -   int32 numElems;
    1.51 -   int32 numCommPaths;
    1.52 -   
    1.53 -   netlist = malloc( sizeof(HWSimNetlist) );
    1.54 -   numElems= 2; 
    1.55 -   elems = malloc( numElems * sizeof(HWSimElem *) );
    1.56 -   netlist->numElems = numElems;
    1.57 -   netlist->elems    = elems;
    1.58 -   netlist->numActivityTypes = 1;
    1.59 -   netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
    1.60 -
    1.61 -   netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
    1.62 -	
    1.63 -   elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
    1.64 -   elems[1] = createAPingPongElem( netlist ); 
    1.65 -   
    1.66 -      //make reset trigger an action on one of the elements
    1.67 -   elems[1]->inPorts[-1].triggeredActivityType =
    1.68 -              netlist->activityTypes[PING_PONG_ACTIVITY];
    1.69 -			  
    1.70 -   /*OutPorts and InPorts may have many commPaths attached.
    1.71 -    *  but an inPort only     
    1.72 -    * has one kind of activity that all incoming communications trigger.  That
    1.73 -    * activity can be zero time and then switch on the type of message then
    1.74 -    * end with a continuation, where the continuation activity is chosen by the    
    1.75 -    * switch. 
    1.76 -    *So, a commPath only connects an out port to an in port
    1.77 -    *The format is: sending elem-index, out-port, dest elem-index, in-port
    1.78 -    */
    1.79 -   numCommPaths          = 2;
    1.80 -   commPaths             = malloc( numCommPaths * sizeof(HWSimCommPath *) );
    1.81 -   netlist->numCommPaths= numCommPaths;
    1.82 -   netlist->commPaths= commPaths;
    1.83 -      //elem 0, out-port 0 to elem 1, in-port 0
    1.84 -   commPaths[0]= malloc(sizeof(HWSimCommPath));
    1.85 -   setCommPathValuesTo(commPaths[0],0,0,1,0);
    1.86 -   commPaths[0]->hasFixedTiming  = TRUE;
    1.87 -   commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.88 -
    1.89 -      //elem 1, out-port 0 to elem 0, in-port 0
    1.90 -   commPaths[1]= malloc(sizeof(HWSimCommPath));
    1.91 -   setCommPathValuesTo(commPaths[1], 1,0,0,0);
    1.92 -   commPaths[1]->hasFixedTiming  = TRUE;
    1.93 -   commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.94 -   
    1.95 -   //TODO: decide how to do bidirectional commPaths, like connection to a bus
    1.96 -   // thinking make it two separate commPaths with guard between in-port and out-port
    1.97 -
    1.98 -	return netlist;
    1.99 - }
   1.100 -
   1.101 -
   1.102 -/*
   1.103 - */
   1.104 -void
   1.105 -freePingPongNetlist (HWSimNetlist *netlist) 
   1.106 - { int i;
   1.107 - 
   1.108 -   for( i = 0; i < netlist->numCommPaths; i++ )
   1.109 -    { free(netlist->commPaths[i]);
   1.110 -    }	
   1.111 -   free(netlist->commPaths);
   1.112 -   for( i= 0; i < netlist->numElems; i++ ) 
   1.113 -    { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
   1.114 -      free(netlist->elems[i]->outPorts);
   1.115 -      free(netlist->elems[i]);
   1.116 -    }
   1.117 -
   1.118 -   free(netlist->activityTypes);
   1.119 -   free(netlist->elems);
   1.120 -   free(netlist);
   1.121 - }
   1.122 - 
   1.123 -HWSimElem *
   1.124 -createAPingPongElem( HWSimNetlist *netlist )
   1.125 - { HWSimElem *elem;
   1.126 -   elem = malloc( sizeof(HWSimElem) );
   1.127 -   elem->numInPorts  = 1;
   1.128 -   elem->numOutPorts = 1;
   1.129 -   elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
   1.130 -   elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.131 -   elem->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.132 -	return elem;
   1.133 - }
   1.134 - 
   1.135 -HWSimActivityType *
   1.136 -createPingPongActivityType( )
   1.137 - { HWSimActivityType *pingPongActivityType;
   1.138 -   pingPongActivityType = malloc( sizeof(HWSimActivityType) );
   1.139 -   
   1.140 -   pingPongActivityType->hasBehavior   = TRUE;
   1.141 -   pingPongActivityType->hasTiming     = TRUE;
   1.142 -   pingPongActivityType->timingIsFixed = TRUE;
   1.143 -   pingPongActivityType->fixedTime     = 10;
   1.144 -   pingPongActivityType->behaviorFn    = &pingPongElem_PingActivity_behavior;
   1.145 -   return pingPongActivityType;
   1.146 - }
   1.147 - 
   1.148 +/*
   1.149 + *  Copyright 2011 OpenSourceResearchInstitute.org
   1.150 + *  Licensed under GNU General Public License version 2
   1.151 + *
   1.152 + * Author: seanhalle@yahoo.com
   1.153 + *
   1.154 + */
   1.155 +#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
   1.156 + 
   1.157 +/* is an expr resolves to an actual commPath struct instance
   1.158 + */
   1.159 +#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
   1.160 +do{\
   1.161 +   commPath->idxOfFromElem     = fromElIdx; \
   1.162 +   commPath->idxOfFromOutPort  = outPort; \
   1.163 +   commPath->idxOfToElem       = toElIdx; \
   1.164 +   commPath->idxOfToInPort     = inPort; \
   1.165 + }while(0); //macro magic for namespace
   1.166 +
   1.167 +
   1.168 +
   1.169 +HWSimActivityType* createPingPongActivityType (); 
   1.170 +
   1.171 +HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
   1.172 +
   1.173 +/*This file constructs the netlist for the Hello World circuit
   1.174 + *
   1.175 + *It has two elements, each with one input port and one output port, and
   1.176 + * a single activity-type.
   1.177 + *
   1.178 + *The elements are cross-coupled, so output port of one connects to input
   1.179 + * port of the other.  The input port has a single trigger, which fires
   1.180 + * the one activity-type.
   1.181 + *
   1.182 + *The activity does nothing, except send a NULL message on the output port.
   1.183 + *The activity-sim-time and communication-sim-time are both constants.
   1.184 + *
   1.185 + *Note that elements are generic.  They are specialized by declaring
   1.186 + * inports and outports, and by registering triggers that fire particular
   1.187 + * activity-types.
   1.188 + */
   1.189 +HWSimNetlist *createPingPongNetlist()
   1.190 + { HWSimNetlist   *netlist;
   1.191 +   HWSimCommPath  **commPaths;
   1.192 +   HWSimElem **elems;
   1.193 +   int32 numElems;
   1.194 +   int32 numCommPaths;
   1.195 +   
   1.196 +   netlist = malloc( sizeof(HWSimNetlist) );
   1.197 +   numElems= 2; 
   1.198 +   elems = malloc( numElems * sizeof(HWSimElem *) );
   1.199 +   netlist->numElems = numElems;
   1.200 +   netlist->elems    = elems;
   1.201 +   netlist->numActivityTypes = 1;
   1.202 +   netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
   1.203 +
   1.204 +   netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
   1.205 +	
   1.206 +   elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
   1.207 +   elems[1] = createAPingPongElem( netlist ); 
   1.208 +   
   1.209 +      //make reset trigger an action on one of the elements
   1.210 +   elems[1]->inPorts[-1].triggeredActivityType =
   1.211 +              netlist->activityTypes[PING_PONG_ACTIVITY];
   1.212 +			  
   1.213 +   /*OutPorts and InPorts may have many commPaths attached.
   1.214 +    *  but an inPort only     
   1.215 +    * has one kind of activity that all incoming communications trigger.  That
   1.216 +    * activity can be zero time and then switch on the type of message then
   1.217 +    * end with a continuation, where the continuation activity is chosen by the    
   1.218 +    * switch. 
   1.219 +    *So, a commPath only connects an out port to an in port
   1.220 +    *The format is: sending elem-index, out-port, dest elem-index, in-port
   1.221 +    */
   1.222 +   numCommPaths          = 2;
   1.223 +   commPaths             = malloc( numCommPaths * sizeof(HWSimCommPath *) );
   1.224 +   netlist->numCommPaths= numCommPaths;
   1.225 +   netlist->commPaths= commPaths;
   1.226 +      //elem 0, out-port 0 to elem 1, in-port 0
   1.227 +   commPaths[0]= malloc(sizeof(HWSimCommPath));
   1.228 +   setCommPathValuesTo(commPaths[0],0,0,1,0);
   1.229 +   commPaths[0]->hasFixedTiming  = TRUE;
   1.230 +   commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
   1.231 +
   1.232 +      //elem 1, out-port 0 to elem 0, in-port 0
   1.233 +   commPaths[1]= malloc(sizeof(HWSimCommPath));
   1.234 +   setCommPathValuesTo(commPaths[1], 1,0,0,0);
   1.235 +   commPaths[1]->hasFixedTiming  = TRUE;
   1.236 +   commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
   1.237 +   
   1.238 +   //TODO: decide how to do bidirectional commPaths, like connection to a bus
   1.239 +   // thinking make it two separate commPaths with guard between in-port and out-port
   1.240 +
   1.241 +	return netlist;
   1.242 + }
   1.243 +
   1.244 +
   1.245 +/*
   1.246 + */
   1.247 +void
   1.248 +freePingPongNetlist (HWSimNetlist *netlist) 
   1.249 + { int i;
   1.250 + 
   1.251 +   for( i = 0; i < netlist->numCommPaths; i++ )
   1.252 +    { free(netlist->commPaths[i]);
   1.253 +    }	
   1.254 +   free(netlist->commPaths);
   1.255 +   for( i= 0; i < netlist->numElems; i++ ) 
   1.256 +    { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
   1.257 +      free(netlist->elems[i]->outPorts);
   1.258 +      free(netlist->elems[i]);
   1.259 +    }
   1.260 +
   1.261 +   free(netlist->activityTypes);
   1.262 +   free(netlist->elems);
   1.263 +   free(netlist);
   1.264 + }
   1.265 + 
   1.266 +/*This creates a simulation element.  A simulation element is of the type
   1.267 + * HWSimElem.  The HWSimElem data structure contains information about
   1.268 + * the input ports and output ports of the element.  In particular, when
   1.269 + * a communication arrives on an input port, that triggers activity inside
   1.270 + * the element.  It is here that the function is registerd, which implements
   1.271 + * the behavior of that activity.
   1.272 + *Triggered activities is the heart of HWSim.  It is inside these functions
   1.273 + * that application defined behavior takes place.
   1.274 + */
   1.275 +HWSimElem *
   1.276 +createAPingPongElem( HWSimNetlist *netlist )
   1.277 + { HWSimElem *elem;
   1.278 +   elem = malloc( sizeof(HWSimElem) );
   1.279 +   elem->numInPorts  = 1;
   1.280 +   elem->numOutPorts = 1;
   1.281 +   elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
   1.282 +   elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.283 +   //point the trigger at an activity that is already in the netlist.
   1.284 +   // The function below creates one of such activities.
   1.285 +   //The netlist creation function first creates the activities, then
   1.286 +   // it calls this function, which grabs activities from the netlist
   1.287 +   elem->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.288 +	return elem;
   1.289 + }
   1.290 +
   1.291 +/*Define a type of activity that is possible.  The netlist creator 
   1.292 + * first calls all of this kind of function, and fills the netlist
   1.293 + * with these data structures that implement activities.
   1.294 + *Then, the creator calls functions that create individual elements.
   1.295 + * Those element-creation functions grab the activity structures out
   1.296 + * of the netlist.
   1.297 + */ 
   1.298 +HWSimActivityType *
   1.299 +createPingPongActivityType( )
   1.300 + { HWSimActivityType *pingPongActivityType;
   1.301 +   pingPongActivityType = malloc( sizeof(HWSimActivityType) );
   1.302 +   
   1.303 +   //For execution speed, some special cases exist, such as activities
   1.304 +   // that have no behavior, or ones that have a fixed time to complete
   1.305 +   pingPongActivityType->hasBehavior   = TRUE;
   1.306 +   pingPongActivityType->hasTiming     = TRUE;
   1.307 +   pingPongActivityType->timingIsFixed = TRUE;
   1.308 +   pingPongActivityType->fixedTime     = 10;
   1.309 +   pingPongActivityType->behaviorFn    = &pingPongElem_PingActivity_behavior;
   1.310 +   return pingPongActivityType;
   1.311 + }
   1.312 +