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@14
|
8 #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
|
Me@11
|
9
|
seanhalle@21
|
10 /* is an expr resolves to an actual commPath struct instance
|
Me@11
|
11 */
|
Me@14
|
12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort,\
|
hausers@16
|
13 timeFnPtr, dataPtr)\
|
Me@11
|
14 do{\
|
Me@14
|
15 commPath->idxOfFromElem = fromElIdx; \
|
hausers@19
|
16 commPath->idxOfFromOutPort = outPort; \
|
Me@14
|
17 commPath->idxOfToElem = toElIdx; \
|
Me@14
|
18 commPath->idxOfToInPort = inPort; \
|
hausers@16
|
19 commPath->commTimeCalcFn = timeFnPtr;\
|
Me@14
|
20 commPath->archSpecCommPathData = dataPtr; \
|
Me@11
|
21 }while(0); //macro magic for namespace
|
hausers@12
|
22
|
hausers@12
|
23
|
hausers@18
|
24
|
Me@14
|
25 HWSimActivityType* createPingPongActivityType ();
|
hausers@12
|
26
|
Me@14
|
27 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
|
hausers@12
|
28
|
Me@11
|
29 /*This file constructs the netlist for the Hello World circuit, which is
|
Me@11
|
30 * used during design and implementation of the HWSim language
|
Me@11
|
31 *
|
Me@14
|
32 *It has two elements, each with one input port and one output port, and
|
Me@14
|
33 * a single activity-type.
|
Me@11
|
34 *
|
Me@14
|
35 *The elements are cross-coupled, so output port of one connects to input
|
Me@11
|
36 * port of the other. The input port has a single trigger, which fires
|
Me@14
|
37 * the one activity-type.
|
Me@11
|
38 *
|
Me@14
|
39 *The activity does nothing, except send a NULL message on the output port.
|
Me@14
|
40 *The activity-sim-time and communication-sim-time are both constants.
|
Me@11
|
41 *
|
Me@14
|
42 *Note that elements are generic. They are specialized by declaring
|
Me@11
|
43 * inports and outports, and by registering triggers that fire particular
|
Me@14
|
44 * activity-types.
|
Me@11
|
45 */
|
Me@11
|
46 HWSimNetlist *createPingPongNetlist()
|
Me@11
|
47 { HWSimNetlist *netlist;
|
Me@14
|
48 HWSimCommPath **commPaths;
|
Me@14
|
49 HWSimElem **elems;
|
Me@14
|
50 int32 numElems;
|
Me@14
|
51 int32 numCommPaths;
|
Me@11
|
52
|
Me@11
|
53 netlist = malloc( sizeof(HWSimNetlist) );
|
hausers@16
|
54 numElems= 2;
|
hausers@20
|
55 elems = malloc( numElems * sizeof(HWSimElem *) );
|
Me@14
|
56 netlist->numElems = numElems;
|
Me@14
|
57 netlist->elems = elems;
|
Me@14
|
58 netlist->numActivityTypes = 1;
|
Me@14
|
59 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
|
hausers@20
|
60 // Stefan: tocheck valgrind
|
seanhalle@22
|
61 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
|
hausers@20
|
62
|
Me@14
|
63 elems[0] = createAPingPongElem( netlist ); //use info from netlist
|
Me@14
|
64 elems[1] = createAPingPongElem( netlist );
|
Me@14
|
65 //on one of the elems, make reset trigger an action
|
hausers@17
|
66 //Stefan: FIXME
|
Me@14
|
67 elems[1]->inPorts[-1].triggeredActivityType =
|
seanhalle@22
|
68 netlist->activityTypes[PING_PONG_ACTIVITY]; //Connect elems together
|
Me@11
|
69
|
Me@14
|
70 /*OutPorts and InPorts may have many commPaths attached.
|
Me@14
|
71 * but an inPort only
|
Me@14
|
72 * has one kind of activity that all incoming communications trigger. That
|
Me@14
|
73 * activity can be zero time and then switch on the type of message then
|
Me@14
|
74 * end with a continuation, where the continuation activity is chosen by the
|
Me@11
|
75 * switch.
|
Me@14
|
76 *So, a commPath only connects an out port to an in port
|
Me@11
|
77 *The format is: sending TL-index, out-port, dest TL-index, in-port
|
Me@11
|
78 */
|
Me@14
|
79 numCommPaths = 2;
|
hausers@20
|
80 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) );
|
Me@14
|
81 netlist->numCommPaths= numCommPaths;
|
Me@14
|
82 netlist->commPaths= commPaths;
|
Me@14
|
83 //TL 0, out-port 0 to TL 1, in-port 0
|
hausers@18
|
84 commPaths[0]= malloc(sizeof(HWSimCommPath));
|
hausers@16
|
85 setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL);
|
Me@14
|
86 //TL 1, out-port 0 to TL 0, in-port 0
|
hausers@18
|
87 commPaths[1]= malloc(sizeof(HWSimCommPath));
|
hausers@16
|
88 setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL);
|
Me@14
|
89
|
Me@14
|
90 //TODO: decide how do in-out bidirectional commPaths -- thinking make it two
|
Me@14
|
91 // separate commPaths with guard between in-port and out-port
|
hausers@16
|
92
|
hausers@16
|
93 return netlist;
|
Me@11
|
94 }
|
hausers@20
|
95
|
hausers@20
|
96 void
|
hausers@20
|
97 freePingPongNetlist (HWSimNetlist *netlist)
|
hausers@20
|
98 {
|
hausers@20
|
99 int i;
|
hausers@20
|
100 for (i= 0; i<netlist->numCommPaths; i++) {
|
hausers@20
|
101 free(netlist->commPaths[i]);
|
hausers@20
|
102 }
|
hausers@20
|
103 free(netlist->commPaths);
|
hausers@20
|
104 for (i= 0; i<netlist->numElems; i++) {
|
hausers@20
|
105 free(&netlist->elems[i]->inPorts[-1]);
|
hausers@20
|
106 free(netlist->elems[i]);
|
hausers@20
|
107 }
|
hausers@20
|
108
|
hausers@20
|
109 free(netlist->activityTypes);
|
hausers@20
|
110 free(netlist->elems);
|
hausers@20
|
111 free(netlist);
|
hausers@20
|
112 }
|
Me@11
|
113
|
Me@14
|
114 HWSimElem *
|
Me@14
|
115 createAPingPongElem( HWSimNetlist *netlist )
|
Me@14
|
116 { HWSimElem *TL;
|
Me@14
|
117 TL = malloc( sizeof(HWSimElem) );
|
Me@11
|
118 TL->numInPorts = 1;
|
Me@11
|
119 TL->numOutPorts = 1;
|
Me@11
|
120 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
|
Me@14
|
121 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
|
seanhalle@22
|
122 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY];
|
hausers@16
|
123 return TL;
|
Me@11
|
124 }
|
Me@11
|
125
|
Me@14
|
126 HWSimActivityType *
|
Me@14
|
127 createPingPongActivityType( )
|
Me@14
|
128 { HWSimActivityType *pingPongActivityType;
|
Me@14
|
129 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
|
seanhalle@22
|
130
|
seanhalle@22
|
131 pingPongActivityType->hasBehavior = true;
|
seanhalle@22
|
132 pingPongActivityType->hasTiming = true;
|
seanhalle@22
|
133 pingPongActivityType->timingIsFixed = true;
|
seanhalle@22
|
134 pingPongActivityType->fixedTime = 10;
|
seanhalle@22
|
135 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
|
Me@14
|
136 return pingPongActivityType;
|
seanhalle@22
|
137 }
|
hausers@12
|
138
|