changeset 26:0deed3ee0b02

update comments for public viewing
author kshalle
date Wed, 25 Feb 2015 15:20:16 -0800
parents b1c9d67643f2
children fb4970a0c337
files CircuitNetlistCreator.c HWSim__PingPong__HWDef/CommPath_TimeSpan_Fns.c HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h HWSim__PingPong__HWDef/HW_DESIGN_NOTES.txt HWSim__PingPong__HWDef/PingPongElem_Activities.c SimParams.c SimParams.h main.c
diffstat 8 files changed, 477 insertions(+), 452 deletions(-) [+]
line diff
     1.1 --- a/CircuitNetlistCreator.c	Thu May 24 08:14:21 2012 -0700
     1.2 +++ b/CircuitNetlistCreator.c	Wed Feb 25 15:20:16 2015 -0800
     1.3 @@ -1,144 +1,165 @@
     1.4 -/*
     1.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     1.6 - *  Licensed under GNU General Public License version 2
     1.7 - *
     1.8 - * Author: seanhalle@yahoo.com
     1.9 - *
    1.10 - */
    1.11 -#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
    1.12 - 
    1.13 -/* is an expr resolves to an actual commPath struct instance
    1.14 - */
    1.15 -#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
    1.16 -do{\
    1.17 -   commPath->idxOfFromElem     = fromElIdx; \
    1.18 -   commPath->idxOfFromOutPort  = outPort; \
    1.19 -   commPath->idxOfToElem       = toElIdx; \
    1.20 -   commPath->idxOfToInPort     = inPort; \
    1.21 - }while(0); //macro magic for namespace
    1.22 -
    1.23 -
    1.24 -
    1.25 -HWSimActivityType* createPingPongActivityType (); 
    1.26 -
    1.27 -HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
    1.28 -
    1.29 -/*This file constructs the netlist for the Hello World circuit, which is
    1.30 - * used during design and implementation of the HWSim language
    1.31 - *
    1.32 - *It has two elements, each with one input port and one output port, and
    1.33 - * a single activity-type.
    1.34 - *
    1.35 - *The elements are cross-coupled, so output port of one connects to input
    1.36 - * port of the other.  The input port has a single trigger, which fires
    1.37 - * the one activity-type.
    1.38 - *
    1.39 - *The activity does nothing, except send a NULL message on the output port.
    1.40 - *The activity-sim-time and communication-sim-time are both constants.
    1.41 - *
    1.42 - *Note that elements are generic.  They are specialized by declaring
    1.43 - * inports and outports, and by registering triggers that fire particular
    1.44 - * activity-types.
    1.45 - */
    1.46 -HWSimNetlist *createPingPongNetlist()
    1.47 - { HWSimNetlist   *netlist;
    1.48 -   HWSimCommPath  **commPaths;
    1.49 -   HWSimElem **elems;
    1.50 -   int32 numElems;
    1.51 -   int32 numCommPaths;
    1.52 -   
    1.53 -   netlist = malloc( sizeof(HWSimNetlist) );
    1.54 -   numElems= 2; 
    1.55 -   elems = malloc( numElems * sizeof(HWSimElem *) );
    1.56 -   netlist->numElems = numElems;
    1.57 -   netlist->elems    = elems;
    1.58 -   netlist->numActivityTypes = 1;
    1.59 -   netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
    1.60 -
    1.61 -   netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
    1.62 -	
    1.63 -   elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
    1.64 -   elems[1] = createAPingPongElem( netlist ); 
    1.65 -   
    1.66 -      //make reset trigger an action on one of the elements
    1.67 -   elems[1]->inPorts[-1].triggeredActivityType =
    1.68 -              netlist->activityTypes[PING_PONG_ACTIVITY];
    1.69 -			  
    1.70 -   /*OutPorts and InPorts may have many commPaths attached.
    1.71 -    *  but an inPort only     
    1.72 -    * has one kind of activity that all incoming communications trigger.  That
    1.73 -    * activity can be zero time and then switch on the type of message then
    1.74 -    * end with a continuation, where the continuation activity is chosen by the    
    1.75 -    * switch. 
    1.76 -    *So, a commPath only connects an out port to an in port
    1.77 -    *The format is: sending elem-index, out-port, dest elem-index, in-port
    1.78 -    */
    1.79 -   numCommPaths          = 2;
    1.80 -   commPaths             = malloc( numCommPaths * sizeof(HWSimCommPath *) );
    1.81 -   netlist->numCommPaths= numCommPaths;
    1.82 -   netlist->commPaths= commPaths;
    1.83 -      //elem 0, out-port 0 to elem 1, in-port 0
    1.84 -   commPaths[0]= malloc(sizeof(HWSimCommPath));
    1.85 -   setCommPathValuesTo(commPaths[0],0,0,1,0);
    1.86 -   commPaths[0]->hasFixedTiming  = TRUE;
    1.87 -   commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.88 -
    1.89 -      //elem 1, out-port 0 to elem 0, in-port 0
    1.90 -   commPaths[1]= malloc(sizeof(HWSimCommPath));
    1.91 -   setCommPathValuesTo(commPaths[1], 1,0,0,0);
    1.92 -   commPaths[1]->hasFixedTiming  = TRUE;
    1.93 -   commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
    1.94 -   
    1.95 -   //TODO: decide how to do bidirectional commPaths, like connection to a bus
    1.96 -   // thinking make it two separate commPaths with guard between in-port and out-port
    1.97 -
    1.98 -	return netlist;
    1.99 - }
   1.100 -
   1.101 -
   1.102 -/*
   1.103 - */
   1.104 -void
   1.105 -freePingPongNetlist (HWSimNetlist *netlist) 
   1.106 - { int i;
   1.107 - 
   1.108 -   for( i = 0; i < netlist->numCommPaths; i++ )
   1.109 -    { free(netlist->commPaths[i]);
   1.110 -    }	
   1.111 -   free(netlist->commPaths);
   1.112 -   for( i= 0; i < netlist->numElems; i++ ) 
   1.113 -    { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
   1.114 -      free(netlist->elems[i]->outPorts);
   1.115 -      free(netlist->elems[i]);
   1.116 -    }
   1.117 -
   1.118 -   free(netlist->activityTypes);
   1.119 -   free(netlist->elems);
   1.120 -   free(netlist);
   1.121 - }
   1.122 - 
   1.123 -HWSimElem *
   1.124 -createAPingPongElem( HWSimNetlist *netlist )
   1.125 - { HWSimElem *elem;
   1.126 -   elem = malloc( sizeof(HWSimElem) );
   1.127 -   elem->numInPorts  = 1;
   1.128 -   elem->numOutPorts = 1;
   1.129 -   elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
   1.130 -   elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.131 -   elem->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.132 -	return elem;
   1.133 - }
   1.134 - 
   1.135 -HWSimActivityType *
   1.136 -createPingPongActivityType( )
   1.137 - { HWSimActivityType *pingPongActivityType;
   1.138 -   pingPongActivityType = malloc( sizeof(HWSimActivityType) );
   1.139 -   
   1.140 -   pingPongActivityType->hasBehavior   = TRUE;
   1.141 -   pingPongActivityType->hasTiming     = TRUE;
   1.142 -   pingPongActivityType->timingIsFixed = TRUE;
   1.143 -   pingPongActivityType->fixedTime     = 10;
   1.144 -   pingPongActivityType->behaviorFn    = &pingPongElem_PingActivity_behavior;
   1.145 -   return pingPongActivityType;
   1.146 - }
   1.147 - 
   1.148 +/*
   1.149 + *  Copyright 2011 OpenSourceResearchInstitute.org
   1.150 + *  Licensed under GNU General Public License version 2
   1.151 + *
   1.152 + * Author: seanhalle@yahoo.com
   1.153 + *
   1.154 + */
   1.155 +#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
   1.156 + 
   1.157 +/* is an expr resolves to an actual commPath struct instance
   1.158 + */
   1.159 +#define setCommPathValuesTo( commPath, fromElIdx, outPort, toElIdx, inPort)\
   1.160 +do{\
   1.161 +   commPath->idxOfFromElem     = fromElIdx; \
   1.162 +   commPath->idxOfFromOutPort  = outPort; \
   1.163 +   commPath->idxOfToElem       = toElIdx; \
   1.164 +   commPath->idxOfToInPort     = inPort; \
   1.165 + }while(0); //macro magic for namespace
   1.166 +
   1.167 +
   1.168 +
   1.169 +HWSimActivityType* createPingPongActivityType (); 
   1.170 +
   1.171 +HWSimElem* createAPingPongElem (HWSimNetlist *netlist);
   1.172 +
   1.173 +/*This file constructs the netlist for the Hello World circuit
   1.174 + *
   1.175 + *It has two elements, each with one input port and one output port, and
   1.176 + * a single activity-type.
   1.177 + *
   1.178 + *The elements are cross-coupled, so output port of one connects to input
   1.179 + * port of the other.  The input port has a single trigger, which fires
   1.180 + * the one activity-type.
   1.181 + *
   1.182 + *The activity does nothing, except send a NULL message on the output port.
   1.183 + *The activity-sim-time and communication-sim-time are both constants.
   1.184 + *
   1.185 + *Note that elements are generic.  They are specialized by declaring
   1.186 + * inports and outports, and by registering triggers that fire particular
   1.187 + * activity-types.
   1.188 + */
   1.189 +HWSimNetlist *createPingPongNetlist()
   1.190 + { HWSimNetlist   *netlist;
   1.191 +   HWSimCommPath  **commPaths;
   1.192 +   HWSimElem **elems;
   1.193 +   int32 numElems;
   1.194 +   int32 numCommPaths;
   1.195 +   
   1.196 +   netlist = malloc( sizeof(HWSimNetlist) );
   1.197 +   numElems= 2; 
   1.198 +   elems = malloc( numElems * sizeof(HWSimElem *) );
   1.199 +   netlist->numElems = numElems;
   1.200 +   netlist->elems    = elems;
   1.201 +   netlist->numActivityTypes = 1;
   1.202 +   netlist->activityTypes = malloc(netlist->numActivityTypes*sizeof(HWSimActivityType*));
   1.203 +
   1.204 +   netlist->activityTypes[PING_PONG_ACTIVITY] = createPingPongActivityType();
   1.205 +	
   1.206 +   elems[0] = createAPingPongElem( netlist ); //use activity types from netlist
   1.207 +   elems[1] = createAPingPongElem( netlist ); 
   1.208 +   
   1.209 +      //make reset trigger an action on one of the elements
   1.210 +   elems[1]->inPorts[-1].triggeredActivityType =
   1.211 +              netlist->activityTypes[PING_PONG_ACTIVITY];
   1.212 +			  
   1.213 +   /*OutPorts and InPorts may have many commPaths attached.
   1.214 +    *  but an inPort only     
   1.215 +    * has one kind of activity that all incoming communications trigger.  That
   1.216 +    * activity can be zero time and then switch on the type of message then
   1.217 +    * end with a continuation, where the continuation activity is chosen by the    
   1.218 +    * switch. 
   1.219 +    *So, a commPath only connects an out port to an in port
   1.220 +    *The format is: sending elem-index, out-port, dest elem-index, in-port
   1.221 +    */
   1.222 +   numCommPaths          = 2;
   1.223 +   commPaths             = malloc( numCommPaths * sizeof(HWSimCommPath *) );
   1.224 +   netlist->numCommPaths= numCommPaths;
   1.225 +   netlist->commPaths= commPaths;
   1.226 +      //elem 0, out-port 0 to elem 1, in-port 0
   1.227 +   commPaths[0]= malloc(sizeof(HWSimCommPath));
   1.228 +   setCommPathValuesTo(commPaths[0],0,0,1,0);
   1.229 +   commPaths[0]->hasFixedTiming  = TRUE;
   1.230 +   commPaths[0]->fixedFlightTime = 10; //all time is stated in (integer) units
   1.231 +
   1.232 +      //elem 1, out-port 0 to elem 0, in-port 0
   1.233 +   commPaths[1]= malloc(sizeof(HWSimCommPath));
   1.234 +   setCommPathValuesTo(commPaths[1], 1,0,0,0);
   1.235 +   commPaths[1]->hasFixedTiming  = TRUE;
   1.236 +   commPaths[1]->fixedFlightTime = 10; //all time is stated in (integer) units
   1.237 +   
   1.238 +   //TODO: decide how to do bidirectional commPaths, like connection to a bus
   1.239 +   // thinking make it two separate commPaths with guard between in-port and out-port
   1.240 +
   1.241 +	return netlist;
   1.242 + }
   1.243 +
   1.244 +
   1.245 +/*
   1.246 + */
   1.247 +void
   1.248 +freePingPongNetlist (HWSimNetlist *netlist) 
   1.249 + { int i;
   1.250 + 
   1.251 +   for( i = 0; i < netlist->numCommPaths; i++ )
   1.252 +    { free(netlist->commPaths[i]);
   1.253 +    }	
   1.254 +   free(netlist->commPaths);
   1.255 +   for( i= 0; i < netlist->numElems; i++ ) 
   1.256 +    { HWSim_ext__free_inPortsArray( netlist->elems[i]->inPorts );
   1.257 +      free(netlist->elems[i]->outPorts);
   1.258 +      free(netlist->elems[i]);
   1.259 +    }
   1.260 +
   1.261 +   free(netlist->activityTypes);
   1.262 +   free(netlist->elems);
   1.263 +   free(netlist);
   1.264 + }
   1.265 + 
   1.266 +/*This creates a simulation element.  A simulation element is of the type
   1.267 + * HWSimElem.  The HWSimElem data structure contains information about
   1.268 + * the input ports and output ports of the element.  In particular, when
   1.269 + * a communication arrives on an input port, that triggers activity inside
   1.270 + * the element.  It is here that the function is registerd, which implements
   1.271 + * the behavior of that activity.
   1.272 + *Triggered activities is the heart of HWSim.  It is inside these functions
   1.273 + * that application defined behavior takes place.
   1.274 + */
   1.275 +HWSimElem *
   1.276 +createAPingPongElem( HWSimNetlist *netlist )
   1.277 + { HWSimElem *elem;
   1.278 +   elem = malloc( sizeof(HWSimElem) );
   1.279 +   elem->numInPorts  = 1;
   1.280 +   elem->numOutPorts = 1;
   1.281 +   elem->inPorts = HWSim_ext__make_inPortsArray( elem->numInPorts );
   1.282 +   elem->inPorts[-1].triggeredActivityType = IDLE_SPAN; //reset port
   1.283 +   //point the trigger at an activity that is already in the netlist.
   1.284 +   // The function below creates one of such activities.
   1.285 +   //The netlist creation function first creates the activities, then
   1.286 +   // it calls this function, which grabs activities from the netlist
   1.287 +   elem->inPorts[0].triggeredActivityType  = netlist->activityTypes[PING_PONG_ACTIVITY];
   1.288 +	return elem;
   1.289 + }
   1.290 +
   1.291 +/*Define a type of activity that is possible.  The netlist creator 
   1.292 + * first calls all of this kind of function, and fills the netlist
   1.293 + * with these data structures that implement activities.
   1.294 + *Then, the creator calls functions that create individual elements.
   1.295 + * Those element-creation functions grab the activity structures out
   1.296 + * of the netlist.
   1.297 + */ 
   1.298 +HWSimActivityType *
   1.299 +createPingPongActivityType( )
   1.300 + { HWSimActivityType *pingPongActivityType;
   1.301 +   pingPongActivityType = malloc( sizeof(HWSimActivityType) );
   1.302 +   
   1.303 +   //For execution speed, some special cases exist, such as activities
   1.304 +   // that have no behavior, or ones that have a fixed time to complete
   1.305 +   pingPongActivityType->hasBehavior   = TRUE;
   1.306 +   pingPongActivityType->hasTiming     = TRUE;
   1.307 +   pingPongActivityType->timingIsFixed = TRUE;
   1.308 +   pingPongActivityType->fixedTime     = 10;
   1.309 +   pingPongActivityType->behaviorFn    = &pingPongElem_PingActivity_behavior;
   1.310 +   return pingPongActivityType;
   1.311 + }
   1.312 + 
     2.1 --- a/HWSim__PingPong__HWDef/CommPath_TimeSpan_Fns.c	Thu May 24 08:14:21 2012 -0700
     2.2 +++ b/HWSim__PingPong__HWDef/CommPath_TimeSpan_Fns.c	Wed Feb 25 15:20:16 2015 -0800
     2.3 @@ -1,35 +1,35 @@
     2.4 -/*
     2.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     2.6 - *  Licensed under GNU General Public License version 2
     2.7 - *
     2.8 - * Author: seanhalle@yahoo.com
     2.9 - *
    2.10 - */
    2.11 -
    2.12 -#include "HWSim__PingPong__HWDef.h"
    2.13 -
    2.14 -
    2.15 -
    2.16 -//====================================================================
    2.17 -/*This is the ping-pong element for the Hello World hardware
    2.18 - *
    2.19 - *It has only one kind of activity, which only puts a communication on
    2.20 - * the element's one out-port.
    2.21 - * 
    2.22 - *The in-port has only one trigger registered on it, which fires that
    2.23 - * activity.
    2.24 - */
    2.25 -
    2.26 -#define NO_MSG NULL
    2.27 -#define PORT0 0
    2.28 -
    2.29 -/*
    2.30 - *Note, the returned value is passed to the timing function
    2.31 - */
    2.32 -HWSimTimeSpan
    2.33 -commPath_TimeSpanCalc( HWSimCommPath *commPath, HWSimActivityInst *sendingActivity )
    2.34 - {
    2.35 -//         DEBUG__printf2( dbgHW, "comm", debugInfoForCommPath(commPath), debugInfoForActivity(sendingActivity) );
    2.36 -   return 5;
    2.37 - }
    2.38 -
    2.39 +/*
    2.40 + *  Copyright 2011 OpenSourceResearchInstitute.org
    2.41 + *  Licensed under GNU General Public License version 2
    2.42 + *
    2.43 + * Author: seanhalle@yahoo.com
    2.44 + *
    2.45 + */
    2.46 +
    2.47 +#include "HWSim__PingPong__HWDef.h"
    2.48 +
    2.49 +
    2.50 +
    2.51 +//====================================================================
    2.52 +/*This file contains functions that calculate how much time inside the
    2.53 + * simulated universe it takes for a communication to go from the 
    2.54 + * outport of the sending element to the in-port of the receiving
    2.55 + * element.
    2.56 + */
    2.57 +
    2.58 +#define NO_MSG NULL
    2.59 +#define PORT0 0
    2.60 +
    2.61 +/*This function calculates the time-of-flight of a communication in 
    2.62 + * the simulated universe.
    2.63 + *
    2.64 + *For the Hello World application, the time-in-flight is fixed.
    2.65 + */
    2.66 +HWSimTimeSpan
    2.67 +commPath_TimeSpanCalc( HWSimCommPath *commPath, HWSimActivityInst *sendingActivity )
    2.68 + {
    2.69 +//   DEBUG__printf2( dbgHW, "comm", debugInfoForCommPath(commPath), debugInfoForActivity(sendingActivity) );
    2.70 +
    2.71 +   return 5;
    2.72 + }
    2.73 +
     3.1 --- a/HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h	Thu May 24 08:14:21 2012 -0700
     3.2 +++ b/HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h	Wed Feb 25 15:20:16 2015 -0800
     3.3 @@ -1,49 +1,46 @@
     3.4 -/*
     3.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     3.6 - *  Licensed under GNU General Public License version 2
     3.7 - */
     3.8 -
     3.9 -
    3.10 -#ifndef _HWSim_TERAFLUX_H_
    3.11 -#define _HWSim_TERAFLUX_H_
    3.12 -
    3.13 -#include <stdio.h>
    3.14 -
    3.15 -#include "HWSim_impl/HWSim_lib.h"
    3.16 -
    3.17 -
    3.18 -//===============================  Defines  ==============================
    3.19 -   //Port 0 is unused, as a bug-catch
    3.20 -#define COMMUNICATOR_OUTPORT  1
    3.21 -
    3.22 -//Different activityTypes
    3.23 -#define PING_PONG_ACTIVITY 0
    3.24 -
    3.25 -#define dbgHW true
    3.26 -//==============================  Structures  ==============================
    3.27 -
    3.28 -
    3.29 -//============================= Activity Functions =========================
    3.30 -void
    3.31 -pingPongElem_PingActivity_behavior( HWSimActivityInst *activityInst );
    3.32 -
    3.33 -HWSimTimeSpan
    3.34 -pingPongElem_PingActivity_timing( HWSimActivityInst *activityInst );
    3.35 -
    3.36 -HWSimTimeSpan
    3.37 -commPath_TimeSpanCalc( HWSimCommPath *commPath, HWSimActivityInst *sendingActivity );
    3.38 -
    3.39 -//======================== Simulation Fake ==================================
    3.40 -#ifdef FAKE
    3.41 -HWSimResults* create_simulation_results__fake(void *simParams,HWSimNetlist *netlist);
    3.42 -#endif
    3.43 -
    3.44 -//======================== Netlist creation ==================================
    3.45 -
    3.46 -HWSimNetlist* createPingPongNetlist ();
    3.47 -
    3.48 -void freePingPongNetlist (HWSimNetlist *netlist);
    3.49 -
    3.50 -#endif /**/
    3.51 -
    3.52 -
    3.53 +/*
    3.54 + *  Copyright 2011 OpenSourceResearchInstitute.org
    3.55 + *  Licensed under GNU General Public License version 2
    3.56 + */
    3.57 +
    3.58 +
    3.59 +#ifndef _HWSim_TERAFLUX_H_
    3.60 +#define _HWSim_TERAFLUX_H_
    3.61 +
    3.62 +#include <stdio.h>
    3.63 +
    3.64 +#include "HWSim_impl/HWSim_lib.h"
    3.65 +
    3.66 +
    3.67 +//===============================  Defines  ==============================
    3.68 +   //Port 0 is unused, as a bug-catch
    3.69 +#define COMMUNICATOR_OUTPORT  1
    3.70 +
    3.71 +//Different activityTypes
    3.72 +#define PING_PONG_ACTIVITY 0
    3.73 +
    3.74 +//Set which debugging printouts to turn on
    3.75 +#define dbgHW true
    3.76 +//==============================  Structures  ==============================
    3.77 +
    3.78 +
    3.79 +//============================= Activity Functions =========================
    3.80 +void
    3.81 +pingPongElem_PingActivity_behavior( HWSimActivityInst *activityInst );
    3.82 +
    3.83 +HWSimTimeSpan
    3.84 +pingPongElem_PingActivity_timing( HWSimActivityInst *activityInst );
    3.85 +
    3.86 +HWSimTimeSpan
    3.87 +commPath_TimeSpanCalc( HWSimCommPath *commPath, HWSimActivityInst *sendingActivity );
    3.88 +
    3.89 +
    3.90 +//======================== Netlist creation ==================================
    3.91 +
    3.92 +HWSimNetlist* createPingPongNetlist ();
    3.93 +
    3.94 +void freePingPongNetlist (HWSimNetlist *netlist);
    3.95 +
    3.96 +#endif /**/
    3.97 +
    3.98 +
     4.1 --- a/HWSim__PingPong__HWDef/HW_DESIGN_NOTES.txt	Thu May 24 08:14:21 2012 -0700
     4.2 +++ b/HWSim__PingPong__HWDef/HW_DESIGN_NOTES.txt	Wed Feb 25 15:20:16 2015 -0800
     4.3 @@ -1,1 +1,1 @@
     4.4 -Implementing the hardware model
     4.5 
     4.6 
     4.7 This is the "hello world" for HWSim.  It is hardware that has just two elements that send a message back and forth between them.  The message has no content, it simply triggers the other element, which then sends the same empty message back, repeating the cycle.
     4.8 
     4.9 Each element has one in-port and one out-port.  The out-port of the first element is connected to the in-port of the second and vice-versa.
    4.10 
    4.11 The code of the activity consists only of sending an empty message on the element's out-port.
    4.12 
    4.13 The trigger for the activity is registered on the in-port and message type 0.
    4.14 
    4.15 The activity timing is a constant.
    4.16 
    4.17 The port-to-port timing is a constant.
    4.18 
    4.19 Both elements are in the same time-domain.
    4.20 
    4.21 at_reset of one element is set to the ping-pong activity, the other element's at_reset is set to idle.
    4.22 
    4.23 And that is the entire hardware.
    4.24 
    4.25 \ No newline at end of file
    4.26 +Implementing the hardware model
    4.27 
    4.28 
    4.29 This is the "hello world" for HWSim.  It is hardware that has just two elements that send a message back and forth between them.  The message has no content, it simply triggers the other element, which then sends the same empty message back, repeating the cycle.
    4.30 
    4.31 Each element has one in-port and one out-port.  The out-port of the first element is connected to the in-port of the second and vice-versa.
    4.32 
    4.33 The code of the activity consists only of sending an empty message on the element's out-port.
    4.34 
    4.35 The trigger for the activity is registered on the in-port and message type 0.
    4.36 
    4.37 The activity timing is a constant.
    4.38 
    4.39 The port-to-port timing is a constant.
    4.40 
    4.41 Both elements are in the same time-domain.
    4.42 
    4.43 the at_reset function of one element points to the ping-pong activity, the other element's at_reset is set to idle.
    4.44 
    4.45 And that is the entire hardware.
    4.46 
    4.47 \ No newline at end of file
     5.1 --- a/HWSim__PingPong__HWDef/PingPongElem_Activities.c	Thu May 24 08:14:21 2012 -0700
     5.2 +++ b/HWSim__PingPong__HWDef/PingPongElem_Activities.c	Wed Feb 25 15:20:16 2015 -0800
     5.3 @@ -1,45 +1,65 @@
     5.4 -/*
     5.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     5.6 - *  Licensed under GNU General Public License version 2
     5.7 - *
     5.8 - * Author: seanhalle@yahoo.com
     5.9 - *
    5.10 - */
    5.11 -
    5.12 -#include <stdio.h>
    5.13 -#include "HWSim__PingPong__HWDef.h"
    5.14 -
    5.15 -
    5.16 -
    5.17 -//====================================================================
    5.18 -/*This is the ping-pong element for the Hello World hardware
    5.19 - *
    5.20 - *It has only one kind of activity, which only puts a communication on
    5.21 - * the element's one out-port.
    5.22 - * 
    5.23 - *The in-port has only one trigger registered on it, which fires that
    5.24 - * activity.
    5.25 - */
    5.26 -
    5.27 -#define NO_MSG NULL
    5.28 -#define PORT0 0
    5.29 -
    5.30 -/*All behavior functions take a ptr to the activity instance they are 
    5.31 - * executing the behavior of.
    5.32 - */
    5.33 -void
    5.34 -pingPongElem_PingActivity_behavior( HWSimActivityInst *activityInst )
    5.35 - {          DEBUG__printf( dbgHW, "ping pong activity\n" );
    5.36 -
    5.37 -   HWSim__send_comm_on_port_and_idle( NO_MSG, PORT0, activityInst );
    5.38 - }
    5.39 -
    5.40 -/*All timing of activity functions take a ptr to the activity instance they are 
    5.41 - * calculating the timing of.
    5.42 - */
    5.43 -HWSimTimeSpan
    5.44 -pingPongElem_PingActivity_timing( HWSimActivityInst *activityInst )
    5.45 - {
    5.46 -   return 10;
    5.47 - }
    5.48 -
    5.49 +/*
    5.50 + *  Copyright 2011 OpenSourceResearchInstitute.org
    5.51 + *  Licensed under GNU General Public License version 2
    5.52 + *
    5.53 + * Author: seanhalle@yahoo.com
    5.54 + *
    5.55 + */
    5.56 +
    5.57 +#include <stdio.h>
    5.58 +#include "HWSim__PingPong__HWDef.h"
    5.59 +
    5.60 +
    5.61 +
    5.62 +//====================================================================
    5.63 +/*This file contains functions that define individual behaviors.
    5.64 + *When creating a netlist, activity structures are created, and those
    5.65 + * structs have pointers to behavior functions.  They also have pointers
    5.66 + * to functions that calculate how long the activity takes in the
    5.67 + * time of the simulated universe.
    5.68 + * 
    5.69 + *This file implements such behavior functions for the Hello World
    5.70 + * hardware.
    5.71 + */
    5.72 +
    5.73 +#define NO_MSG NULL
    5.74 +#define PORT0 0
    5.75 +
    5.76 +/*This activity only does one thing.. it sends a null message on the
    5.77 + * output port 0 of whatever element this activity was executed inside
    5.78 + * of.
    5.79 + *
    5.80 + *Behavior functions take a ptr to the activity instance they are 
    5.81 + * executing the behavior of.  Via this ptr, the function can obtain a
    5.82 + * pointer to the element that the behavior is inside of.  Then, the
    5.83 + * behavior can read state stored inside that element and modify that
    5.84 + * state.  It can also access the inports and outports of the
    5.85 + * element.  For example, an inport can be set to be persistent, and
    5.86 + * an activity can then read the persistent state of the last
    5.87 + * communication to arrive there.  A behavior can also send a
    5.88 + * communication on one of the outports. In this way the behavior is
    5.89 + * generic and manipulates whatever type of element it happens to 
    5.90 + * get assigned to, as long as that element's structure has the
    5.91 + * fields that the behavior is expecting.
    5.92 + */
    5.93 +void
    5.94 +pingPongElem_PingActivity_behavior( HWSimActivityInst *activityInst )
    5.95 + {          DEBUG__printf( dbgHW, "ping pong activity" );
    5.96 +
    5.97 +   HWSim__send_comm_on_port_and_idle( NO_MSG, PORT0, activityInst );
    5.98 + }
    5.99 +
   5.100 +/*Calculate the amount of time spanned by this activity in the 
   5.101 + * simulated universe.
   5.102 + *
   5.103 + *Timing functions take a ptr to the activity instance they are 
   5.104 + * calculating the timing of.  This allows the timing function to
   5.105 + * gain access to the state of the element that is performing the
   5.106 + * activity.
   5.107 + */
   5.108 +HWSimTimeSpan
   5.109 +pingPongElem_PingActivity_timing( HWSimActivityInst *activityInst )
   5.110 + {
   5.111 +   return 10;
   5.112 + }
   5.113 +
     6.1 --- a/SimParams.c	Thu May 24 08:14:21 2012 -0700
     6.2 +++ b/SimParams.c	Wed Feb 25 15:20:16 2015 -0800
     6.3 @@ -1,77 +1,77 @@
     6.4 -/*
     6.5 - *  Copyright 2009 OpenSourceStewardshipFoundation.org
     6.6 - *  Licensed under GNU General Public License version 2
     6.7 - *
     6.8 - * Author: seanhalle@yahoo.com
     6.9 - *
    6.10 - * Created on November 15, 2009, 2:35 AM
    6.11 - */
    6.12 -
    6.13 -
    6.14 -#include <malloc.h>
    6.15 -#include <stdlib.h>
    6.16 -
    6.17 -
    6.18 -#include "SimParams.h"
    6.19 -
    6.20 -
    6.21 -uint8 *
    6.22 -read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName );
    6.23 -
    6.24 -
    6.25 -void
    6.26 -fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag )
    6.27 - { char *guestAppFileName, *systemCodeFileName;
    6.28 -   int numBytesInGuestApp, numBytesInSystemCode;
    6.29 -   
    6.30 -      ParamStruc *param;
    6.31 -
    6.32 -   param = getParamFromBag( "GuestApplicationFileName", paramBag );
    6.33 -   guestAppFileName = param->strValue;
    6.34 -
    6.35 -   param = getParamFromBag( "numBytesInGuestApp", paramBag );
    6.36 -   numBytesInGuestApp = param->intValue;
    6.37 -
    6.38 -   simParams->guestApp =
    6.39 -    read_Machine_Code_From_File( numBytesInGuestApp, guestAppFileName );
    6.40 -
    6.41 -   param = getParamFromBag( "SystemCodeFileName", paramBag );
    6.42 -   systemCodeFileName = param->strValue;
    6.43 -
    6.44 -   param = getParamFromBag( "numBytesInSystemCode", paramBag );
    6.45 -   numBytesInSystemCode = param->intValue;
    6.46 -
    6.47 -   simParams->systemCode =
    6.48 -    read_Machine_Code_From_File( numBytesInSystemCode, systemCodeFileName );
    6.49 -
    6.50 -   param = getParamFromBag( "numNodes", paramBag );
    6.51 -   simParams->numNodes = param->intValue;
    6.52 - }
    6.53 -
    6.54 -
    6.55 -uint8 *
    6.56 -read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName )
    6.57 - { int byte;
    6.58 -   FILE  *file;
    6.59 -   char  *machineCode = malloc( numBytesInFile );
    6.60 -   if( machineCode == NULL ) printf( "\nno mem for machine code\n" );
    6.61 -
    6.62 -   file = fopen( machineCodeFileName, "r" );
    6.63 -   if( file == NULL ) { printf( "\nCouldn't open file!!\n"); exit(1);}
    6.64 -
    6.65 -   fseek( file, 0, SEEK_SET );
    6.66 -   for( byte = 0; byte < numBytesInFile; byte++ )
    6.67 -    {
    6.68 -      if( feof( file ) )  printf( "file ran out too soon" );
    6.69 -//      machineCode[byte] = getchar( file );
    6.70 -    }
    6.71 -   return machineCode;
    6.72 - }
    6.73 -
    6.74 -
    6.75 -//==========================================================================
    6.76 -void
    6.77 -printSimResults( SimulationResults simResults )
    6.78 - { 
    6.79 - }
    6.80 -
    6.81 +/*
    6.82 + *  Copyright 2009 OpenSourceResearchInstitute.org
    6.83 + *  Licensed under GNU General Public License version 2
    6.84 + *
    6.85 + * Author: seanhalle@yahoo.com
    6.86 + *
    6.87 + * Created on November 15, 2009, 2:35 AM
    6.88 + */
    6.89 +
    6.90 +
    6.91 +#include <malloc.h>
    6.92 +#include <stdlib.h>
    6.93 +
    6.94 +
    6.95 +#include "SimParams.h"
    6.96 +
    6.97 +
    6.98 +uint8 *
    6.99 +read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName );
   6.100 +
   6.101 +
   6.102 +void
   6.103 +fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag )
   6.104 + { char *guestAppFileName, *systemCodeFileName;
   6.105 +   int numBytesInGuestApp, numBytesInSystemCode;
   6.106 +   
   6.107 +      ParamStruc *param;
   6.108 +
   6.109 +   param = getParamFromBag( "GuestApplicationFileName", paramBag );
   6.110 +   guestAppFileName = param->strValue;
   6.111 +
   6.112 +   param = getParamFromBag( "numBytesInGuestApp", paramBag );
   6.113 +   numBytesInGuestApp = param->intValue;
   6.114 +
   6.115 +   simParams->guestApp =
   6.116 +    read_Machine_Code_From_File( numBytesInGuestApp, guestAppFileName );
   6.117 +
   6.118 +   param = getParamFromBag( "SystemCodeFileName", paramBag );
   6.119 +   systemCodeFileName = param->strValue;
   6.120 +
   6.121 +   param = getParamFromBag( "numBytesInSystemCode", paramBag );
   6.122 +   numBytesInSystemCode = param->intValue;
   6.123 +
   6.124 +   simParams->systemCode =
   6.125 +    read_Machine_Code_From_File( numBytesInSystemCode, systemCodeFileName );
   6.126 +
   6.127 +   param = getParamFromBag( "numNodes", paramBag );
   6.128 +   simParams->numNodes = param->intValue;
   6.129 + }
   6.130 +
   6.131 +
   6.132 +uint8 *
   6.133 +read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName )
   6.134 + { int byte;
   6.135 +   FILE  *file;
   6.136 +   char  *machineCode = malloc( numBytesInFile );
   6.137 +   if( machineCode == NULL ) printf( "\nno mem for machine code\n" );
   6.138 +
   6.139 +   file = fopen( machineCodeFileName, "r" );
   6.140 +   if( file == NULL ) { printf( "\nCouldn't open file!!\n"); exit(1);}
   6.141 +
   6.142 +   fseek( file, 0, SEEK_SET );
   6.143 +   for( byte = 0; byte < numBytesInFile; byte++ )
   6.144 +    {
   6.145 +      if( feof( file ) )  printf( "file ran out too soon" );
   6.146 +//      machineCode[byte] = getchar( file );
   6.147 +    }
   6.148 +   return machineCode;
   6.149 + }
   6.150 +
   6.151 +
   6.152 +//==========================================================================
   6.153 +void
   6.154 +printSimResults( SimulationResults simResults )
   6.155 + { 
   6.156 + }
   6.157 +
     7.1 --- a/SimParams.h	Thu May 24 08:14:21 2012 -0700
     7.2 +++ b/SimParams.h	Wed Feb 25 15:20:16 2015 -0800
     7.3 @@ -1,45 +1,46 @@
     7.4 -/*
     7.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     7.6 - *  Licensed under GNU General Public License version 2 
     7.7 - */
     7.8 -
     7.9 -#ifndef SIM_PARAMS_
    7.10 -#define SIM_PARAMS_
    7.11 -
    7.12 -#include <stdio.h>
    7.13 -#include <unistd.h>
    7.14 -#include <malloc.h>
    7.15 -
    7.16 -#include "../VMS_Implementations/VMS_impl/VMS_primitive_data_types.h"
    7.17 -#include "../C_Libraries/ParamHelper/Param.h"
    7.18 -
    7.19 -
    7.20 -//==============================  Structures  ==============================
    7.21 -typedef struct
    7.22 - { uint8 *guestApp;
    7.23 -   uint8 *systemCode;
    7.24 -   int32 numNodes;
    7.25 - }
    7.26 -SimulationResults;
    7.27 -
    7.28 -typedef struct
    7.29 - { uint8 *guestApp;
    7.30 -   uint8 *systemCode;
    7.31 -   int32 numNodes;
    7.32 -   SimulationResults *simResults;
    7.33 - }
    7.34 -SimulationParams;
    7.35 -
    7.36 -//==============================  Functions  ================================
    7.37 -void
    7.38 -printSimResults( SimulationResults simResults );
    7.39 -
    7.40 -void
    7.41 -fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag );
    7.42 -
    7.43 -
    7.44 -//===========================================================================
    7.45 -
    7.46 -#endif /**/
    7.47 -
    7.48 -
    7.49 +/*
    7.50 + *  Copyright 2011 OpenSourceResearchInstitute.org
    7.51 + *  Licensed under GNU General Public License version 2 
    7.52 + */
    7.53 +
    7.54 +#ifndef SIM_PARAMS_
    7.55 +#define SIM_PARAMS_
    7.56 +
    7.57 +#include <stdio.h>
    7.58 +#include <unistd.h>
    7.59 +#include <malloc.h>
    7.60 +
    7.61 +#include "../VMS_Implementations/VMS_impl/VMS_primitive_data_types.h"
    7.62 +#include "../C_Libraries/ParamHelper/Param.h"
    7.63 +
    7.64 +
    7.65 +//==============================  Structures  ==============================
    7.66 +//TODO: fill this in with real result values want to collect
    7.67 +typedef struct
    7.68 + { uint8 *guestApp;
    7.69 +   uint8 *systemCode;
    7.70 +   int32 numNodes;
    7.71 + }
    7.72 +SimulationResults;
    7.73 +
    7.74 +typedef struct
    7.75 + { uint8 *guestApp;
    7.76 +   uint8 *systemCode;
    7.77 +   int32 numNodes;
    7.78 +   SimulationResults *simResults;
    7.79 + }
    7.80 +SimulationParams;
    7.81 +
    7.82 +//==============================  Functions  ================================
    7.83 +void
    7.84 +printSimResults( SimulationResults simResults );
    7.85 +
    7.86 +void
    7.87 +fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag );
    7.88 +
    7.89 +
    7.90 +//===========================================================================
    7.91 +
    7.92 +#endif /**/
    7.93 +
    7.94 +
     8.1 --- a/main.c	Thu May 24 08:14:21 2012 -0700
     8.2 +++ b/main.c	Wed Feb 25 15:20:16 2015 -0800
     8.3 @@ -1,56 +1,42 @@
     8.4 -/*
     8.5 - *  Copyright 2011 OpenSourceStewardshipFoundation.org
     8.6 - *  Licensed under BSD
     8.7 - *
     8.8 - * author seanhalle@yahoo.com
     8.9 - */
    8.10 -
    8.11 -#include <malloc.h>
    8.12 -#include <stdlib.h>
    8.13 -
    8.14 -#include "SimParams.h"
    8.15 -#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
    8.16 -#include "ParamHelper/Param.h"
    8.17 -
    8.18 -#include "HWSim_impl/HWSim_tests.h"
    8.19 -
    8.20 -
    8.21 -
    8.22 -/*
    8.23 - *
    8.24 - * 
    8.25 - */
    8.26 -
    8.27 -int main(int argc, char **argv) {
    8.28 -    ParamBag *simParams;
    8.29 -    HWSimNetlist *netlist;
    8.30 -    HWSimResults *simResults;
    8.31 -    int result;
    8.32 -
    8.33 -#ifdef FAKE
    8.34 -    simParams = NULL;
    8.35 -    printf("param file name: %s\n", argv[1]);
    8.36 -    printf("Paraver trace file %s\n", argv[2]);
    8.37 -
    8.38 -#else
    8.39 -   simParams = makeParamBag();
    8.40 -   readParamFileIntoBag( argv[1], simParams );
    8.41 -#endif
    8.42 -
    8.43 -    netlist = createPingPongNetlist();
    8.44 -
    8.45 -#ifdef FAKE
    8.46 -    simResults = create_simulation_results__fake(simParams, netlist);
    8.47 -#else
    8.48 -    simResults = HWSim__run_simulation( simParams, netlist );
    8.49 -    //HWSim_test__run();
    8.50 -#endif
    8.51 -
    8.52 -    //HWSim 
    8.53 -    //HWSim__generate_paraver_output(argv[2], simResults, netlist); //Stefan: my version
    8.54 -    //HWSim__generate_paraver_output(simResults);
    8.55 -    //HWSim__generate_vcd_output( simResults );
    8.56 -
    8.57 -    exit(0); //cleans up
    8.58 -}
    8.59 -
    8.60 +/*
    8.61 + *  Copyright 2011 OpenSourceResearchInstitute.org
    8.62 + *  Licensed under BSD
    8.63 + *
    8.64 + * author seanhalle@yahoo.com
    8.65 + */
    8.66 +
    8.67 +#include <malloc.h>
    8.68 +#include <stdlib.h>
    8.69 +
    8.70 +#include "SimParams.h"
    8.71 +#include "HWSim__PingPong__HWDef/HWSim__PingPong__HWDef.h"
    8.72 +#include "ParamHelper/Param.h"
    8.73 +
    8.74 +#include "HWSim_impl/HWSim_tests.h"
    8.75 +
    8.76 +
    8.77 +
    8.78 +/* This sample code shows
    8.79 + *
    8.80 + * 
    8.81 + */
    8.82 +
    8.83 +int main(int argc, char **argv) 
    8.84 + {
    8.85 +   ParamBag *simParams;
    8.86 +   HWSimNetlist *netlist;
    8.87 +   HWSimResults *simResults;
    8.88 +   int result;
    8.89 +
    8.90 +   //Use a helper called ParamBag to read in paramters from file
    8.91 +   simParams = makeParamBag();
    8.92 +   readParamFileIntoBag( argv[1], simParams );
    8.93 +
    8.94 +   //Create the simulated objects and connect them to each other
    8.95 +   netlist = createPingPongNetlist(); //defined in CircuitNetlistCreator.c
    8.96 +
    8.97 +   simResults = HWSim__run_simulation( simParams, netlist );
    8.98 +
    8.99 +   exit(0); //cleans up
   8.100 + }
   8.101 +