예제 #1
0
/*********************************************************************

    Function:       SendLbaRequest

    Description:    Sends the LBA request to the class driver

*********************************************************************/
static u32 SendLbaRequest(ADI_USB_DEF *pDevice, ADI_FSS_LBA_REQUEST *pLBARequest)
{
    ADI_USB_MSD_SCSI_CMD_BLOCK  SCSICmd;
    u32                         Result;

    SCSICmd.LBASector = pLBARequest->StartSector;
    SCSICmd.BlockSize = pLBARequest->SectorCount;

    /* Pass on request to the Class Driver */
    if (pLBARequest->ReadFlag)
    {
        Result = adi_dev_Control( pDevice->ClassDriverHandle,
                                  ADI_USB_MSD_CMD_SCSI_READ10,
                                  (void*)&SCSICmd
                                );
    }
    else
    {
        Result = adi_dev_Control( pDevice->ClassDriverHandle,
                                  ADI_USB_MSD_CMD_SCSI_WRITE10,
                                  (void*)&SCSICmd
                                );
    }

    return Result;
}
예제 #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;

}
예제 #3
0
static u32 adi_pdd_Control(		// Sets or senses a device specific parameter
	ADI_DEV_PDD_HANDLE 	PDDHandle,	// PDD handle
	u32 				Command,	// command ID
	void 				*Value		// command specific value
) {
	
	ADI_AD1854 				*pAD1854;		// pointer to the device we're working on
	u32 						tmp;			// temporary storage
	u32 						Result;			// return value
	u32							u32Value;		// u32 type to avoid casts/warnings etc.
	u16							u16Value;		// u16 type to avoid casts/warnings etc.
	
	// avoid casts
	pAD1854 = (ADI_AD1854 *)PDDHandle; // Pointer to AD1854 device driver instance
    // assign 16 and 32 bit values for the Value argument
	u32Value = (u32)Value;
    u16Value = ((u16)((u32)Value));
	
	// check for errors if required
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// assume we're going to be successful
	Result = ADI_DEV_RESULT_SUCCESS;	
	
	// CASEOF (Command ID)
	switch (Command) 
	{

		// CASE (query for processor DMA support)
		case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):
			// no, we do support it at this level (it is delegated down to SPORT driver
			*((u32 *)Value) = FALSE;
			break;
		case (ADI_AD1854_CMD_SET_I2S_MODE): //I2S Active Low Frame Sync
			Result = adi_dev_Control(pAD1854->sportHandle, ADI_SPORT_CMD_SET_TCR1, (void *)(TFSR | LTFS | TCKFE));
			Result |= adi_dev_Control(pAD1854->sportHandle, ADI_SPORT_CMD_SET_TCR2, (void *)(SLEN_24 | TSFSE));
			break;		
		// DEFAULT 
		default:
		
			// pass anything we don't specifically handle to the SPORT driver
			return adi_dev_Control(pAD1854->sportHandle,Command,Value);			
		
	// ENDCASE
	}

	return(Result);
}
예제 #4
0
파일: uart.c 프로젝트: 4auka/cmusphinx
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));	
	
}
예제 #5
0
int LinkEstablished(ADI_DEV_DEVICE_HANDLE lan_handle)  // return bool
{
	u16 phyregs[32];
	
	/* read the PHY controller registers */
	adi_dev_Control(lan_handle,ADI_ETHER_CMD_GET_PHY_REGS,phyregs);
	return ((phyregs[1]&0x4) == 0) ? 0 : 1;
}
예제 #6
0
/********************************************************************

    Function:       pdd_Callback

    Description:    The callback to be taken upon buffer completion 
                    and device interrupt callbacks.

********************************************************************/
__ADI_FSD_CACHE_SECTION_CODE
static void pdd_Callback(
    void                *pHandle,
    u32                 Event,
    void                *pArg)
{
    PDD_FSD_CACHE_DEF *pCache;
    ADI_FSS_SUPER_BUFFER *pBuffer;
        
    pCache = (PDD_FSD_CACHE_DEF *)pHandle;
    pBuffer = (ADI_FSS_SUPER_BUFFER *)pArg;

    if ((pBuffer->CompletionBitMask&(~0xADF50000)) == 3)
    {
        /* Upon the completion of the buffer transfer we check to see whether
         * this FSD is responsible for the semaphore. If so, we post it
         */
        if (pBuffer->SemaphoreHandle==pCache->SemaphoreHandle
        )
        {
            adi_sem_Post(pBuffer->SemaphoreHandle);
        }
        
        /* Upon PID Device Interrupt, we can either */
        if (pBuffer->Buffer.pNext)
        {
            /* Submit next LBA request, if requried */
            adi_dev_Control(
                pCache->PIDHandle,
                ADI_PID_CMD_SEND_LBA_REQUEST,
                (void*)&pBuffer->LBARequest);
        }
        else
        {
            /* or, release the PID Lock Semaphore */
            adi_dev_Control(
                pCache->PIDHandle,
                ADI_FSS_CMD_RELEASE_LOCK_SEMAPHORE,
                NULL);
        }
    }
}
예제 #7
0
/*********************************************************************

    Function:       CheckForSCSICommandFailed

    Description:

*********************************************************************/
static void CheckForSCSICommandFailed(ADI_USB_DEF *pDevice)
{
        /* If SCSI command error */
        if(pDevice->SCSICommandError == TRUE)
        {
            pDevice->SCSICommandError = FALSE;
            pDevice->ClassCommandComplete = FALSE;
            adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_REQ_SENSE, 0);
            /* and wait for completion */
            WaitOnCommandCompletion(pDevice);
        }
}
예제 #8
0
int StartMAC(ADI_DEV_DEVICE_HANDLE lan_handle)  // return bool
{
	unsigned int result;
	u16 phyregs[32];

	/* 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);
	if (result != ADI_DEV_RESULT_SUCCESS) return 0;
		
	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);		
	if (phyregs[1] == 0xFFFF) return 0;
		
	return 1;
}
예제 #9
0
/*********************************************************************

    Function:       CallbackFromFSS

    Description:    The callback to be taken upon buffer completion and
                    device interrupt callbacks.
*********************************************************************/
static void CallbackFromFSS(void *pHandle, u32 Event, void *pArg)
{
    ADI_FSS_SUPER_BUFFER *pSuperBuffer = (ADI_FSS_SUPER_BUFFER *)pArg;
    ADI_USB_DEF          *pDevice      = (ADI_USB_DEF *)pHandle;

    if (  Event == ADI_PID_EVENT_DEVICE_INTERRUPT
          && pSuperBuffer->SemaphoreHandle == pDevice->DataSemaphoreHandle )
    {
        adi_dev_Control( pDevice->DeviceHandle, ADI_FSS_CMD_RELEASE_LOCK_SEMAPHORE, NULL );
        adi_sem_Post( pSuperBuffer->SemaphoreHandle );
    }
}
예제 #10
0
err_t nifce_igmp_mac_filter(struct netif* netif, struct ip_addr *group_ip,u8_t action)
{
struct nifce_info* nip = (struct nifce_info*)netif->state;
u32 Result=ADI_DEV_RESULT_FAILED;
	// if we have peripheral device handle
	if(nip->handle != NULL)
	{
	    switch(action)
	    {
		case IGMP_ADD_MAC_FILTER:
			Result = adi_dev_Control(nip->handle, ADI_ETHER_ADD_MULTICAST_MAC_FILTER,(void*)group_ip->addr);
			break;
					
		case IGMP_DEL_MAC_FILTER:
			Result = adi_dev_Control(nip->handle, ADI_ETHER_DEL_MULTICAST_MAC_FILTER,(void*)group_ip->addr);
			break;
		default:
			break;
	    }
	}
return((Result == ADI_DEV_RESULT_SUCCESS) ? 0: -1);
}
예제 #11
0
int Lw_Shutdown(ADI_DEV_DEVICE_HANDLE lan_handle)
{
	// shutdown lan
    int result = adi_dev_Control(lan_handle, ADI_ETHER_CMD_SHUTDOWN_DRIVER, NULL);
	if (result != ADI_DEV_RESULT_SUCCESS) return 0;

	// stop LwIP
	//stop_stack();
	
	// close LAN
	result = adi_dev_Close(lan_handle); 
    if (result != ADI_DEV_RESULT_SUCCESS) return 0;

    return 1;
}
예제 #12
0
/*********************************************************************

    Function:       GetGlobalVolumeDef

    Description:    Assign and return pointer to index'd volume definition

*********************************************************************/
static u32 GetGlobalVolumeDef(ADI_USB_DEF *pDevice, ADI_FSS_VOLUME_DEF *pVolumeDef)
{
    /* Retrieve the Capacity 10 data from the media 
    */
    u32 Result = adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_GET_CAPACITY_TEN_DATA, (void*)&pDevice->CapacityTen);
    
    /* If successful, assign the values 
    */
    if (Result == ADI_DEV_RESULT_SUCCESS) {
        pVolumeDef->StartAddress = 0;
        pVolumeDef->VolumeSize   = pDevice->CapacityTen.NumBlocks;
        pVolumeDef->SectorSize   = pDevice->CapacityTen.BlockSize;
    }
    
    return Result;
}
예제 #13
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);
}
예제 #14
0
 AdiDeviceResult AdiDevice::RunCommand(AdiDeviceCommand &command)
 {
     return adi_dev_Control(m_deviceHandle, ADI_DEV_CMD_PAIR, command.Command());
 }
예제 #15
0
 AdiDeviceResult AdiDevice::ErrorReportingOff()
 {
     return adi_dev_Control(m_deviceHandle, ADI_DEV_CMD_SET_ERROR_REPORTING, (void *)FALSE);
 }
예제 #16
0
 AdiDeviceResult AdiDevice::DataFlowOff()
 {
     return adi_dev_Control(m_deviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)FALSE);
 }
예제 #17
0
static u32 adi_pdd_Control(		// Sets or senses a device specific parameter
	ADI_DEV_PDD_HANDLE 	PDDHandle,	// PDD handle
	u32 				Command,	// command ID
	void 				*Value		// command specific value
) {

	ADI_LCD 				*pLCD;		// pointer to the device we're working on
	u32 						tmp;			// temporary storage
	u32 						Result;			// return value
	u32							u32Value;		// u32 type to avoid casts/warnings etc.
	u16							u16Value;		// u16 type to avoid casts/warnings etc.

	// avoid casts
	pLCD = (ADI_LCD *)PDDHandle; // Pointer to device instance
    // assign 16 and 32 bit values for the Value argument
	u32Value = (u32)Value;
    u16Value = ((u16)((u32)Value));

	// check for errors if required
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// assume we're going to be successful
	Result = ADI_DEV_RESULT_SUCCESS;

	// CASEOF (Command ID)
	switch (Command)
	{

		// CASE (query for processor DMA support)
		case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):
			// no, we do support it at this level (it is delegated down to PPI driver
			*((u32 *)Value) = FALSE;
		break;


	    // CASE (Set PPI Device Number that will be used and open the PPI device)
#if defined ADI_NEC_NL6448BC33_54
    	case (ADI_NL6448BC3354_CMD_OPEN_PPI):
#else
    	case (ADI_LQ10D368_CMD_OPEN_PPI):
#endif

// Check PPI device number
#if defined(__ADSP_TETON__)     // two PPI ports available in BF561
        	if (u32Value > 1)
#if defined ADI_NEC_NL6448BC33_54
		return ( ADI_NL6448BC3354_RESULT_BAD_PPI_DEVICE);
#else
		return ( ADI_LQ10D368_RESULT_BAD_PPI_DEVICE);
#endif
#elif defined(__ADSP_BRAEMAR__) || defined (__ADSP_EDINBURGH__)     // Only one PPI port available in BF533 & BF537
            if (u32Value > 0)
#if defined ADI_NEC_NL6448BC33_54
		return ( ADI_NL6448BC3354_RESULT_BAD_PPI_DEVICE);
#else
		return ( ADI_LQ10D368_RESULT_BAD_PPI_DEVICE);
#endif
#endif
        	// Update the PPI device number
        	pLCD->PPINumber = u32Value;

        	// open PPI device if it is not opened.
    		if (pLCD->ppiHandle) return ADI_DEV_RESULT_SUCCESS;
    		else {
    		 Result = PPI_Open(PDDHandle);
    		}


		break;


		// CASE (query for LCD buffer padding)
#if defined ADI_NEC_NL6448BC33_54
		case (ADI_NL6448BC3354_CMD_GET_TOP_PADDING):
		*((u32 *)Value) = 33;
#else
		case (ADI_LQ10D368_CMD_GET_TOP_PADDING):
		*((u32 *)Value) = 34;
#endif
		break;


		// DEFAULT
		default:
			// pass anything we don't specifically handle to the PPI driver
			return adi_dev_Control(pLCD->ppiHandle,Command,Value);

	// ENDCASE
	}

	return(Result);
}
예제 #18
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);
}
예제 #19
0
/*********************************************************************

  Function:    DevicePollMedia

  Description: Detect media change, this is used in particular to detect
               when a USB memory stick is removed.or inserted.

*********************************************************************/
u32 DevicePollMedia(ADI_USB_DEF *pDevice)
{

    u32 Result = ADI_DEV_RESULT_FAILED;
    u32 DeviceEnumerated = FALSE;
    u32 FSSValue = 0;   /* initiate the value to be sent to FSS as 0 (USB Device number in use) */

    if( pDevice->MediaPresent == FALSE )
    {
        /* The following callback to the FSS will result in any previously mounted file system
         * being unmounted; if first time the call is benign. This has to be done at thread level
         * as it may involve memory allocation tasks.
        */
        if (FSSDirectCallbackFunction) {
            (FSSDirectCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_REMOVED, &FSSValue );
        } else {
            (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_REMOVED, &FSSValue );
        }

        adi_dev_Control( pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_IS_DEVICE_ENUMERATED, &DeviceEnumerated );
        if ( DeviceEnumerated )
        {
            /* Perform additional communications with device to establish
             * the connection and inform the FSS of media insertion.
            */
            ConfigureUsbDevice(pDevice);

            /* Use Result to pass the device number */
            Result = 0;
            /* call back to FSS to inform it of media insertion. The FSS will unmount any previous mount, and will
             * instruct this PID to detect volumes by reading the MBR. On successful return to FSS the Result value
             * will be set accordingly. If successful the MediaPresent flag is set to true.
            */
            if (FSSDirectCallbackFunction)
            {
                (FSSDirectCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_INSERTED, &Result );
            }
            else
            {
                (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_INSERTED, &Result );
            }
            if ( Result==ADI_FSS_RESULT_SUCCESS )
            {
                pDevice->MediaPresent = TRUE;
            } else
            {
                pDevice->MediaPresent = FALSE;
            }
            Result = ADI_DEV_RESULT_SUCCESS;
        }
        else
        {
            Result=ADI_DEV_RESULT_FAILED;
        }
    }

    /* otherwise if media was already present then this call successfully resulted
     * in nothing to do
    */
    else if (pDevice->MediaPresent)
    {
        Result = ADI_DEV_RESULT_SUCCESS;
    }

    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;
}
예제 #21
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);
}
예제 #22
0
    AdiDeviceResult AdiDevice::RunCommand(AdiDeviceCommandsTable &commands) 
    {
    	ESS_ASSERT(commands.IsCorrect());

        return adi_dev_Control(m_deviceHandle, ADI_DEV_CMD_TABLE, commands.Table());
    }
예제 #23
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);
}
예제 #24
0
static u32 adi_pdd_Control(							// Sets	or senses a	device specific	parameter
	ADI_DEV_PDD_HANDLE		PDDHandle,				// PDD handle
	u32						Command,				// command ID
	void					*Value					// command specific	value
) {

	ADI_ADAV801	   *pADAV801; // pointer to	the	device we're working on
	u32				Result;	  // return	value
	u32				u32Value;  // u32 type to avoid	casts/warnings etc.
	u8				u8Value;	// u8 type to avoid	casts/warnings etc.	 
	
	// avoid casts
	pADAV801 = (ADI_ADAV801	*)PDDHandle; //	Pointer	to ADAV801 device driver instance
	// assign 8, 16	and	32 bit values for the Value	argument
	u32Value = (u32) Value;
	u8Value	 = (u8)	u32Value;

    // Location to hold SPI dummy read
    ADI_DEV_ACCESS_REGISTER		DummyRead; 	
	// Structure passed	to device access service
	ADI_DEVICE_ACCESS_REGISTERS		access_device;
	// Structure passed	to select Device type and access type
	ADI_DEVICE_ACCESS_SELECT	SelectSPIAccess[] =	{
		pADAV801->adav801_spi_cs,			// SPI Chip-select
		ADI_DEVICE_ACCESS_LENGTH0,			// No Global address for ADAV801
		ADI_DEVICE_ACCESS_LENGTH1,			// ADAV801 register	address	length (1 byte)
		ADI_DEVICE_ACCESS_LENGTH1,			// ADAV801 register	data length	(1 byte)
		ADI_DEVICE_ACCESS_TYPE_SPI,			// Select SPI access
	};
  
	// check for errors	if required
#ifdef ADI_DEV_DEBUG
	if ((Result	= ValidatePDDHandle(PDDHandle))	!= ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
	
	// assume we're	going to be	successful
	Result = ADI_DEV_RESULT_SUCCESS;

	switch (Command)	
	{

		// CASE	(control dataflow)
		case (ADI_DEV_CMD_SET_DATAFLOW):
		
     		// check if the SPORT device is already open
     		if (pADAV801->sportHandle != NULL)
     		{
     			// if so, Enable/Disable the SPORT device used by ADAV810
     			Result = adi_dev_Control( pADAV801->sportHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)u8Value );
			}
			// else check if the client is trying to enable dataflow without opening the SPORT
			else if (u8Value == TRUE)
			{
				// can not pass this value to SPORT as no valid SPORT handle is available
				// which also means the client hasn't defined the dataflow method yet, return error.
 				return (ADI_DEV_RESULT_DATAFLOW_UNDEFINED);
 			}
 			
         	pADAV801->DataflowStatus = u8Value;	// Save the dataflow status
         		
		break;

		// CASE	(query for processor DMA support)
		case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):
  
			// ADAV801 doesn't support DMA,	but	supports indirectly	thru SPORT operation
			*((u32 *)Value)	= FALSE;
   
			break;

		// CASE	(Set Dataflow method - applies only	for	SPORT)
		case (ADI_DEV_CMD_SET_DATAFLOW_METHOD):

			// Check if sport device to used by ADAV801 is already open
			if (pADAV801->sportHandle == NULL)
				// if not, try to open the SPORT device corresponding to sportDeviceNumber for ADAV801 dataflow
				Result = SPORT_Open(PDDHandle);

// on occurance	of error, return the error code
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

			// Pass	the	dataflow method	to the SPORT device allocated to ADAV801
			Result = adi_dev_Control( pADAV801->sportHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void*)u32Value );
			
		break;

		// CASE	(Read a	specific register from the ADAV801)
		case(ADI_DEV_CMD_REGISTER_READ):
		// CASE	(Configure a specific register in the ADAV801)
		case(ADI_DEV_CMD_REGISTER_WRITE):
		// CASE	(Read a	specific field from	a single device	register)
		case(ADI_DEV_CMD_REGISTER_FIELD_READ):
		// CASE	(Write to a	specific field in a	single device register)
		case(ADI_DEV_CMD_REGISTER_FIELD_WRITE):			
		// CASE	(Read block	of ADAV801 registers starting from first given address)
		case(ADI_DEV_CMD_REGISTER_BLOCK_READ):	
		// CASE	(Write to a	block of ADAV801 registers starting	from first given address)
		case(ADI_DEV_CMD_REGISTER_BLOCK_WRITE):		
		// CASE	(Read a	table of selective registers in	ADAV801)
		case(ADI_DEV_CMD_REGISTER_TABLE_READ):
		// CASE	(Write to a	table of selective registers in	ADAV801)
		case(ADI_DEV_CMD_REGISTER_TABLE_WRITE):		
		// CASE	(Read a	table of selective register(s) field(s)	in ADAV801)
		case(ADI_DEV_CMD_REGISTER_FIELD_TABLE_READ):
		// CASE	(Write to a	table of selective register(s) field(s)	in ADAV801)
		case(ADI_DEV_CMD_REGISTER_FIELD_TABLE_WRITE):	  

			access_device.ManagerHandle		= pADAV801->ManagerHandle;		// device manager handle
			access_device.ClientHandle		= NULL;							// client handle - passed to the internal 'Device' specific	function
			access_device.DeviceNumber		= 0;							// SPI device number
			access_device.DeviceAddress		= 0x00;							// SPI address of ADAV801 Device (Don't	care as	no specific	SPI	address	for	ADAV801)
			access_device.DCBHandle			= pADAV801->DCBHandle;			// handle to the callback manager
			access_device.DeviceFunction	= NULL;							// Function	specific to	ADAV801	driver passed to the 'Device' access service
			access_device.Command			= Command;						// command ID
			access_device.Value				= Value;						// command specific	value
			access_device.FinalRegAddr		= ADAV801_FINAL_REG_ADDRESS;	// Address of the last register	in ADAV801		
			access_device.RegisterField		= RegisterField;				// table for ADAV801 Register Field	Error check	and	Register field access
			access_device.ReservedValues	= ReservedValues;				// table to	configure reserved bits	in ADAV801 to recommended values
			access_device.ValidateRegister	= ValidateRegister;				// table containing	reserved and read-only registers in	ADAV801
			access_device.ConfigTable		= NULL;							// SPI configuration table
			access_device.SelectAccess		= SelectSPIAccess;				// Device Access type
			access_device.pAdditionalinfo	= (void	*)NULL;					// No Additional info

			/* Workaround for Blackfin Audio Extender rev 1.2 hardware anamoly
			Access to first register in a given register access table */
			DummyRead.Address 				= ADAV801_SRC_CLK_CTRL;			// ADAV801 register to be read
     		access_device.Command   		= ADI_DEV_CMD_REGISTER_READ;  	// Read a single register
     		access_device.Value    			= &DummyRead;       			// Location to hold the dummy read value

			Result = adi_device_access (&access_device);
			     		     					
     		access_device.Command   		= Command;                  	// command ID
     		access_device.Value    			= Value;                    	// command specific value						
			
			Result = adi_device_access (&access_device);
			
			break;

/************************
SPI	related	commands
************************/
				
		// CASE	(Set ADAV801 SPI Chipselect)
		case ADI_ADAV801_CMD_SET_SPI_CS:
  
			pADAV801->adav801_spi_cs = u8Value;
		 
			break;
   
		// CASE	(Get ADAV801 SPI Chipselect	value)
		case ADI_ADAV801_CMD_GET_SPI_CS:
   
			*((u8 *)Value) = pADAV801->adav801_spi_cs;

			break;

/************************
SPORT related commands
************************/

		// CASE	(Set SPORT Device Number that will be used for audio dataflow between Blackfin and ADAV801)
		case (ADI_ADAV801_CMD_SET_SPORT_DEVICE_NUMBER):
	   
			// Close the present SPORT device being	used
			Result = SPORT_Close(PDDHandle);
			
			// Update the SPORT	device number
			pADAV801->sportDeviceNumber	= u8Value;

			// Application program should open the new SPORT device, set its data flow method,
			// load	the	buffer(s) for the new SPORT	device & enable	the	dataflow
	
			break;

		// CASE	(Set SPORT word	length)
		// if ADAV801 is configured	for	right-justified	data, SPORT	wordlength should be configured	to it as well.
		// default value of	24 bits	can be	used when operated in other	modes  
		case ADI_ADAV801_CMD_SET_SPORT_TX_WLEN:
		case ADI_ADAV801_CMD_SET_SPORT_RX_WLEN:

			// Check if	the	Word length	is legal
			if ((u8Value < 2) || (u8Value >	31))
				return(ADI_ADAV801_RESULT_SPORT_WLEN_ILLEGAL);
				  
			// if dataflow is on, switch dataflow off before updating SPORT	word length
			if ((pADAV801->DataflowStatus == TRUE) && (pADAV801->sportHandle != NULL))
				Result	= adi_dev_Control( pADAV801->sportHandle, ADI_DEV_CMD_SET_DATAFLOW,	(void*)FALSE );
			
// on occurance	of error, return the error code
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

			if (Command	== ADI_ADAV801_CMD_SET_SPORT_TX_WLEN)
			{
				pADAV801->sport_txlen = u8Value;	   // load the new tx word length
				// Check if	any	SPORT device is	already	open
				// if so, configure	SPORT TX Word Length
				if (pADAV801->sportHandle != NULL)
					Result = adi_dev_Control( pADAV801->sportHandle, ADI_SPORT_CMD_SET_TX_WORD_LENGTH, (void*)u8Value );
			}
			else
			{
				pADAV801->sport_rxlen =	u8Value;	// load	the	new	rx word	length
				// Check if	any	SPORT device is	already	open
				// if so, configure	SPORT TX Word Length
				if (pADAV801->sportHandle != NULL)
					Result = adi_dev_Control( pADAV801->sportHandle, ADI_SPORT_CMD_SET_RX_WORD_LENGTH, (void*)u8Value );
			}

// on occurance	of error, return the error code
#ifdef ADI_DEV_DEBUG
	if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

			// if dataflow was previously on, switch the dataflow on again
			if ((pADAV801->DataflowStatus == TRUE) && (pADAV801->sportHandle != NULL))
				Result = adi_dev_Control( pADAV801->sportHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE );  
   
			break;

		// CASE	(OPEN/CLOSE	SPORT Device to	be used	for	audio dataflow between Blackfin	and	ADAV801)
		case (ADI_ADAV801_CMD_SET_SPORT_STATUS):
		
			// check the SPORT mode
			if ((ADI_ADAV801_SET_SPORT_STATUS) Value == ADI_ADAV801_SPORT_OPEN)
			{
				// check if the SPORT device is already open
				if (pADAV801->sportHandle == NULL)
					// if not, OPEN	Sport Device, else do nothing
					Result = SPORT_Open(PDDHandle);
			}			
			else	// this should be to close the SPORT device
				// Close any SPORT device presently being used by ADAV801
				Result = SPORT_Close(PDDHandle);
			
			break;
		   
		default:
   
			if (pADAV801->sportHandle) // if SPORT device is already opened
				// pass	the	unknown	command	to SPORT
				Result = adi_dev_Control( pADAV801->sportHandle, Command, Value	);
			else
				// return error	indicating as command not valid
				Result = ADI_ADAV801_RESULT_CMD_NOT_SUPPORTED;
   
			break;
	}
 
	return(Result);
}
예제 #25
0
 AdiDeviceResult AdiDevice::SynchronousOn()
 {
     return adi_dev_Control(m_deviceHandle, ADI_DEV_CMD_SET_SYNCHRONOUS, (void *)TRUE);
 }
예제 #26
0
int system_init(ADI_DEV_DEVICE_HANDLE lan_handle, net_config_info *pCfg)  // return -1 if fail
{
	unsigned int result;
	// char *ether_stack_block;
	// u16 phyregs[32];

	/* set the services with in stack */

	set_pli_services(1,&lan_handle);

    UpdateMacAddr();

	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);
	if (result != ADI_DEV_RESULT_SUCCESS) return -1;


	/* 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);
    if (result != ADI_DEV_RESULT_SUCCESS) return -1;
	
	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);
	if (result != ADI_DEV_RESULT_SUCCESS) return -1;

	/* 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);
	// if (ether_stack_block == 0) return -1;

	// init_stack ( 3, p_period, sizeof(GEthernetStack), GEthernetStack);

    int res = InitStackEx(3, p_period, sizeof(GEthernetStack), GEthernetStack, pCfg);

	return 1;
}
예제 #27
0
/*********************************************************************

    Function: adi_pdd_Control

        Senses or Configures AD1980 device registers

    Parameters:
        hPhysicalDevice - Physical Device Handle of the device to work on
        nCommand        - Command ID
        Value           - Command specific value

    Returns:
        ADI_DEV_RESULT_SUCCESS
            - Successfully processed the given command
        DD/SS or AD1980 specific error code

*********************************************************************/
static u32 adi_pdd_Control(
    ADI_DEV_PDD_HANDLE      hPhysicalDevice,
    u32                     nCommand,
    void                    *Value
)
{
    /* u8 type to avoid casts/warnings etc.    */
    u8                                  u8Value;
    /* u32 type to avoid casts/warnings etc.    */
    u32                                 u32Value;
    /* Return value - assume we're going to be successful   */
    u32                                 nResult = ADI_DEV_RESULT_SUCCESS;
    /* pointer to the device we will be working on */
    ADI_AD1980_DEF                      *poDevice;
    /* Pointer to AD1980 Driver init instance */
    ADI_AD1980_INIT_DRIVER              *pInit;
    /* Pointer to the audio data port we're working on */
    ADI_AD1980_DRIVER_DATA_PORT_INFO    *poDataPort = (ADI_AD1980_DRIVER_DATA_PORT_INFO *)hPhysicalDevice;

    /* assign 8 & 32 bit values for the Value argument */
    u32Value = (u32)Value;
    u8Value = (u8)u32Value;

/* for Debug build only - check for errors if required  */
#if defined(ADI_DEV_DEBUG)
    /* Validate the given PDDHandle */
    nResult = ValidatePDDHandle(hPhysicalDevice);

    /* Continue only if the given PDDHandle is valid */
    if (nResult == ADI_DEV_RESULT_SUCCESS)
    {
#endif

        /* Get the address of device instance to work on */
        poDevice = &gaoAD1980Device[poDataPort->nAudioDevNumber];

        /* CASEOF (Command ID)  */
        switch (nCommand)
        {
            /* CASE: Control dataflow */
            case (ADI_DEV_CMD_SET_DATAFLOW):
            /* CASE: Set Dataflow method */
            case (ADI_DEV_CMD_SET_DATAFLOW_METHOD):
                /* IF (AC'97 instance is invalid) */
                if (poDevice->pAC97 == NULL)
                {
                    /* return error (AC'97 instance is invalid) */
                    nResult = ADI_AD1980_RESULT_AC97_INSTANCE_INVALID;
                }
                /* ELSE (AC'97 instance is valid) */
                else
                {
                    /* IF (Data port opened for inbound dataflow) */
                    if (poDataPort->eDirection == ADI_DEV_DIRECTION_INBOUND)
                    {
                        /* IF (Command is to update dataflow status) */
                        if (nCommand == ADI_DEV_CMD_SET_DATAFLOW)
                        {
                            /* Change command to AC'97 specific command to
                               update Rx dataflow for this device */
                            nCommand = ADI_AC97_CMD_SET_RECEIVE_DATAFLOW;
                        }
                        /* ELSE (Command must be to set dataflow method) */
                        else
                        {
                            /* Change command to AC'97 specific command to
                               update Rx dataflow method for this device */
                            nCommand = ADI_AC97_CMD_SET_RECEIVE_DATAFLOW_METHOD;
                        }
                    }
                    /* ELSE IF (Data port opened for outbound dataflow) */
                    else if (poDataPort->eDirection == ADI_DEV_DIRECTION_OUTBOUND)
                    {
                        /* IF (Command is to update dataflow status) */
                        if (nCommand == ADI_DEV_CMD_SET_DATAFLOW)
                        {
                            /* Change command to AC'97 specific command to
                               update Tx dataflow for this device */
                            nCommand = ADI_AC97_CMD_SET_TRANSMIT_DATAFLOW;
                        }
                        /* ELSE (Command must be to set dataflow method) */
                        else
                        {
                            /* Change command to AC'97 specific command to
                               update Tx dataflow method for this device */
                            nCommand = ADI_AC97_CMD_SET_TRANSMIT_DATAFLOW_METHOD;
                        }
                    }
                    /* ELSE (Device is opened for bi-directional dataflow) */
                        /* Pass the command to AC'97 library with out any change */

                    /* Pass command to AC'97 library) */
                    nResult = adi_ac97_Control(poDevice->pAC97,
                                               nCommand,
                                               Value);

                }
                break;

            /* CASE (Initialise AD1980 driver) */
            case (ADI_AD1980_CMD_INIT_DRIVER):

                /* Address of AD1980 driver init structure */
                pInit = (ADI_AD1980_INIT_DRIVER *) Value;

                /* Initialise AC'97 Driver instance */
                nResult = adi_ac97_Init_Instance (Value);

                /* IF (Successfully initialised AC'97 driver instance) */
                if (nResult == ADI_DEV_RESULT_SUCCESS)
                {
                    /* IF (AC'97 Instance was already initialised) */
                    if (poDevice->pAC97 != NULL)
                    {
                        /* Close the SPORT device that is open */
                        nResult = adi_dev_Close(poDevice->hSport);
                    }
                }

                /* IF (Successfully closed the SPORT device opened previously) */
                if (nResult == ADI_DEV_RESULT_SUCCESS)
                {
                    /* save AC'97 driver instance handle */
                    poDevice->pAC97                     = pInit->pAC97;
                    /* AD1980 driver Callback function supplied to the AC'97 driver instance */
                    poDevice->pAC97->CodecCallback      = adi_ad1980_AC97Callback;
                    /* pointer to critical region */
                    poDevice->pAC97->pEnterCriticalArg  = poDevice->pEnterCriticalArg;
                    /* Save the SPORT Device Number */
                    poDevice->nSportDevNumber           = pInit->SportDevNumber;
                    /* Save the Reset Flag ID */
                    poDevice->eResetFlag                = pInit->ResetFlagId;

                    /* Open and Configure SPORT Device connected to AD1980 */
                    nResult = adi_ad1980_SportConfig (poDevice);
                }
                break;

            /* CASE (Update SPORT DMA Bus Width) */
            case (ADI_AC97_CMD_UPDATE_SPORT_DMA_BUS_WIDTH):

                /* IF (The DMA bus width is valid) */
                if ((u32)Value != 0)
                {
                    /* IF (we already have a SPORT device open) */
                    if (poDevice->hSport != NULL)
                    {
                        /* Close the SPORT device that is open */
                        nResult = adi_dev_Close(poDevice->hSport);

                        /* IF (Successfully closed SPORT device) */
                        if (nResult == ADI_DEV_RESULT_SUCCESS)
                        {
                            poDevice->hSport = NULL;
                            /* Update AC'97 instance with new DMA bus width */
                            nResult = adi_ac97_Control(poDevice->pAC97, nCommand, Value);
                        }

                        /* IF (Successfully updated AC'97 instance) */
                        if (nResult == ADI_DEV_RESULT_SUCCESS)
                        {
                            /* Open and Configure SPORT Device connected to AD1980 */
                            nResult = adi_ad1980_SportConfig (poDevice);
                        }
                    }
                    /* ELSE (AC'97 instance is yet to be initialised) */
                    else
                    {
                        /* Save the SPORT DMA bus width */
                        poDevice->nSportDmaBusWidth = (u32)Value;
                    }
                }
                break;

            /* CASE: Set Deferred Callback or Live callback to process AC'97 frames */
            case (ADI_AD1980_CMD_USE_DCB_TO_PROCESS_FRAMES):
                poDevice->hDcbManager = (ADI_DCB_HANDLE)Value;
                break;

            /* CASE: query for processor DMA support */
            case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):

                /* AD1980 doesn't support DMA, but supports indirectly via SPORT */
                *((u32 *)Value) = false;
                break;

            /* other commands - requires a valid AC'97 instance */
            default:
                /* IF (AC'97 instance is invalid) */
                if (poDevice->pAC97 == NULL)
                {
                    /* return error (AC'97 instance is invalid) */
                    nResult = ADI_AD1980_RESULT_AC97_INSTANCE_INVALID;
                }
                /* ELSE (AC'97 instance is valid) */
                else
                {
                    /* Pass this to register access control function
                       assuming this to be a register access command
                       from the upper level layer calling this driver */
                    nResult = adi_ad1980_RegisterAccess(poDevice, nCommand, Value, false);

                    /* IF (Command not supported by register access function) */
                    if (nResult == ADI_AD1980_RESULT_CMD_NOT_SUPPORTED)
                    {
                        /* try passing this command to AC'97 driver */
                        nResult = adi_ac97_Control(poDevice->pAC97, nCommand, Value);
                    }

                    /* IF (Command not supported by AC'97 driver) */
                    if (nResult == ADI_AC97_RESULT_CMD_NOT_SUPPORTED)
                    {
                        /* IF (SPORT driver is already open) */
                        if (poDevice->hSport != NULL)
                        {
                            /* try passing this command to SPORT */
                            nResult = adi_dev_Control(poDevice->hSport, nCommand, Value);
                        }

                    } /* End of if (Command not supported by AC'97 driver) */

                } /* End of if (AC'97 instance is invalid) */
                break;

        } /* End of switch (Command ID) cases */

/* for Debug build only */
#if defined(ADI_DEV_DEBUG)
    }
