/**************************************************************
$Workfile:   bmesinit.c  $
***************************************************************
**
** 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:51 $
**************************************************************/

#include <string.h>
#include <stdio.h> 

#include "dapi.h"
#include "bmeconfig.h"

void InitPortParms(tBmeStruct *pBme, int PortNum);
void InitEMIParms(tBmeStruct *pBme);

/***************************************************************


		this file contains the code to initialize the BME structure
		
		
****************************************************************/

	
/*************************************************************************
	Function: BmeStructInit
	
	Description: Initializes parameter in the BME structure
	
	Input: BmeNum Set						   
	Return: None
************************************************************************/
eApiRv	BmeStructInit(tBmeStruct	*pBme)
{

	int	BmeNum;
	int PortNum;

	BmeNum=pBme->BmeNum;
	/* Initialize Bme state to Inactive state */
	
	pBme->BmeState = INACTIVE;

	/* Initialize Bme Download Verification State to DW_T_BIT_UNKNOWN_STATE */
	pBme->BmeDnldVerifyState = DW_T_BIT_UNKNOWN_STATE;

        /* Initialize the hostResync. 0 indicates there is no host resync in progress */
	pBme->hostResync = 0;

	
	/* Initialize all port parms to zero */
	for (PortNum = 0; PortNum <= IPOS_MAX_PORT_PER_BME; PortNum++)
	{
		InitPortParms(pBme,PortNum);
	};

	/* initialize the EMI (External Memory Interface) parameters	*/
	/*		InitEMIParms (pBme); */

	/* initialize the BME provision	parameters	*/
    
	
		
	/* dummy data */

    pBme->BMEbaseAddr = BME_BASE_ADDR;

		pBme->srcAddr=DPRAM_BASE_ADDR;	/* =1 Source address on BME DPRAM */
		pBme->destAddr=DPRAM_BASE_ADDR;	/* =1 Destination address on BME DPRAM */
		pBme->dpramBaseRxAddr=DPRAM_RX_BASE_ADDR;
		pBme->dpramBaseTxAddr=DPRAM_TX_BASE_ADDR;
		pBme->BMEResetLineAddr=0xde;
		pBme->BMECodeDnldAddr=BME_CODE_DNLD_ADDR; /* 0x40010000 addr in BME - SRAM */
		pBme->BMECodeSize=BME_CODE_SIZE;
		pBme->FifoFlag = 0;

		/* Data pointer points to Bme message buffer. Can 
		alternately point to BME software aray*/
		pBme->dataPtr=&(pBme->BmeMsg[0]);
 
	/* BEGIN: TEST CODE */
		pBme->BmeMsg[_BmeMsgSRC_]	=0x01;
		pBme->BmeMsg[_BmeMsgDEST_]	=0x01;
		pBme->BmeMsg[_BmeMsgOPCODE_]=0x01;
		pBme->BmeMsg[_BmeMsgACK_]	=0x01;
		pBme->BmeMsg[_BmeMsgCTAG_]	=0x01;
		pBme->BmeMsg[_BmeDataLENGTH_]=0;
		pBme->dataLen=6;


		pBme->pBmeIntrFcn=NULL;				/* no interrupt is used	*/

		return (COMPLETE);
	} /* InitBmeStruct */




/*************************************************************************
	Function: InitPortParms
	
	Description: Initializes port parameters in the BME structure. This 
				does not include EOC API parameters for the port.
	
	Return: None
************************************************************************/
void InitPortParms(tBmeStruct *pBme, int PortNum)
	{

	pBme->Port[PortNum].PortParms.pPtrPortProfile=NULL;		/* not port profile	*/
    pBme->Port[PortNum].CmdStatus=(enum eApiRv)5;
	pBme->Port[PortNum].CmdMaxRespTime=0;

	/* Initialize Status reports. These are the initial status of the port 
	assuming it has not been instantiated */

	pBme->Port[PortNum].PortParms.PortStatusBriefParms.Actual=0;
	pBme->Port[PortNum].PortParms.ExpectedPortStatus.Expected=0;

	/* Need to initialize EOC API parameters? */
    pBme->Port[PortNum].PortParms.SendSigParms.SigType=0;

	} /* InitPortParms */


/*************************************************************************
	Function: InitEMIParms
	
	Description: Initializes External Memory Interface parameters in the 
				BME structure, required	to configure EMI of BME.
	
	Return: None
************************************************************************/
void InitEMIParms(tBmeStruct *pBme)
{
    
    pBme->EMIConfig.memType = (enum eBmeMemType)EMI_MEM_SRAM; /* sram mem */
	pBme->EMIConfig.sramMemSize = SRAM_1MB; /* 1 MB of sram */

} /* InitPortParms */





