view CircuitNetlistCreator.c @ 25:b1c9d67643f2

fixed DEBUG to DEBUG__printf2
author Some Random Person <seanhalle@yahoo.com>
date Thu, 24 May 2012 08:14:21 -0700
parents c11c48758df3
children 0deed3ee0b02
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 do{\
14 commPath->idxOfFromElem = fromElIdx; \
15 commPath->idxOfFromOutPort = outPort; \
16 commPath->idxOfToElem = toElIdx; \
17 commPath->idxOfToInPort = inPort; \
18 }while(0); //macro magic for namespace
22 HWSimActivityType* createPingPongActivityType ();
24 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
26 /*This file constructs the netlist for the Hello World circuit, which is
27 * used during design and implementation of the HWSim language
28 *
29 *It has two elements, each with one input port and one output port, and
30 * a single activity-type.
31 *
32 *The elements are cross-coupled, so output port of one connects to input
33 * port of the other. The input port has a single trigger, which fires
34 * the one activity-type.
35 *
36 *The activity does nothing, except send a NULL message on the output port.
37 *The activity-sim-time and communication-sim-time are both constants.
38 *
39 *Note that elements are generic. They are specialized by declaring
40 * inports and outports, and by registering triggers that fire particular
41 * activity-types.
42 */
43 HWSimNetlist *createPingPongNetlist()
44 { HWSimNetlist *netlist;
45 HWSimCommPath **commPaths;
46 HWSimElem **elems;
47 int32 numElems;
48 int32 numCommPaths;
50 netlist = malloc( sizeof(HWSimNetlist) );
51 numElems= 2;
52 elems = malloc( numElems * sizeof(HWSimElem *) );
53 netlist->numElems = numElems;
54 netlist->elems = elems;
55 netlist->numActivityTypes = 1;
56 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
58 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
60 elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
61 elems[1] = createAPingPongElem( netlist );
63 //make reset trigger an action on one of the elements
64 elems[1]->inPorts[-1].triggeredActivityType =
65 netlist->activityTypes[PING_PONG_ACTIVITY];
67 /*OutPorts and InPorts may have many commPaths attached.
68 * but an inPort only
69 * has one kind of activity that all incoming communications trigger. That
70 * activity can be zero time and then switch on the type of message then
71 * end with a continuation, where the continuation activity is chosen by the
72 * switch.
73 *So, a commPath only connects an out port to an in port
74 *The format is: sending elem-index, out-port, dest elem-index, in-port
75 */
76 numCommPaths = 2;
77 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) );
78 netlist->numCommPaths= numCommPaths;
79 netlist->commPaths= commPaths;
80 //elem 0, out-port 0 to elem 1, in-port 0
81 commPaths[0]= malloc(sizeof(HWSimCommPath));
82 setCommPathValuesTo(commPaths[0],0,0,1,0);
83 commPaths[0]->hasFixedTiming = TRUE;
84 commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
86 //elem 1, out-port 0 to elem 0, in-port 0
87 commPaths[1]= malloc(sizeof(HWSimCommPath));
88 setCommPathValuesTo(commPaths[1], 1,0,0,0);
89 commPaths[1]->hasFixedTiming = TRUE;
90 commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
92 //TODO: decide how to do bidirectional commPaths, like connection to a bus
93 // thinking make it two separate commPaths with guard between in-port and out-port
95 return netlist;
96 }
99 /*
100 */
101 void
102 freePingPongNetlist (HWSimNetlist *netlist)
103 { int i;
105 for( i = 0; i < netlist->numCommPaths; i++ )
106 { free(netlist->commPaths[i]);
107 }
108 free(netlist->commPaths);
109 for( i= 0; i < netlist->numElems; i++ )
110 { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
111 free(netlist->elems[i]->outPorts);
112 free(netlist->elems[i]);
113 }
115 free(netlist->activityTypes);
116 free(netlist->elems);
117 free(netlist);
118 }
120 HWSimElem *
121 createAPingPongElem( HWSimNetlist *netlist )
122 { HWSimElem *elem;
123 elem = malloc( sizeof(HWSimElem) );
124 elem->numInPorts = 1;
125 elem->numOutPorts = 1;
126 elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
127 elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
128 elem->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY];
129 return elem;
130 }
132 HWSimActivityType *
133 createPingPongActivityType( )
134 { HWSimActivityType *pingPongActivityType;
135 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
137 pingPongActivityType->hasBehavior = TRUE;
138 pingPongActivityType->hasTiming = TRUE;
139 pingPongActivityType->timingIsFixed = TRUE;
140 pingPongActivityType->fixedTime = 10;
141 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
142 return pingPongActivityType;
143 }