📄 usb_task.c
字号:
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
// add for SRP test, In real case, this should check OTG status first
case MSG_ID_SRP_INIT:
#ifdef __OTG_ENABLE__
if( (OTG_Get_Plug_Type()==OTG_PLUG_B) &&
((OTG_Get_State()==OTG_STATE_START) || (OTG_Get_State()==OTG_STATE_B_IDLE)))
{
if(g_UsbMode.b_start_srp==KAL_TRUE)
{
/* It means user select to start SRP
but not config function(MS, CDC ACM)*/
#ifndef OTG_NORMAL_APP_FIXED
/* Notify UEM plug out first, otherwise next plug in will make MMI assert */
USB_Send_Msg(USB_SEND_MSG_PLUG_OUT, 0, KAL_TRUE);
#endif
}
OTG_Start_SRP();
#ifdef OTG_SRP_HNP_APP_FIXED
OTG_Config_SRP(USB_MASS_STORAGE, g_USB_Mass_Buffer);
#else
/* Notify UEM*/
USB_Send_Msg(USB_SEND_MSG_PLUG_IN, 0, KAL_TRUE);
#endif
}
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
/* mass storage client messages */
case MSG_ID_USB_MSDRV_REC_DONE_CONF:
case MSG_ID_USB_MSDRV_TRX_DONE_CONF:
/* After USB_reset HISR and before stop DMA, a DMA callbcak happen,
this callback message may come after reset message, and make MS state machine error */
if (gUsbDevice.nDevState != DEVSTATE_CONFIG)
break;
case MSG_ID_USB_RESET_IND:
if (gUsbDevice.device_type == USB_MASS_STORAGE)
{
USB_Ms_State_Main(¤t_ilm);
}
else if (gUsbDevice.device_type != USB_UNKOWN) /* be configured as MS_STOP mode */
{
EXT_ASSERT(0, gUsbDevice.device_type, 0, 0);
}
break;
/* mass storage host messages */
case MSG_ID_USB_MSHOST_START_IND:
#ifdef __OTG_ENABLE__
USB_Host_Ms_State_Start();
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
case MSG_ID_USB_MSHOST_QUERY_IND:
#ifdef __OTG_ENABLE__
USB_Host_Ms_State_Main();
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
#ifdef WEBCAM_SUPPORT
/* video class related messages */
case MSG_ID_USB_MED_SET_CAMERA_ATTR_CNF:
case MSG_ID_USB_ENUM_DONE:
case MSG_ID_MED_USB_START_VIDEO_REQ:
case MSG_ID_USB_VIDEO_COMPLETE:
case MSG_ID_USB_VIDEO_DMA_DONE:
case MSG_ID_USB_VIDEO_CHANGE_SIZE:
case MSG_ID_USB_STILL_CAPTURE:
case MSG_ID_USB_STILL_COMPLETE:
case MSG_ID_USB_VIDEO_STILL_DMA_DONE:
case MSG_ID_USB_VIDEO_STILL_DMA_PARTIAL:
case MSG_ID_MED_USB_DEVICE_STILL_REQ:
case MSG_ID_MED_USB_PAUSE_REQ:
case MSG_ID_USB_VIDEO_INCALL_DMA_DONE:
case MSG_ID_USB_VIDEO_INCALL_TIMEOUT:
case MSG_ID_USB_VIDEO_INCALL_CHANGE_SIZE:
case MSG_ID_MED_USB_RESUME_VIDEO_REQ:
/* If device type is no longer video because of plugging out cable, still return error message to media task*/
USBVideo_Parse_Med_Msg(¤t_ilm, gUsbDevice.device_type);
break;
case MSG_ID_USB_VIDEO_ABORT: /* OS sleep and then wakeup, reset USB, called at USBVideo_VS_If_Reset() */
case MSG_ID_MED_USB_STOP_REQ: /* media task want to stop webcam */
if(gUsbDevice.device_type == USB_VIDEO) /* USB cable does not be plugged out */
{
USB_Release_Type(KAL_TRUE, KAL_FALSE); /* disable D+ pull high, but plug out is false */
}
/* In order to return corresponding error message to media task */
USBVideo_Parse_Med_Msg(¤t_ilm, gUsbDevice.device_type);/*device type as UNKNOWN */
break;
#endif /* WEBCAM_SUPPORT */
#ifdef PICTBRIDGE_SUPPORT
case MSG_ID_USB_PTPIMAGE_DATA_RX_DONE_CONF:
case MSG_ID_USB_PTPIMAGE_DMA_TX_DONE_CONF:
if (gUsbDevice.nDevState != DEVSTATE_CONFIG)
break;
case MSG_ID_USB_PTPIMAGE_RESET_IND:
if (gUsbDevice.device_type == USB_IMAGE)
{
PTP_Parse_USB_Meg(¤t_ilm);
}
else
{
EXT_ASSERT(0, gUsbDevice.device_type, 0, 0);
}
break;
case MSG_ID_MMI_USB_DPS_HREQUEST_CONF:
case MSG_ID_MMI_USB_DPS_HRESPONSE_CONF:
case MSG_ID_MMI_USB_DPS_DREQUEST_REQ:
case MSG_ID_MMI_USB_DPS_DRESPONSE_REQ:
case MSG_ID_MMI_USB_START_JOB_IND:
case MSG_ID_MMI_USB_CLOSE_JOB_IND:
if (gUsbDevice.nDevState != DEVSTATE_CONFIG)
break;
if (gUsbDevice.device_type == USB_IMAGE)
{
PTP_Parse_MMI_Meg(¤t_ilm);
}
else
{
EXT_ASSERT(0, gUsbDevice.device_type, 0, 0);
}
break;
case MSG_ID_MMI_USB_IMAGE_STOP_REQ: /* mmi want to stop PICTBRIDGE function */
if (gUsbDevice.nDevState != DEVSTATE_CONFIG)
break;
if(gUsbDevice.device_type == USB_IMAGE) /* USB cable does not be plugged out yet*/
{
USB_Release_Type(KAL_TRUE, KAL_FALSE); /* disable D+ pull high, but plug out is false */
}
/* some confirm messages */
/* release buffer */
break;
#endif /* PICTBRIDGE_SUPPORT */
#ifdef __DSPIRDBG__
case MSG_ID_USB_IRDGB_START_IND:
USB_DSPIRDBG_Start();
break;
#endif /* __DSPIRDBG__*/
default:
EXT_ASSERT(0, current_ilm.msg_id, 0, 0);
break;
}
free_ilm(¤t_ilm);
}
}
/************************************************************
serial string functions
*************************************************************/
/*store unique data to serial string*/
/*this function is used for normal mode, NVRAM task respondes the string by message*/
static void USB_Store_Serial_Value(ilm_struct *ilm_ptr)
{
kal_uint16 len;
nvram_read_cnf_struct *parm_ptr = (nvram_read_cnf_struct *) ilm_ptr->local_para_ptr;
kal_uint8 *pdu_ptr = get_pdu_ptr(ilm_ptr->peer_buff_ptr, &len);
if( (parm_ptr->result == NVRAM_IO_ERRNO_OK) || (parm_ptr->result ==NVRAM_IO_ERRNO_INIT) )
{
//construct serial string
USB_Constrct_Serial_String(pdu_ptr, len);
}
else
EXT_ASSERT(0, 0, 0, 0);
}
/*get and store unique data to serial string*/
/*this function is used for mass storage mode because NAVRAM task not created in mass storage mode*/
void USB_Get_Serial_Value(void)
{
kal_uint8 *serial_buf;
kal_uint16 record, size;
if(nvram_get_info(UNI_ID, &record, &size)!=NVRAM_ERRNO_SUCCESS)
EXT_ASSERT(0, 0, 0, 0);
serial_buf = get_ctrl_buffer(size);
/* read unique string data from NVRAM, and construct USB serial string before init mass sotrage*/
if( nvram_usb_read_data(UNI_ID, serial_buf, size) == KAL_TRUE )
{
USB_Constrct_Serial_String(serial_buf, size);
}
else
{
EXT_ASSERT(0, 0, 0, 0);
}
free_ctrl_buffer(serial_buf);
}
/* convert from val to string type (ascii code)*/
static kal_uint16 USB_Convert_String(kal_uint8 val)
{
kal_uint16 ret;
if(val>0xf)
ASSERT(0);
/* convert to a-f ascii code*/
if(val>=0xa)
ret = val - 0xa + 0x61;
/* convert to 0-9 ascii code*/
else
ret = val + 0x30;
return ret;
}
/* convert from unique charaters to serial string for USB*/
static void USB_Constrct_Serial_String(kal_uint8 *pdu_ptr, kal_uint16 len)
{
kal_uint32 i;
kal_uint32 serial_len;
if(len==0)
ASSERT(0);
/* length must be even */
if((USB_SERIAL_STRING_LEN&0x1)!=0)
EXT_ASSERT(0, USB_SERIAL_STRING_LEN, 0, 0);
serial_len = (len< (USB_SERIAL_STRING_LEN>>1)) ? len:(USB_SERIAL_STRING_LEN>>1);
/* string type and length*/
gUsbDevice.serial_string[0] = 0x0320;
/* conver from pdu_ptr to USB serial string*/
for(i=0; i<(serial_len-1); i++)
{
gUsbDevice.serial_string[(i<<1)+1] = USB_Convert_String((pdu_ptr[i]&0xf0)>>4);
gUsbDevice.serial_string[(i<<1)+2] = USB_Convert_String(pdu_ptr[i]&0xf);
}
gUsbDevice.serial_string[((serial_len-1)<<1)+1] = USB_Convert_String((pdu_ptr[(serial_len-1)]&0xf0)>>4);
}
/************************************************************
cable and message uitility functions
*************************************************************/
/* send message to other tasks*/
void USB_Send_Msg(USB_SEND_MSG_TYPE msg_type, kal_uint8 mode, kal_bool result)
{
drvuem_usbdetect_ind_struct *usbdetect_req;
uart_plugout_ind_struct *uart_plug_out_ind;
local_para_struct *local_ptr = NULL;
ilm_struct *USB_ilm;
drvuem_usbcfg_cnf_struct *USB_Prim;
kal_uint16 record, size;
if(msg_type == USB_SEND_MSG_PLUG_IN)
{
/*Notify UEM*/
/* for USB_UNKOWN, show selection screen*/
/* for USB_MASS_STORAGE, UEM latch power*/
usbdetect_req = (drvuem_usbdetect_ind_struct*)construct_local_para(
sizeof(drvuem_usbdetect_ind_struct), TD_CTRL);
usbdetect_req->action = DETECT_ACTION_PLUGIN;
DRV_BuildPrimitive(USB_ilm,
MOD_USB,
MOD_UEM,
MSG_ID_DRVUEM_USBDETECT_IND,
usbdetect_req);
msg_send_ext_queue(USB_ilm);
}
else if(msg_type == USB_SEND_MSG_PLUG_OUT)
{
/*Notify UEM cable plug out*/
usbdetect_req = (drvuem_usbdetect_ind_struct*)construct_local_para(
sizeof(drvuem_usbdetect_ind_struct), TD_CTRL);
usbdetect_req->action = DETECT_ACTION_PLUGOUT;
DRV_BuildPrimitive(USB_ilm,
MOD_USB,
MOD_UEM,
MSG_ID_DRVUEM_USBDETECT_IND,
usbdetect_req);
msg_send_ext_queue(USB_ilm);
}
else if(msg_type == USB_SEND_MSG_UART_PLUG_OUT)
{
/* Notify UART owner plug out*/
uart_plug_out_ind = (uart_plugout_ind_struct*)construct_local_para(sizeof(uart_plugout_ind_struct), TD_CTRL);
uart_plug_out_ind->port = USB2UARTPort.port_no;
DRV_BuildPrimitive(USB_ilm,
MOD_USB,
USB2UARTPort.ownerid,
MSG_ID_UART_PLUGOUT_IND,
uart_plug_out_ind);
msg_send_ext_queue(USB_ilm);
}
else if(msg_type == USB_SEND_MSG_READ_UNIQUE_STRING)
{
/* Send msg to NVRAM, read serial string data*/
if(nvram_get_info(UNI_ID, &record, &size)!=NVRAM_ERRNO_SUCCESS)
EXT_ASSERT(0, 0, 0, 0);
local_ptr = construct_local_para(size, TD_CTRL);
((nvram_read_req_struct *)local_ptr)->file_idx = UNI_ID;
((nvram_read_req_struct *)local_ptr)->para = NVRAM_SYS_AUTO_DETECT;
DRV_BuildPrimitive(USB_ilm,
MOD_USB,
MOD_NVRAM,
MSG_ID_NVRAM_READ_REQ,
local_ptr);
msg_send_ext_queue(USB_ilm);
}
else if(msg_type == USB_SEND_MSG_CONFIG_CNF)
{
/*Notify UEM*/
USB_Prim = (drvuem_usbcfg_cnf_struct*)
construct_local_para(sizeof(drvuem_usbcfg_cnf_struct), TD_CTRL);
USB_Prim->mode= mode;
USB_Prim->result= result;
DRV_BuildPrimitive(USB_ilm,
MOD_USB,
MOD_UEM,
MSG_ID_DRVUEM_USBCFG_CNF,
USB_Prim);
msg_send_ext_queue(USB_ilm);
}
#ifdef __P_PROPRIETARY_COPYRIGHT__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
else
{
EXT_ASSERT(0, 0, 0, 0);
}
}
/* add for usb charging, check the cable status */
kal_bool USB_GetCableStatus(void)
{
return (g_usb_cable_state!=gUsbDevice.device_param->cable_plugin_level)?(KAL_TRUE):(KAL_FALSE);
}
/* external interrupt HISR */
void USB_EINT_HISR(void)
{
#ifndef __USB_ENABLE__
EXT_ASSERT(0, 0, 0, 0);
#endif
ilm_struct *usb_hisr_ilm;
// USB_Ms_Dbg_Trace(USB_DBG_EINT_HISR,g_usb_cable_state);
//#ifdef __OTG_ENABLE__
// #ifndef _USB_VBUS_DETECT_WITH_NIRQ_
// /* NIRQ not modify the debounce time */
// EINT_SW_Debounce_Modify(g_usb_eint_no, gUsbOtg.eint_time_delay);
// #endif
//#endif
if (g_usb_cable_state!= gUsbDevice.device_param->cable_plugin_level) /*Must modify for different level, plug out*/
{
DRV_BuildPrimitive(usb_hisr_ilm,
MOD_EINT_HISR,
MOD_USB,
MSG_ID_USB_B_PLUGOUT_IND,
NULL);
msg_send_ext_queue(usb_hisr_ilm);
#ifdef MT6318
DRV_BuildPrimitive(usb_hisr_ilm,
MOD_EINT_HISR,
MOD_BMT,
MSG_ID_USB_B_PLUGOUT_IND,
NULL);
msg_send_ext_queue(usb_hisr_ilm);
#elif (!defined(MT6305))
/* On EVB board, there may be no PMIC. */
{
BMT_sendMes2UEM(BMT_USB_NO_CHARGING_OUT);
}
#endif /* MT6318*/
}
else /* first time USB cable plug in */
{
#ifdef __OTG_ENABLE__
if(gUsbOtg.b_check_srp == KAL_TRUE)
{
OTG_B_Set_Session_Valid(KAL_TRUE);
}
#endif
#ifdef __USB_AND_UART_WITH_ONE_GPIO__
/* We must call this function in USB_EINT_HISR() in the case that USB and UART with one GPIO */
USB_Switch_Gpio_to_USB_And_PowerControl(KAL_FALSE);
#endif
DRV_BuildPrimitive(usb_hisr_ilm,
MOD_EINT_HISR,
MOD_USB,
MSG_ID_USB_B_PLUGIN_IND,
NULL);
msg_send_ext_queue(usb_hisr_ilm);
#ifdef MT6318
DRV_BuildPrimitive(usb_hisr_ilm,
MOD_EINT_HISR,
MOD_BMT,
MSG_ID_USB_B_PLUGIN_IND,
NULL);
msg_send_ext_queue(usb_hisr_ilm);
#elif (!defined(MT6305))
/* On EVB board, there may be no PMIC. */
{
BMT_sendMes2UEM(BMT_USB_NO_CHARGING_IN);
}
#endif /* MT6318*/
}
g_usb_cable_state = !g_usb_cable_state;
/* for charger USB, charger will handle this part */
#if !defined(MT6318) && !defined(__CHARGER_USB_DETECT_WIHT_ONE_EINT__) && !defined(_USB_VBUS_DETECT_WITH_NIRQ_)
EINT_Set_Polarity(g_usb_eint_no,g_usb_cable_state);
#endif /* MT6318*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -