📄 usb_task.c
字号:
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool usb_create(comptask_handler_struct **handle)
{
#ifndef __USB_ENABLE__
EXT_ASSERT(0, 0, 0, 0);
#endif
static const comptask_handler_struct usb_handler_info =
{
usb_task_main, /* task entry function */
usb_task_init, /* task initialization function */
NULL, /* task configuration function */
usb_task_reset, /* task reset handler */
usb_task_end /* task termination handler */
};
g_usb_eint_no = custom_eint_get_channel(usb_eint_chann);
// remove to avoid affecting touch panel function
//clear_ext_intr_init(g_usb_eint_no);
*handle = (comptask_handler_struct *)&usb_handler_info;
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* usb_task_init
*
* DESCRIPTION
* This function implements xyz's init handler
*
* PARAMETERS
* task_index - task's index
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
static kal_bool usb_task_init(task_indx_type task_indx)
{
#ifndef __USB_ENABLE__
EXT_ASSERT(0, 0, 0, 0);
#endif
#if defined(__SIM_PLUS__)
kal_uint8 nvram_buffer[NVRAM_EF_SYS_CACHE_OCTET_SIZE];
#endif
kal_uint32 buff_size = 0;
kal_uint8 port_num;
kal_uint32 baudrate;
#ifdef __DSPIRDBG__
kal_uint8 usb_is_irdbg;
#endif
#ifdef __P_PROPRIETARY_COPYRIGHT__
/* under construction !*/
/* under construction !*/
#endif
#ifdef WEBCAM_SUPPORT
kal_uint32 index;
#endif
#ifdef __OTG_ENABLE__
OTG_Drv_Create_ISR();
#else
USB_Drv_Create_ISR(); /* Register USB_HISR, not active, ensure we have enough memory space */
#endif
#ifdef __DSPIRDBG__
#if defined(MT6225)
IRDBG_Drv_Create_ISR();
#endif
#endif
#if defined(__SIM_PLUS__)
/* Check SIM PLUS card exist or not in NVRAM column 4, */
nvram_external_read_data(NVRAM_EF_SYS_CACHE_OCTET_LID,
NVRAM_SYS_SIM_PLUS_SETTING, nvram_buffer, NVRAM_EF_SYS_CACHE_OCTET_SIZE);
g_usb_ms_simplus_exist = nvram_buffer[0];
custom_usb_ms_init();
#endif
/* check engineering mode com port setting */
gUsbDevice.usb_comport_boot = KAL_FALSE;
nvram_get_tst(&port_num, &baudrate);
if (port_num == uart_port_usb)
gUsbDevice.usb_comport_boot = KAL_TRUE;
nvram_get_ps(&port_num, &baudrate);
if (port_num == uart_port_usb)
gUsbDevice.usb_comport_boot = KAL_TRUE;
nvram_get_cti(&port_num, &baudrate);
if (port_num == uart_port_usb)
gUsbDevice.usb_comport_boot = KAL_TRUE;
#ifdef __DSPIRDBG__
nvram_get_swdbg(&usb_is_irdbg);
if((usb_is_irdbg -1) == EM_SWDBG_MCU_DSP_IRDBG)
{
g_usb_boot_as_irdbg = KAL_TRUE;
gUsbDevice.usb_comport_boot = KAL_TRUE;
}
#endif
/* Do task's init here.*/
if((INT_USBBoot() == KAL_TRUE)&&(gUsbDevice.usb_comport_boot == KAL_FALSE)) /* MS mode */
{
#ifdef __P_PROPRIETARY_COPYRIGHT__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#else
buff_size = sizeof(Usb_Disk_Buffer);
#endif
/* get the buffer at initialize time for USB boot mode*/
g_UsbMS.disk_buffer = NULL;
g_UsbMS.disk_buffer = kal_tmp_mem_alloc(buff_size);
if(g_UsbMS.disk_buffer == NULL)
EXT_ASSERT(0, buff_size, 0, 0);
#ifdef __P_PROPRIETARY_COPYRIGHT__
/* under construction !*/
/* under construction !*/
#endif
}
/* get customize parameters*/
gUsbDevice.device_param = USB_GetCustomFunc()->get_device_param_func();
g_UsbMS.ms_param = USB_GetCustomFunc()->get_ms_param_func();
g_UsbACM.acm_param = USB_GetCustomFunc()->get_acm_param_func();
#ifdef WEBCAM_SUPPORT
g_USBVideo.custom_param = USB_GetCustomFunc()->get_video_param_func();
g_USBVideo.camera_param = USBVideo_Get_Camera_Param();
for(index = 0; index < USBVIDEO_VIDEO_SIZE_MAX; index++)
{
g_USBVideo.video_control.default_jpeg_max_size[index] = 0;
g_USBVideo.video_control.b_set_default_jpeg_max_size[index] = KAL_FALSE;
}
#endif
#ifdef PICTBRIDGE_SUPPORT
g_USBImage.image_param = USB_GetCustomFunc()->get_image_param_func();
#endif
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* usb_task_reset
*
* DESCRIPTION
* This function implements xyz's reset handler
*
* PARAMETERS
* task_index - task's index
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
static kal_bool usb_task_reset(task_indx_type task_indx)
{
/* Do task's reset here.
* Notice that: shouldn't execute modules reset handler since
* stack_task_reset() will do. */
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* usb_task_end
*
* DESCRIPTION
* This function implements xyz's termination handler
*
* PARAMETERS
* task_index - task's index
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
static kal_bool usb_task_end(task_indx_type task_indx)
{
/* Do task's termination here.
* Notice that: shouldn't execute modules reset handler since
* stack_task_end() will do. */
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* usb_task_main
*
* DESCRIPTION
* This function implements xyz task's entry function
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
static void usb_task_main( task_entry_struct * task_entry_ptr )
{
ilm_struct current_ilm;
kal_uint32 my_index;
drvuem_usbcfg_req_struct *usbcfg;
#ifndef __USB_ENABLE__
EXT_ASSERT(0, 0, 0, 0);
#endif
/* for adding module id*/
kal_get_my_task_index( &my_index );
stack_set_active_module_id( my_index, MOD_USB);
gUsbDevice.device_type = USB_UNKOWN;
g_UsbMS.b_ms_first_plugin = KAL_TRUE;
/* set external interrupt polarity and register it */
g_usb_cable_state = gUsbDevice.device_param->cable_plugin_level;
#ifdef __OTG_ENABLE__
#ifndef __USB_IN_NORMAL_MODE__
/* OTG enable must be with normal mode compile option */
EXT_ASSERT(0, 0, 0, 0);
#endif
OTG_VBusControl(KAL_FALSE);
USB_Init_Mode();
OTG_Init_A_Plug_Detect();
// gUsbOtg.eint_no = g_usb_eint_no;
// eint_sw_debounce_time_delay = custom_config_eint_sw_debounce_time_delay();
// gUsbOtg.eint_time_delay= eint_sw_debounce_time_delay[g_usb_eint_no];
#endif /* __OTG_ENABLE__ */
if(INT_BootMode() != MTK_FACTORY_MODE)
{
#ifdef MT6318
/*XXXXX*/
#if (!defined(__CHARGER_USB_DETECT_WIHT_ONE_EINT__))
PMIC_ChrDet_Registration(USB_CHR, USB_EINT_HISR); /* called by USB to register its detection handler */
#endif
#else
#ifdef _USB_VBUS_DETECT_WITH_NIRQ_ /* Only in EVB because EINT is not enough, NIRQ can be seen as EINT */
USB_NIRQ_Registration(USB_EINT_HISR);
#else
#if !defined(__CHARGER_USB_DETECT_WIHT_ONE_EINT__) /*if defined, than registered at bmt_task_main.c */
EINT_Registration(g_usb_eint_no, KAL_TRUE, g_usb_cable_state, USB_EINT_HISR, KAL_TRUE);
#endif
#endif
#endif
}
/* request for unique string to construct serial string*/
if(INT_USBBoot() == KAL_FALSE)
{
USB_Send_Msg(USB_SEND_MSG_READ_UNIQUE_STRING, 0, KAL_TRUE);
}
while(1)
{
receive_msg_ext_q(task_info_g[task_entry_ptr->task_indx].task_ext_qid, ¤t_ilm);
switch(current_ilm.msg_id)
{
case MSG_ID_USB_FT_START_REQ:
g_UsbMode.mode_param |= USB_MODE_FT_START_DONE;
#ifdef __OTG_ENABLE__
OTG_Mode_Selection();
#else
USB_Mode_Selection();
#endif
break;
case MSG_ID_NVRAM_READ_CNF:
g_UsbMode.mode_param |= USB_MODE_NVRAM_READ_DONE;
/* store the string value got from NVRAM */
USB_Store_Serial_Value(¤t_ilm); /* store in gUsbDevice.serial_string */
#ifdef __OTG_ENABLE__
OTG_Mode_Selection();
#else
USB_Mode_Selection();
#endif
break;
case MSG_ID_BMT_USB_READ_CALI_DONE_IND:
g_UsbMode.mode_param |= USB_MODE_BMT_READ_DONE;
#ifdef __OTG_ENABLE__
OTG_Mode_Selection();
#else
USB_Mode_Selection();
#endif
break;
case MSG_ID_USB_A_PLUGIN_IND:
#ifdef __OTG_ENABLE__
if((OTG_Get_Plug_Type()==OTG_PLUG_A)&&(g_UsbMode.cable_type == USB_MODE_CABLE_PLUGOUT))
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_PLUGOUT;
g_UsbMode.cable_type = USB_MODE_CABLE_A_PLUGIN;
OTG_Mode_Selection();
}
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
case MSG_ID_USB_B_PLUGIN_IND:
#ifdef __OTG_ENABLE__
if((OTG_Get_Plug_Type()==OTG_PLUG_B)&&(g_UsbMode.cable_type == USB_MODE_CABLE_PLUGOUT))
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_PLUGOUT;
g_UsbMode.cable_type = USB_MODE_CABLE_B_PLUGIN;
OTG_Mode_Selection();
}
#else
if(g_UsbMode.cable_type == USB_MODE_CABLE_PLUGOUT)
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_PLUGOUT;
g_UsbMode.cable_type = USB_MODE_CABLE_B_PLUGIN;
USB_Mode_Selection();
}
/* Configure USB as CDC ACM at plug in message if this flag as ture*/
if(gUsbDevice.usb_comport_boot == KAL_TRUE)
{
#ifdef __DSPIRDBG__
if(g_usb_boot_as_irdbg == KAL_TRUE)
USB_Config_Type(USB_CDC_ACM_IRDBG, KAL_TRUE, NULL);
else
USB_Config_Type(USB_CDC_ACM, KAL_TRUE, NULL);
#else
USB_Config_Type(USB_CDC_ACM, KAL_TRUE, NULL);
#endif
}
#endif
break;
case MSG_ID_USB_A_PLUGOUT_IND:
#ifdef __OTG_ENABLE__
if(g_UsbMode.cable_type == USB_MODE_CABLE_A_PLUGIN)
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_A_PLUGIN;
g_UsbMode.cable_type = USB_MODE_CABLE_PLUGOUT;
OTG_Mode_Selection();
}
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
case MSG_ID_USB_B_PLUGOUT_IND:
#ifdef __OTG_ENABLE__
if(g_UsbMode.cable_type == USB_MODE_CABLE_B_PLUGIN)
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_B_PLUGIN;
g_UsbMode.cable_type = USB_MODE_CABLE_PLUGOUT;
OTG_B_Set_Session_Valid(KAL_FALSE);
OTG_Mode_Selection();
}
#else
if(g_UsbMode.cable_type == USB_MODE_CABLE_B_PLUGIN)
{
g_UsbMode.previous_cable_type = USB_MODE_CABLE_B_PLUGIN;
g_UsbMode.cable_type = USB_MODE_CABLE_PLUGOUT;
USB_Mode_Selection();
}
#endif
break;
case MSG_ID_DRVUEM_USBCFG_REQ:
usbcfg=(drvuem_usbcfg_req_struct *)current_ilm.local_para_ptr;
#ifdef __OTG_ENABLE__
#ifdef OTG_NORMAL_APP_FIXED
/* should not recive this msg*/
ASSERT(0);
#endif
if(g_UsbMode.b_start_hnp==KAL_TRUE)
{
OTG_Config_HNP(usbcfg->mode, usbcfg->parameter);
}
else if (g_UsbMode.b_start_srp==KAL_TRUE)
{
/* For SRP function all the software resource initialization should be configured before SRP,
After A device provide VBUS, B device should connect D+ within 1 sec*/
OTG_Config_SRP(usbcfg->mode, usbcfg->parameter);
}
else
{
/* config request from MMI*/
if(g_UsbMode.cable_type != USB_MODE_CABLE_PLUGOUT)
{
USB_Config_Type(usbcfg->mode, KAL_TRUE, usbcfg->parameter);
USB_Send_Msg(USB_SEND_MSG_CONFIG_CNF, usbcfg->mode, gUsbDevice.usb_config_result);
}
else
{
USB_Send_Msg(USB_SEND_MSG_CONFIG_CNF, usbcfg->mode, KAL_FALSE);
}
}
#else /* __OTG_ENABLE__ */
/* config request from MMI*/
if(g_UsbMode.cable_type != USB_MODE_CABLE_PLUGOUT)
{
//USB_Config_Type(usbcfg->mode, KAL_TRUE, (kal_uint32*)usbcfg->reserved);
USB_Config_Type(usbcfg->mode, KAL_TRUE, usbcfg->parameter);
USB_Send_Msg(USB_SEND_MSG_CONFIG_CNF, usbcfg->mode, gUsbDevice.usb_config_result);
}
else
{
USB_Send_Msg(USB_SEND_MSG_CONFIG_CNF, usbcfg->mode, KAL_FALSE);
}
#endif /* __OTG_ENABLE__ */
break;
case MSG_ID_OTG_HDLR_IND:
#ifdef __OTG_ENABLE__
{
otg_hdr_ind_struct *hdlr_ind=(otg_hdr_ind_struct *)current_ilm.local_para_ptr;
OTG_Hdlr_Select(hdlr_ind->type, hdlr_ind->parameter, hdlr_ind->b_param);
}
#else
EXT_ASSERT(0, 0, 0, 0);
#endif
break;
case MSG_ID_USBD_START_HNP:
#ifdef __OTG_ENABLE__
#ifdef OTG_SRP_HNP_APP_FIXED
OTG_Config_HNP(USB_MASS_STORAGE, g_USB_Mass_Buffer);
#else
g_UsbMode.b_start_hnp = KAL_TRUE;
/* Notify UEM*/
USB_Send_Msg(USB_SEND_MSG_PLUG_IN, 0, KAL_TRUE);
#endif
#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -