Ejemplo n.º 1
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : App_HandleUserInput
* Returned Value : none
* Comments       :
*
*
*END*--------------------------------------------------------------------*/
static void App_HandleUserInput(void)
{
    int8_t character;
#if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX)
    if (status())
    {
        printf("\n\r");
        character = getchar();
#else
    if (uart_getchar_no_block(&character))
    {
        printf("\n\r %c", character);
#endif
        switch (character)
        {

        case '1':
            if (_usb_otg_session_request(g_otg_handle) == USB_OK)
            {
                printf("\n\rSRP request");
            }
            else
            {
                printf("\n\rError Requesting SRP");
            }
            break;
        case '2':
            if (_usb_otg_bus_request(g_otg_handle) == USB_OK)
            {
                printf("\n\rB bus request");
            }
            else
            {
                printf("\n\rError requesting the bus");
            }
            break;

        case '3':
            if (_usb_otg_bus_release(g_otg_handle) == USB_OK)
            {
                printf("\n\rB bus release");
            }
            else
            {
                printf("\n\rError releasing the bus");
            }
            break;
        case '4':
            _usb_otg_set_a_bus_req(g_otg_handle , TRUE);
            printf("\n\rA bus request");
            break;
        case '5':
            _usb_otg_set_a_bus_req(g_otg_handle , FALSE);
            printf("\n\rA bus release");
            break;
        case '6':
            _usb_otg_set_a_bus_drop(g_otg_handle , TRUE);
            printf("\n\rA set a bus drop true");
            break;
        case '7':
            _usb_otg_set_a_bus_drop(g_otg_handle , FALSE);
            printf("\n\rA set a bus drop false");
            break;
        case '8':
            _usb_otg_set_a_clear_err(g_otg_handle);
            break;
        case 'p':
        case 'P':
            App_PrintMenu();
            break;
        default:
            break;
        }
    }
}

/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : App_PrintMenu
* Returned Value : none
* Comments       :
*
*
*END*--------------------------------------------------------------------*/
static void App_PrintMenu(void)
{
    bool a_bus_req;
    bool a_bus_drop;
    printf("\n\r  OTG App User Input Menu");
    if (g_dev_type == dev_a)
    {
        if (g_vbus_err == FALSE)
        {
            if (g_sess_vld == TRUE)
            {
                _usb_otg_get_a_bus_req(g_otg_handle, &a_bus_req);
                if(FALSE == a_bus_req)
                {
                    printf("\n\r      4. A bus request ");
                }
                else
                {
                    printf("\n\r      5. A bus release ");
                }
                printf("\n\r      6. A set a bus drop true (session end)");
            }
            else  /* session not valid */
            {
                _usb_otg_get_a_bus_req(g_otg_handle, &a_bus_req);
                if(FALSE == a_bus_req)
                {
                    printf("\n\r      4. A bus request ");
                }
                else
                {
                    printf("\n\r      5. A bus release ");
                }
                _usb_otg_get_a_bus_drop(g_otg_handle, &a_bus_drop);
                if (TRUE == a_bus_drop)
                {
                    printf("\n\r      7. A set a bus drop false");
                }
            }
        }
        else    /* no VBUS error */
        {
            printf("\n\r      6. A set a bus drop true (session end)");
            printf("\n\r      8. A clear error");
        }
    }
    else if (g_dev_type == dev_b)
    {
        if (g_sess_vld == TRUE)
        {
            if (g_otg_state == OTG_B_PERIPHERAL)
            {
                printf("\n\r      2. B bus request (HNP start)");
            }
            if (g_otg_state == OTG_B_HOST)
            {
                printf("\n\r      3. B bus release");
            }
        }
        else
        {
            printf("\n\r      1. B session request (SRP start)");
        }
    }
}
Ejemplo n.º 2
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : App_Print_Event
* Returned Value : none
* Comments       :
*
*
*END*--------------------------------------------------------------------*/
static void App_Print_Event(uint32_t event)
{
    OS_Event_clear(g_otg_app_event_handle,OTG_A_B_STATE_EVENT_MARK);
    if (event & OTG_B_IDLE)
    {
        printf("\n\r>B: OTG state change to B idle");
    }

    if (event & OTG_B_IDLE_SRP_READY)
    {
        printf("\n\r>B: OTG is ready to initialize SRP");

    }

    if (event & OTG_B_SRP_INIT)
    {
        printf("\n\r>B: OTG has initialized SRP");
    }

    if (event & OTG_B_SRP_FAIL)
    {
        printf("\n\r>B: OTG SRP failed to get a response from the Host");
    }

    if (event & OTG_B_PERIPHERAL)
    {
        printf("\n\r>B: OTG state change to B peripheral.");
        printf("\n\r>B: USB peripheral stack initialized.");
        App_PrintMenu();
    }

    if (event & OTG_B_PERIPHERAL_LOAD_ERROR)
    {
        printf("\n\r>B: OTG state change to B peripheral.");
        printf("\n\r>B: USB peripheral stack initialization failed.");
    }

    if (event & OTG_B_PERIPHERAL_HNP_READY)
    {
        printf("\n\r>B: OTG is ready to initialize HNP.");
    }

    if (event & OTG_B_PERIPHERAL_HNP_START)
    {
        printf("\n\r>B: OTG has initialized the HNP to request the bus from Host");
    }

    if (event & OTG_B_PERIPHERAL_HNP_FAIL)
    {
        printf("\n\r>B: HNP failed. OTG is back into peripheral state");
    }

    if (event & OTG_B_HOST)
    {
        printf("\n\r>B: OTG is in the Host state");
        printf("\n\r>B: USB host stack initialized.");

    }

    if (event & OTG_B_HOST_LOAD_ERROR)
    {
        printf("\n\r>B: OTG is in the Host state");
        printf("\n\r>B: USB host stack initialization failed.");
    }

    if (event & OTG_B_A_HNP_REQ)
    {

        printf("\n\r>B: OTG_B_A_HNP_REQ");

    }

    if (event & OTG_A_WAIT_BCON_TMOUT)
    {
        printf("\n\r>A: OTG_A_WAIT_BCON_TMOUT");
    }

    if (event & OTG_A_BIDL_ADIS_TMOUT)
    {
        printf("\n\r>A: OTG_A_BIDL_ADIS_TMOUT");
    }

    if (event & OTG_A_AIDL_BDIS_TMOUT)
    {
        printf("\n\r>A: OTG_A_AIDL_BDIS_TMOUT");
    }


    if (event & OTG_A_ID_TRUE)
    {
        printf("\n\r>A: ID = TRUE ");
    }


    if (event & OTG_A_WAIT_VRISE_TMOUT)
    {
        printf("\n\r>A: VBUS rise failed");
    }

    if (event & OTG_A_B_HNP_REQ)
    {
        printf("\n\r>A: OTG_A_B_HNP_REQ");
    }

    if (event & OTG_A_IDLE)
    {
        printf("\n\r>A: OTG state change to A_IDLE");
    }

    if (event & OTG_A_WAIT_VRISE)
    {
        printf("\n\r>A: OTG state change to A_WAIT_VRISE");
    }

    if (event & OTG_A_WAIT_BCON)
    {
        printf("\n\r>A: OTG state change to A_WAIT_BCON");
    }

    if (event & OTG_A_HOST)
    {
        printf("\n\r>A: OTG state change to OTG_A_HOST");
        printf("\n\r>A: USB host stack initialized.");
    }
    if (event & OTG_A_HOST_LOAD_ERROR)
    {
        printf("\n\r>A: OTG state change to OTG_A_HOST");
        printf("\n\r>A: USB host stack initialization failed.");
    }

    if (event & OTG_A_SUSPEND)
    {
        printf("\n\r>A: OTG state change to A_SUSPEND");
    }

    if (event & OTG_A_PERIPHERAL)
    {
        printf("\n\r>A: OTG state change to A_PERIPHERAL    ");
        printf("\n\r>A: USB peripheral stack initialized.");
        App_PrintMenu();
    }

    if (event & OTG_A_PERIPHERAL_LOAD_ERROR)
    {
        printf("\n\r>A: USB peripheral stack initialization failed.");
        printf("\n\r>A: OTG state change to A_PERIPHERAL    ");
    }

    if (event & OTG_A_WAIT_VFALL)
    {
        printf("\n\r>A: OTG state change to OTG_A_WAIT_VFALL");
    }

    if (event & OTG_A_VBUS_ERR)
    {
        printf("\n\r>A: VBUS falls below VBUS_Valid treshold");
        printf("\n\r>A: OTG state change to A_VBUS_ERR");
    }
}
Ejemplo n.º 3
0
static void App_HandleUserInput(void)
{
 uint_8 character = TERMIO_GetCharNB();
 
 switch(character)
 {
  case '1': if(_usb_otg_hnp_enable(0, TRUE) == USB_OK)
            {    
             printf("\n\rHNP enabled");
            }
            else
            {
             printf("\n\rError enabling HNP");
            }
   break;
  
  case '2': if(_usb_otg_hnp_enable(0, FALSE) == USB_OK)
            {    
             printf("\n\rHNP disabled");
            }
            else
            {
             printf("\n\rError disabling HNP");
            }             
   break;
  
  case '3': if(_usb_otg_bus_request(otg_handle) == USB_OK)
            {    
             printf("\n\rBus request");
            }
            else
            {
             printf("\n\rError requesting the bus");
            }            
   break;
  
  case '4': if(_usb_otg_bus_release(otg_handle) == USB_OK)
            {    
             printf("\n\rBus release");
            }
            else
            {
             printf("\n\rError releasing the bus");
            }             
   break;         
  
  
  case '5': if(_usb_otg_session_request(otg_handle) == USB_OK)
            {    
             printf("\n\rSRP request");
            }
            else
            {
             printf("\n\rError rerequesting SRP");
            }
   break;           
   
    case '6': _usb_otg_set_a_bus_req(otg_handle , TRUE);
                
             printf("\n\rA BUS REQ");
            
   break;
    case '7': _usb_otg_set_a_bus_req(otg_handle , FALSE);
                
             printf("\n\rA BUS RELEASE");
   break;
   
    case '8': _usb_otg_set_a_bus_drop(otg_handle , TRUE);
                
             printf("\n\rA BUS DROP TRUE");
   break;
    case '9': _usb_otg_set_a_bus_drop(otg_handle , FALSE);
                
             printf("\n\rA BUS DROP FALSE");
   break;
    case 'a':
    case 'A':
             _usb_otg_set_a_clear_err(otg_handle);
   break; 
  
  case 'p':
  case 'P': App_PrintMenu();
   break;
  
  
  default: break;          
 }
}