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

📄 uhc_ahb.c

📁 Spearhead2000的bootloader
💻 C
字号:
/********************************************************************************                                                                           ****  Copyright (c) 2005 ST Microelectronics                                   ****  All rights reserved                                                      ****                                                                           ****      Filename  :  uhc_ahb.c                                               ****      Author    :  Stefano Romano                                          ****      Revision  :  1.0                                                     ****                                                                           ****                                                                           ****                                                                           *********************************************************************************///#include "stdio.h"#include "uhc_ahb.h"#include "vic_pl190.h"#include "uart.h"#include "gp_timers.h"/******************************************************************************************************************************/static ehci_qh_t 	*QueueHead0;/********** set address *************/static ehci_qtd_t	*QTD_SA_01;static char setup_setAddress[8]  =  {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};static ehci_qtd_t	*QTD_SA_02;static char in_SA_buffer[64];/****** Get Device Descriptor *******/static ehci_qtd_t	*QTD_GDD_01;static char setup_GetDevDescr[8] =  {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00};static ehci_qtd_t	*QTD_GDD_02;static char in_GDD_buffer[64];static ehci_qtd_t	*QTD_GDD_03;static char out_GDD_buffer[64];/*** Get Configuration Descriptor ***/static ehci_qtd_t	*QTD_GCD_01;static char setup_GetConfDescr[8] =  {0x80, 0x06, 0x00, 0x02, 0x00, 0x00, 0x40, 0x00};static ehci_qtd_t	*QTD_GCD_02;static char in_GCD_buffer[64];static ehci_qtd_t	*QTD_GCD_03;static char out_GCD_buffer[64];/******************************************************************************************************************************/////////////////////////////// FUNCTs FOR USB HOST////////////////////////////void usbh_GetDescr(){}/**************************** Structures generation **************************/void do_queue(){	/************************ Prepare the "GetDescriptor out" ***********************/	/* qTD memory allocation */	QTD_GCD_03 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GCD_03 = ((int)QTD_GCD_03 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GCD_03->qtd_next      = 0x00000001;	QTD_GCD_03->qtd_altnext   = 0x00000001;	QTD_GCD_03->qtd_status    = 0x80000080;	QTD_GCD_03->qtd_buffer[0] = out_GCD_buffer;	/************************ Prepare the "Get Descriptor in" ***********************/	/* qTD memory allocation */	QTD_GCD_02 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GCD_02 = ((int)QTD_GCD_02 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GCD_02->qtd_next      = QTD_GCD_03;	QTD_GCD_02->qtd_altnext   = QTD_GCD_03;	QTD_GCD_02->qtd_status    = 0x80400180;	QTD_GCD_02->qtd_buffer[0] = in_GCD_buffer;	/************************ Prepare the "Get Descriptor setup" ***********************/	/* qTD memory allocation */	QTD_GCD_01 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GCD_01 = ((int)QTD_GCD_01 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GCD_01->qtd_next      = QTD_GCD_02;	QTD_GCD_01->qtd_altnext   = QTD_GCD_02;	QTD_GCD_01->qtd_status    = 0x00080280;	QTD_GCD_01->qtd_buffer[0] = setup_GetConfDescr;/******************************************************************************************************************************/	/************************ Prepare the "GetDescriptor out" ***********************/	/* qTD memory allocation */	QTD_GDD_03 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GDD_03 = ((int)QTD_GDD_03 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GDD_03->qtd_next      = QTD_GCD_01;	QTD_GDD_03->qtd_altnext   = QTD_GCD_01;	QTD_GDD_03->qtd_status    = 0x80000080;	QTD_GDD_03->qtd_buffer[0] = out_GDD_buffer;	/************************ Prepare the "Get Descriptor in" ***********************/	/* qTD memory allocation */	QTD_GDD_02 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GDD_02 = ((int)QTD_GDD_02 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GDD_02->qtd_next      = QTD_GDD_03;	QTD_GDD_02->qtd_altnext   = QTD_GDD_03;	QTD_GDD_02->qtd_status    = 0x80400180;	QTD_GDD_02->qtd_buffer[0] = in_GDD_buffer;	/************************ Prepare the "Get Descriptor setup" ***********************/	/* qTD memory allocation */	QTD_GDD_01 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_GDD_01 = ((int)QTD_GDD_01 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_GDD_01->qtd_next      = QTD_GDD_02;	QTD_GDD_01->qtd_altnext   = QTD_GDD_02;	QTD_GDD_01->qtd_status    = 0x00080280;	QTD_GDD_01->qtd_buffer[0] = setup_GetDevDescr;/******************************************************************************************************************************/	/************************ Prepare the "Set Address in" ****************************/	/* qTD memory allocation */	QTD_SA_02 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_SA_02 = ((int)QTD_SA_02 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_SA_02->qtd_next      = QTD_GDD_01;	QTD_SA_02->qtd_altnext   = QTD_GDD_01;	QTD_SA_02->qtd_status    = 0x80000180;	QTD_SA_02->qtd_buffer[0] = in_SA_buffer;	/************************** Prepare the "Set Address setup" **************************/	/* qTD memory allocation */	QTD_SA_01    = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0);	QTD_SA_01    = ((int)QTD_SA_01 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1);	/* qTD setting */	QTD_SA_01->qtd_next      = QTD_SA_02;	QTD_SA_01->qtd_altnext   = QTD_SA_02;	QTD_SA_01->qtd_status    = 0x00080280;	QTD_SA_01->qtd_buffer[0] = setup_setAddress;/******************************************************************************************************************************//************************** Prepare the Queue Head **************************/	/* QH memory allocation */	QueueHead0 = kmalloc(sizeof(ehci_qh_t) + EHCI_QH_ALIGN, 0);	QueueHead0 = ((int)QueueHead0 + EHCI_QH_ALIGN - 1) & ~(EHCI_QH_ALIGN - 1);	/* QH setting */	QueueHead0->qh_link    = QueueHead0;	QueueHead0->qh_link    |= 0x00000003;	QueueHead0->qh_endp    = 0xf400e000;  /* 'e' becouse this is the Head of reclamation list */	QueueHead0->qh_endphub = 0x4000ff00;	QueueHead0->qh_curqtd  = QTD_SA_01;	QueueHead0->qh_qtd     = *QTD_SA_01;/*******************************************************************/}static unsigned short USB_Connected = 0;/************************ interrupt handler ************************/void usbh_int_handler(){    volatile unsigned int irq_stat;    unsigned int i,j;     irq_stat =  UHOSTCntl->ehci_USBSTS;    if (irq_stat & EHCI_STS_INT)    {       // Clear Interrupt condition       UHOSTCntl->ehci_USBSTS = EHCI_STS_INT;    }     if (irq_stat & EHCI_STS_PCD)    {	/*put some delay*//*approx 100 ms at 266MHz*/	for(j=0;j<100*1000;j++);	for(i=0;i<250;i++);	/* handle PORT_0 */	if ((UHOSTCntl->ehci_PORTSC_0 & EHCI_PS_CS) == 0x00000001)	{		UART_tx_vec ("device detected on port 0", strlen("device detected on port 0"));				/* Clear Interrupt condition */		UHOSTCntl->ehci_PORTSC_0 |= EHCI_PS_CSC;		UHOSTCntl->ehci_USBSTS = EHCI_STS_PCD;		/* send SE0 to Device */		UHOSTCntl->ehci_PORTSC_0 |= EHCI_PS_PR;		/* Wait some mSec using Timer 1*/		//gptSetTimer(TIMER1, GPT_ENAB | GPT_SINGLE_SHOT | GPT_FREQ_187_5Khz, 1000);		gptSetTimer(TIMER1, GPT_ENAB | GPT_SINGLE_SHOT |  GPT_FREQ_259_766Khz, 1000);		while (!(gptGetTimerVal(1) == 1000));		/* Disable SE0 (reset) */		UHOSTCntl->ehci_PORTSC_0 &= ~EHCI_PS_PR;		/*Wait for port enable: bit 3 high when high speed reset ends*/		while (!((UHOSTCntl->ehci_PORTSC_0 & 0x00000004) == 0x00000004));		UART_tx_vec ("device on port 0 in HS mode", strlen("device on port 0 in HS mode"));		USB_Connected = 1;	}	else 	{		UART_tx_vec ("device on port 0 not connected ", strlen("device on port 0 not connected "));	}	/* handle PORT_1 */	if ((UHOSTCntl->ehci_PORTSC_1 & EHCI_PS_CS) == 0x00000001)	{		UART_tx_vec ("device detected on port 1", strlen("device detected on port 1"));				/* Clear Interrupt condition */		UHOSTCntl->ehci_PORTSC_1 |= EHCI_PS_CSC;		UHOSTCntl->ehci_USBSTS = EHCI_STS_PCD;		/* send SE0 to Device */		UHOSTCntl->ehci_PORTSC_1 |= EHCI_PS_PR;		/* Wait some mSec using Timer 1*/		//gptSetTimer(TIMER1, GPT_ENAB | GPT_SINGLE_SHOT | GPT_FREQ_187_5Khz, 1000);		gptSetTimer(TIMER1, GPT_ENAB | GPT_SINGLE_SHOT |  GPT_FREQ_259_766Khz, 1000);		while (!(gptGetTimerVal(1) == 1000));		/* Disable SE0 (reset) */		UHOSTCntl->ehci_PORTSC_1 &= ~EHCI_PS_PR;		/*Wait for port enable: bit 3 high when high speed reset ends*/		while (!((UHOSTCntl->ehci_PORTSC_1 & 0x00000004) == 0x00000004));		USB_Connected = 1;		UART_tx_vec ("device on port 1 in HS mode", strlen("device on port 1 in HS mode"));	}    }}/*******************************************************************//************************** init function **************************/void init_usbh(){//	UHOSTCntl->ehci_INSREG04 |= 0x00000001;//	UHOSTCntl->ehci_HCSPARAMS &= ~(0x00000010);	unsigned int	temp;		/**********************/	/* host controller run */	UHOSTCntl->ehci_USBCMD = EHCI_CMD_RS;	/***********************/	/* host controller initialization */	UHOSTCntl->ehci_USBINTR = EHCI_INTR_PCIE;	UHOSTCntl->ehci_CONFIGFLAG = EHCI_CONF_CF;	/**********************************/	//calling interrupt handler for USB host	intctlIntRegister(ITC_USBH1_int,usbh_int_handler,1);	/* host controller port power */	UHOSTCntl->ehci_PORTSC_0 |= EHCI_PS_PP;//	UHOSTCntl->ehci_PORTSC_1 |= EHCI_PS_PP;	/******************************/	/* Prepare QueueHeads and qTDs */	do_queue();	/******************************/}/*******************************************************************//***************** comunication: run queue head ********************/void runQueueHead(){    	volatile unsigned int delay;	while (!USB_Connected);		/* Set asynlistaddr */	UHOSTCntl->ehci_ASYNLISTADDR = QueueHead0;	/********************/        /*Wait for some uSOF before start Async Schedule*/	delay = UHOSTCntl->ehci_FRINDEX;        while (UHOSTCntl->ehci_FRINDEX <= (delay + 5));  /* 5 ok for bard */                /***********************************************/       	/* Async schedule enable */	UHOSTCntl->ehci_USBCMD |= EHCI_CMD_ASE;	/*************************/ }/*******************************************************************/

⌨️ 快捷键说明

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