/*FUNCTION*---------------------------------------------------------------- * * Function Name : OTG_App_Load_Unload_Task * Returned Value : none * Comments : * * *END*--------------------------------------------------------------------*/ void OTG_App_Load_Unload_Task(uint32_t event) { if (event & OTG_UNLOAD_DEVICE) { OS_Lock(); DEV_APP_uninit(); OS_Event_clear(g_otg_app_event_handle,OTG_UNLOAD_DEVICE); OS_Unlock(); } if (event & OTG_UNLOAD_HOST) { OS_Lock(); HOST_APP_uninit(); OS_Event_clear(g_otg_app_event_handle,OTG_UNLOAD_HOST); OS_Unlock(); } if (event & OTG_LOAD_DEVICE) { OS_Lock(); DEV_APP_init(); OS_Event_clear(g_otg_app_event_handle,OTG_LOAD_DEVICE); OS_Unlock(); } if (event & OTG_LOAD_HOST) { OS_Lock(); HOST_APP_init(); OS_Event_clear(g_otg_app_event_handle,OTG_LOAD_HOST); OS_Unlock(); } }
/*************************************************************************//*! * * @name USB_Cdc_Ep_Mutex_Lock * * @brief The function locks the mutex for RTOS. For BM, disable interrupt. * * @param none. * @return none. * *****************************************************************************/ void USB_Cdc_Ep_Mutex_Lock(cdc_device_struct_t * cdc_obj_ptr, uint32_t ep_num) { uint8_t index, type, direction; index = USB_Map_Ep_To_Struct_Index(cdc_obj_ptr, ep_num); type = cdc_obj_ptr->ep[index].type; direction = cdc_obj_ptr->ep[index].direction; #if (((OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_SDK) && (USE_RTOS))) switch(type) { case USB_BULK_PIPE: if(direction == USB_SEND) { OS_Mutex_lock(cdc_obj_ptr->send_mutex); } else if(direction == USB_RECV) { OS_Mutex_lock(cdc_obj_ptr->recv_mutex); } break; case USB_INTERRUPT_PIPE: break; default: break; } #else OS_Lock(); #endif }
/*************************************************************************//*! * * @name USB_Cdc_Mutex_Lock * * @brief The function locks the mutex for RTOS. For BM, disable interrupt. * * @param none. * @return none. * *****************************************************************************/ void USB_Cdc_Mutex_Lock(os_mutex_handle handle) { #if (((OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_SDK) && (USE_RTOS))) OS_Mutex_lock(handle); #else OS_Lock(); #endif }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : OTG_App_Init * Returned Value : none * Comments : * * *END*--------------------------------------------------------------------*/ void OTG_App_Init() { /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */ OS_Lock(); g_otg_handle = NULL; g_otg_state = 0; g_dev_type = dev_b; g_sess_vld = FALSE; g_vbus_err = FALSE; g_otg_app_event_handle = OS_Event_create(0); printf("\n\r otg module is initilalizing:"); _usb_otg_init(USBCFG_DEFAULT_OTG_CONTROLLER, (otg_int_struct_t *)&g_otg_init, &g_otg_handle); printf("\n\rPress P to print the menu:"); OS_Unlock(); }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_hostdev_cntrl_request * Returned Value : USB_OK, or error status * Comments : * Function to process class- or vendor-specific control pipe device * requests. * *END*--------------------------------------------------------------------*/ usb_status _usb_hostdev_cntrl_request ( /* usb device */ usb_device_instance_handle dev_handle, /* Device Request to send */ usb_setup_t* devreq, /* buffer to send/receive */ uint8_t * buff_ptr, /* callback upon completion */ tr_callback callback, /* [IN] the parameter to pass back to the callback function */ void* callback_param ) { /* Body */ dev_instance_t* dev_ptr; usb_pipe_handle pipe_handle; tr_struct_t tr; usb_status error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request"); #endif /* Verify that device handle is valid */ OS_Lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, invalid device handle"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ dev_ptr = (dev_instance_t*)dev_handle; if (dev_ptr->state < DEVSTATE_ENUM_OK) { OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, no device found"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ pipe_handle = dev_ptr->control_pipe; usb_hostdev_tr_init(&tr, callback, callback_param); /* Set TR buffer length as required */ if ((REQ_TYPE_IN & devreq->bmrequesttype) != 0) { tr.rx_buffer = buff_ptr; tr.rx_length = USB_SHORT_UNALIGNED_LE_TO_HOST(devreq->wlength); } else { tr.TX_BUFFER = buff_ptr; tr.tx_length = USB_SHORT_UNALIGNED_LE_TO_HOST(devreq->wlength); } /* EndIf */ tr.setup_packet = *devreq; error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request,SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); }