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