Ejemplo 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);
}
Ejemplo n.º 2
0
int ReadMACAddress(char * cMacAddress)
{
	u32 Result = ADI_DEV_RESULT_SUCCESS;
	u32 access_mode = ADI_OTP_ACCESS_READ;
	u64 macaddress;
	u16 i=0;
	char *ptr=cMacAddress;
	char MACaddr[6] = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd };

	// open the OTP driver
	Result = adi_dev_Open(	adi_dev_ManagerHandle,			// DevMgr handle
							&ADIOTPEntryPoint,				// pdd entry point
							0,								// device instance
							NULL,							// client handle callback identifier
							&DevHandleOTP,					// DevMgr handle for this device
							ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
							NULL,							// handle to DmaMgr for this device
							NULL,							// handle to deferred callback service
							OTP_Callback);					// client's callback function

	if (Result != ADI_DEV_RESULT_SUCCESS)
		return 0;

	access_mode = ADI_OTP_ACCESS_READWRITE;

	Result = adi_dev_Control(DevHandleOTP, ADI_OTP_CMD_SET_ACCESS_MODE, &access_mode );
	if (Result != ADI_DEV_RESULT_SUCCESS)
	{
		adi_dev_Close( DevHandleOTP );
		return 0;
	}

	// Set Dataflow method
	Result = adi_dev_Control(DevHandleOTP, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED );
	if(Result != ADI_DEV_RESULT_SUCCESS)
	{
		adi_dev_Close( DevHandleOTP );
		return 0;
    }


	Result = otp_read_page(OTP_MAC_ADDRESS_PAGE, ADI_OTP_LOWER_HALF, (u64*)&MACaddr);
	if( Result != ADI_DEV_RESULT_SUCCESS )
		return 0;

	// The MAC address is in reverse order
	// do byte swape
	for(i=0; i<6; i++)
	{
		*ptr++ = MACaddr[5-i];

	}

    adi_dev_Close( DevHandleOTP );

    return 1;

}
Ejemplo n.º 3
0
    AdiDeviceResult AdiDevice::Open()
    {
    	ESS_ASSERT(!IsOpened());    	

        AdiDeviceResult result = adi_dev_Open(m_deviceManager.Handle(), 
            m_settings.m_pEntryPoint, m_deviceNumber, m_settings.m_clientHandle,
            &m_deviceHandle, m_settings.m_direction, m_settings.m_DMAHandle,
            m_settings.m_DCBHandle, m_settings.m_clientCallback);
        
        if (result.isSuccess())	m_isOpen = true;

        return result;
    }
