annotate CircuitNetlistCreator.c @ 25:b1c9d67643f2

fixed DEBUG to DEBUG__printf2
author Some Random Person <seanhalle@yahoo.com>
date Thu, 24 May 2012 08:14:21 -0700
parents c11c48758df3
children 0deed3ee0b02
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
seanhalle@21 10 /* is an expr resolves to an actual commPath struct instance
Me@11 11 */
seanhalle@24 12 #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
Me@11 13 do{\
Me@14 14 commPath->idxOfFromElem = fromElIdx; \
hausers@19 15 commPath->idxOfFromOutPort = outPort; \
Me@14 16 commPath->idxOfToElem = toElIdx; \
Me@14 17 commPath->idxOfToInPort = inPort; \
Me@11 18 }while(0); //macro magic for namespace
hausers@12 19
hausers@12 20
hausers@18 21
Me@14 22 HWSimActivityType* createPingPongActivityType ();
hausers@12 23
Me@14 24 HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
hausers@12 25
Me@11 26 /*This file constructs the netlist for the Hello World circuit, which is
Me@11 27 * used during design and implementation of the HWSim language
Me@11 28 *
Me@14 29 *It has two elements, each with one input port and one output port, and
Me@14 30 * a single activity-type.
Me@11 31 *
Me@14 32 *The elements are cross-coupled, so output port of one connects to input
Me@11 33 * port of the other. The input port has a single trigger, which fires
Me@14 34 * the one activity-type.
Me@11 35 *
Me@14 36 *The activity does nothing, except send a NULL message on the output port.
Me@14 37 *The activity-sim-time and communication-sim-time are both constants.
Me@11 38 *
Me@14 39 *Note that elements are generic. They are specialized by declaring
Me@11 40 * inports and outports, and by registering triggers that fire particular
Me@14 41 * activity-types.
Me@11 42 */
Me@11 43 HWSimNetlist *createPingPongNetlist()
Me@11 44 { HWSimNetlist *netlist;
Me@14 45 HWSimCommPath **commPaths;
Me@14 46 HWSimElem **elems;
Me@14 47 int32 numElems;
Me@14 48 int32 numCommPaths;
Me@11 49
Me@11 50 netlist = malloc( sizeof(HWSimNetlist) );
seanhalle@24 51 numElems= 2;
hausers@20 52 elems = malloc( numElems * sizeof(HWSimElem *) );
Me@14 53 netlist->numElems = numElems;
Me@14 54 netlist->elems = elems;
Me@14 55 netlist->numActivityTypes = 1;
Me@14 56 netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
seanhalle@24 57
seanhalle@22 58 netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
hausers@20 59
seanhalle@24 60 elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
Me@14 61 elems[1] = createAPingPongElem( netlist );
seanhalle@24 62
seanhalle@24 63 //make reset trigger an action on one of the elements
Me@14 64 elems[1]->inPorts[-1].triggeredActivityType =
seanhalle@24 65 netlist->activityTypes[PING_PONG_ACTIVITY];
Me@11 66
seanhalle@24 67 /*OutPorts and InPorts may have many commPaths attached.
Me@14 68 * but an inPort only
seanhalle@24 69 * has one kind of activity that all incoming communications trigger. That
seanhalle@24 70 * activity can be zero time and then switch on the type of message then
seanhalle@24 71 * end with a continuation, where the continuation activity is chosen by the
seanhalle@24 72 * switch.
seanhalle@24 73 *So, a commPath only connects an out port to an in port
seanhalle@24 74 *The format is: sending elem-index, out-port, dest elem-index, in-port
seanhalle@24 75 */
Me@14 76 numCommPaths = 2;
hausers@20 77 commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) );
Me@14 78 netlist->numCommPaths= numCommPaths;
Me@14 79 netlist->commPaths= commPaths;
seanhalle@24 80 //elem 0, out-port 0 to elem 1, in-port 0
seanhalle@24 81 commPaths[0]= malloc(sizeof(HWSimCommPath));
seanhalle@24 82 setCommPathValuesTo(commPaths[0],0,0,1,0);
seanhalle@24 83 commPaths[0]->hasFixedTiming = TRUE;
seanhalle@24 84 commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
seanhalle@24 85
seanhalle@24 86 //elem 1, out-port 0 to elem 0, in-port 0
seanhalle@24 87 commPaths[1]= malloc(sizeof(HWSimCommPath));
seanhalle@24 88 setCommPathValuesTo(commPaths[1], 1,0,0,0);
seanhalle@24 89 commPaths[1]->hasFixedTiming = TRUE;
seanhalle@24 90 commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
Me@14 91
seanhalle@24 92 //TODO: decide how to do bidirectional commPaths, like connection to a bus
seanhalle@24 93 // thinking make it two separate commPaths with guard between in-port and out-port
hausers@16 94
hausers@16 95 return netlist;
Me@11 96 }
hausers@20 97
seanhalle@24 98
seanhalle@24 99 /*
seanhalle@24 100 */
hausers@20 101 void
hausers@20 102 freePingPongNetlist (HWSimNetlist *netlist)
seanhalle@24 103 { int i;
seanhalle@24 104
seanhalle@24 105 for( i = 0; i < netlist->numCommPaths; i++ )
seanhalle@24 106 { free(netlist->commPaths[i]);
seanhalle@24 107 }
seanhalle@24 108 free(netlist->commPaths);
seanhalle@24 109 for( i= 0; i < netlist->numElems; i++ )
seanhalle@24 110 { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
seanhalle@24 111 free(netlist->elems[i]->outPorts);
seanhalle@24 112 free(netlist->elems[i]);
seanhalle@24 113 }
hausers@20 114
seanhalle@24 115 free(netlist->activityTypes);
seanhalle@24 116 free(netlist->elems);
seanhalle@24 117 free(netlist);
seanhalle@24 118 }
Me@11 119
Me@14 120 HWSimElem *
Me@14 121 createAPingPongElem( HWSimNetlist *netlist )
seanhalle@24 122 { HWSimElem *elem;
seanhalle@24 123 elem = malloc( sizeof(HWSimElem) );
seanhalle@24 124 elem->numInPorts = 1;
seanhalle@24 125 elem->numOutPorts = 1;
seanhalle@24 126 elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
seanhalle@24 127 elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
seanhalle@24 128 elem->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY];
seanhalle@24 129 return elem;
Me@11 130 }
Me@11 131
Me@14 132 HWSimActivityType *
Me@14 133 createPingPongActivityType( )
Me@14 134 { HWSimActivityType *pingPongActivityType;
Me@14 135 pingPongActivityType = malloc( sizeof(HWSimActivityType) );
seanhalle@22 136
seanhalle@24 137 pingPongActivityType->hasBehavior = TRUE;
seanhalle@24 138 pingPongActivityType->hasTiming = TRUE;
seanhalle@24 139 pingPongActivityType->timingIsFixed = TRUE;
seanhalle@22 140 pingPongActivityType->fixedTime = 10;
seanhalle@22 141 pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior;
Me@14 142 return pingPongActivityType;
seanhalle@22 143 }
hausers@12 144