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