コード例 #1
0
ファイル: otg_mouse.c プロジェクト: BillyZhangZ/wifi
/*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();
    }
}
コード例 #2
0
ファイル: usb_cdc.c プロジェクト: konstantinElsiel/centaurian
/*************************************************************************//*!
 *
 * @name  USB_Cdc_Ep_Mutex_Unlock
 *
 * @brief The function unlocks the mutex for RTOS. For BM, enable interrupt.
 *
 * @param none.
 * @return none.
 *
 *****************************************************************************/
void USB_Cdc_Ep_Mutex_Unlock(cdc_device_struct_t * cdc_obj_ptr, uint8_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_unlock(cdc_obj_ptr->send_mutex);
        }
        else if(direction == USB_RECV)
        {
            OS_Mutex_unlock(cdc_obj_ptr->recv_mutex);
        }
        break;
    case USB_INTERRUPT_PIPE:
        break;
    default:
        break;
    }
#else
    OS_Unlock();
#endif

}
コード例 #3
0
ファイル: usb_cdc.c プロジェクト: konstantinElsiel/centaurian
/*************************************************************************//*!
 *
 * @name  USB_Cdc_Mutex_Unlock
 *
 * @brief The function unlocks the mutex for RTOS. For BM, enable interrupt.
 *
 * @param none.
 * @return none.
 *
 *****************************************************************************/
void USB_Cdc_Mutex_Unlock(os_mutex_handle handle)
{
#if (((OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_SDK) && (USE_RTOS)))
    OS_Mutex_unlock(handle);
#else
    OS_Unlock();
#endif

}
コード例 #4
0
ファイル: otg_mouse.c プロジェクト: BillyZhangZ/wifi
/*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();
}
コード例 #5
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_feature
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_feature
(
    /* usb device */
    usb_device_instance_handle   dev_handle,
    /* request type device/interface/endpoint */
    uint8_t            req_type,
    /* device = 0, or interface/endpoint */
    uint8_t            intf_endpt,
    /* feature selection */
    uint16_t           feature
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_feature");
    #endif

    switch (req_type) {
        case REQ_TYPE_DEVICE:
            break;
        case REQ_TYPE_INTERFACE:
        case REQ_TYPE_ENDPOINT:
            *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(intf_endpt);
            break;
        default:
            OS_Unlock();
            #ifdef _HOST_DEBUG_
                DEBUG_LOG_TRACE("_usb_host_ch9_set_feature, invalid param");
            #endif
            return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE);
    } /* EndSwitch */

    request.bmrequesttype = (uint8_t)(req_type | REQ_TYPE_OUT);
    request.brequest = REQ_SET_FEATURE;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(feature);

    error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_feature, SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #6
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*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);
}
コード例 #7
0
ファイル: usb_otg_main.c プロジェクト: kylemanna/kinetis-sdk1
/*FUNCTION*-------------------------------------------------------------------
 *
 * Function Name    : usb_otg_init
 * Returned Value   : initialization message
 * Comments         : Initializes OTG stack 
 *    
 *
 *END*----------------------------------------------------------------------*/
usb_status usb_otg_init
(
    /* [IN] the USB device controller to initialize */
    uint8_t controller_id,
    /*[IN] address of the OTG initialization  structure */
    otg_int_struct_t * init_struct_ptr,
    /* [IN] the USB otg board init handle */
    otg_board_init  board_init_callback,   
    /* [OUT] the USB host handle */
    usb_otg_handle * handle
)
{
    usb_status error = USB_OK;
    const usb_otg_api_functions_struct_t * otg_api = NULL;
    usb_otg_state_struct_t * usb_otg_ptr = NULL;
    if ((init_struct_ptr == NULL) || (handle == NULL))
    {
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("usb_otg_init invalid parameters");
#endif

        return USBERR_ERROR;
    }
    _usb_otg_get_api(controller_id, &otg_api);
    if (otg_api == NULL)
    {
        return USBERR_ERROR;
    }
    /* Initialize the USB interface. */
    if (otg_api->otg_preinit != NULL)
    {
        error = otg_api->otg_preinit((usb_otg_handle *) (&(usb_otg_ptr)));
        if (error || (usb_otg_ptr == NULL))
        {
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
            DEBUG_LOG_TRACE ("usb_OTG_init preinit failure");
#endif
            return USBERR_ALLOC;
        }
    }
    g_usb_otg_handle = usb_otg_ptr;
    usb_otg_ptr->otg_controller_api = otg_api; 
    if( NULL !=board_init_callback )
    {
        error = (uint32_t)board_init_callback(controller_id);
    }
    else
    {
        error = USB_OK;
    }
    if(USB_OK == error)
    {
        error = usb_otg_soc_init(controller_id);
    }
    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            error = otg_api->otg_shutdown(usb_otg_ptr);
        }
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("_usb_host_init: BSP-specific USB initialization failure");
#endif
        return USB_log_error(__FILE__, __LINE__, USBERR_UNKNOWN_ERROR);
    }

    usb_otg_ptr->init_struct = init_struct_ptr;
    /* initialize the event used for application signaling and for ISR*/
    usb_otg_ptr->otg_app_event = OS_Event_create(0);
    usb_otg_ptr->otg_isr_event = OS_Event_create(0);
    usb_otg_ptr->device_state = USB_OTG_DEVSTATE_UNDEFINED;
    usb_otg_ptr->sub_state = USB_OTG_SM_UNDEFINED;
    usb_otg_ptr->power_up = TRUE;

    if (otg_api->otg_init != NULL)
    {
        error = otg_api->otg_init(controller_id, usb_otg_ptr);
    }

    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            error = otg_api->otg_shutdown(usb_otg_ptr);
        }
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("_usb_host_init: BSP-specific USB initialization failure");
#endif
        return USB_log_error(__FILE__, __LINE__, USBERR_UNKNOWN_ERROR);
    }

    error = _usb_otg_task_create(usb_otg_ptr);

    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            otg_api->otg_shutdown(usb_otg_ptr);
        }
        (void) OS_Event_destroy(usb_otg_ptr->otg_app_event);
        (void) OS_Event_destroy(usb_otg_ptr->otg_isr_event);
        OS_Mem_free(usb_otg_ptr);
        usb_otg_ptr = NULL;

        OS_Unlock();
        return error;
    }
    *handle = (usb_otg_handle) usb_otg_ptr;
    return USB_OK;
}