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

📄 usbdevhal.c

📁 SmartARM2400系列开发板全套资料
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			USBHAL.c
** Last modified Date:	2007-07-08
** Last Version:		V1.0
** Descriptions:		USBHAL.c, 硬件抽象层,设置 USB 设备的运行条件
**						USBHAL.c, Hardware abstract layer, configure the running condition of USB device
**------------------------------------------------------------------------------------------------------
** Created by:			郑明远 		MingYuan Zheng
** Created date:		2007-07-08
** Version:				V1.0
** Descriptions:		初始版本	The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			
** Modified date:
** Version:				
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/

/**************************************************************************************
PLL1:			USB device PLL clock

P0.23:   		VBUS — Indicates the presence of USB bus power.
P0.31:   		UP_LED  --- USB Good Link LED indicator. or 
	 	 		CONNECT --- signal used to switch an external 1.5K resistor under software control   
P0.26(Pin 10):	USB D+	 
P0.27(Pin 11):  USB D-

USB Interrupt VIC = 22
**************************************************************************************/

#include  "config.h"
#include "usbdevconfig.h"


#ifndef USBClkCtrl
#define  USBClkCtrl         (*(volatile unsigned long *)(0xFFE0CFF4))  
#endif

#ifndef USBClkSt
#define  USBClkSt           (*(volatile unsigned long *)(0xFFE0CFF8)) 
#endif

#ifndef USBPortSel
#define  USBPortSel         (*(volatile unsigned long *)(0xFFE0C110))	/* LPC2378 Only */
#endif


#define __USB_DEV_CLK_EN          (0x01 << 1)
#define __USB_I2C_CLK_EN          (0x01 << 2)
#define __USB_OTG_CLK_EN          (0x01 << 3)
#define __USB_AHB_CLK_EN          (0x01 << 4)

#define __USB_TDI                 (0x01 << 0)

/*******************************************************************************************************************
** 函数名称: USB_InitHardware					Name:	  USB_InitHareware
** 功能描述: 初始化 USB 设备控制器硬件			Function: Initialize the hardware of USB device controller 
********************************************************************************************************************/
void USB_InitHardware(void)
{
    USB_INT32U  uiClkCtrl = (__USB_I2C_CLK_EN | __USB_OTG_CLK_EN | \
                             __USB_DEV_CLK_EN | __USB_AHB_CLK_EN);
      
    PCONP |= 0x80000000;                                                /*  给USB控制器提供电源         */
    OTGClkCtrl = uiClkCtrl;                                             /*  配置USB时钟控制寄存器       */
    while ((OTGClkSt & uiClkCtrl) != uiClkCtrl);       
    
    OTGStCtrl &= ~0x01;                                                   /*  U1 HOST, U2 HOST            */
    PINSEL1 &= ~(0x03U << 26);                                          /*  P0.29 为 LPC2400 USB        */
    PINSEL1 |= (0x01U << 26);                                           /*  ...Device(1) 的D+           */
    
    PINSEL1 &= ~(0x03U << 28);                                          /*  P0.30 为 LPC2400 USB        */
    PINSEL1 |= (0x01U << 28);                                           /*  ...Device(1) 的 D-          */
     
    PINSEL3 &= ~(0x03U << 28);                                          /*  P1.30 为 LPC2400 USB        */
    PINSEL3 |= (0x02U << 28);                                           /*  Device(1)和(2) 的 VBUS      */
     
    PINSEL3 &= ~(0x03U << 4);                                           /*  P1.18 为 LPC2400 USB        */
    PINSEL3 |= (0x01U << 4);                                            /*  ...Device(1) UP_LED         */

    PINSEL3 &= ~(0x0F << 24);                                           /*  P1.28 为 USB_SCL1, P1.29    */
    PINSEL3 |= (0x05 << 24);                                            /*  ...为 USB_SDA1              */
    
    __isp1301DisEnPswOE();
    __isp1301Write(__OTG_CTL1_CLR, __OTG_CTL1_DM_PULLDOWN | __OTG_CTL1_DP_PULLDOWN |
                                   __OTG_CTL1_DM_PULLUP);
}

/************************************************************
** Name	   : USB_Disconnect 
** Function: disconnect USB bus
************************************************************/
void USB_Disconnect(void)
{
    /*
     *  取消 ISP1301 上的 D+ 线电阻上拉
     */
    OTG_I2C_TX = 0x15A;                                                 /*  发送 ISP1301 地址,          */
                                                                        /*  ...R/W=0, 写操作            */
    OTG_I2C_TX = 0x007;                                                 /*  send OTG Control (Set)      */
                                                                        /*  ...register address         */
    OTG_I2C_TX = 0x201;                                                 /*  Set DP_PULLUP bit,          */
                                                                        /*  ...send STOP condition      */
    while (!(OTG_I2C_STS & __USB_TDI));                                 /*  Wait for TDI to be set      */
    
    OTG_I2C_STS = __USB_TDI;                                            /*  Clear TDI                   */
    
}

/************************************************************
** Name	   : USB_Connect
** Function: connect USB bus
************************************************************/
void USB_Connect(void)
{
    /*
     *  设置 ISP1301 上的 D+ 线电阻上拉
     */
    OTG_I2C_TX = 0x15A;                                                 /*  发送 ISP1301 地址,          */
                                                                        /*  ...R/W=0, 写操作            */
    OTG_I2C_TX = 0x006;                                                 /*  send OTG Control (Set)      */
                                                                        /*  ...register address         */
    OTG_I2C_TX = 0x201;                                                 /*  Set DP_PULLUP bit,          */
                                                                        /*  ...send STOP condition      */
    while (!(OTG_I2C_STS & __USB_TDI));                                 /*  Wait for TDI to be set      */
    
    OTG_I2C_STS = __USB_TDI;                                            /*  Clear TDI                   */
}

/************************************************************
** Name	   : USB_Reconnect
** Function: reconnect USB bus
************************************************************/
void USB_Reconnect(void)
{
	INT32U clk_cnt;

	USB_Disconnect();							    /* disconnect USB bus */
    for (clk_cnt = 0;clk_cnt<= 0x1FFFF;clk_cnt++);  /* delay */
    
    USB_Connect();								    /* connect USB bus */
}

/*******************************************************************************************************************
** 函数名称: USB_USBDevIntConfig				Name:	  USB_USBDevIntConfig
** 功能描述: 配置USB设备控制器的中断			Function: Config the Interrupt of USB device controller 
********************************************************************************************************************/
void USB_USBDevIntConfig(void)
{
	INT32U tmp = EP_SLOW;
	
	OS_ENTER_CRITICAL();
    // Clears the frame interrupt flag in USBDevIntClr
    USBDevIntClr = tmp | FRAME;									        /*  禁止同步传输帧中断              */

	// Enables ep_slow and dev_stat interrupt only in USBDevIntEn 
    USBDevIntEn = tmp;										            /*  使能状态中断, 低速中断          */
      
	// the EP_FAST interrupt is slow priority interrupt
    USBDevIntPri = 0; 				  						            /*  使能端点中断为低优先级中断      */

#if DMA_ENGINE_EN
	   tmp = (0x01 << 0) + (0x01 << 1);						            /*  使能控制传输端点从机中断        */
#else
	   tmp = (0x01 << 0) + (0x01 << 1) + (0x01 << 2) + 
	         (0x01 << 3) + (0x01 << 4) + (0x01 << 5);			        /*  使能端点 0 ~ 5 从机中断         */
#endif
		
	// Enable Endpoint Interrupt: endpoint 0 ~ 5
    USBEpIntEn = tmp;	  									            /*  使能物理端点 0 ~ 5中断          */
	
	// Routes all endp ints to the ep_slow int USBEpIntPri
    USBEpIntPri &= ~tmp;									            /* 设置物理端点 0 ~ 5为低优先级中断 */
    OS_EXIT_CRITICAL();
}

/*******************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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