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

📄 usb_transaction_layer.c

📁 freescale atk source code
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* Check the type of interface selected i.e FS or HS */    hs_interface = ipl_is_interface_high_speed();       /* Select the common descriptors , these descriptor are independent of speed and security mode */     g_usb_desc.device_desc = &g_usb_device_desc ;    g_usb_desc.device_qf_desc = &g_usb_device_qf_desc;    g_usb_desc.str_desc0 = &g_usb_otg_str0_desc;    g_usb_desc.str_desc1 = &g_usb_otg_string_desc1;    g_usb_desc.str_desc3 = &g_usb_otg_string_desc3;    type = (U8)(*((volatile U8*)0x53FF0810));    type &= 0xF;	    switch(type)    {        case HAB_SEC_DISABLED:            /* Select the descriptors which are specific to Non Secure Boot */            g_usb_desc.str_desc2 = &g_usb_otg_string_desc2_ns;            if(hs_interface)            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_hs_ns;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_fs_ns;            }            else            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_fs_ns;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_hs_ns;            }        break;                 case HAB_ENGINEERING:            /* Select the descriptors which are specific to Secure Engineering Boot */            g_usb_desc.str_desc2 = &g_usb_otg_string_desc2_se;            if(hs_interface)            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_hs_s;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_fs_s;            }            else            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_fs_s;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_hs_s;            }        default:            /* Select the descriptors which are specific to Secure Production Boot */            g_usb_desc.str_desc2 = &g_usb_otg_string_desc2_sp;            if(hs_interface)            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_hs_s;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_fs_s;            }            else            {                /* Selct the descriptors which are speed dependent also */                g_usb_desc.config_desc = &g_usb_config_desc_fs_s;                g_usb_desc.ot_speed_config_desc = &g_usb_config_desc_hs_s;            }        break;    }         /* Get Number of Endpoints supported from Configuration Descriptor ( Use Secure Config Descriptor as Endpoint information for       both Secure and Non Secure is same */    g_number_of_endpoints = g_usb_desc.config_desc->usb_interface_desc.num_of_endpts;      /* Store the Endpoint specific information in local variable structure to this Layer */    for ( i = 0 ; i< g_number_of_endpoints ; i++)    {        g_end_pt_info[i].end_pt_no = ((g_usb_desc.config_desc->usb_endpoint_desc[i].endpoint_addrs) & ENDPT_NUMBER_MASK);    		g_end_pt_info[i].direction = (((g_usb_desc.config_desc->usb_endpoint_desc[i].endpoint_addrs) & ENDPT_DIR_MASK )>>ENDPT_DIR_SHIFT);		g_end_pt_info[i].transfer_type = (g_usb_desc.config_desc->usb_endpoint_desc[i].attributes & ENDPT_TRNS_TYPE_MASK);		g_end_pt_info[i].max_pkt_size = ((g_usb_desc.config_desc->usb_endpoint_desc[i].max_pkt_size_l) | (( g_usb_desc.config_desc->usb_endpoint_desc[i].max_pkt_size_h ) << 8 ));    }}/*==================================================================================================FUNCTION: tl_get_stateDESCRIPTION:    	This function return the current state of USB Bus.ARGUMENTS PASSED:	None  RETURN VALUE:	usb_state_t  g_usb_dev_state : State of the USB Bus .  	IMPORTANT NOTES:	==================================================================================================*/usb_state_ttl_get_state(void){    return g_usb_dev_state;}/*==================================================================================================FUNCTION: tl_configureDESCRIPTION:    	This function Does the enumeration of the USB . ARGUMENTS PASSED:	None  RETURN VALUE:	None	IMPORTANT NOTES:	==================================================================================================*/voidtl_configure(void){#ifdef SIMULATOR_TESTING    int i;#endif    while(g_usb_dev_state!= USB_DEV_CONFIGURED_STATE)    {        /* Check if Bus Reset Received */        if(ipl_check_bus_reset() == TRUE)        {    	    /* Handle Bus Reset */            tl_handle_bus_reset();         }	    #ifdef SIMULATOR_TESTING        /* Required to wait endlessly for setup pkt , not checking for reset as per behavior in simulator */        while(g_usb_dev_state != USB_DEV_CONFIGURED_STATE)        {#endif            /* Check if Reset is already received and Setup Token Received */            if((g_usb_dev_state != USB_DEV_DUMMY_STATE) && (ipl_check_setup_token() == TRUE))            {	            /* Handle Setup Token */                tl_handle_setup_phase();            }#ifdef SIMULATOR_TESTING        }    /* Delay needs to be introduced for CORE simulated in simulator to reach DONE state */    for(i =0;i<1000000;i++);#endif    }}/*==================================================================================================FUNCTION: tl_send_dataDESCRIPTION:    	This function Handle the Send Request on USB Bus ARGUMENTS PASSED:	usb_buffer_descriptor_t* bd  RETURN VALUE:	IMPORTANT NOTES:	==================================================================================================*/usb_status_ttl_send_data(usb_buffer_descriptor_t* bd){    usb_status_t status = USB_FAILURE;    U8 i,endpoint = 0x0;#ifndef SIMULATOR_TESTING        /* Check if Bus Reset Received */    if(ipl_check_bus_reset() == TRUE)    {	/* Handle Bus Reset and return Failure*/        tl_handle_bus_reset();     }    /* Check if set up token Received */    else if(ipl_check_setup_token() == TRUE)    {	/* Handle the setup token*/        tl_handle_setup_phase();     }#endif     /* Check the State of USB . If It is in  configured state than send data */    if ( g_usb_dev_state == USB_DEV_CONFIGURED_STATE )    {        /* buffer pointer should not be NULL */        if( bd->buffer != NULL )	{	    /* Get the endpoint number which is configured for IN */	    for ( i = 0 ; i< g_number_of_endpoints ; i++)	    {                if(g_end_pt_info[i].direction == IN)		{		    endpoint = g_end_pt_info[i].end_pt_no;		    break;		}		    	    }	    /* Check for endpoint number */	    if(endpoint)	    {		/* Send Data */                status = (usb_status_t )ipl_send_data(endpoint,bd,FALSE);	    }	    else	    {	        status = USB_INVALID; /* If no endpoint is configured */	    }	}	else	{	    status = USB_INVALID; /* if the buffer pointer is NULL */	}    }    return(status);}/*==================================================================================================FUNCTION: tl_receive_dataDESCRIPTION: 	This Function Handles the received request on usb busARGUMENTS PASSED:	usb_buffer_descriptor_t* bd  RETURN VALUE:	IMPORTANT NOTES:	==================================================================================================*/usb_status_ttl_receive_data(usb_buffer_descriptor_t* bd){    usb_status_t status = USB_FAILURE;     U8 i,endpoint = 0x0;#ifndef SIMULATOR_TESTING       /* Check if Bus Reset Received  */    if(ipl_check_bus_reset() == TRUE)    {	/* Handle Bus Reset and return Failure */        tl_handle_bus_reset();     }    /* Check if set up token Received. */    else if(ipl_check_setup_token() == TRUE)    {	/* Handle the setup token */        tl_handle_setup_phase();     }#endif    /* Check the State of USB . If It is in  configured state than receive data */    if ( g_usb_dev_state == USB_DEV_CONFIGURED_STATE )    {        /* buffer pointer should not be NULL */	if( bd->buffer != NULL )	{	    /* Get the endpoint number which is configured for OUT */	    for ( i = 0 ; i< g_number_of_endpoints ; i++)	    {                if(g_end_pt_info[i].direction == OUT)		{		    endpoint = g_end_pt_info[i].end_pt_no;		    break;		}		    	    }	    /* endpoint number should not be EP0 */	    if(endpoint)	    {		/* Receive data */                status = (usb_status_t )ipl_receive_data(endpoint,bd);	    }	    else	    {	        status = USB_INVALID; /* If no endpoint is configured */	    }	}	else	{	    status = USB_INVALID; /* if the buffer pointer is NULL */	}    }    return(status);}/*==================================================================================================FUNCTION: tl_handle_setup_phaseDESCRIPTION:    	This function Handle the Setup Token from USB HostARGUMENTS PASSED:	None  RETURN VALUE:	None	IMPORTANT NOTES:	==================================================================================================*/void tl_handle_setup_phase(void){    usb_buffer_descriptor_t bd ;    usb_status_t status;    int i;    /* Receive the SetUp Data */    bd.buffer = (P_U32)g_usb_setup_data;    bd.size   = 0;    status = ipl_receive_setup_data(&bd);		/*for (i=0; i< SETUP_DATA_LENGTH; i++)		printf("g_usb_setup[%d]:0x%x \n",i, g_usb_setup_data[i]);*/		    if( status == USB_SUCCESS)    {         /* Parser the Setup Request Type */        switch (g_usb_setup_data[BREQUEST])                     {             case USB_GET_DESCRIPTOR:                /* Handle the GET DESCRIPTOR Request */	        tl_handle_get_descriptor();	       // 	printf("tl_handle_get_descriptor \n ");	    break;		    case USB_SET_ADDRESS:                /* Handle the SET ADDRESS Request */	        tl_handle_set_addrs();             //printf("tl_handle_set_addrs \n ");		    break;	    	    case USB_SET_CONFIGURATION:                /* Handle the SET CONFIGURATION Request */	        if ((g_usb_setup_data[WINDEX_LOWBYTE] == 0) &&                    (g_usb_setup_data[WINDEX_HIGHBYTE] == 0) &&                    (g_usb_setup_data[WLENGTH_LOWBYTE] == 0) &&                    (g_usb_setup_data[WLENGTH_HIGHBYTE] == 0) &&                    (g_usb_setup_data[WVALUE_HIGHBYTE] == 0)) 	        {                    tl_handle_set_configuration();                    //printf("tl_handle_set_configuration \n ");		        }	        else	        {	            /* Send STALL Handshake   */	            ipl_send_stall_handshake(EP0,OUT);	            //printf("ipl_send_stall_handshake \n ");		        }	    break;	    case USB_GET_CONFIGURATION:	        /* GET CONFIGURATION request handler */	        tl_handle_get_configuration();	        //printf("tl_handle_get_configuration \n ");		    default:		        /* Send STALL Handshake   */	        ipl_send_stall_handshake(EP0,OUT);	        //printf("ipl_send_stall_handshake \n ");	    break;	}     /* service watch dog */	         	*(volatile U16 *)0x53FDC002 = 0x5555; 		*(volatile U16 *)0x53FDC002 = 0xAAAA;    }    	}/*==================================================================================================FUNCTION: tl_handle_get_descriptorDESCRIPTION:    	This function Handle the GET DESCRIPTOR requestARGUMENTS PASSED:	None  RETURN VALUE:	None	IMPORTANT NOTES:	None		==================================================================================================*/void tl_handle_get_descriptor(){    switch (g_usb_setup_data[WVALUE_HIGHBYTE])    {        case DEVICE_DESC:  	/* device descriptor*/			            tl_handle_get_device_desc();	    break;

⌨️ 快捷键说明

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