Exemplo n.º 1
0
int OpenLan(/* out */ ADI_DEV_DEVICE_HANDLE *pRes)  // return bool
{
	ADI_DEV_DEVICE_HANDLE lan_handle;
	unsigned int result;
	
    /* Initialize interrupt manager and device manager */
//    adi_ssl_Init();  // ?? -- already done in VDK startup code

	/* Initialize the kernel */
	ker_init((void*)0);

	/* set thread type for the stack threads */
	ker_set_auxdata((void*)kADI_TOOLS_IOEThreadType);



	/* open lan-device */
	result = adi_dev_Open(
                           adi_dev_ManagerHandle,
                           &ADI_ETHER_BF537_Entrypoint,
                           0,
                           NULL,
                           &lan_handle,
                           ADI_DEV_DIRECTION_BIDIRECTIONAL,
                           NULL,
                           NULL,
                           (ADI_DCB_CALLBACK_FN)stack_callback_handler);
                           
    *pRes = lan_handle;
	
	return (result == ADI_DEV_RESULT_SUCCESS);
}
Exemplo n.º 2
0
/******************************************************************
 *
 *  Function: system_init()
 *  Description:
 *  		Initializes Device Manager, Interrupt
 *  		Manager and the Stack.
 *   Return:
 *   		Returns 1 upon success -1 upon failure.
 *
 ******************************************************************/
