hello_object.cc revision 12337
110388SAndreas.Sandberg@ARM.com/* 211932Ssascha.bischoff@arm.com * Copyright (c) 2017 Jason Lowe-Power 310388SAndreas.Sandberg@ARM.com * All rights reserved. 410388SAndreas.Sandberg@ARM.com * 510388SAndreas.Sandberg@ARM.com * Redistribution and use in source and binary forms, with or without 610388SAndreas.Sandberg@ARM.com * modification, are permitted provided that the following conditions are 710388SAndreas.Sandberg@ARM.com * met: redistributions of source code must retain the above copyright 810388SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer; 910388SAndreas.Sandberg@ARM.com * redistributions in binary form must reproduce the above copyright 1010388SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer in the 1110388SAndreas.Sandberg@ARM.com * documentation and/or other materials provided with the distribution; 1210388SAndreas.Sandberg@ARM.com * neither the name of the copyright holders nor the names of its 1310388SAndreas.Sandberg@ARM.com * contributors may be used to endorse or promote products derived from 1410388SAndreas.Sandberg@ARM.com * this software without specific prior written permission. 1510388SAndreas.Sandberg@ARM.com * 1610388SAndreas.Sandberg@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710388SAndreas.Sandberg@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1810388SAndreas.Sandberg@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1910388SAndreas.Sandberg@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2010388SAndreas.Sandberg@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110388SAndreas.Sandberg@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2210388SAndreas.Sandberg@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310388SAndreas.Sandberg@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410388SAndreas.Sandberg@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2510388SAndreas.Sandberg@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610388SAndreas.Sandberg@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710388SAndreas.Sandberg@ARM.com * 2810388SAndreas.Sandberg@ARM.com * Authors: Jason Lowe-Power 2910388SAndreas.Sandberg@ARM.com */ 3010388SAndreas.Sandberg@ARM.com 3110388SAndreas.Sandberg@ARM.com#include "learning_gem5/part2/hello_object.hh" 3210388SAndreas.Sandberg@ARM.com 3310388SAndreas.Sandberg@ARM.com#include "base/misc.hh" 3410388SAndreas.Sandberg@ARM.com#include "debug/HelloExample.hh" 3510388SAndreas.Sandberg@ARM.com 3610388SAndreas.Sandberg@ARM.comHelloObject::HelloObject(HelloObjectParams *params) : 3710388SAndreas.Sandberg@ARM.com SimObject(params), 3810388SAndreas.Sandberg@ARM.com // This is a C++ lambda. When the event is triggered, it will call the 3910388SAndreas.Sandberg@ARM.com // processEvent() function. (this must be captured) 4011793Sbrandon.potter@amd.com event([this]{ processEvent(); }, name() + ".event"), 4111793Sbrandon.potter@amd.com goodbye(params->goodbye_object), 4211932Ssascha.bischoff@arm.com // Note: This is not needed as you can *always* reference this->name() 4311930Sandreas.sandberg@arm.com myName(params->name), 4410388SAndreas.Sandberg@ARM.com latency(params->time_to_wait), 4510388SAndreas.Sandberg@ARM.com timesLeft(params->number_of_fires) 4610388SAndreas.Sandberg@ARM.com{ 4710388SAndreas.Sandberg@ARM.com DPRINTF(HelloExample, "Created the hello object\n"); 4810559Sandreas.hansson@arm.com panic_if(!goodbye, "HelloObject must have a non-null GoodbyeObject"); 4910559Sandreas.hansson@arm.com} 5010388SAndreas.Sandberg@ARM.com 5110388SAndreas.Sandberg@ARM.comvoid 5210388SAndreas.Sandberg@ARM.comHelloObject::startup() 5311932Ssascha.bischoff@arm.com{ 5411932Ssascha.bischoff@arm.com // Before simulation starts, we need to schedule the event 5511932Ssascha.bischoff@arm.com schedule(event, latency); 5611932Ssascha.bischoff@arm.com} 5711932Ssascha.bischoff@arm.com 5811932Ssascha.bischoff@arm.comvoid 5910388SAndreas.Sandberg@ARM.comHelloObject::processEvent() 6010388SAndreas.Sandberg@ARM.com{ 6110388SAndreas.Sandberg@ARM.com timesLeft--; 6210388SAndreas.Sandberg@ARM.com DPRINTF(HelloExample, "Hello world! Processing the event! %d left\n", 6310388SAndreas.Sandberg@ARM.com timesLeft); 6410388SAndreas.Sandberg@ARM.com 6510388SAndreas.Sandberg@ARM.com if (timesLeft <= 0) { 6610388SAndreas.Sandberg@ARM.com DPRINTF(HelloExample, "Done firing!\n"); 6710388SAndreas.Sandberg@ARM.com goodbye->sayGoodbye(myName); 6810388SAndreas.Sandberg@ARM.com } else { 6910388SAndreas.Sandberg@ARM.com schedule(event, curTick() + latency); 7010388SAndreas.Sandberg@ARM.com } 7110388SAndreas.Sandberg@ARM.com} 7210388SAndreas.Sandberg@ARM.com 7310388SAndreas.Sandberg@ARM.comHelloObject* 7410388SAndreas.Sandberg@ARM.comHelloObjectParams::create() 7510388SAndreas.Sandberg@ARM.com{ 7610388SAndreas.Sandberg@ARM.com return new HelloObject(this); 7711930Sandreas.sandberg@arm.com} 7810388SAndreas.Sandberg@ARM.com