⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drv_usb.c

📁 基于omap5912平台的usb设备驱动源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	CSL_usbfHaltEp(
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->CTRL, USBF_CTRL_SET_HALT, 1 );
}


void
	CSL_usbfResetEp(
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->CTRL, USBF_CTRL_RESET_EP, 1 );
}


void
	CSL_usbfEnableFifo(
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->CTRL, USBF_CTRL_SET_FIFO_EN, 1 );
}


void
	CSL_usbfConnectDevice(
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->SYSCON1, USBF_SYSCON1_PULLUP_EN, 1 );
}


void
	CSL_usbfDisconnectDevice(
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->SYSCON1, USBF_SYSCON1_PULLUP_EN, 0 );
}


void
	CSL_usbfClearInterrupt(
		CSL_UsbfHandle   hUsbf,
		CSL_BitMask16        intMask
)
{
    hUsbf->regs->IRQ_SRC |= intMask ;
}


void
	CSL_usbfEnableInterrupt(
		CSL_UsbfHandle   hUsbf,
		CSL_BitMask16        intMask
)
{
    hUsbf->regs->IRQ_EN |= intMask ;
}


void
	CSL_usbfDisableInterrupt(
		CSL_UsbfHandle   hUsbf,
		CSL_BitMask16        intMask
)
{
    hUsbf->regs->IRQ_EN &= ~intMask ;
}


void
	CSL_usbfEnableDmaInterrupt(
		CSL_UsbfHandle   hUsbf,
		CSL_BitMask16        intMask
)
{
    hUsbf->regs->DMA_IRQ_EN |= intMask ;
}


void
	CSL_usbfDisableDmaInterrupt(
		CSL_UsbfHandle   hUsbf,
		CSL_BitMask16        intMask
)
{
    hUsbf->regs->DMA_IRQ_EN &= ~intMask ;
}


void
	CSL_usbfWriteFifo(
		CSL_UsbfHandle   hUsbf,
		CSL_UsbfRxTxFifo *pTxfifo
)
{
    CSL_UsbfEpNum epNum;
    INT16U i ;
    epNum = (CSL_UsbfEpNum) CSL_FEXT(hUsbf->regs->EPNUM, USBF_EPNUM_EP_NUM);
    
    /* Enable access to endpoint FIFO */
    CSL_FINS(hUsbf->regs->EPNUM, USBF_EPNUM_EP_SEL, 1);

    if (pTxfifo->length > 64) 
        pTxfifo->length = 64;
    
    for ( i = 0 ; i < pTxfifo->length ; i++ )
           *(volatile INT8U *)&hUsbf->regs->DATA = *(pTxfifo->data)++;
    
    hUsbf->regs->EPNUM = 0x10 | epNum;
    hUsbf->regs->CTRL = 0x0004;
}




void
	CSL_usbfReadFifo(
		CSL_UsbfHandle   hUsbf,
		CSL_UsbfRxTxFifo *pRxfifo
)
{
    CSL_UsbfEpNum epNum;
    INT16U i ;
	INT32U length = 0;

    length = hUsbf->regs->RXFSTAT;
    
    epNum = (CSL_UsbfEpNum) CSL_FEXT(hUsbf->regs->EPNUM, USBF_EPNUM_EP_NUM);
    
    /* Enable access to endpoint FIFO */
    CSL_FINS(hUsbf->regs->EPNUM, USBF_EPNUM_EP_SEL, 1);

    if (length > pRxfifo->length) 
        length = pRxfifo->length;

    for ( i = 0 ; i < length ; i++ )
           *(pRxfifo->data)++ = *(volatile Uint8 *)&hUsbf->regs->DATA;

    /* Setup Endpoint to retreive the next incoming packet. */ 
    hUsbf->regs->EPNUM = 0x00 | epNum;
    /* Setup USB to receive data on Endpoint [endpt_num] */ 
    hUsbf->regs->CTRL = 0x0004;
    pRxfifo->length = length;

}


