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

📄 usb_bsp.c

📁 ucusb 关于sl811驱动移植源码
💻 C
字号:
/*
*********************************************************************************************************
*                                           Micrium, Inc.
*                                       949 Crestview Circle
*                                      Weston,  FL 33327-1848
*
*                                           uC/USB-Bulk
*
*                               (c) Copyright 2003 - 2004, Micrium, Inc.
*                                       All rights reserved.
*
*********************************************************************************************************

--------------------------------------------------------------------------------------------------------
File    : USB_bsp.c
Purpose : This file defines the functions used to intialize the SL811HS.  Functions for reading and 
          writing buffers are also provided.  
--------  END-OF-HEADER  -------------------------------------------------------------------------------
*/

#include "USB_bsp.h"

/*
*********************************************************************************************************
*                                     Write to an SL811HS Buffer
*
* Description: This function writes data to a buffer on the SL811HS.  The SL811HS allows writes to 
*              consecutive locations to be performed without writing the address each time; this 
*              function takes advantage of this feature.
* 
* Arguments  : pData       Pointer to the data to be written
*              reg_addr    Address of the register which holds the address of the buffer to be written
*              num_bytes   The number of bytes to write
* 
* Returns    : None
*********************************************************************************************************
*/

USB_U8  USB_Reg_Wr_Buf (USB_U8 *pData, USB_U8 reg_addr, USB_U8 num_bytes)
{    
    USB_U8  mem_addr;
    USB_U8  i;
  
  
    USB_ADDR_REG  = reg_addr;             /* Set the IP's address register to the appropriate device ...       */
                                          /* ... register which should hold the location of a buffer.          */
    mem_addr      = USB_DATA_REG;         /* mem_address now references the location that will be written      */
    USB_ADDR_REG  = mem_addr;             /* Reset the address register so the location can be written         */
    for (i = 0; i < num_bytes; i++) {    
        USB_DATA_REG = *pData;            /* Sequential accesses of DataReg write to sequential locations      */
        pData++;
    }
    
    return (i);
}  

/*
*********************************************************************************************************
*                                   Read from an SL811HS Buffer
*
* Description: This function reads data from a buffer on the SL811HS.  The SL811HS allows reads from 
*              consecutive locations to be performed without writing the address each time; this 
*              function takes advantage of this feature.
* 
* Arguments  : pData        A pointer to a buffer that will hold the data that is read
*              reg_addr     The address of the register which holds the address of the buffer to read
*              num_bytes    The number of bytes to read
* 
* Returns    : None
*********************************************************************************************************
*/

void  USB_Reg_Rd_Buf(USB_U8 *pData, USB_U8 reg_addr, USB_U8 num_bytes)
{
    USB_U8  mem_addr;
    USB_U8  i;
    
        
    USB_ADDR_REG = reg_addr;              /* Set the IP's address register to the appropriate device ...       */
                                          /* ... register which should hold the location of a buffer.          */
    mem_addr     = USB_DATA_REG;          /* mem__address now references the location that will be read        */
    USB_ADDR_REG = mem_addr;              /* Reset the address register so the location can be read            */
    for (i = 0; i < num_bytes; i++) {               
        *pData   = USB_DATA_REG;          /* Sequential accesses of DataReg read from sequential locations     */
        *pData++;
    }     
}    
    
/*
*********************************************************************************************************
*                                    USB Interrupt Service Routine
*
* Description: This is the routine that is registered with the HAL to handle USB interrupts.  The 
*              function checks the USB controller's interrupt status register and calls the appropriate
*              handler.
* 
* Arguments  : parg    Unused
*              irqnum  Unused
* 
* Returns    : None
*********************************************************************************************************
*/

void  USB_HW_MainISR (void *parg, USB_U32 irqnum)
{
    USB_U8 status;                        /* Copy of the interrupt status register                             */
    
    
    (void)parg;                       
    (void)irqnum;
                                          /* Check the interrupt status register                               */
    USB_REG_RD(INT_STATUS_REG, status);
                                          /* Handle USB reset interrupts                                       */
    if((status & INT_STATUS_USB_RESET) != 0) {         
        USB_ISR_Reset();                                           
    }                               
                                          /* Handle interrupts on Endpoint 0                                   */
    if((status & INT_STATUS_ENDPOINT0) != 0) {
        USB_ISR_EP0();                                 
    } 
                                          /* Handle interrupts on Endpoint 1                                   */
    if((status & INT_STATUS_ENDPOINT1) != 0) {
        USB_ISR_Function();                                
    }
                                          /* Handle interrupts on Endpoint 2                                   */
    if((status & INT_STATUS_ENDPOINT2) != 0) {       
        USB_ISR_Function();
    }
                                          /* Clear any interrupts                                              */
    USB_REG_WR(INT_STATUS_REG, INT_STATUS_CLEAR_ALL);
}

/*
*********************************************************************************************************
*                                      Initialize the SL811HS
*
* Description: This function performs the initializations needed to use the SL811HS on the 
*              Microtronix cyclone development board.  These initializations include registering
*              an interrupt controller with the HAL, and enabling interrupts from the Avalon interface
*              for the SL811HS.
* 
* Arguments  : None
* 
* Returns    : None
*********************************************************************************************************
*/

void USB_SL811HS_Init(void)
{  
                                          /* Register the interrupt handler for USB Interrupts                 */
    alt_irq_register(USB_IRQ, (void *)0, USB_HW_MainISR);   
       
    USB_CTRL_REG = 0x0004;                /* Enable interrupts through the USB IP                              */
                                          /* Enable Endpoint 0 and USB reset interrupts                        */
}      


                               

⌨️ 快捷键说明

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