/*****************************************************************************
* usbhost.c: USB host initialization C file for NXP LPC23xx/24xx Family
* Microprocessors
*
* Copyright(C) 2006, NXP Semiconductor
* All rights reserved.
*
* History
* 2007.07.20 ver 1.00 Prelimnary version, first Release
*
*****************************************************************************/
#include "LPC23xx.h" /* 24xx Peripheral Registers */
/* Note: lpc23xx.h is the superset for
both LPC23xx and LPC24xx MCUs. */
#include "type.h"
#include "irq.h"
#include "target.h"
#include "timer.h"
#include "usbhost.h"
/* statistics of all the interrupts */
volatile DWORD intOverRunCnt = 0;
volatile DWORD intWriteBackDoneCnt = 0;
volatile DWORD intSOFCnt = 0;
volatile DWORD intResumeDetectCnt = 0;
volatile DWORD intUnrecoverErrCnt = 0;
volatile DWORD intFrameNumOverflowCnt = 0;
volatile DWORD intRHStatusChangeCnt = 0;
volatile DWORD intOwnershipChangeCnt = 0;
volatile DWORD NumDownStreamPorts = 0;
/*****************************************************************************
** Function name: OHCIIntEnable
**
** Descriptions: USB host OHCI Interrupt enable
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void OHCIIntEnable(void )
{
if ( !(HC_INT_EN & 0x80000000) )
{
HC_INT_EN |= 0x80000000;
}
return;
}
/*****************************************************************************
** Function name: OHCIIntDisable
**
** Descriptions: USB host OHCI Interrupt disable
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void OHCIIntDisable(void )
{
if ( HC_INT_EN & 0x80000000 )
{
HC_INT_DIS |= 0x80000000;
}
return;
}
/*****************************************************************************
** Function name: OHCIInit
**
** Descriptions: USB host OHCI initialization.
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
DWORD OHCIInit( void )
{
DWORD regVal;
/* Do a hardware Reset */
HC_CONTROL = 0;
delayMs(1, 1);
/* Reset the Host controller */
HC_CMD_STAT = 0x01;
while ( HC_CMD_STAT & 0x01 );
regVal = HC_REVISION;
if ( (regVal & 0xFF) != 0x10)
{
return( FALSE );
}
/* Initialize OHCI Registers */
/* Make the Host controller Operational, enable all control,
bulk, and ISO, set CBSR to 0x03 */
HC_CONTROL = (0x2<<6)|(0x01<<5)|(0x01<<4)|(0x01<<3)|(0x03);
/* Disable all Interrupts */
HC_INT_DIS = 0x7F;
OHCIIntDisable(); /* Disable global MIE bit */
HC_BULK_HEAD_ED = 0;
HC_CTRL_HEAD_ED = 0;
HC_HCCA = USB_OHCI_ADDR;
HC_FM_INTERVAL = (FM_INTERVAL_FSMPS << 16)|FM_INTERVAL_FI;
/* Use typical value described in OHCI spec. */
HC_PERIOD_START = PERIODIC_START;
HC_LS_THRHLD = LS_THRESHOLD;
/* Enable all interrupts including MIE*/
HC_INT_EN = 0x0000007F;
HC_INT_STAT = 0x8000007F; /* clear all interrupts */
OHCIIntEnable(); /* Eable global MIE bit */
regVal = (PWRON_TO_PWRGOOD << 24) & 0xFF000000;
HC_RH_DESCA = regVal;
/* POTPGT value divided by two as delay */
regVal = (regVal >> 24) << 1;
/* milliseconds, power on to power good time */
delayMs(1, regVal);
HC_RH_DESCB = 0x0000;
/* Set global power, LPSC bit */
HC_RH_STAT = 0x00010000;
return( TRUE );
}
/*****************************************************************************
** Function name: OHCIPortOpen
**
** Descriptions: USB host OHCI port open.
**
** parameters: port number
** Returned value: None
**
*****************************************************************************/
void OHCIPortOpen( DWORD portNum )
{
if ( portNum == 1 )
{
/* Port 1 is connected */
delayMs(1, 100); /* wait to eliminate signal glitches */
HC_RH_PORT_STAT1 |= 0x10;
delayMs(1, 10);
/* PRSC should be set after port1 reset is finished. */
while ( !(HC_RH_PORT_STAT1 & (0x10 << 16)) );
/* Set bit 8(PPS) and 1(PES), port 1 power is on and enabled */
HC_RH_PORT_STAT1 = 0x102;
}
else if ( portNum == 2 )
{
/* Port 2 is connected */
delayMs(1, 100); /* wait to eliminate signal glitches */
HC_RH_PORT_STAT2 |= 0x10;
delayMs(1, 10);
/* PRSC should be set after port2 reset is finished. */
while ( !(HC_RH_PORT_STAT2 & (0x10 << 16)) );
/* Set bit 8(PPS) and 1(PES), port 2 power is on and enabled */
HC_RH_PORT_STAT2 = 0x102;
}
/* OCPM is 1, over current is reported on per-port base
PSM is 1, each port is powered individually
NPS is 1, ports are always powered when HC is powered. */
HC_RH_DESCA = 0x0B01;
HC_RH_DESCB = 0x0000;
return;
}
/*****************************************************************************
** Function name: OHCIPortClose
**
** Descriptions: USB host OHCI port close.
**
** parameters: port number
** Returned value: None
**
*****************************************************************************/
void OHCIPortClose( DWORD portNum )
{
if ( portNum == 1 )
{
/* Port 1 is disconnected */
delayMs(1, 100); /* wait to eliminate signal glitches */
HC_RH_PORT_STAT1 |= 0x10;
delayMs(1, 10);
/* PRSC should be set after port1 reset is finished. */
while ( !(HC_RH_PORT_STAT1 & (0x10 << 16)) );
/* Clear bit 8(PPS) and 1(PES), port 1 power is off and disabled */
HC_RH_PORT_STAT1 &= ~0x102;
}
else if ( portNum == 2 )
{
/* Port 2 is disconnected */
delayMs(1, 100); /* wait to eliminate signal glitches */
HC_RH_PORT_STAT2 |= 0x10;
delayMs(1, 10);
/* PRSC should be set after port2 reset is finished. */
while ( !(HC_RH_PORT_STAT2 & (0x10 << 16)) );
/* Clear bit 8(PPS) and 1(PES), port 2 power is off and disabled */
HC_RH_PORT_STAT2 &= ~0x102;
}
return;
}
/*****************************************************************************
** Function name: OHCISetAddress
**
** Descriptions: USB host OHCI Set device address
**
** parameters: port type
** Returned value: None
**
*****************************************************************************/
void OHCISetAddress( void )
{
return;
}
/*****************************************************************************
** Function name: ISP1301_I2CRequest
**
** Descriptions: Send a I2c Request to OTG chip ISP 1301.
** Normally, it's three bytes, in formatting the
** request, first with a I2C_START, the last with
** a I2C_STOP.
**
** parameters: pointer to the request, data length
** Returned value: None
**
*****************************************************************************/
void ISP1301_I2CRequest( DWORD *ReqPtr, DWORD DataLen )
{
DWORD i;
for ( i = 0; i < DataLen; i++ )
{
OTG_I2C_TX = *(ReqPtr+i);
}
/* Wait for TDI bit to be set */
while (!(OTG_I2C_STS & 0x1));
/* Clear TDI bit */
OTG_I2C_STS = 0x1;
return;
}
/*****************************************************************************
** Function name: USBHostHandler
**
** Descriptions: USB host interrupt handler.
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void USBHostHandler (void) __irq
{
OHCIIntDisable();
if ( HC_INT_STAT & 0x01 ) // Scheduling overrun
{
HC_INT_STAT |= 0x01;
intOverRunCnt++;
}
if ( HC_INT_STAT & 0x02 ) // Write back done
{
HC_INT_STAT |= 0x02;
intWriteBackDoneCnt++;
}
if ( HC_INT_STAT & 0x04 ) // SOF packet
{
HC_INT_STAT |= 0x04;
intSOFCnt++;
}
if ( HC_INT_STAT & 0x08 ) // Resume detected
{
HC_INT_STAT |= 0x08;
intResumeDetectCnt++;
OHCIInit();
}
if ( HC_I
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
LPC2468/2478的USBHOST/OTG功能是一般ARM设备所不具备的,因此对其配置和使用在一些应用场合很有必要,本程序主要是在无操作系统下最小化的USBHOST/OTG解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
USB-HOST-OTG.rar (42个子文件)
USB-HOST-OTG
print
printc.c 7KB
uart.h 1KB
USB_MAIN
USB_MAIN.map 81KB
timer.d 210B
printc.crf 35KB
usbhost.d 251B
target.o 71KB
irq.d 129B
swi_handler.lst 11KB
swi_handler.o 2KB
USB_MAIN.htm 56KB
USB_MAIN_Target 1.dep 3KB
irq.crf 31KB
USB_MAIN.Uv2 3KB
target.crf 32KB
USB_MAIN.Opt 5KB
printc.d 282B
USB_MAIN.hex 36KB
USB_MAIN.axf 47KB
Startup.o 3KB
usbhost.o 78KB
timer.o 73KB
timer.crf 33KB
ExtDll.iex 19B
usbhost.crf 35KB
usb_main.crf 34KB
USB_Main.c 3KB
target.d 181B
usb_main.o 74KB
irq.o 69KB
Startup.lst 24KB
USB_MAIN.lnp 350B
USB_MAIN.sct 479B
printc.o 77KB
USB_MAIN_Opt.Bak 5KB
USB_MAIN_Uv2.Bak 3KB
usb_main.d 277B
JLinkArm_Target 1.ini 194B
USB_MAIN.plg 416B
USB_MAIN.tra 1KB
USB_SRC
usbhost.c 13KB
usbhost.h 2KB
共 42 条
- 1
资源评论
御道御小黑
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功