view CircuitNetlistCreator.c @ 17:fa277c6ce6f2

first compilable version
author hausers
date Mon, 20 Feb 2012 17:06:56 +0100
parents df53f52ef49c
children b0e9969d8d15
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 = fromElIdx; \
17 commPath->idxOfToElem = toElIdx; \
18 commPath->idxOfToInPort = inPort; \
19 commPath->commTimeCalcFn = timeFnPtr;\
20 commPath->archSpecCommPathData = dataPtr; \
21 }while(0); //macro magic for namespace
24 HWSimActivityType* createPingPongActivityType ();
26 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
28 /*This file constructs the netlist for the Hello World circuit, which is
29 * used during design and implementation of the HWSim language
30 *
31 *It has two elements, each with one input port and one output port, and
32 * a single activity-type.
33 *
34 *The elements are cross-coupled, so output port of one connects to input
35 * port of the other. The input port has a single trigger, which fires
36 * the one activity-type.
37 *
38 *The activity does nothing, except send a NULL message on the output port.
39 *The activity-sim-time and communication-sim-time are both constants.
40 *
41 *Note that elements are generic. They are specialized by declaring
42 * inports and outports, and by registering triggers that fire particular
43 * activity-types.
44 */
45 HWSimNetlist *createPingPongNetlist()
46 { HWSimNetlist *netlist;
47 HWSimCommPath **commPaths;
48 HWSimElem **elems;
49 int32 numElems;
50 int32 numCommPaths;
52 netlist = malloc( sizeof(HWSimNetlist) );
53 numElems= 2;
54 elems = malloc( numElems * sizeof(HWSimElem) );
55 netlist->numElems = numElems;
56 netlist->elems = elems;
57 netlist->numActivityTypes = 1;
58 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
59 netlist->activityTypes[PING_PONG_TYPE] = createPingPongActivityType();
60 elems[0] = createAPingPongElem( netlist ); //use info from netlist
61 elems[1] = createAPingPongElem( netlist );
62 //on one of the elems, make reset trigger an action
63 //Stefan: FIXME
64 elems[1]->inPorts[-1].triggeredActivityType =
65 netlist->activityTypes[PING_PONG_TYPE]; //Connect elems together
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 TL-index, out-port, dest TL-index, in-port
75 */
76 numCommPaths = 2;
77 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath) );
78 netlist->numCommPaths= numCommPaths;
79 netlist->commPaths= commPaths;
80 //TL 0, out-port 0 to TL 1, in-port 0
81 setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL);
82 //TL 1, out-port 0 to TL 0, in-port 0
83 setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL);
85 //TODO: decide how do in-out bidirectional commPaths -- thinking make it two
86 // separate commPaths with guard between in-port and out-port
88 return netlist;
89 }
91 //Stefan: copy netlist struct with VMS malloc after VMS initialized?
92 //Sean: yes, otherwise the user has to deal with VMS details.
93 // So we should do this in HWSim__make_netlist_simulatable ?
94 // If so, I can do this
95 HWSimElem *
96 createAPingPongElem( HWSimNetlist *netlist )
97 { HWSimElem *TL;
98 TL = malloc( sizeof(HWSimElem) );
99 TL->numInPorts = 1;
100 TL->numOutPorts = 1;
101 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
102 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
103 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_TYPE];
104 return TL;
105 }
107 HWSimActivityType *
108 createPingPongActivityType( )
109 { HWSimActivityType *pingPongActivityType;
110 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
111 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
112 pingPongActivityType->timingFn = &pingPongElem_PingActivity_timing;
113 return pingPongActivityType;
114 }