uhc_ahb.c.svn-base
来自「Spearhead2000 的 USB驱动程序」· SVN-BASE 代码 · 共 897 行 · 第 1/3 页
SVN-BASE
897 行
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 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 = 0xf400e001; /* 'e' becouse this is the Head of reclamation list */ QueueHead0->qh_endphub = 0x4000ff00; QueueHead0->qh_curqtd = QTD_GDD_01; QueueHead0->qh_qtd = *QTD_GDD_01; /* 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; /*************************/ //wait till set configuration complete while(!(UHOSTCntl->ehci_USBSTS & EHCI_STS_INT)); UHOSTCntl->ehci_USBSTS |= EHCI_STS_INT; kfree(QTD_SA_02); kfree(QTD_SA_01); kfree(QueueHead0); kfree(QTD_SCV_02); kfree(QTD_SCV_01); kfree(QTD_GCD_03); kfree(QTD_GCD_02); kfree(QTD_GCD_01); kfree(QTD_GDD_03); kfree(QTD_GDD_02); kfree(QTD_GDD_01); }static unsigned short USB_Connected = 0;static unsigned short device_enumerated = 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) { if ((unsigned int)UHOSTCntl == EHCI_Base0) UART_tx_vec ("device detected on port 0", strlen("device detected on port 0")); else UART_tx_vec ("device detected on port 1", strlen("device detected on port 1")); /* 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)); if ((unsigned int)UHOSTCntl == EHCI_Base0) UART_tx_vec ("device on port 0 in HS mode", strlen("device on port 0 in HS mode")); else UART_tx_vec ("device on port 1 in HS mode", strlen("device on port 1 in HS mode")); USB_Connected = 1; } else { /* Clear Interrupt condition */ UHOSTCntl->ehci_PORTSC_0 |= EHCI_PS_CSC; UHOSTCntl->ehci_USBSTS = EHCI_STS_PCD; if ((unsigned int)UHOSTCntl == EHCI_Base0) UART_tx_vec ("device on port 0 not connected ", strlen("device on port 0 not connected ")); else UART_tx_vec ("device on port 1 not connected ", strlen("device on port 1 not connected ")); }#if 0 /* 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")); } else { /* Clear Interrupt condition */ UHOSTCntl->ehci_PORTSC_1 |= EHCI_PS_CSC; UHOSTCntl->ehci_USBSTS = EHCI_STS_PCD; UART_tx_vec ("device on port 1 not connected ", strlen("device on port 1 not connected ")); }#endif }}#if 0/*******************************************************************//************************** init function **************************/void init_usbh(){// UHOSTCntl->ehci_INSREG04 |= 0x00000001;// UHOSTCntl->ehci_HCSPARAMS &= ~(0x00000010); /**********************/ /* 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; /*************************/ }#endif/*******************************************************************/static void send_get_descriptor(){ unsigned int delay; /************************ 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 = 0x00000001; QTD_GDD_03->qtd_altnext = 0x00000001; 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 = 0x80000180 | (DEV_DESC_LEN_LB<<16) | (DEV_DESC_LEN_UB<<24); 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 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_GDD_01; QueueHead0->qh_qtd = *QTD_GDD_01; /* 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; /*************************/ kfree(QTD_GDD_03); kfree(QTD_GDD_02); kfree(QTD_GDD_01); kfree(QueueHead0); }enum hc_test_mode{ TEST_J = 1, TEST_K, TEST_SE0_NAK, TEST_PACKET, TEST_FORCE_ENABLE};static void set_port_power(){ /* host controller port power */ UHOSTCntl->ehci_PORTSC_0 |= EHCI_PS_PP; /* Wait some mSec using Timer 1*/ gptSetTimer(TIMER1, GPT_ENAB | GPT_SINGLE_SHOT | GPT_FREQ_259_766Khz, 1000); while (!(gptGetTimerVal(1) == 1000));}static void set_port_enable(){ /* 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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?