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