rev |
line source |
Me@11
|
1 /*
|
Me@11
|
2 * Copyright 2011 OpenSourceStewardshipFoundation.org
|
Me@11
|
3 * Licensed under GNU General Public License version 2
|
Me@11
|
4 *
|
Me@11
|
5 * Author: seanhalle@yahoo.com
|
Me@11
|
6 *
|
Me@11
|
7 */
|
Me@14
|
8 #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
|
Me@11
|
9
|
Me@14
|
10 /*'' is an expr resolves to an actual commPath struct instance
|
Me@11
|
11 */
|
Me@14
|
12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort,\
|
Me@14
|
13 commTimeFnPtr, dataPtr)\
|
Me@11
|
14 do{\
|
Me@14
|
15 commPath->idxOfFromElem = fromElIdx; \
|
Me@14
|
16 commPath->idxOfFromOutPort = fromElIdx; \
|
Me@14
|
17 commPath->idxOfToElem = toElIdx; \
|
Me@14
|
18 commPath->idxOfToInPort = inPort; \
|
Me@14
|
19 commPath->commTimeFnPtr = commTimeFnPtr;\
|
Me@14
|
20 commPath->archSpecCommPathData = dataPtr; \
|
Me@11
|
21 }while(0); //macro magic for namespace
|
hausers@12
|
22
|
hausers@12
|
23
|
Me@14
|
24 HWSimActivityType* createPingPongActivityType ();
|
hausers@12
|
25
|
Me@14
|
26 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
|
hausers@12
|
27
|
Me@11
|
28 /*This file constructs the netlist for the Hello World circuit, which is
|
Me@11
|
29 * used during design and implementation of the HWSim language
|
Me@11
|
30 *
|
Me@14
|
31 *It has two elements, each with one input port and one output port, and
|
Me@14
|
32 * a single activity-type.
|
Me@11
|
33 *
|
Me@14
|
34 *The elements are cross-coupled, so output port of one connects to input
|
Me@11
|
35 * port of the other. The input port has a single trigger, which fires
|
Me@14
|
36 * the one activity-type.
|
Me@11
|
37 *
|
Me@14
|
38 *The activity does nothing, except send a NULL message on the output port.
|
Me@14
|
39 *The activity-sim-time and communication-sim-time are both constants.
|
Me@11
|
40 *
|
Me@14
|
41 *Note that elements are generic. They are specialized by declaring
|
Me@11
|
42 * inports and outports, and by registering triggers that fire particular
|
Me@14
|
43 * activity-types.
|
Me@11
|
44 */
|
Me@11
|
45 HWSimNetlist *createPingPongNetlist()
|
Me@11
|
46 { HWSimNetlist *netlist;
|
Me@14
|
47 HWSimCommPath **commPaths;
|
Me@14
|
48 HWSimElem **elems;
|
Me@14
|
49 int32 numElems;
|
Me@14
|
50 int32 numCommPaths;
|
Me@14
|
51 HWSimActivityType *foo;
|
Me@11
|
52
|
Me@11
|
53 netlist = malloc( sizeof(HWSimNetlist) );
|
Me@14
|
54 //declare elems numElems = 2;
|
Me@14
|
55 elems = malloc( numElems * sizeof(HWSimElem) );
|
Me@14
|
56 netlist->numElems = numElems;
|
Me@14
|
57 netlist->elems = elems;
|
Me@14
|
58 netlist->numActivityTypes = 1;
|
Me@14
|
59 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
|
Me@14
|
60 netlist->activityTypes[PING_PONG_TYPE] = createPingPongActivityType();
|
Me@14
|
61 elems[0] = createAPingPongElem( netlist ); //use info from netlist
|
Me@14
|
62 elems[1] = createAPingPongElem( netlist );
|
Me@14
|
63 //on one of the elems, make reset trigger an action
|
Me@14
|
64 elems[1]->inPorts[-1].triggeredActivityType =
|
Me@14
|
65 netlist->activityTypes[PING_PONG_TYPE]; //Connect elems together
|
Me@11
|
66
|
Me@14
|
67 /*OutPorts and InPorts may have many commPaths attached.
|
Me@14
|
68 * but an inPort only
|
Me@14
|
69 * has one kind of activity that all incoming communications trigger. That
|
Me@14
|
70 * activity can be zero time and then switch on the type of message then
|
Me@14
|
71 * end with a continuation, where the continuation activity is chosen by the
|
Me@11
|
72 * switch.
|
Me@14
|
73 *So, a commPath only connects an out port to an in port
|
Me@11
|
74 *The format is: sending TL-index, out-port, dest TL-index, in-port
|
Me@11
|
75 */
|
Me@14
|
76 numCommPaths = 2;
|
Me@14
|
77 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath) );
|
Me@14
|
78 netlist->numCommPaths= numCommPaths;
|
Me@14
|
79 netlist->commPaths= commPaths;
|
Me@14
|
80 //TL 0, out-port 0 to TL 1, in-port 0
|
Me@14
|
81 setCommPathValuesTo(commPaths[0], 0,0,1,0, &commPath_TimeSpanCalc, NULL);
|
Me@14
|
82 //TL 1, out-port 0 to TL 0, in-port 0
|
Me@14
|
83 setCommPathValuesTo(commPaths[1], 1,0,0,0, &commPath_TimeSpanCalc, NULL);
|
Me@14
|
84
|
Me@14
|
85 //TODO: decide how do in-out bidirectional commPaths -- thinking make it two
|
Me@14
|
86 // separate commPaths with guard between in-port and out-port
|
Me@11
|
87 }
|
Me@11
|
88
|
Me@14
|
89 //Stefan: copy netlist struct with VMS malloc after VMS initialized?
|
Me@14
|
90 HWSimElem *
|
Me@14
|
91 createAPingPongElem( HWSimNetlist *netlist )
|
Me@14
|
92 { HWSimElem *TL;
|
Me@14
|
93 TL = malloc( sizeof(HWSimElem) );
|
Me@11
|
94 TL->numInPorts = 1;
|
Me@11
|
95 TL->numOutPorts = 1;
|
Me@11
|
96 TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts );
|
Me@14
|
97 TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
|
Me@14
|
98 TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_TYPE];
|
Me@11
|
99 }
|
Me@11
|
100
|
Me@14
|
101 HWSimActivityType *
|
Me@14
|
102 createPingPongActivityType( )
|
Me@14
|
103 { HWSimActivityType *pingPongActivityType;
|
Me@14
|
104 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
|
Me@14
|
105 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
|
Me@14
|
106 pingPongActivityType->timingFn = &pingPongElem_PingActivity_timing;
|
Me@14
|
107 return pingPongActivityType;
|
Me@11
|
108 }
|
hausers@12
|
109
|