Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > HWSim > HWSim__PingPong__HWDef
view CircuitNetlistCreator.c @ 19:ba3883d39e62
small changes
author | hausers |
---|---|
date | Fri, 02 Mar 2012 18:14:06 +0100 |
parents | b0e9969d8d15 |
children | 3a4be4048a21 |
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 netlist->activityTypes[PING_PONG_TYPE] = createPingPongActivityType();
61 elems[0] = createAPingPongElem( netlist ); //use info from netlist
62 elems[1] = createAPingPongElem( netlist );
63 //on one of the elems, make reset trigger an action
64 //Stefan: FIXME
65 elems[1]->inPorts[-1].triggeredActivityType =
66 netlist->activityTypes[PING_PONG_TYPE]; //Connect elems together
68 /*OutPorts and InPorts may have many commPaths attached.
69 * but an inPort only
70 * has one kind of activity that all incoming communications trigger. That
71 * activity can be zero time and then switch on the type of message then
72 * end with a continuation, where the continuation activity is chosen by the
73 * switch.
74 *So, a commPath only connects an out port to an in port
75 *The format is: sending TL-index, out-port, dest TL-index, in-port
76 */
77 numCommPaths = 2;
78 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath) );
79 netlist->numCommPaths= numCommPaths;
80 netlist->commPaths= commPaths;
81 //TL 0, out-port 0 to TL 1, in-port 0
82 commPaths[0]= malloc(sizeof(HWSimCommPath));
83 setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL);
84 //TL 1, out-port 0 to TL 0, in-port 0
85 commPaths[1]= malloc(sizeof(HWSimCommPath));
86 setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL);
88 //TODO: decide how do in-out bidirectional commPaths -- thinking make it two
89 // separate commPaths with guard between in-port and out-port
91 return netlist;
92 }
94 //Stefan: copy netlist struct with VMS malloc after VMS initialized?
95 //ANSWER: yes, otherwise the user has to deal with VMS details.
96 // So we should do this in HWSim__make_netlist_simulatable -> yes
97 // If so, I can do this
98 HWSimElem *
99 createAPingPongElem( HWSimNetlist *netlist )
100 { HWSimElem *TL;
101 TL = malloc( sizeof(HWSimElem) );
102 TL->numInPorts = 1;
103 TL->numOutPorts = 1;
104 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
105 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
106 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_TYPE];
107 return TL;
108 }
110 HWSimActivityType *
111 createPingPongActivityType( )
112 { HWSimActivityType *pingPongActivityType;
113 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
114 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
115 pingPongActivityType->timingFn = &pingPongElem_PingActivity_timing;
116 return pingPongActivityType;
117 }