int system_init()
{
	unsigned int result;
	ADI_DEV_DEVICE_HANDLE lan_handle;
	char *ether_stack_block;
	u16 phyregs[32];


    /* Initialize interrupt manager and device manager */
    adi_ssl_Init();

#ifdef __ADSPBF526__

	/* Set CCLK = 400 MHz, SCLK = 80 MHz */
	adi_pwr_SetFreq(400000000,80000000, ADI_PWR_DF_NONE);

#endif
	/* Initialize the kernel */

	ker_init((void*)0);

	/* set thread type for the stack threads */

	ker_set_auxdata((void*)kADI_TOOLS_IOEThreadType);



	/* open lan-device */

	result = adi_dev_Open(
                           adi_dev_ManagerHandle,
#if ( defined(USB_LAN) || defined(__ADSPBF533__) || defined(__ADSPBF561__) || defined(__ADSPBF538__) )
                           &ADI_ETHER_USBLAN_Entrypoint,
#elif defined(__ADSPBF526__)
                           &ADI_ETHER_BF526_Entrypoint,
#elif defined(__ADSPBF527__)
                           &ADI_ETHER_BF527_Entrypoint,
#elif ( defined(__ADSPBF537__) || defined(__ADSPBF536__) )
                           &ADI_ETHER_BF537_Entrypoint,
#elif defined(__ADSPBF548__)
                           &ADI_ETHER_LAN9218_Entrypoint,
#endif
                           0,
                           NULL,
                           &lan_handle,
                           ADI_DEV_DIRECTION_BIDIRECTIONAL,
                           NULL,
                           NULL,
                           (ADI_DCB_CALLBACK_FN)stack_callback_handler);

	DEBUG_PRINT("Failed to open the lan-device\n",result != ADI_DEV_RESULT_SUCCESS);

	/* set the services with in stack */

	set_pli_services(1,&lan_handle);

#if (!defined(USB_LAN) && (defined(__ADSPBF527__) || defined(__ADSPBF526__) || defined(__ADSPBF537__) || defined(__ADSPBF536__) ) )

	*pEBIU_AMGCTL = 0x1FF;

#if defined(__ADSPBF527__)
	result = ReadMACAddress(hwaddr);
#endif //BF527

	/*
	 * Read the EZ-KIT Lite's assigned MAC address, found at address 0x203F0000 +- offset.
	 * We need to first set the AMGCTL register to allow access to asynchronous
	 * memory.
	 *
	 * Bit 8 of the EBIU_AMGCTL register is also set to ensure that DMA gets more priority over
	 * the processor while accessing external memory. If this is not done then frequent
	 * DMA under and over runs occur when executing instructions from SDRAM
	 */

#if ( defined(__ADSPBF526__) || defined(__ADSPBF537__) || defined(__ADSPBF536__) )
	memcpy ( &hwaddr, (unsigned char *) ADDRESS_OF_MAC_ADDRESS, sizeof ( hwaddr ) );
#endif
	result = adi_dev_Control(
                              lan_handle,
                              ADI_ETHER_CMD_SET_MAC_ADDR,
                              (void*)&hwaddr);

	DEBUG_PRINT("Failed set MAC address\n",result != ADI_DEV_RESULT_SUCCESS);

#endif
	/* supply some memory for the driver */

	result = adi_dev_Control(
                              lan_handle,
                              ADI_ETHER_CMD_SUPPLY_MEM,
                              &memtable);

	DEBUG_PRINT("Failed to supply memory to driver\n",result != ADI_DEV_RESULT_SUCCESS);

	result = adi_dev_Control(
                              lan_handle,
                              ADI_DEV_CMD_SET_DATAFLOW_METHOD,
                              (void*)TRUE);

	/* if __cplb_ctrl is defined to non-zero value inform the driver about it */
	if(__cplb_ctrl){
	result = adi_dev_Control(
	                         lan_handle,
	                         ADI_ETHER_CMD_BUFFERS_IN_CACHE,
	                         (void *)TRUE);
        }

	DEBUG_PRINT("Failed to set caching mode in driver\n",result != ADI_DEV_RESULT_SUCCESS);

	/* Initialze the stack with user specified configuration priority -3 and
	 * poll period of p_period msec.  The stack is allocated a memory buffer as well.
	 */

	ether_stack_block = (char *) malloc ( ETHER_STACK_SIZE );

	DEBUG_PRINT("Failed to malloc stack \n",!ether_stack_block);

	init_stack ( 3, p_period, ETHER_STACK_SIZE, ether_stack_block );

	/* Start the MAC */

	result = adi_dev_Control (
								lan_handle,
								ADI_ETHER_CMD_START,
								NULL);

	DEBUG_PRINT("Failed to start the driver\n",result != ADI_DEV_RESULT_SUCCESS);

	/* read the PHY controller registers */
	adi_dev_Control(lan_handle,ADI_ETHER_CMD_GET_PHY_REGS,phyregs);

	DEBUG_PRINT("PHY Controller has failed and the board needs power cycled\n",phyregs[1]==0xFFFF);

	/* wait for the link to be up */
	if ( (phyregs[1]&0x4) ==0)
	{
		printf("Waiting for the link to be established\n");
		while ( (phyregs[1]&0x4) ==0)
		{
			// wait period of time
			VDK_PendSemaphore(kPeriodic,0);
			adi_dev_Control(lan_handle,ADI_ETHER_CMD_GET_PHY_REGS,phyregs);
		}
	}

	printf("Link established\n");

	return 1;
}
/******************************************************************
 * 
 *  Function: system_init()
 *  Description:
 *  		Initializes Device Manager, Interrupt
 *  		Manager and the Stack. 
 *   Return:
 *   		Returns 1 upon success -1 upon failure.
 *
 ******************************************************************/
