#include #include #include #include #include sc_clock UTick; // Global "Untimed Tick" clock (not an oxymoron ! :-) // This is used for atomic advance of autonomous threads since // there seems to be no implicitly defined way to do this in SystemC // as there is in CoWare. // -- johnS 6-22-00 #include "Routed.hxx" #include "Testbench.hxx" #include "Calendar.hxx" #include "Scheduler.hxx" #include "RouteConfig.hxx" #include "SceMiDispatcher.hxx" static void errorHandler( void */*context*/, SceMiEC *ec ); // Forward declaration (see end of file). class System: public sc_module { public: sc_link_mp newDay; sc_link_mp announceArrival; sc_link_mp advanceCalendar; sc_link_mp scheduleLeg; sc_link_mp<> loadRouteMap; sc_link_mp<> done; sc_link_mp<> advanceClock; sc_link_mp todaysDate; sc_link_mp loadRoute; //------------------------------------------------------- // Module declarations Testbench *testbench; Calendar *calendar; Scheduler *scheduler; RouteConfig *routeConfig; SceMiDispatcher *dispatcher; System( sc_module_name name, SceMi *sceMi ) : sc_module( name ) { testbench = new Testbench( "testbench" ); testbench->NewDay( newDay ); testbench->AnnounceArrival( announceArrival ); testbench->AdvanceCalendar( advanceCalendar ); testbench->ScheduleLeg( scheduleLeg ); testbench->LoadRouteMap( loadRouteMap ); testbench->Done( done ); calendar = new Calendar( "calendar", sceMi ); calendar->AdvanceCalendar( advanceCalendar ); calendar->AdvanceClock( advanceClock ); calendar->NewDay( newDay ); calendar->TodaysDate( todaysDate ); scheduler = new Scheduler( "scheduler", sceMi ); scheduler->TodaysDate( todaysDate ); scheduler->ScheduleLeg( scheduleLeg ); scheduler->LoadRoute( loadRoute ); scheduler->AnnounceArrival( announceArrival ); routeConfig = new RouteConfig( "routeConfig" ); routeConfig->LoadRouteMap( loadRouteMap ); routeConfig->LoadRoute( loadRoute ); routeConfig->AdvanceClock( advanceClock ); dispatcher = new SceMiDispatcher( "dispatcher", sceMi ); dispatcher->Done( done ); } }; int sc_main( int argc, char *argv[] ){ //--------------------------------------------------------- // Instantiate SceMi SceMi::RegisterErrorHandler( errorHandler, NULL ); SceMi *sceMi = NULL; try { int sceMiVersion = SceMi::Version( SCEMI_VERSION_STRING ); SceMiParameters parameters( "mct" ); sceMi = SceMi::Init( sceMiVersion, ¶meters ); //--------------------------------------------------------- // Instantiate the system here. Autonomous threads nested // inside the DispatcherDriver and the Testbench will advance // untimed activity. Such threads are senstitive to UTick defined // at the top of this file. // -- johnS 8-29-00 System system( "system", sceMi ); //------------------------------------------------- // Kick off SystemC kernel ... cerr << "Let 'er rip !" << endl; sc_start(-1); } catch( string message ) { cerr << message << endl; cerr << "Fatal Error: Program aborting." << endl; if( sceMi ) SceMi::Shutdown( sceMi ); return -1; } catch(...) { cerr << "Error: Unclassified exception." << endl; cerr << "Fatal Error: Program aborting." << endl; if( sceMi ) SceMi::Shutdown( sceMi ); return -1; } return 0; } static void errorHandler( void */*context*/, SceMiEC *ec ) { char buf[32]; sprintf( buf, "%d", (int)ec->Type ); string messageText( "SCE-MI Error[" ); messageText += buf; messageText += "]: Function: "; messageText += ec->Culprit; messageText += "\n"; messageText += ec->Message; throw messageText; }