Files
DRAMSys/dram/src/core/ControllerState.cpp
2014-05-05 23:24:36 +02:00

112 lines
2.9 KiB
C++

/*
* controller_state.cpp
*
* Created on: Mar 5, 2014
* Author: jonny
*/
#include "ControllerState.h"
#include <algorithm>
#include "TimingCalculation.h"
namespace core {
const ScheduledCommand ControllerState::getLastCommand(Command command, Bank bank) //TODO const reference? and make const
{
return lastCommandsOnBus[command][bank];
}
const ScheduledCommand ControllerState::getLastCommand(Command command)
{
ScheduledCommand max;
for (unsigned int i = 0; i < config->NumberOfBanks; ++i)
{
ScheduledCommand current = getLastCommand(command, Bank(i));
if (current.getStart() > max.getStart())
max = current;
}
return max;
}
const ScheduledCommand ControllerState::getLastScheduledCommand()
{
ScheduledCommand lastCommand;
for(Command cmd : getAllCommands())
{
for(Bank bank : Configuration::getInstance().getBanks())
{
ScheduledCommand& current = lastCommandsOnBus[cmd][bank];
if (current.getStart() > lastCommand.getStart())
lastCommand = current;
}
}
return lastCommand;
}
const ScheduledCommand ControllerState::getLastScheduledCommand(Bank bank)
{
ScheduledCommand lastCommand;
for(Command cmd : getAllCommands())
{
ScheduledCommand& current = lastCommandsOnBus[cmd][bank];
if (current.getStart() > lastCommand.getStart())
lastCommand = current;
}
return lastCommand;
}
void ControllerState::change(const ScheduledCommand& scheduledCommand)
{
//TODO double check if slot free?
bus.blockSlot(scheduledCommand.getStart());
lastCommandsOnBus[scheduledCommand.getCommand()][scheduledCommand.getBank()] = scheduledCommand;
switch (scheduledCommand.getCommand())
{
case Command::Read:
lastDataStrobeCommands.emplace_back(scheduledCommand);
break;
case Command::ReadA:
bankStates.closeRowBuffer(scheduledCommand.getBank());
lastDataStrobeCommands.emplace_back(scheduledCommand);
break;
case Command::Write:
lastDataStrobeCommands.emplace_back(scheduledCommand);
break;
case Command::WriteA:
bankStates.closeRowBuffer(scheduledCommand.getBank());
lastDataStrobeCommands.emplace_back(scheduledCommand);
break;
case Command::AutoRefresh:
break;
case Command::Activate:
bankStates.openRowInRowBuffer(scheduledCommand.getBank(), scheduledCommand.getRow());
lastActivates.emplace(scheduledCommand.getStart(), scheduledCommand.getBank());
break;
case Command::Precharge:
bankStates.closeRowBuffer(scheduledCommand.getBank());
break;
case Command::PrechargeAll:
bankStates.closeAllRowBuffers();
break;
default:
break;
}
}
void ControllerState::cleanUp(sc_time time)
{
bus.cleanUpSlots(time);
lastDataStrobeCommands.remove_if([&](ScheduledCommand command){return command.getEnd() < time && getDistance(command.getEnd(), time) > config->Timings.tDataStrobeHistory();});
lastActivates.erase(lastActivates.begin(), lastActivates.lower_bound(time - config->Timings.tActHistory()));
}
} /* namespace controller */