view CircuitNetlistCreator.c @ 22:fac65c465f98

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