📄 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, 硬件抽象层,设置 USB 设备的运行条件
** 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"
/*******************************************************************************************************************
** 函数名称: USB_ConfigPll Name: USB_ConfigPll
** 功能描述: 配置 USB 设备控制器的时钟 Function: Config the clock of USB device controller
** 注 意: PLL的输出必须是 12MHZ 的整数倍, 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 */
}
/*******************************************************************************************************************
** 函数名称: USB_InitHareware Name: USB_InitHareware
** 功能描述: 初始化 USB 设备控制器硬件 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 */
}
/*******************************************************************************************************************
** 函数名称: 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 + -