Beispiel #1
0
u32 adi_ssl_Init(void) {

    u32 i;
    u32 Result;

    do {
        // initialize the interrupt manager, parameters are
        //      pointer to memory for interrupt manager to use
        //      memory size (in bytes)
        //      location where the number of secondary handlers that can be
        //          supported will be stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_int_Init(InterruptServiceData,
                              sizeof(InterruptServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_INT_RESULT_SUCCESS != Result) \
            ||(ADI_SSL_INT_NUM_SECONDARY_HANDLERS != i))
        {
        }

       //  initialize the EBIU, parameters are
       //  address of table containing RAM parameters
       //  0 - reserved field, always 0
       //  Ignores result, so it can keep going if it's already initialized
        Result = adi_ebiu_Init(config_ram, 0);
        while ((ADI_EBIU_RESULT_SUCCESS != Result) &&
        (ADI_EBIU_RESULT_ALREADY_INITIALIZED != Result))
        {

        }

        // initialize power, parameters are
        //      address of table containing processor information
        // keep going if it's already initialized
        Result = adi_pwr_Init(config_power);
        while ((ADI_PWR_RESULT_SUCCESS != Result) &&
            (ADI_PWR_RESULT_ALREADY_INITIALIZED != Result))
        {

        }
        
        // U-boot done setFreq
        Result = adi_pwr_SetFreq (256000000, 256000000, ADI_PWR_DF_ON);
        while (ADI_PWR_RESULT_SUCCESS != Result)
        {

        }
        
        // initialize port control, parameters are
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_ports_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_PORTS_RESULT_SUCCESS != Result)
        {

        }

        // initialize deferred callback service if needed, parameters are
        //      pointer to data
        //      size of data
        //      location where number of servers is stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_DCB_NUM_SERVERS != 0)
        Result = adi_dcb_Init(DeferredCallbackServiceData,
                              sizeof(DeferredCallbackServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_DCB_RESULT_SUCCESS != Result) \
            || (ADI_SSL_DCB_NUM_SERVERS != i))
        {

        }
#endif

        // initialize the dma manager if needed, parameters are
        //      pointer to memory for the DMA manager to use
        //      memory size (in bytes)
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_DMA_NUM_CHANNELS != 0)
        Result = adi_dma_Init(DMAServiceData,
                              sizeof(DMAServiceData),
                              &i, &adi_dma_ManagerHandle, ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_DMA_RESULT_SUCCESS) \
            || (ADI_SSL_DMA_NUM_CHANNELS != i))
        {

        }
#endif


        // initialize the flag manager, parameters are
        //      pointer to memory for the flag service to use
        //      memory size (in bytes)
        //      location where the number of flag callbacks that can be
        //          supported will be stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_flag_Init(FlagServiceData, sizeof(FlagServiceData),
                               &i, ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_FLAG_RESULT_SUCCESS) \
            || (ADI_SSL_FLAG_NUM_CALLBACKS != i))
        {

        }

        // initialize the timer manager, parameters are
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_tmr_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_TMR_RESULT_SUCCESS != Result)
        {

        }


#if !defined(ADI_SSL_RTC_NO_INIT)
        // initialize the RTC service
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_rtc_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_RTC_RESULT_SUCCESS != Result)
        {

        }
#endif

        // initialize the semaphore service if needed, parameters are
        //      pointer to memory for the semaphore service to use
        //      memory size (in bytes)
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_SEM_NUM_SEMAPHORES != 0)
        Result = adi_sem_Init(SemaphoreServiceData,
                              sizeof(SemaphoreServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_SEM_RESULT_SUCCESS != Result) \
            || (ADI_SSL_SEM_NUM_SEMAPHORES != i))
        {

        }
#endif

        // initialize the device manager if needed, parameters are
        //      pointer to data for the device manager to use
        //      size of the data in bytes
        //      location where the number of devices that can be managed
        //          will be stored
        //      location where the device manager handle will be stored
        //      parameter for adi_int_EnterCriticalRegion() function
        //          (always NULL for standalone and VDK)
#if     (ADI_SSL_DEV_NUM_DEVICES != 0)
        Result = adi_dev_Init(DevMgrData, sizeof(DevMgrData),
                              &i,  &adi_dev_ManagerHandle,
                              ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_DEV_RESULT_SUCCESS) \
            || (ADI_SSL_DEV_NUM_DEVICES != i))
        {

        }
#endif
     } while (0);     // WHILE (no errors or 1 pass complete)
    return (Result);
}
/******************************************************************
 * 
 *  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;
}