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