130 lines
3.9 KiB
C++
130 lines
3.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 lastScheduledByCommandAndBank[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 = lastScheduledByCommandAndBank[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 = lastScheduledByCommandAndBank[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());
|
|
|
|
// if(getLastCommand(scheduledCommand.getCommand()).getStart() > scheduledCommand.getStart())
|
|
// cout << commandToString(scheduledCommand.getCommand()) << " wurde vorgezogen! " << std::endl;
|
|
|
|
lastScheduledByCommandAndBank[scheduledCommand.getCommand()][scheduledCommand.getBank()] = scheduledCommand;
|
|
//lastScheduledByBank[scheduledCommand.getCommand()] = 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;
|
|
case Command::SREF:
|
|
bankStates.closeRowBuffer(scheduledCommand.getBank());
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// cout << "Last Data Strobe Commands Size: " << lastDataStrobeCommands.size() << std::endl;
|
|
// cout << "Last Activates Size: " << lastActivates.size() << std::endl;
|
|
// cout << "Bus Slots: " << bus.slotSet.size();
|
|
}
|
|
|
|
void ControllerState::cleanUp(sc_time time)
|
|
{
|
|
bus.cleanUpSlots(time);
|
|
vector<ScheduledCommand> tmp;
|
|
for(ScheduledCommand& command: lastDataStrobeCommands)
|
|
{
|
|
if(command.getEnd() >= time || getDistance(command.getEnd(), time) <= config->Timings.tDataStrobeHistory())
|
|
tmp.push_back(command);
|
|
}
|
|
lastDataStrobeCommands = tmp;
|
|
lastActivates.erase(lastActivates.begin(), lastActivates.lower_bound(time - config->Timings.tActHistory()));
|
|
}
|
|
|
|
} /* namespace controller */
|