Ejemplo n.º 4
0
void UARTinit( u32 baudrate )
{
    ADI_DCB_HANDLE			DCBManagerHandle = 0;		// handle to the callback service
	u32 cclk, sclk, vco;							// frequencies (note these are in MHz)
	u32 i; 											//loop variable
	
	ADI_DEV_CMD_VALUE_PAIR ConfigurationTable [] = {	// configuration table for the UART driver
		{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, 	(void *)ADI_DEV_MODE_CHAINED	},
		{ ADI_UART_CMD_SET_DATA_BITS, 		(void *)8						},
		{ ADI_UART_CMD_ENABLE_PARITY, 		(void *)FALSE					},
		{ ADI_UART_CMD_SET_STOP_BITS, 		(void *)1						},
		{ ADI_UART_CMD_SET_BAUD_RATE, 		(void *)baudrate				},
		{ ADI_UART_CMD_SET_LINE_STATUS_EVENTS, 	(void *)TRUE					},
		{ ADI_DEV_CMD_END,					NULL							},
	};
	
	InputBufferhead = 0;
	InputBuffertail = 0;
	
	// create two buffers that will be initially be placed on the inbound queue
	// only the inbound buffer will have a callback
	InboundBuffer.Data = &InboundData;
	InboundBuffer.ElementCount = 1;
	InboundBuffer.ElementWidth = 1;
	InboundBuffer.CallbackParameter = (void*)&InboundBuffer;
	InboundBuffer.ProcessedFlag = FALSE;
	InboundBuffer.pNext = NULL;
	
	sending_done = 1;
	OutboundBuffer.Data = OutboundData;
	OutboundBuffer.ElementCount = 1;
	OutboundBuffer.ElementWidth = 1;
	OutboundBuffer.CallbackParameter = (void*)&OutboundBuffer;
	OutboundBuffer.ProcessedFlag = TRUE;
	OutboundBuffer.pNext = NULL;

	// open the UART driver for bidirectional data flow
	ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIUARTEntryPoint, 0, NULL, &DriverHandle, ADI_DEV_DIRECTION_BIDIRECTIONAL, NULL, DCBManagerHandle, Callback));
		
	// configure the UART driver with the values from the configuration table
   	ezErrorCheck(adi_dev_Control(DriverHandle, ADI_DEV_CMD_TABLE, ConfigurationTable));
		
	// give the device the inbound buffer
	ezErrorCheck(adi_dev_Read(DriverHandle, ADI_DEV_1D, (ADI_DEV_BUFFER *)&InboundBuffer));

	// enable data flow
	ezErrorCheck(adi_dev_Control(DriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));	
	
}
Ejemplo n.º 5
0
/*********************************************************************
*
*	Function:		SPORT_Open
*
*	Description:	Opens the SPORT	device for ADAV801 audio dataflow
*
*********************************************************************/
static u32 SPORT_Open( 
	ADI_DEV_PDD_HANDLE PDDHandle	// Physical	Device Driver Handle
) {
	
	//	Pointer	to ADAV801 device driver instance
	ADI_ADAV801	 *pADAV801 = (ADI_ADAV801 *)PDDHandle;
	// default return code
	u32	Result = ADI_DEV_RESULT_SUCCESS;

	// Open	the	SPORT driver
	Result = adi_dev_Open( 
		pADAV801->ManagerHandle,		// device manager handle
		&ADISPORTEntryPoint,			// SPORT Entry point
		pADAV801->sportDeviceNumber,	// SPORT device	number
		pADAV801,						// client handle - passed to internal callback function
		&pADAV801->sportHandle,			// pointer to DM handle	(for SPORT driver) location
		pADAV801->sportDirection,		// SPORT data direcion
		pADAV801->DMAHandle,			// handle to the DMA manager
		pADAV801->DCBHandle,			// handle to the callback manager
		sportCallbackFunction			// internal	callback function
	);

// return with appropriate code	if SPORT driver	fails to open
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

// SPORT Configuration (by default)
// Active Low, External	Frame sync,	MSB	first, External	CLK
// Stereo frame	sync enable, Secondary side	enabled, 24-bit	data

ADI_DEV_CMD_VALUE_PAIR SPORT_Config[] =	{
	{ ADI_SPORT_CMD_SET_TCR1,		(void *)(TFSR |	LTFS | TCKFE)						},
	{ ADI_SPORT_CMD_SET_TCR2,		(void *)(pADAV801->sport_txlen|	TXSE| TSFSE	)		},
	{ ADI_SPORT_CMD_SET_RCR1,		(void *)(RFSR |	LRFS | RCKFE)						},
	{ ADI_SPORT_CMD_SET_RCR2,		(void *)(pADAV801->sport_rxlen|	RXSE | RSFSE)		},
	{ ADI_DEV_CMD_END,				(void *)NULL										},
};

	// Configure SPORT device
	Result = adi_dev_Control( pADAV801->sportHandle, ADI_DEV_CMD_TABLE,	(void*)SPORT_Config	);
	
	return (Result);
}
Ejemplo n.º 6
0
static u32 adi_pdd_Open(
	ADI_DEV_MANAGER_HANDLE	ManagerHandle,			// device manager handle
	u32 					DeviceNumber,			// device number
	ADI_DEV_DEVICE_HANDLE	DMHandle,				// device handle
	ADI_DEV_PDD_HANDLE 		*pPDDHandle,			// pointer to PDD handle location 
	ADI_DEV_DIRECTION 		Direction,				// data direction
	void					*pEnterCriticalArg,		// enter critical region parameter
	ADI_DMA_MANAGER_HANDLE	DMAHandle,				// handle to the DMA manager
	ADI_DCB_HANDLE			DCBHandle,				// callback handle
	ADI_DCB_CALLBACK_FN		DMCallback				// client callback function
) {

	// default return code
	u32 Result = ADI_DEV_RESULT_SUCCESS;
	ADI_AD7477A *pAD7477A;		// pointer to the AD7477A device we're working on
	void *pExitCriticalArg;		// exit critical region parameter
	
	// Check for a valid device number and that we're only doing input
#ifdef ADI_DEV_DEBUG
	if (DeviceNumber >= ADI_AD7477A_NUM_DEVICES) return (ADI_DEV_RESULT_BAD_DEVICE_NUMBER);
	if (Direction != ADI_DEV_DIRECTION_INBOUND) return (ADI_DEV_RESULT_DIRECTION_NOT_SUPPORTED);
#endif

	// assign the pointer to the device instance
	pAD7477A = &Device[DeviceNumber];
	// and store the Device Manager handle 
	pAD7477A->DMHandle = DMHandle;
	// and callback function
	pAD7477A->DMCallback = DMCallback;
	// Assign the quiet period factor, to enable us to more accurately 
	// modify the requested sample rate to what is achievable. This value is the 
	// (1+e)*1000, where e = (tsample - tconvert)/tconvert.
	// (see description under case ADI_AD7477A_CMD_SET_QUIET_PERIOD_FACTOR in the 
	// adi_pdd_Control function for more details). 
	// The default value is based on experimental evidence using two ADSP-BF537 
	// EZ-Kits.
	pAD7477A->tquiet_factor = 1062;
	// Check that this device instance is not already in use. If not, 
	// assign flag to indicate that it is now.
	// the device starts in powerup mode
	//pAD7477A->CurMode = ADI_AD7477A_MODE_NORMAL;
	pExitCriticalArg = adi_int_EnterCriticalRegion(pEnterCriticalArg);
	if (pAD7477A->InUseFlag == FALSE) {
		pAD7477A->InUseFlag = TRUE;
		Result = ADI_DEV_RESULT_SUCCESS;
	}
	adi_int_ExitCriticalRegion(pExitCriticalArg);
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// Open the SPI driver 
	Result = adi_dev_Open(
					ManagerHandle,			// device manager handle
					&ADISPIDMAEntryPoint,	// dma-driven SPI driver entry point
					0,						// device number
					pAD7477A,				// client handle - passed to internal callback function
					&pAD7477A->spiHandle,	// pointer to DM handle (for SPI driver) location 
					Direction,				// data direction as input
					DMAHandle,				// handle to the DMA manager
					DCBHandle,				// handle to the callback manager
					spiCallbackFunction		// internal callback function 
	);
	// return with appropriate code if SPI driver fails to open
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// Configure the SPI Control register (SPI_CTL) for the 
	// appropriate values for the AD7477A device
	ADI_DEV_CMD_VALUE_PAIR SPI_config[] = {
		{ ADI_SPI_CMD_SET_TRANSFER_INIT_MODE, (void*)2 },	// DMA read
		{ ADI_SPI_CMD_SET_GET_MORE_DATA, (void*)0 },		// discard incoming data if SPI_RDBR register is full
		{ ADI_SPI_CMD_SET_PSSE, (void*)0 },					// free up PF0
		{ ADI_SPI_CMD_SET_MISO, (void*)1 },					// allow data in
		{ ADI_SPI_CMD_SET_WORD_SIZE, (void*)16 },			// Data word size 16 Bit (we need 16bits
															// since the AD7477A device generates 10 bits data with 4 leading
															// and 2 trailing zeros)
		{ ADI_SPI_CMD_SET_LSB_FIRST, (void*)0 },			// Most Significant Bit transmitted first
		{ ADI_SPI_CMD_SET_CLOCK_PHASE, (void*)0 },			// Clock phase field = 0 is required for DMA
		{ ADI_SPI_CMD_SET_CLOCK_POLARITY, (void*)1 },		// Clock polarity - sample on falling edge of serial clock
		{ ADI_SPI_CMD_SET_MASTER, (void*)1 },				// The SPI port is the master
		{ ADI_SPI_CMD_SET_EXCLUSIVE_ACCESS, (void*) TRUE},	// get us exclusive access to the SPI driver
		{ ADI_DEV_CMD_END, (void*)0 }
	};
	Result = adi_dev_Control( pAD7477A->spiHandle, ADI_DEV_CMD_TABLE, (void*)SPI_config );
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// save the physical device handle in the client supplied location
	*pPDDHandle = (ADI_DEV_PDD_HANDLE *)pAD7477A;

	// return after successful completion 
	return(Result);
}
Ejemplo n.º 7
0
/*********************************************************************

    Function: adi_ad1980_SportConfig

        Opens and Configures SPORT device allocated to AD1980 Audio Codec

    Parameters:
        poDevice         - Pointer to AD1980 device instance to work on

    Returns:
        ADI_DEV_RESULT_SUCCESS
            - Successfully opened and configured SPORT device
        Error code returned from SPORT driver

*********************************************************************/
static u32 adi_ad1980_SportConfig(
    ADI_AD1980_DEF          *poDevice
)
{

    /* default return code */
    u32     nResult = ADI_DEV_RESULT_SUCCESS;

    /* SPORT Configuration Table */
    ADI_DEV_CMD_VALUE_PAIR  aoSportConfigTable[] =
    {
        /* clear any previous Tx errors */
        { ADI_SPORT_CMD_CLEAR_TX_ERRORS,    (void *)NULL                    },
        /* clear any previous Rx errors */
        { ADI_SPORT_CMD_CLEAR_RX_ERRORS,    (void *)NULL                    },
        /* SPORT in Circular mode       */
        { ADI_DEV_CMD_SET_DATAFLOW_METHOD,  (void *)ADI_DEV_MODE_CIRCULAR   },
        /* Enable Streaming mode        */
        { ADI_DEV_CMD_SET_STREAMING,        (void *)true                    },
        /* External Frame sync, MSB first, No TFS required  */
        { ADI_SPORT_CMD_SET_TCR1,           (void *)0                       },
        /* Secondary disabled   */
        { ADI_SPORT_CMD_SET_TCR2,           (void *)0                       },
        /* Tx Wordlength = 16 bits  */
        { ADI_SPORT_CMD_SET_TX_WORD_LENGTH, (void *)15                      },
        /* Internal RFS, Require RFS for every data */
        { ADI_SPORT_CMD_SET_RCR1,           (void *)0x0600                  },
        /* Secondary disabled   */
        { ADI_SPORT_CMD_SET_RCR2,           (void *)0                       },
        /* Rx Wordlength = 16 bits  */
        { ADI_SPORT_CMD_SET_RX_WORD_LENGTH, (void *)15                      },
        /* sets RFS to 48kHz (BIT_CLK for AC'97 = 12.288MHz) */
        { ADI_SPORT_CMD_SET_RFSDIV,         (void *)0xFF                    },
        /* MFD = 1, Enable Multi Channel, Enable Tx/Rx DMA packing */
        { ADI_SPORT_CMD_SET_MCMC2,          (void *)0x101C                  },
        /* 16 Channels */
        { ADI_SPORT_CMD_SET_MTCS0,          (void *)0xFFFF                  },
        /* 16 Channels */
        { ADI_SPORT_CMD_SET_MRCS0,          (void *)0xFFFF                  },
        /* Window Size = ((16 Channels/8) - 1) = 1 */
        { ADI_SPORT_CMD_SET_MCMC1,          (void *)0x1000                  },
        /* Enable error reporting */
        { ADI_DEV_CMD_SET_ERROR_REPORTING,  (void *)true                    },
        /* End of Configuration table */
        { ADI_DEV_CMD_END,                  (void *)NULL                    },
    };

    /* IF (Reset Flag ID is valid) */
    if (poDevice->eResetFlag != ADI_FLAG_UNDEFINED)
    {
        /* Issue a Hardware reset to AD1980 */
        nResult = adi_ac97_HwReset(poDevice->pAC97, poDevice->eResetFlag);
    }
    /* ELSE (Invalid reset flag) */
    else
    {
        /* Report failure (Invalid Reset Flag) */
        nResult = ADI_AD1980_RESULT_RESET_FLAG_ID_INVALID;
    }

    /* IF (Successfully Reset AD1980) */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
        /* Open SPORT Device connected to AD1980 */
        nResult = adi_dev_Open(poDevice->hDeviceManager,
                               &ADISPORTEntryPoint,
                               poDevice->nSportDevNumber,
                               poDevice,
                               &poDevice->hSport,
                               ADI_DEV_DIRECTION_BIDIRECTIONAL,
                               poDevice->hDmaManager,
                               NULL,
                               adi_ad1980_SportCallback);
    }

    /* IF (Successfully opened SPORT device) */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
        /* Configure SPORT Device */
        nResult = adi_dev_Control(poDevice->hSport,
                                  ADI_DEV_CMD_TABLE,
                                  (void *)&aoSportConfigTable[0]);
    }

    /* IF (Successfully Configured the SPORT driver) */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
        /* Submit outbound buffer */
        nResult = adi_dev_Write (poDevice->hSport,
                                 ADI_DEV_CIRC,
                                 (ADI_DEV_BUFFER *)(&poDevice->pAC97->DacCircBuf));
    }

    /* IF (Successfully Submitted outbound buffer) */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
        /* Submit inbound buffer */
        nResult = adi_dev_Read (poDevice->hSport,
                                ADI_DEV_CIRC,
                                (ADI_DEV_BUFFER *)(&poDevice->pAC97->AdcCircBuf));
    }

    /* IF (Successfully Opened and Configured SPORT Device) */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
        /* Enable SPORT dataflow - this enables AC-Link to AD1980 */
        nResult = adi_dev_Control(poDevice->hSport,
                                  ADI_DEV_CMD_SET_DATAFLOW,
                                  (void *)true);
    }

    return (nResult);
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/*********************************************************************
*
*   Function:       PPI_Open
*
*   Description:    Opens the ppi device for NL6448BC33-54 LCD dataflow
*
*********************************************************************/
static u32 PPI_Open(
    ADI_DEV_PDD_HANDLE PDDHandle    // Physical Device Driver Handle
) {


    ADI_LCD *pLCD;	// pointer to the device we're working on
    pLCD = (ADI_LCD *)PDDHandle; // Pointer to device driver instance

    // default return code
    u32 Result = ADI_DEV_RESULT_SUCCESS;

    // storage for PPI frame sync timer values
    ADI_PPI_FS_TMR FsTmrBuf = {0};  // initialize - sets all fields to zero

    // Configure the PPI registers for LCD
	ADI_DEV_CMD_VALUE_PAIR PPI_Cfg[] = {
#if defined (__ADSPBF561__)
        // by default, PPI is configured as output & DMA32 enabled
	{ ADI_PPI_CMD_SET_CONTROL_REG,	 (void *)0xB91E	},// tx-mode,2or3 syncs,16bits and FS_INVERT = 1
#else	// for BF533 & BF537
    	{ ADI_PPI_CMD_SET_CONTROL_REG,	 (void *)0xB81E	},// tx-mode,2or3 syncs,16bits and FS_INVERT = 1
#endif
#if defined ADI_NEC_NL6448BC33_54
	{ ADI_PPI_CMD_SET_DELAY_COUNT_REG, 	(void *)143 },// clk delay after frame sync
#else // ADI_SHARP_LQ10D368
#if defined (__ADSPBF537__)
    	{ ADI_PPI_CMD_SET_DELAY_COUNT_REG, 	(void *)199 },//BF537 clk delay after frame sync
#else
    	{ ADI_PPI_CMD_SET_DELAY_COUNT_REG, 	(void *)199 },//BF533 or BF561 clk delay after frame sync
#endif
#endif

		{ ADI_PPI_CMD_SET_TRANSFER_COUNT_REG,	(void *)639 	},// 640 active pixels
		{ ADI_DEV_CMD_END, 			(void *)0 	}
    	};



    // Open the PPI driver
    Result = adi_dev_Open(
        pLCD->ManagerHandle,	// device manager handle
        &ADIPPIEntryPoint,          // ppi Entry point
        pLCD->PPINumber,  // ppi device number
        pLCD,                   // client handle - passed to internal callback function
        &pLCD->ppiHandle,       // pointer to DM handle (for PPI driver) location
        ADI_DEV_DIRECTION_OUTBOUND, // PPI used only to receive video data
        pLCD->DMAHandle,        // handle to the DMA manager
        pLCD->DCBHandle,        // handle to the callback manager
        ppiCallbackFunction         // internal callback function
    );

    // return with appropriate code if PPI driver fails to open
#ifdef ADI_DEV_DEBUG
    if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
	// set the PPI configuration
	Result = adi_dev_Control( pLCD->ppiHandle, ADI_DEV_CMD_TABLE, (void*)PPI_Cfg );
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// set the frame sync configuration.
	FsTmrBuf.pulse_hi = 0;//positive action pulse
	FsTmrBuf.emu_run = 1;// timer counter runs during emulation

	// timer 0 configuration (Hsync)
#if defined ADI_NEC_NL6448BC33_54
	FsTmrBuf.period = 800; // timer0 period (800clk = 1H)
#else // ADI_SHARP_LQ10D368
	FsTmrBuf.period = 900; // timer0 period (900clk)
#endif
	FsTmrBuf.width = 96; // timer0 width (96clk)
	Result = adi_dev_Control( pLCD->ppiHandle, ADI_PPI_CMD_SET_TIMER_FRAME_SYNC_1, (void*)&FsTmrBuf );

#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
	// timer 1 configuration (Vsync)
#if defined ADI_NEC_NL6448BC33_54
	FsTmrBuf.period = 0x668A0; // timer1 period (525H = 525*800clk)
#else // ADI_SHARP_LQ10D368
	FsTmrBuf.period = 0x735B4; // timer1 period (525*900clk)
#endif
	FsTmrBuf.width = 1600; // timer1 width (2H = 2*800clk)
	Result = adi_dev_Control( pLCD->ppiHandle, ADI_PPI_CMD_SET_TIMER_FRAME_SYNC_2, (void*)&FsTmrBuf );

#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif


    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;
}
Ejemplo n.º 11
0
/*********************************************************************

    Function:       Activate

    Description:    Activates the host and enumerates the attached
                    device

*********************************************************************/
static u32 Activate(ADI_USB_DEF *pDevice, u32 EnableFlag)
{
    u32 Result = ADI_FSS_RESULT_SUCCESS;
    u32 i      = 0;

    /* The reset is only performed once for all PID's in chain */
    if (EnableFlag)
    {
        /* Initialize the core */
        if (pDevice->UseDefaultController)
        {
            adi_usb_CoreInit((void*)&Result);

            /*  Open the BF54x USB Driver */
            Result = adi_dev_Open(
                                    pDevice->ManagerHandle,                 /* DevMgr handle */
                                    &ADI_USBDRC_Entrypoint,                 /* pdd entry point */
                                    0,                                      /* device instance */
                                    (void*)1,                               /* client handle callback identifier */
                                    &pDevice->ControllerHandle,             /* device handle */
                                    ADI_DEV_DIRECTION_BIDIRECTIONAL,        /* data direction for this device */
                                    pDevice->DMAHandle,                     /* handle to DmaMgr for this device */
                                    pDevice->DCBHandle,                     /* handle to deferred callback service */
                                    ControllerCallback                      /* client's callback function */
                                );
        }

        /* Get the current Device ID. Once the driver is opened its */
        /* suppose to create the device. If the device is already opened then */
        /* it must return the same device ID. */
        if ((Result != ADI_DEV_RESULT_SUCCESS) || (pDevice->ControllerHandle == NULL))
        {
            Result = ADI_FSS_RESULT_FAILED;
        }

        if ( Result==ADI_DEV_RESULT_SUCCESS && !pDevice->UseDefaultClassDriver )
        {
            Result = adi_dev_Control ( pDevice->ClassDriverHandle, ADI_DEV_CMD_CHANGE_CLIENT_HANDLE, (void*)pDevice );
            Result = adi_dev_Control ( pDevice->ClassDriverHandle, ADI_DEV_CMD_CHANGE_CLIENT_CALLBACK_FUNCTION, (void*)ClassDriverCallback );
        }

        if ( Result==ADI_DEV_RESULT_SUCCESS && pDevice->UseDefaultClassDriver )
        {
            /* open the class driver */
            Result = adi_dev_Open(
                                    pDevice->ManagerHandle,                    /* DevMgr handle */
                                    &ADI_USB_Host_MassStorageClass_Entrypoint, /* pdd entry point */
                                    0,                                         /* device instance */
                                    pDevice,                                   /* client handle callback identifier */
                                    &pDevice->ClassDriverHandle,               /* device handle */
                                    ADI_DEV_DIRECTION_BIDIRECTIONAL,           /* data direction for this device */
                                    pDevice->DMAHandle,                        /* handle to DmaMgr for this device */
                                    pDevice->DCBHandle,                        /* handle to deferred callback service */
                                    ClassDriverCallback                        /* client's callback function */
                                );
        }
        if ((Result != ADI_DEV_RESULT_SUCCESS) || (pDevice->ClassDriverHandle == NULL))
        {
            Result = ADI_FSS_RESULT_FAILED;
        }

        /* If the controller and class drivers are supplied, we assume that these steps
         * have already been taken
        */
        if (pDevice->UseDefaultClassDriver && Result == ADI_DEV_RESULT_SUCCESS)
        {
            /* configure the controller mode */
            Result = adi_dev_Control(
                                        pDevice->ClassDriverHandle,
                                        ADI_USB_CMD_CLASS_SET_CONTROLLER_HANDLE,
                                        (void*)pDevice->ControllerHandle
                                    );

            /* configure the class driver */
            if (Result == ADI_DEV_RESULT_SUCCESS)
            {
                Result = adi_dev_Control(
                                            pDevice->ClassDriverHandle,
                                            ADI_USB_CMD_CLASS_CONFIGURE,
                                            (void*)0
                                        );
            }

            /* configure the data flow method */
            if (Result == ADI_DEV_RESULT_SUCCESS)
            {
                Result = adi_dev_Control(
                                            pDevice->ClassDriverHandle,
                                            ADI_DEV_CMD_SET_DATAFLOW_METHOD,
                                            (void*)ADI_DEV_MODE_CHAINED
                                        );
            }
            /* enable data flow */
            if (Result == ADI_DEV_RESULT_SUCCESS)
            {
                Result = adi_dev_Control(
                                            pDevice->ClassDriverHandle,
                                            ADI_DEV_CMD_SET_DATAFLOW,
                                            (void*)TRUE
                                        );
            }
            if (Result == ADI_DEV_RESULT_SUCCESS)
            {
                Result = adi_dev_Control(
                                            pDevice->ControllerHandle,
                                            ADI_USB_CMD_ENABLE_USB,
                                            0
                                        );
            }
        }

    }
    else {
        /* Deactivate */
        pDevice->MediaPresent = false;
    }


    return Result;
}
Ejemplo n.º 12
0
static u32 adi_pdd_Open(
	ADI_DEV_MANAGER_HANDLE	ManagerHandle,			// device manager handle
	u32 					DeviceNumber,			// device number
	ADI_DEV_DEVICE_HANDLE	DMHandle,				// device handle
	ADI_DEV_PDD_HANDLE 		*pPDDHandle,			// pointer to PDD handle location 
	ADI_DEV_DIRECTION 		Direction,				// data direction
	void					*pEnterCriticalArg,		// enter critical region parameter
	ADI_DMA_MANAGER_HANDLE	DMAHandle,				// handle to the DMA manager
	ADI_DCB_HANDLE			DCBHandle,				// callback handle
	ADI_DCB_CALLBACK_FN		DMCallback				// client callback function
) {

	// default return code
	u32 Result = ADI_DEV_RESULT_SUCCESS;
	ADI_AD1854 *pAD1854;		// pointer to the AD1854 device we're working on
	void *pExitCriticalArg;		// exit critical region parameter
	u32 ResponseCount;	
	
	// Check for a valid device number and that we're only doing input
#ifdef ADI_DEV_DEBUG
	if (DeviceNumber >= ADI_AD1854_NUM_DEVICES) return (ADI_DEV_RESULT_BAD_DEVICE_NUMBER);
	if (Direction != ADI_DEV_DIRECTION_OUTBOUND) return (ADI_DEV_RESULT_DIRECTION_NOT_SUPPORTED);
#endif
	
	// assign the pointer to the device instance
	pAD1854 = &Device[DeviceNumber];
	// and store the Device Manager handle 
	pAD1854->DMHandle = DMHandle;
	// and callback function
	pAD1854->DMCallback = DMCallback;	
		
	pExitCriticalArg = adi_int_EnterCriticalRegion(pEnterCriticalArg);
	if (pAD1854->InUseFlag == FALSE) {
		pAD1854->InUseFlag = TRUE;
		Result = ADI_DEV_RESULT_SUCCESS;
	}
	adi_int_ExitCriticalRegion(pExitCriticalArg);
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// Open SPORT0 for communication
	Result = adi_dev_Open(ManagerHandle, &ADISPORTEntryPoint, 0, pAD1854, &(pAD1854->sportHandle), ADI_DEV_DIRECTION_OUTBOUND, DMAHandle, DCBHandle, sportCallbackFunction);

	// return with appropriate code if SPORT driver fails to open
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
    
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// save the physical device handle in the client supplied location
	*pPDDHandle = (ADI_DEV_PDD_HANDLE *)pAD1854;
	
	//Reset_DAC();

	// return after successful completion 
	return(Result);

}
Ejemplo n.º 13
0
/*********************************************************************

    Function:       Activate

    Description:    Activates the host and enumerates the attached
                    device

*********************************************************************/
__ADI_NAND_SECTION_CODE
static u32 Activate(ADI_NAND_DEF *pDevice, u32 EnableFlag)
{
    u32                     Result = ADI_FSS_RESULT_SUCCESS;
    u32                     i      = 0;
    void                    *Value = NULL;              /* pointer to argument */
    ADI_FSS_SUPER_BUFFER    FSSBuffer;
    F_PHY                   FtlPhyLayer;


    /* The reset is only performed once for all PID's in chain */
    if (!pDevice->Active)
    {

        if (!pDevice->NFC_DeviceHandle)
        {
            /* The NFC was not previously opened so open it  */
            Result = adi_dev_Open(  pDevice->ManagerHandle, /* Device Manager handle                */
                                    &ADI_NFC_EntryPoint,    /* NFC driver Entry point               */
                                    pDevice->DeviceNumber,  /* NFC device number                    */
                                    NULL,                   /* client handle                        */
                                    &pDevice->NFC_DeviceHandle,      /* Location to store NFC device handle  */
                                    pDevice->Direction,     /* NFC Direction                        */
                                    pDevice->DMAHandle,     /* DMA manager Handle                   */
                                    pDevice->DCBHandle,     /* DCB Manager Handle                   */
                                    CallbackFromNFC         /* NFC callback function                */
                                    );
        }

        /* configure the NFC driver */
        if (Result==ADI_FSS_RESULT_SUCCESS)
        {
            Result = ConfigNFC( pDevice );
        }

        /* If needed and enabled format the device */
        if (( pDevice->Perform_Format_Flag == TRUE ) && (Result==ADI_FSS_RESULT_SUCCESS))
        {
            if (adi_ftl_NandFormat())
            {
                /* if format NFD failed, return error */
                Result = ADI_FSS_RESULT_FAILED;
            }
        }

        /*  Initialize the entry points for the wear leveling. */
        if (Result == ADI_FSS_RESULT_SUCCESS)
        {
            /* initialize FTL layer */
            pDevice->pFtlEntryPoints = adi_ftl_Init();
            if (!pDevice->pFtlEntryPoints) {
                Result = ADI_FSS_RESULT_NO_MEDIA;
            }
        }

        if (Result==ADI_FSS_RESULT_SUCCESS)
        {
            /* Get Global Size parameters from FTL */
            (pDevice->pFtlEntryPoints->getphy)(pDevice->pFtlEntryPoints, &FtlPhyLayer);
            pDevice->GlobalVolumeDef.VolumeSize = FtlPhyLayer.number_of_sectors;
            pDevice->GlobalVolumeDef.SectorSize = FtlPhyLayer.bytes_per_sector;

        }
        if (Result==ADI_FSS_RESULT_SUCCESS) {
            pDevice->Active = true;
        }

    }
    else {
        /* Deactivate */
        pDevice->Active = false;
        pDevice->MediaPresent = false;

    }

    return Result;
}