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@11: #include "HWSim__Hello_World_HW/HWSim__Hello_World_HW.h" Me@11: Me@11: /*'wire' is an expr resolves to an actual wire struct instance Me@11: */ Me@11: #define setWireValuesTo( wire, fromTLIdx, outPort, toTLIdx, inPort, dataPtr)\ Me@11: do{\ Me@11: wire.idxOfFromTimeline = fromTLIdx; \ Me@11: wire.idxOfFromOutPort = fromTLIdx; \ Me@11: wire.idxOfToTimeline = toTLIdx; \ Me@11: wire.idxOfToInPort = inPort; \ Me@11: wire.archSpecWireData = dataPtr; \ Me@11: }while(0); //macro magic for namespace Me@11: 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@11: *It has two timelines, each with one input port and one output port, and Me@11: * a single span-type. Me@11: * Me@11: *The timelines 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@11: * the one span-type. Me@11: * Me@11: *The span does nothing, except send a NULL message on the output port. Me@11: *The span-sim-time and communication-sim-time are both constants. Me@11: * Me@11: *Note that timelines are generic. They are specialized by declaring Me@11: * inports and outports, and by registering triggers that fire particular Me@11: * span-types. Me@11: */ Me@11: HWSimNetlist *createPingPongNetlist() Me@11: { HWSimNetlist *netlist; Me@11: NetlistWire *wires; Me@11: HWSimTimeline **timelines; Me@11: int numTimelines; Me@11: int numWires; Me@11: Me@11: netlist = malloc( sizeof(HWSimNetlist) ); Me@11: //declare timelines numTimelines = 2; Me@11: timelines = malloc( numTimelines * sizeof(HWSimTimeline) ); Me@11: netlist->numTimelines = numTimelines; Me@11: netlist->timelines = timelines; Me@11: netlist->numSpanTypes = 1; Me@11: netlist->spanTypes = malloc(netlist->numSpanTypes*sizeof(HWSimSpanType*)); Me@11: netlist->spanTypes[PING_PONG_TYPE] = createPingPongSpanType(); Me@11: timelines[0] = createAPingPongTimeline( netlist ); //use info from netlist Me@11: timelines[1] = createAPingPongTimeline( netlist ); Me@11: //on one of the timelines, make reset trigger an action Me@11: timelines[1]->inPorts[-1].triggeredSpanType = Me@11: netlist->spanTypes PING_PONG_TYPE]; //Connect timelines together Me@11: Me@11: /*OutPorts and InPorts may have many wires attached, but an inPort only Me@11: * has one kind of span that all incoming communications trigger. That Me@11: * span can be zero time and then switch on the type of message then Me@11: * end with a continuation, where the continuation span is chosen by the Me@11: * switch. Me@11: *So, a wire 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@11: numWires = 2; Me@11: wires = malloc( numWires * sizeof(NetlistWire) ); Me@11: netlist->numWires = numWires; Me@11: netlist->wires = wires; Me@11: //TL 0, out-port 0 to TL 1, in-port 0 Me@11: setWireValuesTo(wires[0], 0,0,1,0, NULL); //These NetlistWires turned into Me@11: setWireValuesTo(wires[1], 1,0,0,0, NULL); // HWSimWires inside ckt create Me@11: //TODO: decide how do in-out bidirectional wires -- thinking make it two Me@11: // separate wires with guard between in-port and out-port Me@11: //TODO: decide how do guards between ports Me@11: } Me@11: Me@11: //Note: copy netlist struct with VMS malloc after VMS initialized Me@11: HWSimTimeline * Me@11: createAPingPongTimeline( HWSimNetlist *netlist ) Me@11: { HWSimTimeline *TL; Me@11: TL = malloc( sizeof(HWSimTimeline) ); Me@11: TL->numInPorts = 1; Me@11: TL->numOutPorts = 1; Me@11: TL->inPorts = HWSim_ext__make_inPortsArray( TL->numInPorts ); Me@11: TL->inPorts[-1].triggeredSpanType = IDLE_SPAN; //reset port Me@11: TL->inPorts[0].triggeredSpanType = netlist->spanTypes[PING_PONG_TYPE]; Me@11: } Me@11: Me@11: HWSimSpanType * Me@11: createPingPongSpanType( ) Me@11: { HWSimSpanType *pingPongSpanType; Me@11: pingPongSpanType = malloc( sizeof(HWSimSpanType) ); Me@11: pingPongSpanType->behaviorFn = &behaviorOf_ping_pong_span; Me@11: pingPongSpanType->timingFn = &timingOf_ping_pong_span; Me@11: return pingPongSpanType; Me@11: } Me@11: