Ejemplo n.º 1
0
 AdiDeviceResult AdiDevice::Write(ADI_DEV_BUFFER_TYPE bufferType, 
     ADI_DEV_BUFFER *pBuffer)
 {
     ESS_ASSERT(IsOpened());
     
     return adi_dev_Write(m_deviceHandle, bufferType, pBuffer);
 }
Ejemplo n.º 2
0
void UARTwrite(u8* data, u32 len)
{
    while (len>0)
    {
		while (UARTsending());
		sending_done = 0;
		
		OutboundBuffer.ElementCount = min(OUTBUFLEN,len);
		memcpy( OutboundData, data, OutboundBuffer.ElementCount );
		len -= OutboundBuffer.ElementCount;
		data+= OutboundBuffer.ElementCount;
		OutboundBuffer.ProcessedFlag = 0;
		
		// requeue the outbound buffer
		ezErrorCheck(adi_dev_Write(DriverHandle, ADI_DEV_1D, (ADI_DEV_BUFFER *)&OutboundBuffer));
    }
	while (UARTsending());
}
Ejemplo n.º 3
0
static u32 adi_pdd_Write(							// Writes data or queues an	outbound buffer	to a device
	ADI_DEV_PDD_HANDLE		PDDHandle,				// PDD handle
	ADI_DEV_BUFFER_TYPE		BufferType,				// buffer type
	ADI_DEV_BUFFER			*pBuffer				// pointer to buffer
) {

	//	Pointer	to ADAV801 device driver instance	
	ADI_ADAV801	 *pADAV801 = (ADI_ADAV801 *)PDDHandle;
	
#ifdef ADI_DEV_DEBUG
	// check for errors	if required
	u32	Result = ADI_DEV_RESULT_SUCCESS;
	if ((Result	= ValidatePDDHandle(PDDHandle))	!= ADI_DEV_RESULT_SUCCESS) return (Result);
#endif

	// pass	write operation	to SPORT
	return(adi_dev_Write(pADAV801->sportHandle,BufferType,pBuffer));
 
}
Ejemplo n.º 4
0
static u32 adi_pdd_Write(		// Writes data or queues an outbound buffer to a device
	ADI_DEV_PDD_HANDLE 	PDDHandle,	// PDD handle
	ADI_DEV_BUFFER_TYPE	BufferType,	// buffer type
	ADI_DEV_BUFFER 		*pBuffer	// pointer to buffer
){

// check for errors if required
	u32 Result = ADI_DEV_RESULT_SUCCESS;
#if defined(ADI_DEV_DEBUG)
	if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
	// Simply pass the request on
	ADI_LCD *pLCD = (ADI_LCD *)PDDHandle;
	Result = adi_dev_Write(pLCD->ppiHandle,BufferType,pBuffer);

	return(Result);


}
Ejemplo n.º 5
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.º 6
0
/*##########################################################################
* 
* Output pbuf chain to hardware. It is assumed that there is a complete and
* correct ethernet frame in p. The only buffering in this system is in the
* list of tx ADI_ETHER_BUFFER's. If there is no room in it, then drop the frame.
*
*#########################################################################*/
static err_t
low_level_output(struct netif* netif, struct pbuf* p)
{
  struct nifce_info* nip = (struct nifce_info*)netif->state;
  ADI_ETHER_BUFFER* tx;
  struct pbuf *q;
  char* data;
  unsigned short *ps;
  struct hw_eth_hdr* ethhdr;
  u32_t old_level;
  int len;

  if (p->tot_len > nip->tx_buff_datalen)
  {
    // frame too big for our buffers
#ifdef LINK_STATS
    lwip_stats.link.memerr++;
#endif
    return ERR_MEM;
  }

  // No need of data maipulation as we are directly getting from pbufs.
  if (Trace_Function) Trace_Function('T',p->tot_len,((unsigned char *)p->payload)+2);

  // see whether we've got a free transmit buffer
  old_level = sys_arch_protect();

  tx = (ADI_ETHER_BUFFER*)nip->x;
  if (tx == NULL)
  {
#ifdef LINK_STATS
    lwip_stats.link.memerr++;
#endif

    sys_arch_unprotect(old_level);
    return ERR_MEM;
  }

  // remove first free one from the list
  nip->x = tx->pNext;
  tx->pNext = NULL;
  sys_arch_unprotect(old_level);

  // copy data from pbuf(s) into our buffer
  q = p;
  //data = (char*)tx->Data;
  
  //
  // first two bytes reserved for length
  data = (char*)tx->Data+2;

  // ... first pbuf: skip field unused1 in struct eth_hdr
  memcpy(data, ((u8_t*)q->payload) + 2, q->len - 2);
  data += (q->len - 2);
  len = q->len - 2;
  q = q->next;
  // copy any subsequent pbufs
  while (q) {
    memcpy(data, q->payload, q->len);
    data += q->len;
    len += q->len;
    q = q->next;
  }
  LWIP_ASSERT("low_level_output: data length correct", len == (p->tot_len - 2));
  //tx->ElementCount = p->tot_len - 2;
  tx->ElementCount = p->tot_len; // total element count including 2 byte header

 

  // see whether we need to shuffle etharp frame up to account for
  // the alignment fields unused2 and unused3
  //ethhdr  = (struct hw_eth_hdr*)tx->Data;
  //
  ethhdr  = (struct hw_eth_hdr*)((char*)tx->Data+2);//skip the header
  if (htons(ethhdr->type) == ETHTYPE_ARP)
  {
    u8_t* pdst = (u8_t*)tx->Data + 28 +2;
    u8_t* psrc = pdst + 2;  // skip unused2 field

    memmove(pdst, psrc, 10);
    pdst += 10;
    psrc += 12;             // skip unused3 field
    memmove(pdst, psrc, 4);

    //tx->num_elements -= 4;
    tx->ElementCount -= 4;
  }

   ps = (unsigned short*)tx->Data;
  *ps = tx->ElementCount-2; // only the frame size excluding 2 byte header
  tx->PayLoad =  0; // payload is part of the packet
  tx->StatusWord = 0; // changes from 0 to the status info 
  // give it to the physical driver
  adi_dev_Write(nip->handle,ADI_DEV_1D,(ADI_DEV_BUFFER*)tx);

#ifdef LINK_STATS
  lwip_stats.link.xmit++;
#endif

  //sys_arch_unprotect(old_level);

  return ERR_OK;
}
Ejemplo n.º 7
0
static u32 adi_pdd_Write(
    ADI_DEV_PDD_HANDLE PDDHandle,   /* PDD handle */
    ADI_DEV_BUFFER_TYPE BufferType, /* buffer type */
    ADI_DEV_BUFFER *pBuffer         /* pointer to buffer */
)
{
    u32 Result;

    /* Expose the Device Definition structure */
    ADI_USB_DEF          *pDevice      = (ADI_USB_DEF *)PDDHandle;

    /* Expose the FSS super buffer structure */
    ADI_FSS_SUPER_BUFFER *pSuperBuffer = (ADI_FSS_SUPER_BUFFER *)pBuffer;

    /* Assign callback function and handle to Super Buffer */
    pSuperBuffer->PIDCallbackFunction = CallbackFromFSS;
    pSuperBuffer->PIDCallbackHandle = (void*)pDevice;

#if defined(_BF527_SDRAM_ISSUE_WORKAROUND)
    /* tranfser 'gEndPointMaxPacketSize' bytes at at time & copy to request buffer */
    ADI_DEV_1D_BUFFER  TempBuffer, *pClientBuffer;
    u32                 BytesRemaining = pBuffer->OneD.ElementCount*pBuffer->OneD.ElementWidth;
    u32                 *pClientData   = (u32*)pBuffer->OneD.Data;
    u32                 *pTempData;
    u32                 i;
    u32                 SectorNumber   = pSuperBuffer->LBARequest.StartSector;
    u32                 BufferSize;
    u32                 SectorIncrement;

    if (BytesRemaining< TEMP_BUF_SIZE) {
        BufferSize = BytesRemaining;
    } else {
        BufferSize = TEMP_BUF_SIZE;
    }

    SectorIncrement = BufferSize/512;

    /* change LBA request to 1 sector */
    pSuperBuffer->LBARequest.SectorCount = SectorIncrement;

    /* get max end point buffer size from MSH class driver */
    //adi_dev_Control( pDevice->ClassDriverHandle, ADI_USB_MSD_CMD_GET_MAX_EP_PACKET_SIZE, (void*)&TempBuffer.ElementCount );

    TempBuffer.Data = (void*)&TempBufferData[0];
    TempBuffer.ElementWidth = sizeof(u8);
    TempBuffer.ElementCount = BufferSize;
    TempBuffer.ProcessedElementCount = 0;
    TempBuffer.ProcessedFlag = FALSE;
    TempBuffer.CallbackParameter = &TempBuffer;
    TempBuffer.pNext = NULL;

    pClientBuffer = &pSuperBuffer->Buffer;


    while (pClientBuffer)
    {
        while (BytesRemaining)
        {
            pTempData = (u32*)&TempBufferData[0];
            /* If a Memory DMA stream has been registered with the driver then it is used for the
             * transfer between the L1 temporary buffer and the client buffer
            */
            if (pDevice->MemDMAStreamHandle) {
                adi_dma_MemoryCopy(
                                    pDevice->MemDMAStreamHandle,            /* Stream Handle      */
                                    pTempData,                              /* Destination buffer      */
                                    pClientData,                            /* Source buffer */
                                    sizeof(u32),                            /* Element Width      */
                                    (TempBuffer.ElementCount)/sizeof(u32),  /* Number of elements */
                                    MemDmaCallback                          /* Callback function  */
                                    );

                /* pend on completion */
                adi_sem_Pend(MemDmaSemaphoreHandle,ADI_SEM_TIMEOUT_FOREVER);
                pClientData += (TempBuffer.ElementCount)/sizeof(u32);
            }
            /* Otherwise a core copy is used */
            else {
                for(i=0;i<(TempBuffer.ElementCount)/sizeof(u32);i++,pClientData++,pTempData++)
                {
                    *pTempData = *pClientData;
                }
            }
            pDevice->ClassCommandComplete = FALSE;
            /* Pass LBA request to the Class Driver */
            SendLbaRequest(pDevice,&pSuperBuffer->LBARequest);
            /* queue the buffer */
            Result = adi_dev_Write( pDevice->ClassDriverHandle, ADI_DEV_1D, (ADI_DEV_BUFFER*)&TempBuffer );
            if (Result!=ADI_DEV_RESULT_SUCCESS) {
                return Result;
            }

            /* and wait for completion */
            WaitOnCommandCompletion(pDevice);

            BytesRemaining -= TempBuffer.ElementCount;
            pSuperBuffer->LBARequest.StartSector += SectorIncrement;
        }

        pClientBuffer = pClientBuffer->pNext;
    }

    (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_DEV_EVENT_BUFFER_PROCESSED, (void *)pBuffer );
    (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_PID_EVENT_DEVICE_INTERRUPT, (void *)pBuffer);

#else
#if defined(_USE_BACKG_XFER)
    /* save aside the next buffer in the chain */
    pNextBufferInChain = (ADI_FSS_SUPER_BUFFER *)pBuffer->OneD.pNext;

    /* and clear it so that the USB driver only deals with a single buffer */
    pBuffer->OneD.pNext = NULL;
#endif
#if defined(_USE_BACKG_XFER)
    /* Pass LBA request to the Class Driver */
    SendLbaRequest(pDevice,&pSuperBuffer->LBARequest);
#endif

    /* Pass on the request to the Class Driver */
    Result = adi_dev_Write( pDevice->ClassDriverHandle, BufferType, pBuffer );
#endif

    return(Result);
}
Ejemplo n.º 8
0
/*********************************************************************

    Function:       CallbackFromFSS

    Description:    This is the callback to be taken from the Class
                    Driver.
*********************************************************************/
static void ClassDriverCallback(void *pHandle, u32 Event, void *pArg)
{
    ADI_USB_DEF *pDevice = (ADI_USB_DEF *)pHandle;
    void        *pExitCriticalArg;
    u32         Result;

    switch (Event)
    {
        /* CASE (USB DEVICE INSERTED) */
        case ADI_USB_EVENT_CONNECT:
            /* Callback FSS with ADI_FSS_EVENT_MEDIA_DETECTED event, which may pass the event on to
             * the application which can take action to Poll for Media.
            */
#if 0            
            if (FSSDirectCallbackFunction) {
                (FSSDirectCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_DETECTED, 0 );
            } else {
                (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_DETECTED, 0 );
            }
#endif            
            if (MediaDetectionCallbackFunction) {
                (MediaDetectionCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_DETECTED, 0 );
            }
            break;

        /* CASE (USB DEVICE REMOVED) */
        case ADI_USB_EVENT_DISCONNECT:
            /* simply flag as not present. Next ADI_PID_CMD_POLL_MEDIA_CHANGE command will
             * result in the ADI_FSS_EVENT_MEDIA_REMOVED event being sent to FSS.
            */
            if (pDevice->MediaPresent)
            {
                pDevice->MediaPresent = FALSE;
            }
            if (MediaDetectionCallbackFunction) {
                (MediaDetectionCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_REMOVED, 0 );
            }
            break;

        /* CASE (USB DATA TRANSFER COMPLETE) */
        case ADI_DEV_EVENT_BUFFER_PROCESSED:
           /* pass on event to FSS via DM callback */
#if !defined(_BF527_SDRAM_ISSUE_WORKAROUND)
           (pDevice->DMCallback)( pDevice->DeviceHandle, Event, pArg);
#endif

           /* If there is another buffer in the chain, send the next LBA request and
            * queue the next buffer with the class driver
           */
#if defined(_USE_BACKG_XFER)
           if (pNextBufferInChain)
           {
               ADI_FSS_SUPER_BUFFER *pSuperBuffer = pNextBufferInChain;

               /* The next buffer may not have an LBA Request associated with it, as
                * it may have been combimed with the previous buffer. In which case
                * we do not need to send the LBA request
               */
               if (pSuperBuffer->LBARequest.SectorCount)
               {
                   SendLbaRequest(pDevice, &pSuperBuffer->LBARequest);
               }
               pNextBufferInChain = (ADI_FSS_SUPER_BUFFER *)pSuperBuffer->Buffer.pNext;
               pSuperBuffer->Buffer.pNext = NULL;

               /* Queue the data buffer with the class driver */
               if (pSuperBuffer->LBARequest.ReadFlag)
               {
                    adi_dev_Read( pDevice->ClassDriverHandle, ADI_DEV_1D, (ADI_DEV_BUFFER *)pSuperBuffer);
               }
               else
               {
                    adi_dev_Write( pDevice->ClassDriverHandle, ADI_DEV_1D, (ADI_DEV_BUFFER *)pSuperBuffer );
               }
           }
           else
#endif
           {
               /* At the end of the chain we issue the Device Interrupt event to signal
                * total completion
               */
#if defined(_BF527_SDRAM_ISSUE_WORKAROUND)
                pExitCriticalArg = adi_int_EnterCriticalRegion( pDevice->pEnterCriticalArg );
                pDevice->ClassCommandComplete = TRUE;
                adi_int_ExitCriticalRegion(pExitCriticalArg);
#else
               (pDevice->DMCallback)( pDevice->DeviceHandle, ADI_PID_EVENT_DEVICE_INTERRUPT, pArg);
#endif
           }
            break;

        case ADI_USB_MSD_EVENT_SCSI_CMD_COMPLETE:
            /* post the semaphore upon which the DevicePollMedia function is pending */
            pExitCriticalArg = adi_int_EnterCriticalRegion( pDevice->pEnterCriticalArg );
            pDevice->ClassCommandComplete = TRUE;
            adi_int_ExitCriticalRegion(pExitCriticalArg);
        break;

        case ADI_USB_MSD_EVENT_SCSI_CMD_ERROR:
            pExitCriticalArg = adi_int_EnterCriticalRegion( pDevice->pEnterCriticalArg );
            pDevice->SCSICommandError = TRUE;
            adi_int_ExitCriticalRegion(pExitCriticalArg);
        break;
        
        case ADI_FSS_EVENT_MEDIA_ERROR:
        {
            if (FSSDirectCallbackFunction)
            {
                (FSSDirectCallbackFunction)( &pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_REMOVED, 0 );
            } else 
            {
                (pDevice->DMCallback) ( pDevice->DeviceHandle, ADI_FSS_EVENT_MEDIA_REMOVED, 0 );
            }
        }
        break;
    }
}