void
	CSL_usbfSelectEp (
		CSL_UsbfHandle   hUsbf,
		INT8U    epNum
)
{
    register INT16U _epnum ;
    INT8U epDir;
    _epnum = hUsbf->regs->EPNUM;

    epDir = (epNum & 0x10) >> 4  ;
    epNum = epNum & 0xf ;  
    
    CSL_FINS(_epnum, USBF_EPNUM_EP_NUM, epNum  );
    CSL_FINS(_epnum, USBF_EPNUM_EP_DIR, epDir  );
    CSL_FINS(_epnum, USBF_EPNUM_EP_SEL, 1);
    hUsbf->regs->EPNUM = _epnum;
}


void
	CSL_usbfDeselectEp (
		CSL_UsbfHandle   hUsbf
)
{
    CSL_FINS(hUsbf->regs->EPNUM, USBF_EPNUM_EP_SEL, 0);
}


void
	CSL_usbfReadSetup (
		CSL_UsbfHandle          hUsbf,
		CSL_UsbfSetupPacket *   pSetupPacket
)
{
    register INT16U _epnum ;
    INT16U data;

    /* Select endpoint 0 for setup FIFO reading */
    _epnum = hUsbf->regs->EPNUM ;
    CSL_FINS(_epnum, USBF_EPNUM_EP_NUM, 0 );
    CSL_FINS(_epnum, USBF_EPNUM_EP_DIR, 0  );
    CSL_FINS(_epnum, USBF_EPNUM_SETUP_SEL, 1);
    CSL_FINS(_epnum, USBF_EPNUM_EP_SEL, 0);
    hUsbf->regs->EPNUM = _epnum;

    data = hUsbf->regs->DATA ;

    pSetupPacket->new_packet   = TRUE;
    pSetupPacket->bmRequestType = data & 0xff;
    pSetupPacket->bRequest     = ( data >> 8 ) & 0xff;
    pSetupPacket->wValue       = hUsbf->regs->DATA;
    pSetupPacket->wIndex       = hUsbf->regs->DATA;
    pSetupPacket->wLength      = hUsbf->regs->DATA;
    
    /* Deselect endpoint 0 for setup FIFO reading */
    CSL_FINS(hUsbf->regs->EPNUM, USBF_EPNUM_SETUP_SEL, 0);
}


INT16U
	CSL_usbfGetRxFifoCount (
		CSL_UsbfHandle   hUsbf
)
{
    return (CSL_FEXT(hUsbf->regs->RXFSTAT, USBF_RXFSTAT_RXF_COUNT));
}

INT16U
	CSL_usbfGetIsoEpStatus (
		CSL_UsbfHandle   hUsbf
)
{
    return (hUsbf->regs->STAT_FLG);
}

INT16U
	CSL_usbfGetNonIsoEpStatus (
		CSL_UsbfHandle   hUsbf
)
{
    return (hUsbf->regs->STAT_FLG);
}

INT16U
	CSL_usbfGetDeviceStatus (
		CSL_UsbfHandle   hUsbf
)
{
    return (hUsbf->regs->DEVSTAT);
}

INT16U
	CSL_usbfGetFrameTimerStatus (
		CSL_UsbfHandle   hUsbf
)
{
    return (hUsbf->regs->SOF);
}


void
	CSL_usbfGetFrameNonisoEpIntStatus(
		CSL_UsbfHandle   hUsbf,
		CSL_UsbfNonIsoEpIntStatus * intStatus
)
{
    intStatus->rxEpIntSource = (CSL_UsbfEpNum) CSL_FEXT(hUsbf->regs->EPN_STAT, USBF_EPN_STAT_RX_IT_SRC);
    intStatus->txEpIntSource = (CSL_UsbfEpNum) CSL_FEXT(hUsbf->regs->EPN_STAT, USBF_EPN_STAT_TX_IT_SRC);
}


void
	CSL_usbfGetFrameNonisoEpDmaIntStatus(
		CSL_UsbfHandle   hUsbf,
		CSL_UsbfNonIsoDmaIntStatus * intStatus
)
{
    register INT16U _reg ;
    _reg = hUsbf->regs->DMAN_STAT ;
    intStatus->eotDmaIntPending = CSL_FEXT(_reg, USBF_DMAN_STAT_RX_SB);
    intStatus->rxdmaIntSource = (CSL_UsbfEpNum) CSL_FEXT(_reg, USBF_DMAN_STAT_RX_IT_SRC);
    intStatus->txdmaIntSource = (CSL_UsbfEpNum) CSL_FEXT(_reg, USBF_DMAN_STAT_TX_IT_SRC);
}


CSL_BitMask16
	CSL_usbfGetIntSrc(
		CSL_UsbfHandle   hUsbf
)
{
    return (hUsbf->regs->IRQ_SRC);
}


CSL_UsbfRev
	CSL_usbfGetDeviceRevision(
		CSL_UsbfHandle   hUsbf
)
{
    return ((CSL_UsbfRev)CSL_FEXT(hUsbf->regs->REV, USBF_REV_REV_NB));
}

/** Traces the various parameters of a particular USBF module (passed as handle)
 * 
 * <b> Usage Constraints: </b>
 * Both @a CSL_usbfInit() and @a CSL_usbfOpen() must be called successfully
 * in that order before @a CSL_usbfGetHwStatus() can be called. For the
 * argument type that can be @a void* casted & passed with a particular query
 * refer to @a CSL_UsbfHwStatusQuery
 * 
 * @b Example:
 * @verbatim

 
    CSL_UsbfHandle hUsbf;
    CSL_Status status;
    CSL_UsbfHwSetup setup;
    ...
    status = CSL_usbfGetHwStatus(hUsbf,
                                  CSL_USBF_QUERY_CURRENT_HWSETUP,
                                  &setup);
   @endverbatim
 * 
 * @return returns the status of the operation
 * 
 */
CSL_Status  CSL_usbfGetHwStatus(
    /** Pointer to the object that holds reference to the
     * instance of USBF requested after the call */
    CSL_UsbfHandle        hUsbf,
    /** Query that indicates the status/setup to be returned */
    CSL_UsbfHwStatusQuery query,
    /** Placeholder to return the status; @a void* casted */
    void                 *response
)
{
    CSL_Status status = CSL_SOK ;
    
    if(hUsbf == NULL)
        return CSL_ESYS_BADHANDLE;
    
    if(response == NULL)
        return CSL_ESYS_INVPARAMS;

    switch(query)
    {
        /* Get the receive FIFO count */
        case CSL_USBF_QUERY_RX_FIFO_COUNT:
            (*(INT16U *)response) = CSL_usbfGetRxFifoCount(hUsbf);
            break;
            
        /* Get the ISO endpoint status */
        case CSL_USBF_QUERY_ISO_EP_STATUS:
            (*(INT16U *)response) = CSL_usbfGetIsoEpStatus(hUsbf);
            break;
            
        /* Get the ISO endpoint status */
        case CSL_USBF_QUERY_NONISO_EP_STATUS:
            (*(INT16U *)response) = CSL_usbfGetNonIsoEpStatus(hUsbf);
            break;            
            
        /* Get the device status */
        case CSL_USBF_QUERY_DEVICE_STATUS:
            (*(INT16U *)response) = CSL_usbfGetDeviceStatus(hUsbf);
            break;
                        
        /* Get the frame timer status */
        case CSL_USBF_QUERY_FRAME_TIMER_STATUS:
            (*(INT16U *)response) = CSL_usbfGetFrameTimerStatus(hUsbf);
            break;                            
            
        /* Get the non-ISO endpoint status */
        case CSL_USBF_QUERY_FRAME_NONISO_EP_INT_STATUS:
            	CSL_usbfGetFrameNonisoEpIntStatus(hUsbf, (CSL_UsbfNonIsoEpIntStatus *)response);
            break;
            
        /* Get the non-ISO DMA status */
        case CSL_USBF_QUERY_FRAME_NONISO_DMA_INT_STATUS:
            	CSL_usbfGetFrameNonisoEpDmaIntStatus(hUsbf, (CSL_UsbfNonIsoDmaIntStatus *)response);
             break;               

        /* Get the interrupt source */
        case CSL_USBF_QUERY_IRQ_SRC:
            (*(CSL_BitMask16 *)response) = 	CSL_usbfGetIntSrc(hUsbf) ;
            break;
            
        /* Get the revision of USBF */
        case CSL_USBF_QUERY_DEVICE_REVISION:
            (*(CSL_UsbfRev *)response) = 	CSL_usbfGetDeviceRevision(hUsbf);
            break;
       
        case CSL_USBF_QUERY_STATUS:
            break;                    
            
            default:
            status = CSL_ESYS_INVQUERY;
    }
	
    return status ;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -