view CircuitNetlistCreator.c @ 12:4862640793b6

small changes to the netlist creation
author hausers
date Tue, 31 Jan 2012 17:10:29 +0100
parents a587ea56af8e
children abe3db0025d5
line source
1 /*
2 * Copyright 2011 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
8 #include "HWSim__Hello_World_HW/HWSim__Hello_World_HW.h"
10 /*'wire' is an expr resolves to an actual wire struct instance
11 */
12 #define setWireValuesTo( wire, fromTLIdx, outPort, toTLIdx, inPort, dataPtr)\
13 do{\
14 wire->idxOfFromTimeline = fromTLIdx; \
15 wire->idxOfFromOutPort = fromTLIdx; \
16 wire->idxOfToTimeline = toTLIdx; \
17 wire->idxOfToInPort = inPort; \
18 wire->archSpecCommPathData = dataPtr; \
19 }while(0); //macro magic for namespace
22 HWSimSpanType* createPingPongSpanType ();
24 HWSimTimeline* createAPingPongTimeline (HWSimNetlist *netlist);
26 /*This file constructs the netlist for the Hello World circuit, which is
27 * used during design and implementation of the HWSim language
28 *
29 *It has two timelines, each with one input port and one output port, and
30 * a single span-type.
31 *
32 *The timelines are cross-coupled, so output port of one connects to input
33 * port of the other. The input port has a single trigger, which fires
34 * the one span-type.
35 *
36 *The span does nothing, except send a NULL message on the output port.
37 *The span-sim-time and communication-sim-time are both constants.
38 *
39 *Note that timelines are generic. They are specialized by declaring
40 * inports and outports, and by registering triggers that fire particular
41 * span-types.
42 */
43 HWSimNetlist *createPingPongNetlist()
44 { HWSimNetlist *netlist;
45 HWSimCommPath **wires;
46 HWSimTimeline **timelines;
47 int32 numTimelines;
48 int32 numWires;
49 HWSimSpanType *foo;
51 netlist = malloc( sizeof(HWSimNetlist) );
52 //declare timelines numTimelines = 2;
53 timelines = malloc( numTimelines * sizeof(HWSimTimeline) );
54 netlist->numTimelines = numTimelines;
55 netlist->timelines = timelines;
56 netlist->numSpanTypes = 1;
57 netlist->spanTypes = malloc(netlist->numSpanTypes*sizeof(HWSimSpanType*));
58 netlist->spanTypes[PING_PONG_TYPE] = createPingPongSpanType();
59 timelines[0] = createAPingPongTimeline( netlist ); //use info from netlist
60 timelines[1] = createAPingPongTimeline( netlist );
61 //on one of the timelines, make reset trigger an action
62 timelines[1]->inPorts[-1].triggeredSpanType =
63 netlist->spanTypes[PING_PONG_TYPE]; //Connect timelines together
65 /*OutPorts and InPorts may have many wires attached, but an inPort only
66 * has one kind of span that all incoming communications trigger. That
67 * span can be zero time and then switch on the type of message then
68 * end with a continuation, where the continuation span is chosen by the
69 * switch.
70 *So, a wire only connects an out port to an in port
71 *The format is: sending TL-index, out-port, dest TL-index, in-port
72 */
73 numWires = 2;
74 wires = malloc( numWires * sizeof(HWSimCommPath) );
75 netlist->numCommPaths= numWires;
76 netlist->commPaths= wires;
77 //TL 0, out-port 0 to TL 1, in-port 0
78 setWireValuesTo(wires[0], 0,0,1,0, NULL); //These NetlistWires turned into
79 setWireValuesTo(wires[1], 1,0,0,0, NULL); // HWSimWires inside ckt create
80 //TODO: decide how do in-out bidirectional wires -- thinking make it two
81 // separate wires with guard between in-port and out-port
82 //TODO: decide how do guards between ports
83 }
85 //Note: copy netlist struct with VMS malloc after VMS initialized
86 HWSimTimeline *
87 createAPingPongTimeline( HWSimNetlist *netlist )
88 { HWSimTimeline *TL;
89 TL = malloc( sizeof(HWSimTimeline) );
90 TL->numInPorts = 1;
91 TL->numOutPorts = 1;
92 //Sean: here we create only inPorts -> outPorts will be created be HWSim ?
93 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
94 TL->inPorts[-1].triggeredSpanType = IDLE_SPAN; //reset port
95 TL->inPorts[0].triggeredSpanType = netlist->spanTypes[PING_PONG_TYPE];
96 }
98 HWSimSpanType *
99 createPingPongSpanType( )
100 { HWSimSpanType *pingPongSpanType;
101 pingPongSpanType = malloc( sizeof(HWSimSpanType) );
102 pingPongSpanType->behaviorFn = &behaviorOf_ping_pong_span;
103 pingPongSpanType->timingFn = &timingOf_ping_pong_span;
104 return pingPongSpanType;
105 }