int system_init()
{
	ADI_DEV_MANAGER_HANDLE devmgr_handle;
	unsigned int result;
	u32 response_count,critical_reg;
	ADI_DEV_DEVICE_HANDLE lan_handle;
	char *ether_stack_block;
	u16 phyregs[32];
#ifdef __ADSPBF537__
	const unsigned int mac_address_in_flash = 0x203F0000;
#endif

  
	/* initialize the interrupt manager */

	result = adi_int_Init(
                           intmgr_storage,
                           sizeof(intmgr_storage),
                           &response_count,
                           &critical_reg);
	 
	DEBUG_PRINT("Failed to Initialize interrupt manager\n",result != ADI_DEV_RESULT_SUCCESS);

	/* initialize the device manager */

	result = adi_dev_Init(
                            devmgr_storage,
                            sizeof(devmgr_storage),
                            &response_count,
                            &devmgr_handle,
                            &imask_storage);
	
	DEBUG_PRINT("Failed to Initilize device manager\n",result != ADI_DEV_RESULT_SUCCESS);
  
	/* Initialize the kernel */

	ker_init((void*)0);
  
	/* set thread type for the stack threads */

	ker_set_auxdata((void*)kADI_TOOLS_IOEThreadType);


	
	/* open lan-device */

	result = adi_dev_Open(
                           devmgr_handle,
#if defined(__ADSPBF533__)
                           &ADI_ETHER_USBLAN_Entrypoint,
#elif defined(__ADSPBF537__)
                           &ADI_ETHER_BF537_Entrypoint,
#endif
                           0,
                           NULL,
                           &lan_handle,
                           ADI_DEV_DIRECTION_BIDIRECTIONAL,
                           NULL,
                           NULL,
                           (ADI_DCB_CALLBACK_FN)stack_callback_handler);

	DEBUG_PRINT("Failed to open the lan-device\n",result != ADI_DEV_RESULT_SUCCESS);
 
	/* set the services with in stack */

	set_pli_services(1,&lan_handle);

#ifdef __ADSPBF537__

	/*
	 * Read the EZ-KIT Lite's assigned MAC address, found at address 0x203F0000.
	 * We need to first set the AMGCTL register to allow access to asynchronous
	 * memory. 
	 * 
	 * DMA gets more priority than the processor while accessing SDRAM.
	 */

	*pEBIU_AMGCTL = 0xFF | 0x100;
	

	memcpy ( &hwaddr, (unsigned char *) mac_address_in_flash, sizeof ( hwaddr ) );
	
	result = adi_dev_Control(
                              lan_handle,
                              ADI_ETHER_CMD_SET_MAC_ADDR,
                              (void*)&hwaddr);
                              
	DEBUG_PRINT("Failed set MAC address\n",result != ADI_DEV_RESULT_SUCCESS);
#endif 
	
	/* supply some memory for the driver */

	result = adi_dev_Control(
                              lan_handle,
                              ADI_ETHER_CMD_SUPPLY_MEM,
                              &memtable);

	DEBUG_PRINT("Failed to supply memory to driver\n",result != ADI_DEV_RESULT_SUCCESS);

	result = adi_dev_Control(
                              lan_handle,
                              ADI_DEV_CMD_SET_DATAFLOW_METHOD,
                              (void*)TRUE);


	/* Initialze the stack with user specified configuration priority -3 and
	 * poll period of p_period msec.  The stack is allocated a memory buffer as well.
	 */
   
	ether_stack_block = (char *) malloc ( ETHER_STACK_SIZE );

	DEBUG_PRINT("Failed to malloc stack \n",!ether_stack_block);
   
	init_stack ( 3, p_period, ETHER_STACK_SIZE, ether_stack_block );
	
	/* Start the MAC */

	result = adi_dev_Control (
								lan_handle,
								ADI_ETHER_CMD_START,
								NULL);

	DEBUG_PRINT("Failed to start the driver\n",result != ADI_DEV_RESULT_SUCCESS);
	
	/* read the PHY controller registers */
	adi_dev_Control(lan_handle,ADI_ETHER_CMD_GET_PHY_REGS,phyregs);
	
	DEBUG_PRINT("PHY Controller has failed and the board needs power cycled\n",phyregs[1]==0xFFFF);
	
	/* wait for the link to be up */
	if ( (phyregs[1]&0x4) ==0)
	{
		printf("Waiting for the link to be established\n");
		while ( (phyregs[1]&0x4) ==0)
		{		
			adi_dev_Control(lan_handle,ADI_ETHER_CMD_GET_PHY_REGS,phyregs);
		}
	}
	
	printf("Link established\n");
    
	return 1;
}