#endif

    /* return */
    return(nResult);
}
예제 #28
0
static void ConfigureUsbDevice(ADI_USB_DEF *pDevice)
{
    /* Before we can use the USB mass storage media we need to send the following commands */

    /* Allocate memory so we can Read the MBR */
#if defined(_BF527_SDRAM_ISSUE_WORKAROUND)
    u8 *pMBR = &TempBufferData[0];
#else
    u8 *pMBR = (u8*)_adi_fss_malloc( pDevice->CacheHeapID, 512 );
#endif
    /* Send 'Inquiry' command tro Class Driver */
    pDevice->ClassCommandComplete = FALSE;
    pDevice->SCSICommandError = FALSE;
    adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_INQUIRY, 0);
    /* and wait for completion */
    WaitOnCommandCompletion(pDevice);

    /* Check if SCSI commad failed */
    CheckForSCSICommandFailed(pDevice);

    /* Send 'read format' command to Class Driver */
    pDevice->ClassCommandComplete = FALSE;
    pDevice->SCSICommandError = FALSE;
    adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_READ_FORMAT_CAPACITIES, 0);
    /* and wait for completion */
    WaitOnCommandCompletion(pDevice);

    /* Check if SCSI commad failed */
    CheckForSCSICommandFailed(pDevice);

    /* Send 'read capacity' command to Class Driver */
    pDevice->ClassCommandComplete = FALSE;
    pDevice->SCSICommandError = FALSE;
    adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_READ_CAPACITY, 0);
    /* and wait for completion */
    WaitOnCommandCompletion(pDevice);

    /* Check if SCSI commad failed */
    CheckForSCSICommandFailed(pDevice);

    adi_fss_TransferSectors(
                            pDevice->DeviceHandle, 
                            (u16*)pMBR,
                            0,
                            0,
                            1,
                            512,
                            sizeof(u8),
                            READ,
                            pDevice->DataSemaphoreHandle
    );
    
    /* Send 'test unit ready' command to Class Driver */
    pDevice->ClassCommandComplete = FALSE;
    pDevice->SCSICommandError = FALSE;
    adi_dev_Control(pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_TEST_UNIT_READY, 0);
    /* and wait for completion */
    WaitOnCommandCompletion(pDevice);

    /* Check if SCSI commad failed */
    CheckForSCSICommandFailed(pDevice);

#if !defined(_BF527_SDRAM_ISSUE_WORKAROUND)
    /* Remove the allocated memory */
    _adi_fss_free( pDevice->CacheHeapID, pMBR );
#endif
}
예제 #29
0
static u32 adi_pdd_Control(		// Sets or senses a device specific parameter
	ADI_DEV_PDD_HANDLE 	PDDHandle,	// PDD handle
	u32 				Command,	// command ID
	void 				*Value		// command specific value
) {
	
	ADI_AD7477A 				*pAD7477A;		// pointer to the device we're working on
	u32 						tmp;			// temporary storage
	u32 						Result;			// return value
	u32							u32Value;		// u32 type to avoid casts/warnings etc.
	u16							u16Value;		// u16 type to avoid casts/warnings etc.
	
	// avoid casts
	pAD7477A = (ADI_AD7477A *)PDDHandle; // Pointer to AD7477A device driver instance
    // assign 16 and 32 bit values for the Value argument
	u32Value = (u32)Value;
    u16Value = ((u16)((u32)Value));
	
	// check for errors if required
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// assume we're going to be successful
	Result = ADI_DEV_RESULT_SUCCESS;	

	// CASEOF (Command ID)
	switch (Command) 
	{
		// CASE (query for processor DMA support)
		case (ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT):
			// no, we do support it at this level (it is delegated down to SPI driver
			*((u32 *)Value) = FALSE;
			break;

		// CASE (Set the sample rate of the AD7477A device)
		case (ADI_AD7477A_CMD_SET_SAMPLE_RATE):
			{
				// note that for this option the user passes in the address containing
				// the requested sampling rate value, which is replaced by the achievable
				// value - due to the granularity of the SPI_BAUD register.
				u32 fsample = *(u32*)Value;
				
				// Obtain the System Clock freqency, fsclk, from  the
				// power management module of the System Services library. This is returned
				// as a MHz value. If the Power management module is not initialized, the 
				// reset value is used.
				u32 fcclk,fsclk,fvco;
				if (adi_pwr_GetFreq(&fcclk,&fsclk,&fvco)!=ADI_PWR_RESULT_SUCCESS)
					fsclk = 50000000;
				
				// Calculate the BAUD rate.
				// The calculation is split into two parts to enable integer arithmetic to be
				// used. NB. fsclk ~ O(1E8), pAD7477A->tquiet_factor # O(1000), so that x will 
				// be at least 0(1E4).
				u32 y = 32*pAD7477A->tquiet_factor;
				u32 x = fsclk/y;
				// remainder (is significant for calculation of achievable sample rate)
				u32 yy = fsclk - x*y;
				// We can only take the higher Baud value (i.e. if the floating point 
				// value is 3.5 then we must use 4 as using 3 would result in a higher 
				// sampling rate than requested).
				u32 spi_baud = (x*1000/fsample) + 1;
				
				// and configure the SPI_BAUD register in the SPI device driver
				Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_SET_BAUD_REG, (void*)spi_baud);

				// Now calculate the revised value which is returned to the user to facilitate the
				// the interpretation of the sampled data. 
				// For example, it is the value to be used in the Sample 
				// Rate box of the Data Processing tab of the Plot Settings dialog to enable
				// the '2D FFT magnitude' Data Process to correctly identify the frequency
				// content in the sampled data.
				fsample = x*1000/spi_baud;
				fsample += (yy*1000/(y*spi_baud)); 
				*(u32*)Value = fsample;

			}
			break;

		// CASE (Set mode of operation)
		case (ADI_AD7477A_CMD_SET_OPERATION_MODE):
			
			// IF (powering down the device)
			//if (u32Value==ADI_AD7477A_MODE_POWERDOWN && pAD7477A->CurMode==ADI_AD7477A_MODE_NORMAL)
			if (u32Value == ADI_AD7477A_MODE_POWERDOWN) {
				
				// pause SPI dataflow
				if (Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_PAUSE_DATAFLOW, (void*)TRUE)) break;
				
				// execute a dummy 8 bit read to force the part into powerdown
				if (Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_EXECUTE_DUMMY_READ, (void*)8)) break;
				
			// ELSE 
			//} else if (u32Value==ADI_AD7477A_MODE_NORMAL && pAD7477A->CurMode==ADI_AD7477A_MODE_POWERDOWN)  {
			} else {
				
				// execute a dummy 16 bit read to force the part to power up
				if (Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_EXECUTE_DUMMY_READ, (void*)16)) break;
				
				// resume SPI dataflow
				if (Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_PAUSE_DATAFLOW, (void*)FALSE)) break;
				
			// ENDIF
			}
			break;

		// CASE (declares the slave select line we're connected to)
		case (ADI_AD7477A_CMD_DECLARE_SLAVE_SELECT):

			// tell the SPI driver to enable our slave select line		
			// note that because we use DMA and therefore CPHA = 0, the hardware
			// automatically drives the slave select line so we don't have to set the 
			// FLGx bits of the SPI flag register, only enable the proper slave select
			Result = adi_dev_Control(pAD7477A->spiHandle, ADI_SPI_CMD_ENABLE_SLAVE_SELECT, Value);
			break;
		
		// CASE (replace the default quiet period factor)
		case (ADI_AD7477A_CMD_SET_QUIET_PERIOD_FACTOR):

			// Should the build-in quiet period factor not be sufficient, the user
			// can change it. The requested value should conform to the form
			// (1+e)*1000,  where e = (tsample - tconvert)/tconvert, ie. the proportion 
			// of time after the conversion is complete and the next falling edge of 
			// /cs line. 
			// An integer value is used to avoid pulling in floating point library. This 
			// limits the value of e to 3 decimal places, eg: 0.062 in the default case
			pAD7477A->tquiet_factor = u32Value;

		// DEFAULT 
		default:
		
			// pass anything we don't specifically handle to the SPI driver
			Result = adi_dev_Control(pAD7477A->spiHandle,Command,Value);
			break;
		
	// ENDCASE
	}
		
	// return
	return(Result);
}
예제 #30
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;
}