/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef __MINGOA_POLICER_AVAILABLE__
	#define __MINGOA_POLICER_AVAILABLE__

#include <api_oam_sdk/common/constants/inc/mr_constants.h>
#include <api_oam_sdk/common/error_codes/inc/mr_error_codes.h>
#include <api_oam_sdk/metroam_hal/inc/mr_hal.h>
#include <api_oam_sdk/policer_mef10p2/inc/policer_mef10p2.h>
#include <api_oam_sdk/table_access/inc/table_access_constants.h>
#include <stdio.h>
#include <string.h>

// -----------------------------------------------------------------------------------------------------
// Global Variables


// External Global Variables
//extern 	char 	msgStr[500];

static uint16_t		log_handle				= 0;		// handle used to log messages for this module
static bool			polInitialised			= false;

// -----------------------------------------------------------------------------------------------------
// enPolicing(enDis);
// -----------------------------------------------------------------------------------------------------
// This function enables or disables the policer HW.
// =====================================================================================================
int polEnPolicing(enDis_t enDis)
{
	uint32_t	data;

	DO_LOG_INFO(log_handle,"%s Policer", enDis ? "Enabled":"Disabled");

	mrHalRegRead(DEV_CFG_REG_ADDR,&data);

	if (enDis == enable)
		data |= DEV_CFG_REG_POLICER_EN_MASK;
	else
		data &= ~DEV_CFG_REG_POLICER_EN_MASK;

	mrHalRegWrite(DEV_CFG_REG_ADDR,data);

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// setPolicingMode(mode);
// -----------------------------------------------------------------------------------------------------
// Enables or disables Port only mode. If enabled, the policer regulates traffic based
// on data rates on the port rather than individual services (vlans)
// =====================================================================================================
int polSetPolicingMode(uint8_t mode)
{
	uint32_t	data;

	DO_LOG_INFO(log_handle,"%s Port Only Mode", mode ? "Enabled":"Disabled");

	mrHalRegRead(DEV_CFG_REG_ADDR,&data);

	if (mode == enable)
		data |= DEV_CFG_REG_POL_PORT_ONLY_MASK;
	else
		data &= ~DEV_CFG_REG_POL_PORT_ONLY_MASK;

	mrHalRegWrite(DEV_CFG_REG_ADDR,data);

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// getPolicingMode(mode);
// -----------------------------------------------------------------------------------------------------
// This function will retrieve the current value of the PortOnly Mode.
// =====================================================================================================
int polGetPolicingMode(uint8_t *mode)
{
	uint32_t	data;

	mrHalRegRead(DEV_CFG_REG_ADDR,&data);

	data &= DEV_CFG_REG_POL_PORT_ONLY_MASK;
	*mode = (enDis_t) (data >> DEV_CFG_REG_POL_PORT_ONLY_OFFSET);

	DO_LOG_DEBUG(log_handle,"Port Only Mode is %s", enable ? "Enabled":"Disabled");

	return(NO_ERR);
}

#if 0
// -----------------------------------------------------------------------------------------------------
// setFwdClass(recClass,fwdClass);
// -----------------------------------------------------------------------------------------------------
// This function sets the forwarding class value associated with a specified receive class
// =====================================================================================================
int setFwdClass(uint8_t recClass,uint8_t fwdClass)
{
	int 	retVal;
	uint32_t	data;

	#if defined(MINGOA_ENABLE_DEBUG_LOGGING) && ((defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL == MINGOA_DEBUG_LEVEL_SERVICES)) || (!defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL <= MINGOA_DEBUG_LEVEL_SERVICES)))
		sprintf(msgStr, "INFO::setFwdClass: Set Rcv class = %d mapped to  Fwd class = %d\n",recClass,fwdClass);
		writeLog(MINGOA_DEBUG_LEVEL_SERVICES,msgStr);
	#endif

	if ((retVal = mrHalRegRead(POLICE_FWD_CLASS_REG_ADDR,&data)))
		return(retVal);

	data &= ~(0x7<<(recClass*3));
	data |= ((uint32_t) fwdClass) << (recClass*3);

	if ((retVal = mrHalRegWrite(POLICE_FWD_CLASS_REG_ADDR,data)))
		return(retVal);

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// getFwdClass(recClass,*fwdClass);
// -----------------------------------------------------------------------------------------------------
// This function retrieves the forwarding class value associated with a specified receive class
// =====================================================================================================
int getFwdClass(uint8_t recClass,uint8_t *fwdClass)
{
	int 	retVal;
	uint32_t	data;

	if ((retVal = mrHalRegRead(POLICE_FWD_CLASS_REG_ADDR,&data)))
		return(retVal);

	*fwdClass = (uint8_t) ((data >> (recClass*3)) & 0x7);

	#if defined(MINGOA_ENABLE_DEBUG_LOGGING) && ((defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL == MINGOA_DEBUG_LEVEL_SERVICES)) || (!defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL <= MINGOA_DEBUG_LEVEL_SERVICES)))
		sprintf(msgStr, "INFO::getFwdClass:  Rcv class = %d is mapped to  Fwd class = %d\n",recClass,*fwdClass);
		writeLog(MINGOA_DEBUG_LEVEL_SERVICES,msgStr);
	#endif

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// initPolVlan(void);
// -----------------------------------------------------------------------------------------------------
// This function will clear all setting for the policer to default values
// =====================================================================================================
int initPolVlan(void)
{
	int 	retVal;
	uint8_t	k;
	uint32_t	data;

	#if defined(MINGOA_ENABLE_DEBUG_LOGGING) && ((defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL == MINGOA_DEBUG_LEVEL_SERVICES)) || (!defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL <= MINGOA_DEBUG_LEVEL_SERVICES)))
		sprintf(msgStr, "INFO::initPolVlan:  Initialise Policer\n");
		writeLog(MINGOA_DEBUG_LEVEL_SERVICES,msgStr);
	#endif

	data = 0x00FAC688; // This value sets the fwd maping to 1->1, 2->2,...7->7
	if ((retVal = mrHalRegWrite(POLICE_FWD_CLASS_REG_ADDR,data)))
		return(retVal);

	data = (MR_NULL_VLAN << 12) + MR_NULL_VLAN;
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG0_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG1_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG2_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG3_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG4_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG5_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG6_REG_ADDR,data)))
		return(retVal);
	if ((retVal = mrHalRegWrite(POLICE_VLAN_CFG7_REG_ADDR,data)))
		return(retVal);

	// clear all the policer stats
	for (k=0;k<128;k++)
		setPolStats(k,0,0,0,0);

	return(NO_ERR);
}


// -----------------------------------------------------------------------------------------------------
// setVlan(uint8_t vlanIdx,uint16_t vLan);
// -----------------------------------------------------------------------------------------------------
// This function allows one to configure the policer settings for 1 of 8
// vlan configuration tables. Each table can set the Vlan value, dscp Mode
// and indicate if regulation is based on Vlan only or on Vlan & Class.
// =====================================================================================================
int setVlan(uint8_t vlanIdx,uint16_t vLan, enDis_t dscpMode, enDis_t vlanOnly)
{
	int 	retVal;
	uint32_t	data;
	uint32_t	selVlanReg;

	#if defined(MINGOA_ENABLE_DEBUG_LOGGING) && ((defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL == MINGOA_DEBUG_LEVEL_SERVICES)) || (!defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL <= MINGOA_DEBUG_LEVEL_SERVICES)))
		sprintf(msgStr, "INFO::setVlan:  Set Vlan Index %d to vlan = %d,dscpMode = %d, vlanOnly Mode = %s\n",vlanIdx,vLan,dscpMode,vlanOnly ? "Enabled":"Disabled");
		writeLog(MINGOA_DEBUG_LEVEL_SERVICES,msgStr);
	#endif

	switch (vlanIdx>>1)
	{
		case 0: {selVlanReg = POLICE_VLAN_CFG0_REG_ADDR; break;}
		case 1: {selVlanReg = POLICE_VLAN_CFG1_REG_ADDR; break;}
		case 2: {selVlanReg = POLICE_VLAN_CFG2_REG_ADDR; break;}
		case 3: {selVlanReg = POLICE_VLAN_CFG3_REG_ADDR; break;}
		case 4: {selVlanReg = POLICE_VLAN_CFG4_REG_ADDR; break;}
		case 5: {selVlanReg = POLICE_VLAN_CFG5_REG_ADDR; break;}
		case 6: {selVlanReg = POLICE_VLAN_CFG6_REG_ADDR; break;}
		case 7: {selVlanReg = POLICE_VLAN_CFG7_REG_ADDR; break;}
	}

	if ((retVal = mrHalRegRead(selVlanReg,&data)))
		return(retVal);

	if (vlanIdx & 1)
	{
		// odd index so upper entry must be updated
		data &= POLICE_VLAN_CFG_REG_DSCP_ONLY_E_MASK + POLICE_VLAN_CFG_REG_VLAN_ONLY_E_MASK + POLICE_VLAN_CFG_REG_VLAN_E_MASK;
		data |= ((((uint32_t) dscpMode) << POLICE_VLAN_CFG_REG_DSCP_ONLY_O_OFFSET) & POLICE_VLAN_CFG_REG_DSCP_ONLY_O_MASK) |
				((((uint32_t) vlanOnly) << POLICE_VLAN_CFG_REG_VLAN_ONLY_O_OFFSET) & POLICE_VLAN_CFG_REG_VLAN_ONLY_O_MASK) |
				((((uint32_t) vLan) << POLICE_VLAN_CFG_REG_VLAN_O_OFFSET) & POLICE_VLAN_CFG_REG_VLAN_O_MASK);

	}
	else
	{
		// even index so lower entry must be updated
		data &= POLICE_VLAN_CFG_REG_DSCP_ONLY_O_MASK + POLICE_VLAN_CFG_REG_VLAN_ONLY_O_MASK + POLICE_VLAN_CFG_REG_VLAN_O_MASK;
		data |= ((((uint32_t) dscpMode) << POLICE_VLAN_CFG_REG_DSCP_ONLY_E_OFFSET) & POLICE_VLAN_CFG_REG_DSCP_ONLY_E_MASK) |
				((((uint32_t) vlanOnly) << POLICE_VLAN_CFG_REG_VLAN_ONLY_E_OFFSET) & POLICE_VLAN_CFG_REG_VLAN_ONLY_E_MASK) |
				((((uint32_t) vLan) << POLICE_VLAN_CFG_REG_VLAN_E_OFFSET) & POLICE_VLAN_CFG_REG_VLAN_E_MASK);
	}
	if ((retVal = mrHalRegWrite(selVlanReg,data)))
		return(retVal);

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// getVlan(uint8_t vlanIdx,uint16_t *vLan, uint8_t *dscpMode, uint8_t *vlanOnly);
// -----------------------------------------------------------------------------------------------------
// This function allows one to retrieve the configuration of the policer settings for 1 of 8
// vlan configuration tables. Each table can set the Vlan value, dscp Mode
// and indicate if regulation is based on Vlan only or on Vlan & Class.
// =====================================================================================================
int getVlan(uint8_t vlanIdx,uint16_t *vLan, enDis_t *dscpMode, enDis_t *vlanOnly)
{
	int 	retVal;
	uint32_t	data;
	uint32_t	selVlanReg;

	switch (vlanIdx>>1)
	{
		case 0: {selVlanReg = POLICE_VLAN_CFG0_REG_ADDR; break;}
		case 1: {selVlanReg = POLICE_VLAN_CFG1_REG_ADDR; break;}
		case 2: {selVlanReg = POLICE_VLAN_CFG2_REG_ADDR; break;}
		case 3: {selVlanReg = POLICE_VLAN_CFG3_REG_ADDR; break;}
		case 4: {selVlanReg = POLICE_VLAN_CFG4_REG_ADDR; break;}
		case 5: {selVlanReg = POLICE_VLAN_CFG5_REG_ADDR; break;}
		case 6: {selVlanReg = POLICE_VLAN_CFG6_REG_ADDR; break;}
		case 7: {selVlanReg = POLICE_VLAN_CFG7_REG_ADDR; break;}
	}

	if ((retVal = mrHalRegRead(selVlanReg,&data)))
		return(retVal);

	if (vlanIdx & 1)
	{
		// odd index so upper entry must be extracted
		*vLan = (uint16_t) ((data & POLICE_VLAN_CFG_REG_VLAN_O_MASK) >> POLICE_VLAN_CFG_REG_VLAN_O_OFFSET);
		*dscpMode = (data & POLICE_VLAN_CFG_REG_DSCP_ONLY_O_MASK) ? enable : disable;
		*vlanOnly = (data & POLICE_VLAN_CFG_REG_VLAN_ONLY_O_MASK) ? enable : disable;
	}
	else
	{
		// even index so lower entry must be extracted
		*vLan = (uint16_t) ((data & POLICE_VLAN_CFG_REG_VLAN_E_MASK) >> POLICE_VLAN_CFG_REG_VLAN_E_OFFSET);
		*dscpMode = (data & POLICE_VLAN_CFG_REG_DSCP_ONLY_E_MASK) ? enable : disable;
		*vlanOnly = (data & POLICE_VLAN_CFG_REG_VLAN_ONLY_E_MASK) ? enable : disable;
	}

	#if defined(MINGOA_ENABLE_DEBUG_LOGGING) && ((defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL == MINGOA_DEBUG_LEVEL_SERVICES)) || (!defined(MINGOA_DEBUG_LEVEL_MATCH) && (MINGOA_DEBUG_LEVEL <= MINGOA_DEBUG_LEVEL_SERVICES)))
		sprintf(msgStr, "INFO::getVlan:  Set Vlan Index %d to vlan = %d,dscpMode = %d, vlanOnly Mode = %s\n",vlanIdx,*vLan,*dscpMode,*vlanOnly ? "Enabled":"Disabled");
		writeLog(MINGOA_DEBUG_LEVEL_SERVICES,msgStr);
	#endif

	return(NO_ERR);
}
#endif

// -----------------------------------------------------------------------------------------------------
// setQOSCfg(uint8_t vlanIdx,uint16_t EBS, uint16_t CBS, uint32_t EIR, uint32_t CIR, uint8_t coupling, uint8_t colourMode);
// -----------------------------------------------------------------------------------------------------
// Set the Quality of Service (QOS) parameters for 1 of 8 vlan configuration tables.
// =====================================================================================================
int polSetQOSCtxt(uint8_t flowNum, uint8_t prio,uint32_t timer, uint32_t EIR, uint32_t CIR)
{
	uint32_t	data;
	uint32_t	index = ((flowNum * 8) + prio) * POL_CFG_ENTRY_SIZE;

	DO_LOG_DEBUG(log_handle,"write: flowNum=%d prio=%d; timer=%lu,EIR=%lu, CIR=%lu", flowNum, prio,timer ,EIR, CIR);

	data = timer;
	mrHalRamWrite((index) + 0,POLICER_CTXT_RAM_SEL, data);

	data = EIR;
	mrHalRamWrite((index) + 1,POLICER_CTXT_RAM_SEL, data);

	data = CIR;
	mrHalRamWrite((index) + 2,POLICER_CTXT_RAM_SEL, data);

	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// setQOSCfg(uint8_t vlanIdx,uint16_t EBS, uint16_t CBS, uint32_t EIR, uint32_t CIR, uint8_t coupling, uint8_t colourMode);
// -----------------------------------------------------------------------------------------------------
// Set the Quality of Service (QOS) parameters for 1 of 8 vlan configuration tables.
// =====================================================================================================
int polSetQOSCfg(uint8_t flowNum, uint8_t prio,uint16_t EBS, uint16_t CBS, uint32_t EIR, uint32_t CIR, uint8_t coupling, uint8_t colourMode)
{
	uint32_t	data;
	uint32_t	index = ((flowNum * 8) + prio) * POL_CFG_ENTRY_SIZE;

	DO_LOG_DEBUG(log_handle,"write: flowNum=%d prio=%d; EBS=%d, CBS=%d, EIR=%lu, CIR=%lu, coupling=%d, colourMode=%d", flowNum, prio, EBS, CBS, EIR, CIR, coupling, colourMode);

	data = ((((uint32_t) EBS) << POL_CFG_RAM_EBS_OFFSET) & POL_CFG_RAM_EBS_MASK) |
			((((uint32_t)CBS) << POL_CFG_RAM_CBS_OFFSET) & POL_CFG_RAM_CBS_MASK);
	mrHalRamWrite((index) + POL_CFG_RAM_CBS_EBS_DWORD,POLICER_CFG_RAM_SEL, data);

	data = ((CIR << POL_CFG_RAM_CIR_OFFSET) & POL_CFG_RAM_CIR_MASK);
	mrHalRamWrite((index) + POL_CFG_RAM_CIR_DWORD,POLICER_CFG_RAM_SEL, data);

	data = ((EIR << POL_CFG_RAM_EIR_OFFSET) & POL_CFG_RAM_EIR_MASK);
	mrHalRamWrite((index) + POL_CFG_RAM_EIR_DWORD,POLICER_CFG_RAM_SEL, data);

	data = ((((uint32_t) coupling) << POL_CFG_RAM_COUPLING_OFFSET) & POL_CFG_RAM_COUPLING_MASK) |
				((((uint32_t)colourMode) << POL_CFG_RAM_COLOR_MODE_OFFSET) & POL_CFG_RAM_COLOR_MODE_MASK);
	mrHalRamWrite((index) + POL_CFG_RAM_COUPLING_DWORD,POLICER_CFG_RAM_SEL, data);
	return(NO_ERR);
}


// -----------------------------------------------------------------------------------------------------
// getQOSCfg(uint8_t vlanIdx,uint16_t *EBS, uint16_t *CBS, uint32_t *EIR, uint32_t *CIR, uint8_t *coupling, uint8_t *colourMode);
// -----------------------------------------------------------------------------------------------------
// Retrieve the Quality of Service (QOS) parameters for 1 of 8 vlan configuration tables.
// =====================================================================================================
int polGetQOSCfg(uint8_t flowNum, uint8_t prio,uint16_t *EBS, uint16_t *CBS, uint32_t *EIR, uint32_t *CIR, uint8_t *coupling, uint8_t *colourMode)
{
	uint32_t	data;
	uint32_t	index = ((flowNum * 8) + prio) * POL_CFG_ENTRY_SIZE;

	mrHalRamRead((index) + POL_CFG_RAM_CBS_EBS_DWORD,POLICER_CFG_RAM_SEL, &data);
	*CBS = (uint16_t) ((data & POL_CFG_RAM_CBS_MASK) >> POL_CFG_RAM_CBS_OFFSET);
	*EBS = (uint16_t) ((data & POL_CFG_RAM_EBS_MASK) >> POL_CFG_RAM_EBS_OFFSET);

	mrHalRamRead((index) + POL_CFG_RAM_CIR_DWORD,POLICER_CFG_RAM_SEL, &data);
	*CIR = ((data & POL_CFG_RAM_CIR_MASK) >> POL_CFG_RAM_CIR_OFFSET);

	mrHalRamRead((index) + POL_CFG_RAM_EIR_DWORD,POLICER_CFG_RAM_SEL, &data);
	*EIR = ((data & POL_CFG_RAM_EIR_MASK) >> POL_CFG_RAM_EIR_OFFSET);

	mrHalRamRead((index) + POL_CFG_RAM_COUPLING_DWORD,POLICER_CFG_RAM_SEL, &data);
	*coupling = (uint8_t) ((data & POL_CFG_RAM_COUPLING_MASK) >> POL_CFG_RAM_COUPLING_OFFSET);
	*colourMode = (uint8_t) ((data & POL_CFG_RAM_COLOR_MODE_MASK) >> POL_CFG_RAM_COLOR_MODE_OFFSET);

	DO_LOG_DEBUG(log_handle,"read: flowNum=%d prio=%d; EBS=%d, CBS=%d, EIR=%lu, CIR=%lu, coupling=%d, colourMode=%d", flowNum, prio, *EBS, *CBS, *EIR, *CIR, *coupling, *colourMode);
	return(NO_ERR);
}

// -----------------------------------------------------------------------------------------------------
// polSetStats(uint8_t vlanIdx,uint32_t green, uint32_t yellow, uint32_t red, uint32_t discard);
// -----------------------------------------------------------------------------------------------------
// This allows on to write new values (typically 0) to the Policer Stats counters
// associated with a specific vlan configuration
// =====================================================================================================
int polSetStats(uint8_t flowNum, uint8_t prio,uint32_t green, uint32_t yellow, uint32_t red, uint32_t discard)
{
	uint32_t	index = ((flowNum * 8) + prio) * POL_CFG_ENTRY_SIZE;

	DO_LOG_DEBUG(log_handle,"write:flowNum=%d prio=%d green = %lu, yellow = %lu, red = %lu, discard = %lu", flowNum, prio, green,yellow,red,discard);

	mrHalRamWrite((index) + POL_CFG_RAM_GREEN_DWORD,POLICER_STATS_RAM_SEL, green);

	mrHalRamWrite((index) + POL_CFG_RAM_YELLOW_DWORD,POLICER_STATS_RAM_SEL, yellow);

	mrHalRamWrite((index) + POL_CFG_RAM_RED_DWORD,POLICER_STATS_RAM_SEL, red);

	mrHalRamWrite((index) + POL_CFG_RAM_DISCARD_DWORD,POLICER_STATS_RAM_SEL, discard);
	return(NO_ERR);
}


// -----------------------------------------------------------------------------------------------------
// polGetStats(uint8_t vlanIdx,uint32_t *green, uint32_t *yellow, uint32_t *red, uint32_t *discard);
// -----------------------------------------------------------------------------------------------------
// This allows on to retrieve the current values of the Policer Stats counters
// associated with a specific vlan configuration
// =====================================================================================================
int polGetStats(uint8_t flowNum, uint8_t prio,uint32_t *green, uint32_t *yellow, uint32_t *red, uint32_t *discard)
{
	uint32_t	index = ((flowNum * 8) + prio) * POL_CFG_ENTRY_SIZE;

	mrHalRamRead((index) + POL_CFG_RAM_GREEN_DWORD,POLICER_STATS_RAM_SEL, green);

	mrHalRamRead((index) + POL_CFG_RAM_YELLOW_DWORD,POLICER_STATS_RAM_SEL, yellow);

	mrHalRamRead((index) + POL_CFG_RAM_RED_DWORD,POLICER_STATS_RAM_SEL, red);

	mrHalRamRead((index) + POL_CFG_RAM_DISCARD_DWORD,POLICER_STATS_RAM_SEL, discard);

	DO_LOG_DEBUG(log_handle,"read:flowNum=%d prio=%d green = %lu, yellow = %lu, red = %lu, discard = %lu", flowNum, prio, *green,*yellow,*red,*discard);
	return(NO_ERR);
}

/*
 * @brief	Called at device startup to initialise Policer module
 *
 * Safe to call repeatedly.
 */
void policerInit(void)
{
	log_init();	// Initialises the logging system if it's not already initialised

	// Get a log handle if we don't already have one
	if (log_handle == 0)
		log_handle = log_register("policer");

	// If not already initialised clear the RMep list for first use.
	if (!polInitialised)
	{
		// Set the default logging level to NOTICE
		setModuleLogLevel(log_handle, eLOG_LEVEL_NOTICE);

		DO_LOG_DEBUG(log_handle,"Preparing the Policer for first use");

		polInitialised = true;
	}
}

#endif
