📄 uhc_ahb.c.svn-base
字号:
/******************************************************************************** **** 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"/******************************************************************************************************************************///device descriptor length :lower and upper bytes#define DEV_DESC_LEN_LB 18#define DEV_DESC_LEN_UB 0//configuration descriptor length :lower and upper bytes#define CONFIG_DESC_LEN_LB 32#define CONFIG_DESC_LEN_UB 0//configuration value : lower and upper bytes#define CONFIG_VAL_LB 1#define CONFIG_VAL_UB 0 static ehci_qh_t *QueueHead0;/********** set address *************/static ehci_qtd_t *QTD_SA_01;static char setup_setAddress[8] = {0x00, 0x05, 0x01, 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, DEV_DESC_LEN_LB, DEV_DESC_LEN_UB};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, CONFIG_DESC_LEN_LB, CONFIG_DESC_LEN_UB};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];/*** Set Configuration ***/static ehci_qtd_t *QTD_SCV_01;static char setup_SetConfValue[8] = {0x00, 0x09, CONFIG_VAL_LB,CONFIG_VAL_UB, 0x00, 0x00, 0x00, 0x00};static ehci_qtd_t *QTD_SCV_02;static char in_SCV_buffer[64];#if 0/******************************************************************************************************************************/////////////////////////////// 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;/*******************************************************************/}#endifstatic void enumerate_device(){ unsigned int delay; /************************ 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 = 0x00000001; QTD_SA_02->qtd_altnext = 0x00000001; QTD_SA_02->qtd_status = 0x80008180; 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; /* 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 address complete while(!(UHOSTCntl->ehci_USBSTS & EHCI_STS_INT)); UHOSTCntl->ehci_USBSTS |= EHCI_STS_INT; UHOSTCntl->ehci_USBCMD &= ~EHCI_CMD_ASE; /************************ Prepare the "Set Configuration in" ***********************/ /* qTD memory allocation */ QTD_SCV_02 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0); QTD_SCV_02 = ((int)QTD_SCV_02 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1); /* qTD setting */ QTD_SCV_02->qtd_next = 0x00000001; QTD_SCV_02->qtd_altnext = 0x00000001; QTD_SCV_02->qtd_status = 0x80008180; QTD_SCV_02->qtd_buffer[0] = in_SCV_buffer; /************************ Prepare the "Set Configuration Setup" ***********************/ /* qTD memory allocation */ QTD_SCV_01 = kmalloc(sizeof(ehci_qtd_t) + EHCI_QTD_ALIGN, 0); QTD_SCV_01 = ((int)QTD_SCV_01 + EHCI_QTD_ALIGN - 1) & ~(EHCI_QTD_ALIGN - 1); /* qTD setting */ QTD_SCV_01->qtd_next = QTD_SCV_02; QTD_SCV_01->qtd_altnext = QTD_SCV_02; QTD_SCV_01->qtd_status = 0x00080280; QTD_SCV_01->qtd_buffer[0] = setup_SetConfValue; /************************ 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 = QTD_SCV_01; QTD_GCD_03->qtd_altnext = QTD_SCV_01; 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 = 0x80000180 | (CONFIG_DESC_LEN_LB<<16) | (CONFIG_DESC_LEN_UB<<24); 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 = 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -