?? 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: 2005-8-6
** Last Version: V1.0
** Descriptions: USBHAL.c, 硬件抽象層,設(shè)置 USB 設(shè)備的運行條件
** USBHAL.c, Hardware abstract layer, configure the running condition of USB device
**------------------------------------------------------------------------------------------------------
** Created by: 鄭明遠 MingYuan Zheng
** Created date: 2005-8-6
** 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"
/*******************************************************************************************************************
** 函數(shù)名稱: USB_ConfigPll Name: USB_ConfigPll
** 功能描述: 配置 USB 設(shè)備控制器的時鐘 Function: Config the clock of USB device controller
** 注 意: PLL的輸出必須是 12MHZ 的整數(shù)倍, Note: The output frequency of the PLL must the Multiplier of 12MHZ,
而且必須是 2 倍以上. and it must be above 2 times.
********************************************************************************************************************/
void USB_ConfigPll(void)
{
/* 外部 Fosc = 12MHz, 配置 PLL1 輸出值為 48MHz. Fosc = 12MHz, Configure PLL1 (USB PLL) for 48 MHz. */
PLL1CFG = 0x23; /* P = 2, M = 4 */
PLL1CON = 0x1; /* Enable PLL1 */
PLL1FEED = 0xAA;
PLL1FEED = 0x55; /* PLL Feed */
while((PLL1STAT & 0x400) == 0); /* 等待 PLL1 鎖定 */
PLL1CON = 0x3; /* Enable and connect*/
PLL1FEED = 0xaa;
PLL1FEED = 0x55; /* PLL Feed part 2 */
}
/*******************************************************************************************************************
** 函數(shù)名稱: USB_InitHareware Name: USB_InitHareware
** 功能描述: 初始化 USB 設(shè)備控制器硬件 Function: Initialize the hardware of USB device controller
********************************************************************************************************************/
void USB_InitHareware(void)
{
USB_ConfigPll(); /* 配置USB時鐘 config USB clock */
PINSEL1 &= ~(0x03U << 30);
PINSEL1 |= (0x02U << 30); /* P0.31為SoftConnect引腳 P0.31 is SoftConnect Pin */
PINSEL1 &= ~(0x03U << 14);
PINSEL1 |= (0x01U << 14); /* P0.23為 Vbus 引腳 P0.23 is Vbus Pin */
PCONP |= 0x80000000; /* 給USB控制器提供電源 power on USB controller */
}
/*******************************************************************************************************************
** 函數(shù)名稱: USB_USBDevIntConfig Name: USB_USBDevIntConfig
** 功能描述: 配置USB設(shè)備控制器的中斷 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; /* 使能復(fù)位中斷, 低速中斷 */
// the EP_FAST interrupt is slow priority interrupt
USBDevIntPri = 0; /* 使能端點中斷為低優(yōu)先級中斷 */
#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; /* 設(shè)置物理端點 0 ~ 5為低優(yōu)先級中斷 */
}
/*******************************************************************************************************
** End Of File
********************************************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -