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: seanhalle@21: /* is an expr resolves to an actual commPath struct instance Me@11: */ seanhalle@24: #define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\ Me@11: do{\ Me@14: commPath->idxOfFromElem = fromElIdx; \ hausers@19: commPath->idxOfFromOutPort = outPort; \ Me@14: commPath->idxOfToElem = toElIdx; \ Me@14: commPath->idxOfToInPort = inPort; \ Me@11: }while(0); //macro magic for namespace hausers@12: hausers@12: hausers@18: 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) ); seanhalle@24: numElems= 2; hausers@20: 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*)); seanhalle@24: seanhalle@22: netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType(); hausers@20: seanhalle@24: elems[0] = createAPingPongElem( netlist ); //use activity types from netlist Me@14: elems[1] = createAPingPongElem( netlist ); seanhalle@24: seanhalle@24: //make reset trigger an action on one of the elements Me@14: elems[1]->inPorts[-1].triggeredActivityType = seanhalle@24: netlist->activityTypes[PING_PONG_ACTIVITY]; Me@11: seanhalle@24: /*OutPorts and InPorts may have many commPaths attached. Me@14: * but an inPort only seanhalle@24: * has one kind of activity that all incoming communications trigger. That seanhalle@24: * activity can be zero time and then switch on the type of message then seanhalle@24: * end with a continuation, where the continuation activity is chosen by the seanhalle@24: * switch. seanhalle@24: *So, a commPath only connects an out port to an in port seanhalle@24: *The format is: sending elem-index, out-port, dest elem-index, in-port seanhalle@24: */ Me@14: numCommPaths = 2; hausers@20: commPaths = malloc( numCommPaths * sizeof(HWSimCommPath *) ); Me@14: netlist->numCommPaths= numCommPaths; Me@14: netlist->commPaths= commPaths; seanhalle@24: //elem 0, out-port 0 to elem 1, in-port 0 seanhalle@24: commPaths[0]= malloc(sizeof(HWSimCommPath)); seanhalle@24: setCommPathValuesTo(commPaths[0],0,0,1,0); seanhalle@24: commPaths[0]->hasFixedTiming = TRUE; seanhalle@24: commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units seanhalle@24: seanhalle@24: //elem 1, out-port 0 to elem 0, in-port 0 seanhalle@24: commPaths[1]= malloc(sizeof(HWSimCommPath)); seanhalle@24: setCommPathValuesTo(commPaths[1], 1,0,0,0); seanhalle@24: commPaths[1]->hasFixedTiming = TRUE; seanhalle@24: commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units Me@14: seanhalle@24: //TODO: decide how to do bidirectional commPaths, like connection to a bus seanhalle@24: // thinking make it two separate commPaths with guard between in-port and out-port hausers@16: hausers@16: return netlist; Me@11: } hausers@20: seanhalle@24: seanhalle@24: /* seanhalle@24: */ hausers@20: void hausers@20: freePingPongNetlist (HWSimNetlist *netlist) seanhalle@24: { int i; seanhalle@24: seanhalle@24: for( i = 0; i < netlist->numCommPaths; i++ ) seanhalle@24: { free(netlist->commPaths[i]); seanhalle@24: } seanhalle@24: free(netlist->commPaths); seanhalle@24: for( i= 0; i < netlist->numElems; i++ ) seanhalle@24: { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts ); seanhalle@24: free(netlist->elems[i]->outPorts); seanhalle@24: free(netlist->elems[i]); seanhalle@24: } hausers@20: seanhalle@24: free(netlist->activityTypes); seanhalle@24: free(netlist->elems); seanhalle@24: free(netlist); seanhalle@24: } Me@11: Me@14: HWSimElem * Me@14: createAPingPongElem( HWSimNetlist *netlist ) seanhalle@24: { HWSimElem *elem; seanhalle@24: elem = malloc( sizeof(HWSimElem) ); seanhalle@24: elem->numInPorts = 1; seanhalle@24: elem->numOutPorts = 1; seanhalle@24: elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts ); seanhalle@24: elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port seanhalle@24: elem->inPorts[0].triggeredActivityType = netlist->activityTypes[PING_PONG_ACTIVITY]; seanhalle@24: return elem; Me@11: } Me@11: Me@14: HWSimActivityType * Me@14: createPingPongActivityType( ) Me@14: { HWSimActivityType *pingPongActivityType; Me@14: pingPongActivityType = malloc( sizeof(HWSimActivityType) ); seanhalle@22: seanhalle@24: pingPongActivityType->hasBehavior = TRUE; seanhalle@24: pingPongActivityType->hasTiming = TRUE; seanhalle@24: pingPongActivityType->timingIsFixed = TRUE; seanhalle@22: pingPongActivityType->fixedTime = 10; seanhalle@22: pingPongActivityType->behaviorFn = &pingPongElem_PingActivity_behavior; Me@14: return pingPongActivityType; seanhalle@22: } hausers@12: