merged everythin into one project
This commit is contained in:
131
dram/src/common/xmlAddressdecoder.cpp
Normal file
131
dram/src/common/xmlAddressdecoder.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "xmlAddressdecoder.h"
|
||||
#include <systemc.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
string xmlAddressDecoder::URI = "";
|
||||
|
||||
xmlAddressDecoder::xmlAddressDecoder(string URI)
|
||||
{
|
||||
doc = new TiXmlDocument(URI.c_str());
|
||||
if (doc->LoadFile())
|
||||
{
|
||||
dramconfig = doc->FirstChildElement("dramconfig");
|
||||
addressmap = dramconfig->FirstChildElement("addressmap");
|
||||
|
||||
unsigned int from;
|
||||
unsigned int to;
|
||||
|
||||
// get channel:
|
||||
TiXmlElement* channel = addressmap->FirstChildElement("channel");
|
||||
|
||||
from = getAttribute<unsigned int>(channel, "from");
|
||||
to = getAttribute<unsigned int>(channel, "to");
|
||||
|
||||
channelShift = from;
|
||||
channelMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0);
|
||||
channelSize = pow(2.0, to - from + 1.0);
|
||||
|
||||
// get row:
|
||||
TiXmlElement* row = addressmap->FirstChildElement("row");
|
||||
|
||||
from = getAttribute<unsigned int>(row, "from");
|
||||
to = getAttribute<unsigned int>(row, "to");
|
||||
|
||||
rowShift = from;
|
||||
rowMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0);
|
||||
rowSize = pow(2.0, to - from + 1.0);
|
||||
|
||||
// get bank:
|
||||
TiXmlElement* bank = addressmap->FirstChildElement("bank");
|
||||
|
||||
from = getAttribute<unsigned int>(bank, "from");
|
||||
to = getAttribute<unsigned int>(bank, "to");
|
||||
|
||||
bankShift = from;
|
||||
bankMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0);
|
||||
bankSize = pow(2.0, to - from + 1.0);
|
||||
|
||||
// get colum:
|
||||
TiXmlElement* colum = addressmap->FirstChildElement("colum");
|
||||
|
||||
from = getAttribute<unsigned int>(colum, "from");
|
||||
to = getAttribute<unsigned int>(colum, "to");
|
||||
|
||||
columShift = from;
|
||||
columMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0);
|
||||
columSize = pow(2.0, to - from + 1.0);
|
||||
|
||||
// get bytes:
|
||||
TiXmlElement* bytes = addressmap->FirstChildElement("bytes");
|
||||
|
||||
from = getAttribute<unsigned int>(bytes, "from");
|
||||
to = getAttribute<unsigned int>(bytes, "to");
|
||||
|
||||
bytesShift = from;
|
||||
bytesMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0);
|
||||
bytesSize = pow(2.0, to - from + 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SC_REPORT_ERROR("xmlAddressDecoder can not find ", URI.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
xmlAddressDecoder& xmlAddressDecoder::getInstance()
|
||||
{
|
||||
static xmlAddressDecoder decoder(xmlAddressDecoder::URI);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
xmlAddressDecoder::~xmlAddressDecoder()
|
||||
{
|
||||
delete doc;
|
||||
}
|
||||
|
||||
void xmlAddressDecoder::getNode(unsigned int addr, node * n)
|
||||
{
|
||||
n->channel = (addr & channelMask) >> channelShift;
|
||||
n->row = (addr & rowMask) >> rowShift;
|
||||
n->bank = (addr & bankMask) >> bankShift;
|
||||
n->colum = (addr & columMask) >> columShift;
|
||||
}
|
||||
|
||||
void xmlAddressDecoder::getBRC(unsigned int addr, unsigned int &bank, unsigned int &row,
|
||||
unsigned int &colum)
|
||||
{
|
||||
row = (addr & rowMask) >> rowShift;
|
||||
bank = (addr & bankMask) >> bankShift;
|
||||
colum = (addr & columMask) >> columShift;
|
||||
}
|
||||
|
||||
void xmlAddressDecoder::getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank,
|
||||
unsigned int &row, unsigned int &colum)
|
||||
{
|
||||
channel = (addr & channelMask) >> channelShift;
|
||||
getBRC(addr, bank, row, colum);
|
||||
}
|
||||
void xmlAddressDecoder::getC(unsigned int addr, unsigned int &channel)
|
||||
{
|
||||
channel = (addr & channelMask) >> channelShift;
|
||||
}
|
||||
|
||||
unsigned int xmlAddressDecoder::getNumberOfBanks()
|
||||
{
|
||||
return bankSize;
|
||||
}
|
||||
|
||||
unsigned int xmlAddressDecoder::getNumberOfRowsPerBank()
|
||||
{
|
||||
return rowSize;
|
||||
}
|
||||
|
||||
unsigned int xmlAddressDecoder::getNumberOfColumsPerRow()
|
||||
{
|
||||
return columSize;
|
||||
}
|
||||
|
||||
unsigned int xmlAddressDecoder::getNumberOfBytesPerColumn()
|
||||
{
|
||||
return bytesSize;
|
||||
}
|
||||
Reference in New Issue
Block a user