view CircuitNetlistCreator.c @ 15:8d9d367e96f9

updated for VMS name chgs from VMS__malloc to VMS_int__malloc
author Me@portablequad
date Sun, 12 Feb 2012 01:47:58 -0800
parents abe3db0025d5
children df53f52ef49c 561d3a06ffc5
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 commTimeFnPtr, dataPtr)\
14 do{\
15 commPath->idxOfFromElem = fromElIdx; \
16 commPath->idxOfFromOutPort = fromElIdx; \
17 commPath->idxOfToElem = toElIdx; \
18 commPath->idxOfToInPort = inPort; \
19 commPath->commTimeFnPtr = commTimeFnPtr;\
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;
51 HWSimActivityType *foo;
53 netlist = malloc( sizeof(HWSimNetlist) );
54 //declare elems 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 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
87 }
89 //Stefan: copy netlist struct with VMS malloc after VMS initialized?
90 HWSimElem *
91 createAPingPongElem( HWSimNetlist *netlist )
92 { HWSimElem *TL;
93 TL = malloc( sizeof(HWSimElem) );
94 TL->numInPorts = 1;
95 TL->numOutPorts = 1;
96 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
97 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
98 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_TYPE];
99 }
101 HWSimActivityType *
102 createPingPongActivityType( )
103 { HWSimActivityType *pingPongActivityType;
104 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
105 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
106 pingPongActivityType->timingFn = &pingPongElem_PingActivity_timing;
107 return pingPongActivityType;
108 }