📄 usb_transaction_layer.c
字号:
case CONF_DESC: /* configuration descriptor*/ tl_handle_get_config_desc(CONF_DESC); break; case STRING_DESC: /* string descriptor*/ tl_handle_get_string_desc(); break; case DEVICE_QUALIFIER: tl_handle_get_device_qf_desc(); /* device qualifier descriptor */ break; case OTHER_SPEED_CONF_DESC: tl_handle_get_config_desc(OTHER_SPEED_CONF_DESC); /* other speed configuration descriptor */ break; default: /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); break; }}/*==================================================================================================FUNCTION: tl_handle_set_configurationDESCRIPTION: This function Handle the SET CONFIGURATION requestARGUMENTS PASSED: None RETURN VALUE: None IMPORTANT NOTES: None ==================================================================================================*/void tl_handle_set_configuration(){ usb_end_pt_info_t config_data ; U8 i; switch (g_usb_dev_state) { case USB_DEV_ADDRESSED_STATE : if (g_usb_setup_data[WVALUE_LOWBYTE] == USB_DEV_VALUE_OF_UNCONFIG) { /* Send Ack to Host*/ tl_status_phase(IN); } /* Check if the configuration value received request is same as in Config descriptor */ else if(g_usb_setup_data[WVALUE_LOWBYTE] == g_usb_desc.config_desc->configuration_value) {#ifndef SIMULATOR_TESTING /* Configure endpoints */ for ( i = 0 ; i< g_number_of_endpoints ; i++) { config_data.end_pt_no = g_end_pt_info[i].end_pt_no; config_data.direction = g_end_pt_info[i].direction; config_data.transfer_type = g_end_pt_info[i].transfer_type; config_data.max_pkt_size = g_end_pt_info[i].max_pkt_size; ipl_set_configuration(&config_data); }#endif /* Send Ack to Host*/ tl_status_phase(IN); g_usb_dev_state = USB_DEV_CONFIGURED_STATE ; } else { /* Invalid configuration value. Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); } break; case USB_DEV_CONFIGURED_STATE : if(g_usb_setup_data[WVALUE_LOWBYTE] == USB_DEV_CONFIG_DESC_CONFIG_VALUE) { /* Send Ack to Host*/ tl_status_phase(IN); } else if (g_usb_setup_data[WVALUE_LOWBYTE] == USB_DEV_VALUE_OF_UNCONFIG) { /* Send Ack to Host*/ tl_status_phase(IN); /* Change USB State to Addressed State */ g_usb_dev_state = USB_DEV_ADDRESSED_STATE; } break; default : /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); break; }}/*==================================================================================================FUNCTION: tl_handle_get_configurationDESCRIPTION: This function Handle the GET CONFIGURATION requestARGUMENTS PASSED: None RETURN VALUE: None IMPORTANT NOTES: None ==================================================================================================*/void tl_handle_get_configuration(void){ usb_buffer_descriptor_t bd; U32 buffer_addrs; U32* buffer_ptr; if((g_usb_setup_data[WINDEX_LOWBYTE] == 0) && (g_usb_setup_data[WINDEX_HIGHBYTE] == 0) && (g_usb_setup_data[WVALUE_LOWBYTE] == 0) && (g_usb_setup_data[WVALUE_HIGHBYTE] == 0) && (g_usb_setup_data[WLENGTH_LOWBYTE] == LEN_OF_CONFIG_VALUE) && (g_usb_setup_data[WLENGTH_HIGHBYTE] == 0)) { switch(g_usb_dev_state) { case USB_DEV_DEFAULT_STATE : /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); break; case USB_DEV_ADDRESSED_STATE: /* If the Device is in Address state then return 0x0 : See USB2.0 Spec */ buffer_addrs = ipl_get_ep0_rxtx_buffer(); buffer_ptr = (U32 *)buffer_addrs; *buffer_ptr = 0x0; bd.buffer = buffer_ptr; bd.size=LEN_OF_CONFIG_VALUE; ipl_send_data(EP0,&bd,FALSE); /* Receive Ack from Host*/ tl_status_phase(OUT); break; case USB_DEV_CONFIGURED_STATE: buffer_addrs = ipl_get_ep0_rxtx_buffer(); buffer_ptr = (U32 *)buffer_addrs; *buffer_ptr = (UINT32 )g_usb_desc.config_desc->configuration_value; bd.buffer = buffer_ptr; bd.size=LEN_OF_CONFIG_VALUE; ipl_send_data(EP0,&bd,FALSE); /* Receive Ack from Host*/ tl_status_phase(OUT); break; default: /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); } } }/*==================================================================================================FUNCTION: tl_handle_set_addrsDESCRIPTION: This function Handle the SET ADDRESS Request from USB HostARGUMENTS PASSED: None RETURN VALUE: None IMPORTANT NOTES: ==================================================================================================*/void tl_handle_set_addrs(){ U16 device_addrs; /* Get the Device Address to be SET from the Setup Data */ device_addrs = g_usb_setup_data[WVALUE_LOWBYTE] + (g_usb_setup_data[WVALUE_HIGHBYTE]<<8); 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) && (device_addrs <= USB_MAX_DEVICE_ADDR)) { switch(g_usb_dev_state) { case USB_DEV_DEFAULT_STATE : /* Send Ack to Host */ tl_status_phase(IN); if (device_addrs == USB_DEFAULT_ADDR) { /* no handling needed */ } else { /* Set the Device Address */ ipl_set_device_address(device_addrs); /* Change state to ADDRESSED STATE */ g_usb_dev_state = USB_DEV_ADDRESSED_STATE; } break; case USB_DEV_ADDRESSED_STATE : /* Send Ack to Host */ tl_status_phase(IN); if ( device_addrs == USB_DEFAULT_ADDR ) { /* Set the Device Address */ ipl_set_device_address(USB_DEFAULT_ADDR); /* Change state to ADDRESSED STATE */ g_usb_dev_state = USB_DEV_DEFAULT_STATE; } else { /* Set the Device Address */ ipl_set_device_address(device_addrs); } break; case USB_DEV_CONFIGURED_STATE : /* Send Ack to Host */ tl_status_phase(IN); if ( device_addrs == USB_DEFAULT_ADDR) { /* Set the Device Address */ ipl_set_device_address(device_addrs); /* Change state to ADDRESSED STATE */ g_usb_dev_state = USB_DEV_DEFAULT_STATE; } else { /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); } default : break; } } else { /* Send STALL Handshake */ ipl_send_stall_handshake(EP0,OUT); } }/*==================================================================================================FUNCTION: tl_handle_get_device_descDESCRIPTION: This function Handle the GET DEVICE DESCRIPTOR requestARGUMENTS PASSED: None RETURN VALUE: None IMPORTANT NOTES: None ==================================================================================================*/void tl_handle_get_device_desc(void){ usb_buffer_descriptor_t bd ; U32 buffer_addrs; U16 desc_length = 0x0; BOOL zlt = FALSE; /* get the buffer address for data transfer over EP0 */ buffer_addrs = ipl_get_ep0_rxtx_buffer(); /* Fill the buffer with the descriptor data */ tl_fill_buffer_ep0in(FILL_DEVICE_DESC,buffer_addrs); /* Get the length of descriptor requested */ desc_length = g_usb_setup_data[WLENGTH_LOWBYTE]; desc_length |= ( g_usb_setup_data[WLENGTH_HIGHBYTE] <<0x8); /* If requested length of descriptor is lesser than actual length of descriotor then send * requested length of descroptor only else send the actual length of descriptor*/#ifdef SIMULATOR_TESTING if(desc_length <= g_usb_desc.device_desc->length) { bd.size = desc_length; } else { bd.size = g_usb_desc.device_desc->length; if ( bd.size > 8) { zlt = TRUE; } }#else if( g_usb_dev_state == USB_DEV_DEFAULT_STATE ) { bd.size = MPS_8; } else { bd.size = USB_DEV_DESC_LEN; }#endif /* Send descriptor */ ipl_send_data(EP0,&bd,zlt); /* Status Phase -- OUT */ tl_status_phase(OUT); }/*==================================================================================================FUNCTION: tl_handle_get_device_qf_descDESCRIPTION: This function Handle the GET DEVICE QUALIFIER DESCRIPTOR requestARGUMENTS PASSED: None RETURN VALUE: None IMPORTANT NOTES: None ==================================================================================================*/void tl_handle_get_device_qf_desc(void){ usb_buffer_descriptor_t bd ; U32 buffer_addrs; U16 desc_length = 0x0; BOOL zlt = FALSE; /* get the buffer address for data transfer over EP0 */ buffer_addrs = ipl_get_ep0_rxtx_buffer(); /* Fill the buffer with the descriptor data */ tl_fill_buffer_ep0in(FILL_DEVICE_QF_DESC,buffer_addrs); /* Get the length of descriptor requested */ desc_length = g_usb_setup_data[WLENGTH_LOWBYTE]; desc_length |= ( g_usb_setup_data[WLENGTH_HIGHBYTE] <<0x8); /* If requested length of descriptor is lesser than actual length of descriotor then send * requested length of descroptor only else send the actual length of descriptor*/ if(desc_length <= g_usb_desc.device_qf_desc->length) { bd.size = desc_length; } else { bd.size = g_usb_desc.device_qf_desc->length; if ( bd.size > MPS_64) { zlt = TRUE; } } /* Send descriptor */ ipl_send_data(EP0,&bd,zlt); /* Status Phase -- OUT */ tl_status_phase(OUT); }/*==================================================================================================FUNCTION: tl_handle_get_config_descDESCRIPTION: This function Handle the GET CONFIGURATION DESCRIPTOR request
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -