/**************************************************************
$Workfile:   led.c  $
***************************************************************
**							    										
**	Filename    : bmeintr.c 		    									
**	Description : c source file defining the BME interrupts	 					
**	Author	    : jeya					    									
**	Date	    : 27 Feb 2001					 								
**	Notes	    :		  	   		    										
**  References  : Host Interface Controller Block Definition Doc
					prepared by Weiluo		    											 	
**	Revision History :				    										
**							    												
****************************************************************/

/***************************************************************
**
** FIRMWARE, Copyright (C) 2000-2002
** Ikanos Communication, Fremont, CA
** All rights reserved.
**
** The information and contents of this file are the
** proprietary information of Ikanos Communication and may not
** be disclosed or used without the formal written approval of
** Ikanos Communication
**
$Revision: 1.1 $
$Date: 2006/10/16 04:34:49 $
***************************************************************/

/* Include files                 */
#ifdef USE_VXWORKS  /* IXDP425 */  
#include "vxWorks.h"
#include "vme.h"
#include "memLib.h"
#include "cacheLib.h"  
#include "sysLib.h" 
#include "config.h"
#endif
#include "string.h"
#ifdef USE_VXWORKS
#include "intLib.h"
#include "logLib.h"
#endif
#include "stdio.h"
#ifdef USE_VXWORKS
#include "taskLib.h" 
#include "vxLib.h"
#include "tyLib.h"
#include "arch/ppc/vxPpcLib.h"
#include "private/vmLibP.h"
#include "drv/multi/mdpm860Siu.h"
#include "sysLed.h"
#include "drv/mem/eeprom.h"
#ifdef   INCLUDE_NETWORK
#include "sysNet.h"
#endif  /* INCLUDE_NETWORK */
#include "hsiMdpPro8xxT.h"
#endif
//#include "oamp.h"

#include "ipos.h"
#include "appconfig.h"
#include "oampdef.h"
#include "oampstruct.h"

#ifdef USE_VXWORKS
#define BME_INTERFACE

#ifdef BME_INTERFACE
#include "bme.h"
#endif /* BME_INTERFACE */
#endif
/* Global variables */
unsigned int PortFreq[8];
unsigned int CpuFreq=0;
int ON[8];
/*extern uPortStruct portStatus[NUM_PORTS];
extern unsigned char numPorts;
*/

extern oamp_bme oampBme [IPOS_MAX_BME]; 
extern int		getBmePortId( int	lineNum, ipos_port_id *pid);
extern int ConsoleTimer;
extern int PasswordVerified;
extern int autoStart;

void hostLedOn(int portNum,int enable)
{
#ifdef MPC_855 /* IXDP425 */
	int /*i=0,*/ immrVal = vxImmrGet();

#if (defined CO_4P_BOARD || defined CPE_1P_BOARD || defined P2CPE)
switch (portNum)
{

case 4:
	if (!enable)
	*PBDAT (immrVal) &= ~PB14;
	else
	*PBDAT (immrVal) |= PB14;
break;

case 3:
	if (!enable)
	*PBDAT (immrVal) &= ~PB15;
	else
	*PBDAT (immrVal) |= PB15;
break;

case 2:
	if (!enable)
	*PBDAT (immrVal) &= ~PB16;
	else
	*PBDAT (immrVal) |= PB16;
break;

case 1:
	if (!enable)
	*PBDAT (immrVal) &= ~PB17;
	else
	*PBDAT (immrVal) |= PB17;
break;

case 5:
	if (!enable)
	*PBDAT (immrVal) &= ~PB18;
	else
	*PBDAT (immrVal) |= PB18;
break;

case 6:
	if (!enable)
	*PBDAT (immrVal) &= ~PB20;
	else
	*PBDAT (immrVal) |= PB20;
break;

case 7:
	if (!enable)
	*PBDAT (immrVal) &= ~PB21;
	else
	*PBDAT (immrVal) |= PB21;
break;

case 8:
	if (!enable)
	*PBDAT (immrVal) &= ~PB22;
	else
	*PBDAT (immrVal) |= PB22;
break;

case 9:
	if (!enable)
	*PDDAT (immrVal) &= ~PD14;
	else
	*PDDAT (immrVal) |= PD14;
break;

case 10:
	if (!enable)
	*PDDAT (immrVal) &= ~PD15;
	else
	*PDDAT (immrVal) |= PD15;
break;

} //switch

#else 
switch (portNum)
{
case 1:
	if (!enable)
	*PBDAT (immrVal) &= ~PB17;
	else
	*PBDAT (immrVal) |= PB17;
break;

case 2:
	if (!enable)
	*PBDAT (immrVal) &= ~PB16;
	else
	*PBDAT (immrVal) |= PB16;
break;

case 3:
	if (!enable)
	*PBDAT (immrVal) &= ~PB15;
	else
	*PBDAT (immrVal) |= PB15;
break;

case 4:
	if (!enable)
	*PBDAT (immrVal) &= ~PB14;
	else
	*PBDAT (immrVal) |= PB14;
break;

case 5:
	if (!enable)
	*PBDAT (immrVal) &= ~PB23;
	else
	*PBDAT (immrVal) |= PB23;
break;

case 6:
	if (!enable)
	*PBDAT (immrVal) &= ~PB22;
	else
	*PBDAT (immrVal) |= PB22;
break;
case 7:
	if (!enable)
	*PBDAT (immrVal) &= ~PB21;
	else
	*PBDAT (immrVal) |= PB21;
break;
case 8:
	if (!enable)
	*PBDAT (immrVal) &= ~PB20;
	else
	*PBDAT (immrVal) |= PB20;
break;
case 9:
	if (!enable)
	*PDDAT (immrVal) &= ~PD14;
	else
	*PDDAT (immrVal) |= PD14;
break;
case 10: 
	if (!enable)
	*PDDAT (immrVal) &= ~PD15;
	else
	*PDDAT (immrVal) |= PD15;
break;

} //switch

#endif
#endif
} // hostLedOn

void processLed()
{
int i,j;
ipos_port_id pid;
BYTE PortStatus;


// CPU heartbeat
if (CpuFreq++ & 0x1)	
	hostLedOn (10,1);
	else
	hostLedOn (10,0);

for (j=0;j<MAX_NUM_OF_BMES;j++)
{
pid.bmeNum=j+1;

for (i=0;i<MAX_PORTS_PER_BME;i++)
{
pid.portNum=i+1;

  getBmePortId(i+1,&pid);
	PortStatus = oampBme[pid.bmeNum].oampPort[pid.portNum].portState;
  
if (PortStatus==uACTIVATING)
	{
	if (PortFreq[i]++ & 0x1)//(PortFreq++ %2==0)
		{hostLedOn (i+1,ON[i]);
		ON[i]=!ON[i];
		}
	} 
else{
	if(PortStatus == uSHOWTIME)
	{hostLedOn(i+1,1);}
	else {hostLedOn(i+1,0); ON[i]=0;}
	}

} // for j
} // for i


}



