Download AMBA Bus Library

Transcript
AMBA Bus Library
Example of a User-Defined Arbiter for an Output Stage Bus
#ifndef CWR_AMBA_OUTPUTSTAGE_ARBITER_FIXED_H
#define CWR_AMBA_OUTPUTSTAGE_ARBITER_FIXED_H
#include <systemc.h>
#include "AMBA/AMBA.h"
#include "AMBA/AMBABusModel.h"
// header for userblocks
// header for busmodel
namespace AMBA {
class AMBA_OutputStage_Arbiter_Fixed: public AMBA_OutputStage_Arbiter_if, public sc_channel
{
AMBAOutputStageNodeArbiterScExport mArbiterPort;
AMBA_OutputStage_Arbiter_Fixed(sc_module_name name) :
sc_channel(name),
mArbiterPort(*this),
CurrentlyGranted(0),
size(3),
mArbiterApi(0),
ports(0)
{
}
~AMBA_OutputStage_Arbiter_Fixed()
{
if (ports) {
delete [] ports;
}
}
virtual void arbitrate()
{
int tobeGranted = 0;
bool bMastLock = false;
AMBATransaction *currentTra = mArbiterApi->getCurrentTransaction();
bool bIdle = currentTra ? true : false;
if ( currentTra && CurrentlyGranted != 0 ) {
bIdle = currentTra->AddrTrf.Type == tlmIdle &&
currentTra->AddrTrf.Group != tlmBurstIdle;
bMastLock = currentTra->LockTrf.Lock;
}
if(!bIdle && !bMastLock && mArbiterApi->queryHREADYHigh()) {
tobeGranted = 0;
for ( unsigned int i = 1; i <= size; i++ ){
if (ports[i-1]->queryRequest()||
(CurrentlyGranted == i && ports[i-1]->querySelect() ) ) {
tobeGranted = i;
break;
}
}
}else if( bIdle && !bMastLock && mArbiterApi->queryHREADYHigh()) {
tobeGranted = 0;
for (unsigned int i = 1; i <= size; i++ ){
if (ports[i-1]->queryRequest()){
tobeGranted = i;
break;
}
}
if(tobeGranted == 0 && ports[CurrentlyGranted-1]->querySelect()) {
tobeGranted = CurrentlyGranted;
}
} else {
tobeGranted = CurrentlyGranted;
}
CurrentlyGranted = tobeGranted;
if(tobeGranted != 0){
ports[tobeGranted-1]->doEventGrant();
}
mArbiterApi->setArbitrated(ports[tobeGranted-1]);
return;
}
134
Chapter 11
Product Version V2004.2.2
User-Defined Arbiter
January 2005