?? usbhal.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 "USBConfig.h"
#include "USBCI.h"
#include "USBHAL.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 DEV_CLK_EN (0x01 << 1)
#define PORTSEL_CLK_EN (0x01 << 3)
#define AHB_CLK_EN (0x01 << 4)
/*******************************************************************************************************************
** 函數名稱: USB_InitHardware Name: USB_InitHareware
** 功能描述: 初始化 USB 設備控制器硬件 Function: Initialize the hardware of USB device controller
********************************************************************************************************************/
void USB_InitHardware(void)
{
INT32U clkctrl = DEV_CLK_EN | AHB_CLK_EN;
USBClkCtrl = clkctrl; /* 配置USB時鐘控制寄存器 */
while (!(USBClkSt & (DEV_CLK_EN | AHB_CLK_EN)));
#if USB_PORT2_EN
USBClkCtrl |= PORTSEL_CLK_EN;
while (!(USBClkSt & (PORTSEL_CLK_EN)));
USBPortSel = 0x03;
PINSEL0 &= ~(0x03 << 26); /* P0.13 is LPC23xx USB Device(2) U2UP_LED */
PINSEL0 |= (0x01 << 26);
PINSEL0 &= ~(0x03 << 28); /* P0.14 is LPC23xx USB Device(2) U2CONNECT */
PINSEL0 |= (0x02 << 28);
PINSEL1 &= ~(0x03U << 30); /* P0.31 is USB2 D+ */
PINSEL1 |= (0x01 << 30);
PINSEL3 &= ~(0x03U << 28); /* P1.30 為 LPC23xx USB Device(1)和(2) 的VBUS */
PINSEL3 |= (0x02U << 28);
#else
PINSEL1 &= ~(0x03U << 26); /* P0.29 為 LPC23xx USB Device(1) 的D+ */
PINSEL1 |= (0x01U << 26);
PINSEL1 &= ~(0x03U << 28); /* P0.30 為 LPC23xx USB Device(1) 的D- */
PINSEL1 |= (0x01U << 28);
/* P2.9 is a GPIO */
PINSEL4 &= ~(0x03U << 18); /* P2.9 為 LPC23xx USB Device(1) 的SoftConnect */
//PINSEL4 |= (0x01U << 18);
FIO2DIR |= 0x01 << 9; /* P2.9 is output pin */
FIO2SET |= 0x01 << 9;
PINSEL3 &= ~(0x03U << 28); /* P1.30 為 LPC23xx USB Device(1)和(2) 的VBUS */
PINSEL3 |= (0x02U << 28);
PINSEL3 &= ~(0x03U << 4); /* P1.18 為 LPC23xx USB Device(1) UP_LED */
PINSEL3 |= (0x01U << 4);
#endif
PCONP |= 0x80000000; /* 給USB控制器提供電源 power on USB controller */
}
/************************************************************
** Name : USB_Disconnect
** Function: disconnect USB bus
************************************************************/
void USB_Disconnect(void)
{
FIO2SET |= 0x01 << 9;
}
/************************************************************
** Name : USB_Connect
** Function: connect USB bus
************************************************************/
void USB_Connect(void)
{
FIO2CLR |= 0x01 << 9;
}
/************************************************************
** 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;
// Clears the frame interrupt flag in USBDevIntClr
USBDevIntClr = 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為低優先級中斷 */
}
/*******************************************************************************************************
** End Of File
********************************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -