Me@11: /* Me@11: * Copyright 2011 OpenSourceStewardshipFoundation.org Me@11: * Licensed under GNU General Public License version 2 Me@11: * Me@11: * Author: seanhalle@yahoo.com Me@11: * Me@11: */ Me@14: #include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h" Me@11: Me@14: /*'' is an expr resolves to an actual commPath struct instance Me@11: */ Me@14: #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort,\ hausers@16: timeFnPtr, dataPtr)\ Me@11: do{\ Me@14: commPath->idxOfFromElem = fromElIdx; \ Me@14: commPath->idxOfFromOutPort = fromElIdx; \ Me@14: commPath->idxOfToElem = toElIdx; \ Me@14: commPath->idxOfToInPort = inPort; \ hausers@16: commPath->commTimeCalcFn = timeFnPtr;\ Me@14: commPath->archSpecCommPathData = dataPtr; \ Me@11: }while(0); //macro magic for namespace hausers@12: hausers@12: Me@14: HWSimActivityType* createPingPongActivityType (); hausers@12: Me@14: HWSimElem* createAPingPongElem (HWSimNetlist *netlist); hausers@12: Me@11: /*This file constructs the netlist for the Hello World circuit, which is Me@11: * used during design and implementation of the HWSim language Me@11: * Me@14: *It has two elements, each with one input port and one output port, and Me@14: * a single activity-type. Me@11: * Me@14: *The elements are cross-coupled, so output port of one connects to input Me@11: * port of the other. The input port has a single trigger, which fires Me@14: * the one activity-type. Me@11: * Me@14: *The activity does nothing, except send a NULL message on the output port. Me@14: *The activity-sim-time and communication-sim-time are both constants. Me@11: * Me@14: *Note that elements are generic. They are specialized by declaring Me@11: * inports and outports, and by registering triggers that fire particular Me@14: * activity-types. Me@11: */ Me@11: HWSimNetlist *createPingPongNetlist() Me@11: { HWSimNetlist *netlist; Me@14: HWSimCommPath **commPaths; Me@14: HWSimElem **elems; Me@14: int32 numElems; Me@14: int32 numCommPaths; Me@11: Me@11: netlist = malloc( sizeof(HWSimNetlist) ); hausers@16: numElems= 2; Me@14: elems = malloc( numElems * sizeof(HWSimElem) ); Me@14: netlist->numElems = numElems; Me@14: netlist->elems = elems; Me@14: netlist->numActivityTypes = 1; Me@14: netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*)); Me@14: netlist->activityTypes[PING_PONG_TYPE] = createPingPongActivityType(); Me@14: elems[0] = createAPingPongElem( netlist ); //use info from netlist Me@14: elems[1] = createAPingPongElem( netlist ); Me@14: //on one of the elems, make reset trigger an action hausers@17: //Stefan: FIXME Me@14: elems[1]->inPorts[-1].triggeredActivityType = Me@14: netlist->activityTypes[PING_PONG_TYPE]; //Connect elems together Me@11: Me@14: /*OutPorts and InPorts may have many commPaths attached. Me@14: * but an inPort only Me@14: * has one kind of activity that all incoming communications trigger. That Me@14: * activity can be zero time and then switch on the type of message then Me@14: * end with a continuation, where the continuation activity is chosen by the Me@11: * switch. Me@14: *So, a commPath only connects an out port to an in port Me@11: *The format is: sending TL-index, out-port, dest TL-index, in-port Me@11: */ Me@14: numCommPaths = 2; Me@14: commPaths = malloc( numCommPaths * sizeof(HWSimCommPath) ); Me@14: netlist->numCommPaths= numCommPaths; Me@14: netlist->commPaths= commPaths; Me@14: //TL 0, out-port 0 to TL 1, in-port 0 hausers@16: setCommPathValuesTo(commPaths[0],0,0,1,0, commPath_TimeSpanCalc, NULL); Me@14: //TL 1, out-port 0 to TL 0, in-port 0 hausers@16: setCommPathValuesTo(commPaths[1], 1,0,0,0, commPath_TimeSpanCalc, NULL); Me@14: Me@14: //TODO: decide how do in-out bidirectional commPaths -- thinking make it two Me@14: // separate commPaths with guard between in-port and out-port hausers@16: hausers@16: return netlist; Me@11: } Me@11: Me@14: //Stefan: copy netlist struct with VMS malloc after VMS initialized? hausers@16: //Sean: yes, otherwise the user has to deal with VMS details. hausers@16: // So we should do this in HWSim__make_netlist_simulatable ? hausers@16: // If so, I can do this Me@14: HWSimElem * Me@14: createAPingPongElem( HWSimNetlist *netlist ) Me@14: { HWSimElem *TL; Me@14: TL = malloc( sizeof(HWSimElem) ); Me@11: TL->numInPorts = 1; Me@11: TL->numOutPorts = 1; Me@11: TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts ); Me@14: TL->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port Me@14: TL->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_TYPE]; hausers@16: return TL; Me@11: } Me@11: Me@14: HWSimActivityType * Me@14: createPingPongActivityType( ) Me@14: { HWSimActivityType *pingPongActivityType; Me@14: pingPongActivityType = malloc( sizeof(HWSimActivityType) ); Me@14: pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior; Me@14: pingPongActivityType->timingFn = &pingPongElem_PingActivity_timing; Me@14: return pingPongActivityType; Me@11: } hausers@12: