| rev |
line source |
|
kshalle@26
|
1 /*
|
|
kshalle@26
|
2 * Copyright 2011 OpenSourceResearchInstitute.org
|
|
kshalle@26
|
3 * Licensed under GNU General Public License version 2
|
|
kshalle@26
|
4 *
|
|
kshalle@26
|
5 * Author: seanhalle@yahoo.com
|
|
kshalle@26
|
6 *
|
|
kshalle@26
|
7 */
|
|
kshalle@26
|
8 #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
|
|
kshalle@26
|
9
|
|
kshalle@26
|
10 /* is an expr resolves to an actual commPath struct instance
|
|
kshalle@26
|
11 */
|
|
kshalle@26
|
12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
|
|
kshalle@26
|
13 do{\
|
|
kshalle@26
|
14 commPath->idxOfFromElem = fromElIdx; \
|
|
kshalle@26
|
15 commPath->idxOfFromOutPort = outPort; \
|
|
kshalle@26
|
16 commPath->idxOfToElem = toElIdx; \
|
|
kshalle@26
|
17 commPath->idxOfToInPort = inPort; \
|
|
kshalle@26
|
18 }while(0); //macro magic for namespace
|
|
kshalle@26
|
19
|
|
kshalle@26
|
20
|
|
kshalle@26
|
21
|
|
kshalle@26
|
22 HWSimActivityType* createPingPongActivityType ();
|
|
kshalle@26
|
23
|
|
kshalle@26
|
24 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
|
|
kshalle@26
|
25
|
|
kshalle@26
|
26 /*This file constructs the netlist for the Hello World circuit
|
|
kshalle@26
|
27 *
|
|
kshalle@26
|
28 *It has two elements, each with one input port and one output port, and
|
|
kshalle@26
|
29 * a single activity-type.
|
|
kshalle@26
|
30 *
|
|
kshalle@26
|
31 *The elements are cross-coupled, so output port of one connects to input
|
|
kshalle@26
|
32 * port of the other. The input port has a single trigger, which fires
|
|
kshalle@26
|
33 * the one activity-type.
|
|
kshalle@26
|
34 *
|
|
kshalle@26
|
35 *The activity does nothing, except send a NULL message on the output port.
|
|
kshalle@26
|
36 *The activity-sim-time and communication-sim-time are both constants.
|
|
kshalle@26
|
37 *
|
|
kshalle@26
|
38 *Note that elements are generic. They are specialized by declaring
|
|
kshalle@26
|
39 * inports and outports, and by registering triggers that fire particular
|
|
kshalle@26
|
40 * activity-types.
|
|
kshalle@26
|
41 */
|
|
kshalle@26
|
42 HWSimNetlist *createPingPongNetlist()
|
|
kshalle@26
|
43 { HWSimNetlist *netlist;
|
|
kshalle@26
|
44 HWSimCommPath **commPaths;
|
|
kshalle@26
|
45 HWSimElem **elems;
|
|
kshalle@26
|
46 int32 numElems;
|
|
kshalle@26
|
47 int32 numCommPaths;
|
|
kshalle@26
|
48
|
|
kshalle@26
|
49 netlist = malloc( sizeof(HWSimNetlist) );
|
|
kshalle@26
|
50 numElems= 2;
|
|
kshalle@26
|
51 elems = malloc( numElems * sizeof(HWSimElem *) );
|
|
kshalle@26
|
52 netlist->numElems = numElems;
|
|
kshalle@26
|
53 netlist->elems = elems;
|
|
kshalle@26
|
54 netlist->numActivityTypes = 1;
|
|
kshalle@26
|
55 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
|
|
kshalle@26
|
56
|
|
kshalle@26
|
57 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
|
|
kshalle@26
|
58
|
|
kshalle@26
|
59 elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
|
|
kshalle@26
|
60 elems[1] = createAPingPongElem( netlist );
|
|
kshalle@26
|
61
|
|
kshalle@26
|
62 //make reset trigger an action on one of the elements
|
|
kshalle@26
|
63 elems[1]->inPorts[-1].triggeredActivityType =
|
|
kshalle@26
|
64 netlist->activityTypes[PING_PONG_ACTIVITY];
|
|
kshalle@26
|
65
|
|
kshalle@26
|
66 /*OutPorts and InPorts may have many commPaths attached.
|
|
kshalle@26
|
67 * but an inPort only
|
|
kshalle@26
|
68 * has one kind of activity that all incoming communications trigger. That
|
|
kshalle@26
|
69 * activity can be zero time and then switch on the type of message then
|
|
kshalle@26
|
70 * end with a continuation, where the continuation activity is chosen by the
|
|
kshalle@26
|
71 * switch.
|
|
kshalle@26
|
72 *So, a commPath only connects an out port to an in port
|
|
kshalle@26
|
73 *The format is: sending elem-index, out-port, dest elem-index, in-port
|
|
kshalle@26
|
74 */
|
|
kshalle@26
|
75 numCommPaths = 2;
|
|
kshalle@26
|
76 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) );
|
|
kshalle@26
|
77 netlist->numCommPaths= numCommPaths;
|
|
kshalle@26
|
78 netlist->commPaths= commPaths;
|
|
kshalle@26
|
79 //elem 0, out-port 0 to elem 1, in-port 0
|
|
kshalle@26
|
80 commPaths[0]= malloc(sizeof(HWSimCommPath));
|
|
kshalle@26
|
81 setCommPathValuesTo(commPaths[0],0,0,1,0);
|
|
kshalle@26
|
82 commPaths[0]->hasFixedTiming = TRUE;
|
|
kshalle@26
|
83 commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
|
|
kshalle@26
|
84
|
|
kshalle@26
|
85 //elem 1, out-port 0 to elem 0, in-port 0
|
|
kshalle@26
|
86 commPaths[1]= malloc(sizeof(HWSimCommPath));
|
|
kshalle@26
|
87 setCommPathValuesTo(commPaths[1], 1,0,0,0);
|
|
kshalle@26
|
88 commPaths[1]->hasFixedTiming = TRUE;
|
|
kshalle@26
|
89 commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
|
|
kshalle@26
|
90
|
|
kshalle@26
|
91 //TODO: decide how to do bidirectional commPaths, like connection to a bus
|
|
kshalle@26
|
92 // thinking make it two separate commPaths with guard between in-port and out-port
|
|
kshalle@26
|
93
|
|
kshalle@26
|
94 return netlist;
|
|
kshalle@26
|
95 }
|
|
kshalle@26
|
96
|
|
kshalle@26
|
97
|
|
kshalle@26
|
98 /*
|
|
kshalle@26
|
99 */
|
|
kshalle@26
|
100 void
|
|
kshalle@26
|
101 freePingPongNetlist (HWSimNetlist *netlist)
|
|
kshalle@26
|
102 { int i;
|
|
kshalle@26
|
103
|
|
kshalle@26
|
104 for( i = 0; i < netlist->numCommPaths; i++ )
|
|
kshalle@26
|
105 { free(netlist->commPaths[i]);
|
|
kshalle@26
|
106 }
|
|
kshalle@26
|
107 free(netlist->commPaths);
|
|
kshalle@26
|
108 for( i= 0; i < netlist->numElems; i++ )
|
|
kshalle@26
|
109 { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
|
|
kshalle@26
|
110 free(netlist->elems[i]->outPorts);
|
|
kshalle@26
|
111 free(netlist->elems[i]);
|
|
kshalle@26
|
112 }
|
|
kshalle@26
|
113
|
|
kshalle@26
|
114 free(netlist->activityTypes);
|
|
kshalle@26
|
115 free(netlist->elems);
|
|
kshalle@26
|
116 free(netlist);
|
|
kshalle@26
|
117 }
|
|
kshalle@26
|
118
|
|
kshalle@26
|
119 /*This creates a simulation element. A simulation element is of the type
|
|
kshalle@26
|
120 * HWSimElem. The HWSimElem data structure contains information about
|
|
kshalle@26
|
121 * the input ports and output ports of the element. In particular, when
|
|
kshalle@26
|
122 * a communication arrives on an input port, that triggers activity inside
|
|
kshalle@26
|
123 * the element. It is here that the function is registerd, which implements
|
|
kshalle@26
|
124 * the behavior of that activity.
|
|
kshalle@26
|
125 *Triggered activities is the heart of HWSim. It is inside these functions
|
|
kshalle@26
|
126 * that application defined behavior takes place.
|
|
kshalle@26
|
127 */
|
|
kshalle@26
|
128 HWSimElem *
|
|
kshalle@26
|
129 createAPingPongElem( HWSimNetlist *netlist )
|
|
kshalle@26
|
130 { HWSimElem *elem;
|
|
kshalle@26
|
131 elem = malloc( sizeof(HWSimElem) );
|
|
kshalle@26
|
132 elem->numInPorts = 1;
|
|
kshalle@26
|
133 elem->numOutPorts = 1;
|
|
kshalle@26
|
134 elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
|
|
kshalle@26
|
135 elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
|
|
kshalle@26
|
136 //point the trigger at an activity that is already in the netlist.
|
|
kshalle@26
|
137 // The function below creates one of such activities.
|
|
kshalle@26
|
138 //The netlist creation function first creates the activities, then
|
|
kshalle@26
|
139 // it calls this function, which grabs activities from the netlist
|
|
kshalle@26
|
140 elem->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY];
|
|
kshalle@26
|
141 return elem;
|
|
kshalle@26
|
142 }
|
|
kshalle@26
|
143
|
|
kshalle@26
|
144 /*Define a type of activity that is possible. The netlist creator
|
|
kshalle@26
|
145 * first calls all of this kind of function, and fills the netlist
|
|
kshalle@26
|
146 * with these data structures that implement activities.
|
|
kshalle@26
|
147 *Then, the creator calls functions that create individual elements.
|
|
kshalle@26
|
148 * Those element-creation functions grab the activity structures out
|
|
kshalle@26
|
149 * of the netlist.
|
|
kshalle@26
|
150 */
|
|
kshalle@26
|
151 HWSimActivityType *
|
|
kshalle@26
|
152 createPingPongActivityType( )
|
|
kshalle@26
|
153 { HWSimActivityType *pingPongActivityType;
|
|
kshalle@26
|
154 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
|
|
kshalle@26
|
155
|
|
kshalle@26
|
156 //For execution speed, some special cases exist, such as activities
|
|
kshalle@26
|
157 // that have no behavior, or ones that have a fixed time to complete
|
|
kshalle@26
|
158 pingPongActivityType->hasBehavior = TRUE;
|
|
kshalle@26
|
159 pingPongActivityType->hasTiming = TRUE;
|
|
kshalle@26
|
160 pingPongActivityType->timingIsFixed = TRUE;
|
|
kshalle@26
|
161 pingPongActivityType->fixedTime = 10;
|
|
kshalle@26
|
162 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
|
|
kshalle@26
|
163 return pingPongActivityType;
|
|
kshalle@26
|
164 }
|
|
kshalle@26
|
165
|