#include "HoAreaModel.h"

namespace cosi {

namespace models {

namespace onchipcommunication {

using namespace cosi::library::onchipcommunication ;

HoAreaModel::HoAreaModel(Technology pTech) {


	cosi::io::onchipcommunication::HoOrionModelParser* P = 0x0 ;

	if ( pTech == T90 ) {
		P = new cosi::io::onchipcommunication::HoOrionModelParser(CosiRoot + "/models/onchipcommunication/link/ho-orion-90nm.xml") ;
	} else if ( pTech == T65 ) {
		P = new cosi::io::onchipcommunication::HoOrionModelParser(CosiRoot + "/models/onchipcommunication/link/ho-orion-65nm.xml") ;
	} else if (pTech == T45) {
		P = new cosi::io::onchipcommunication::HoOrionModelParser(CosiRoot + "/models/onchipcommunication/link/ho-orion-45nm.xml") ;
	}

	P->Parse() ;

	mWmin = P->GetWmin() ;
	mC0 = P->GetC0() ;
	mCp = P->GetCp() ;
	mR0 = P->GetR0() ;
	mR = P->GetR();
	mC = P->GetC() ;
	mPitch = P->GetPitch() ;


	delete P ;

	//Compute optimal repeater size
	mKopt = ( int ) sqrt(mR0 * (mC[6] )/ (mR[6] *mC0)) ;
	//Optimal sequential length
	mHopt = sqrt( 2*mR0*(mC0 + mCp)/(mR[6] * (mC[6] ))) ;
}

HoAreaModel::~HoAreaModel() {
}

double HoAreaModel::GetDeviceArea(Name pName,
		cosi::quantity::onchipcommunication::Interface pSource,
		cosi::quantity::onchipcommunication::Interface pDest, WiringPath pPath,
		cosi::quantity::onchipcommunication::LinkParameter pParam) {

	//Compute the length
	double Length = pPath.Length() ;
	//Compute the flit width
	int Width = pSource.GetWidth() ;

	return (Length/mHopt*mWmin*mWmin*mKopt*Width/2.0);

}

double HoAreaModel::GetWiringArea(Name pName,
		cosi::quantity::onchipcommunication::Interface pSource,
		cosi::quantity::onchipcommunication::Interface pDest, WiringPath pPath,
		cosi::quantity::onchipcommunication::LinkParameter pParam) {

	//Compute the length
	double Length = pPath.Length() ;
	//Compute the flit width
	int Width = pSource.GetWidth() ;
	return (Length * mPitch[6] * Width );

}



}

}

}
