diff CircuitNetlistCreator.c @ 11:a587ea56af8e

changed directory structure -- thin project repository with this as sub-repo
author Me@portablequad
date Sat, 07 Jan 2012 17:45:10 -0800
parents
children 4862640793b6
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/CircuitNetlistCreator.c	Sat Jan 07 17:45:10 2012 -0800
     1.3 @@ -0,0 +1,99 @@
     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__Hello_World_HW/HWSim__Hello_World_HW.h"
    1.12 + 
    1.13 +/*'wire' is an expr resolves to an actual wire struct instance
    1.14 + */
    1.15 +#define setWireValuesTo( wire, fromTLIdx, outPort, toTLIdx, inPort, dataPtr)\
    1.16 +do{\
    1.17 +   wire.idxOfFromTimeline = fromTLIdx; \
    1.18 +   wire.idxOfFromOutPort  = fromTLIdx; \
    1.19 +   wire.idxOfToTimeline   = toTLIdx; \
    1.20 +   wire.idxOfToInPort     = inPort; \
    1.21 +   wire.archSpecWireData  = dataPtr; \
    1.22 + }while(0); //macro magic for namespace
    1.23 + 
    1.24 +/*This file constructs the netlist for the Hello World circuit, which is
    1.25 + * used during design and implementation of the HWSim language
    1.26 + *
    1.27 + *It has two timelines, each with one input port and one output port, and
    1.28 + * a single span-type.
    1.29 + *
    1.30 + *The timelines are cross-coupled, so output port of one connects to input
    1.31 + * port of the other.  The input port has a single trigger, which fires
    1.32 + * the one span-type.
    1.33 + *
    1.34 + *The span does nothing, except send a NULL message on the output port.
    1.35 + *The span-sim-time and communication-sim-time are both constants.
    1.36 + *
    1.37 + *Note that timelines are generic.  They are specialized by declaring
    1.38 + * inports and outports, and by registering triggers that fire particular
    1.39 + * span-types.
    1.40 + */
    1.41 +HWSimNetlist *createPingPongNetlist()
    1.42 + { HWSimNetlist   *netlist;
    1.43 +   NetlistWire    *wires;
    1.44 +   HWSimTimeline **timelines;
    1.45 +   int numTimelines;
    1.46 +   int numWires;
    1.47 +   
    1.48 +   netlist = malloc( sizeof(HWSimNetlist) );
    1.49 +   //declare timelines   numTimelines = 2;
    1.50 +   timelines = malloc( numTimelines * sizeof(HWSimTimeline) );
    1.51 +   netlist->numTimelines = numTimelines;
    1.52 +   netlist->timelines    = timelines;
    1.53 +   netlist->numSpanTypes = 1;
    1.54 +   netlist->spanTypes = malloc(netlist->numSpanTypes*sizeof(HWSimSpanType*));
    1.55 +   netlist->spanTypes[PING_PONG_TYPE] = createPingPongSpanType();
    1.56 +   timelines[0] = createAPingPongTimeline( netlist ); //use info from netlist
    1.57 +   timelines[1] = createAPingPongTimeline( netlist ); 
    1.58 +      //on one of the timelines, make reset trigger an action   
    1.59 +   timelines[1]->inPorts[-1].triggeredSpanType =
    1.60 +              netlist->spanTypes PING_PONG_TYPE]; //Connect timelines together
    1.61 +			  
    1.62 +	/*OutPorts and InPorts may have many wires attached, but an inPort only     
    1.63 +	 * has one kind of span that all incoming communications trigger.  That
    1.64 +	 * span can be zero time and then switch on the type of message then
    1.65 +	 * end with a continuation, where the continuation span is chosen by the    
    1.66 +	 * switch. 
    1.67 +	 *So, a wire only connects an out port to an in port
    1.68 +	 *The format is: sending TL-index, out-port, dest TL-index, in-port
    1.69 +	 */
    1.70 +   numWires          = 2;
    1.71 +   wires             = malloc( numWires * sizeof(NetlistWire) );
    1.72 +   netlist->numWires = numWires;
    1.73 +   netlist->wires    = wires;
    1.74 +   //TL 0, out-port 0 to TL 1, in-port 0
    1.75 +   setWireValuesTo(wires[0], 0,0,1,0, NULL); //These NetlistWires turned into
    1.76 +   setWireValuesTo(wires[1], 1,0,0,0, NULL); // HWSimWires inside ckt create
    1.77 +   //TODO: decide how do in-out bidirectional wires -- thinking make it two
    1.78 +   // separate wires with guard between in-port and out-port
    1.79 +   //TODO: decide how do guards between ports
    1.80 + }
    1.81 + 
    1.82 +   //Note: copy netlist struct with VMS malloc after VMS initialized
    1.83 +HWSimTimeline *
    1.84 +createAPingPongTimeline( HWSimNetlist *netlist )
    1.85 + { HWSimTimeline *TL;
    1.86 +   TL = malloc( sizeof(HWSimTimeline) );
    1.87 +   TL->numInPorts  = 1;
    1.88 +   TL->numOutPorts = 1;
    1.89 +   TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
    1.90 +   TL->inPorts[-1].triggeredSpanType = IDLE_SPAN; //reset port
    1.91 +   TL->inPorts[0].triggeredSpanType  = netlist->spanTypes[PING_PONG_TYPE];
    1.92 + }
    1.93 + 
    1.94 +HWSimSpanType *
    1.95 +createPingPongSpanType( )
    1.96 + { HWSimSpanType *pingPongSpanType;
    1.97 +   pingPongSpanType = malloc( sizeof(HWSimSpanType) );
    1.98 +   pingPongSpanType->behaviorFn = &behaviorOf_ping_pong_span;
    1.99 +   pingPongSpanType->timingFn   = &timingOf_ping_pong_span;
   1.100 +   return pingPongSpanType;
   1.101 + } 
   1.102 + 
   1.103 \ No newline at end of file