Esempio n. 1
0
//! @breif This function checks the specific request and if known then processes it
//!
//! @param type      corresponding at bmRequestType (see USB specification)
//! @param request   corresponding at bRequest (see USB specification)
//!
//! @return TRUE,  when the request is processed
//! @return FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function).
//!
Bool usb_user_read_request(U8 type, U8 request)
{
   U16   wInterface;
   U8    wValue_msb;
   U8    wValue_lsb;

   // Read wValue
   wValue_lsb = Usb_read_byte();
   wValue_msb = Usb_read_byte();

   //** Specific request from Class MassStorage
   if( USB_SETUP_SET_CLASS_INTER == type )
   {
      switch( request )
      {
         case SETUP_MASS_STORAGE_RESET:
         // wValue must be 0
         // wIndex = Interface
         if( (0!=wValue_lsb) || (0!=wValue_msb) )
            break;
         LSB(wInterface)=Usb_read_byte();
         MSB(wInterface)=Usb_read_byte();
         if( INTERFACE_NB != wInterface )
            break;
         Usb_ack_receive_setup();
         Usb_send_control_in();
         while(!Is_usb_in_ready());         
         return TRUE;
         break;
      }
   }
   if( USB_SETUP_GET_CLASS_INTER == type )
   {
      switch( request )
      {
         case SETUP_MASS_STORAGE_GET_MAX_LUN:
         // wValue must be 0
         // wIndex = Interface
         if( (0!=wValue_lsb) || (0!=wValue_msb) )
            break;
         LSB(wInterface)=Usb_read_byte();
         MSB(wInterface)=Usb_read_byte();
         if( INTERFACE_NB != wInterface )
            break;
         Usb_ack_receive_setup();
         Usb_write_byte( (get_nb_lun()-1) );
         Usb_send_control_in();
         while(!Is_usb_in_ready());
         while( !Is_usb_receive_out() );
         Usb_ack_receive_out();         
         ms_multiple_drive = 1;
         return TRUE;
         break;
      }
   }
   
   return FALSE;  // No supported request
}
Esempio n. 2
0
void sd_mmc_mci_read_multiple_sector_callback(const void *psector)
{
#ifdef USB_DEVICE_VENDOR_ID
   // USB Device Stack V2
   udi_msc_trans_block( true, (uint8_t*)psector, SD_MMC_SECTOR_SIZE, NULL);
#else
  // USB Device Stack V1
  uint16_t data_to_transfer = SD_MMC_SECTOR_SIZE;

  // Transfer read sector to the USB interface.
  while (data_to_transfer)
  {
    while (!Is_usb_in_ready(g_scsi_ep_ms_in))
    {
      if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in))
         return; // USB Reset
    }

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
    data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
                                             data_to_transfer, &psector);
    Usb_ack_in_ready_send(g_scsi_ep_ms_in);
  }
#endif
}
//!
//! @brief USB Command Status Wrapper (CSW) management
//!
//! This function sends the status in relation with the last CBW.
//!
static void usb_mass_storage_csw(void)
{
  while (Is_usb_endpoint_stall_requested(EP_MS_IN))
  {
    if (Is_usb_setup_received()) usb_process_request();
  }

  while (Is_usb_endpoint_stall_requested(EP_MS_OUT))
  {
    if (Is_usb_setup_received()) usb_process_request();
  }

  while (!Is_usb_in_ready(EP_MS_IN));

  Usb_reset_endpoint_fifo_access(EP_MS_IN);

  //! Write CSW Signature
  Usb_write_endpoint_data(EP_MS_IN, 32, *(U32 *)&"USBS");

  //! Write stored CBW Tag
  Usb_write_endpoint_data(EP_MS_IN, 32, dCBWTag);

  //! Write data residual value
  Usb_write_endpoint_data(EP_MS_IN, 32,
                          usb_format_mcu_to_usb_data(32, g_scsi_data_remaining));

  //! Write command status
  Usb_write_endpoint_data(EP_MS_IN, 8, g_scsi_status);

  Usb_ack_in_ready_send(EP_MS_IN);
}
Esempio n. 4
0
void sendKeys(u8* buffer)
{
  u32 i;
#ifdef NOT_USED
  if (bDeviceState == CONFIGURED)
  {
    while(!PrevXferComplete);
      
    PrevXferComplete = 0;
  /* Use the memory interface function to write to the selected endpoint */
    UserToPMABufferCopy(buffer, ENDP4_TXADDR, 8);
   
  /* Update the data length in the control register */
    SetEPTxCount(ENDP4, 8);
    SetEPTxStatus (ENDP4, EP_TX_VALID);
      
  }
#endif

  while (Is_usb_endpoint_stall_requested(EP_KB_IN))
  {
    if (Is_usb_setup_received())
    {
      usb_process_request();
    }
  }

  // MSC Compliance - Free BAD out receive during SCSI command
  while( Is_usb_out_received(EP_CCID_OUT) ) {
    Usb_ack_out_received_free(EP_CCID_OUT);
  }

  while (!Is_usb_in_ready(EP_KB_IN))
  {
     if(!Is_usb_endpoint_enabled(EP_KB_IN))
     {
       i = 0; // todo USB Reset
     }
  }

  Usb_reset_endpoint_fifo_access(EP_KB_IN);
/*
  Usb_write_endpoint_data(EP_KB_IN, 8, 'D');
  Usb_write_endpoint_data(EP_KB_IN, 8, 'D');
  Usb_write_endpoint_data(EP_KB_IN, 8, 'D');
  Usb_write_endpoint_data(EP_KB_IN, 8, 'D');
*/
  usb_write_ep_txpacket(EP_KB_IN, buffer, 8, NULL);
//  Usb_send_in(EP_CONTROL);

  Usb_ack_in_ready_send(EP_KB_IN);


  // MSC Compliance - Wait end of all transmitions on USB line
  while( 0 != Usb_nb_busy_bank(EP_KB_IN) )
  {
    if (Is_usb_setup_received()) usb_process_request();
  }

}
//! @brief Send data report to Host
//!
void hid_report_in(void)
{

  int joy   =0;
  char* ptr_cram=txbuf;
  int data_to_transfer=0;

  if(!Is_usb_write_enabled(EP_HID_GENERIC_IN))
      return;                                // Not ready to send report

  // Build the Joystick report
  if(is_joystick_up()|| is_joystick_down() || is_joystick_right() || is_joystick_left() )                     //! Check for UP event
  {
    joy=0x01;
  }
  if(joy==last_joy) {
     return;                                // Same report then no send report
  }

  last_joy=joy;
  memset(txbuf, 0, RXBUF_SIZE);
  txbuf[0] = joy;

  // Send report
  data_to_transfer = sizeof(txbuf);
  while (data_to_transfer)
  {
       while (!Is_usb_in_ready(EP_HID_GENERIC_IN));

       Usb_reset_endpoint_fifo_access(EP_HID_GENERIC_IN);
       data_to_transfer = usb_write_ep_txpacket(EP_HID_GENERIC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram);
       Usb_ack_in_ready_send(EP_HID_GENERIC_IN);
   }
}
static void USB_CCID_SendDataToUSB (void)
{
    int USB_Datalen_s32;
    int i;

    while (Is_usb_endpoint_stall_requested (EP_CCID_IN))
    {
        if (Is_usb_setup_received ())
            usb_process_request ();
    }

    while (Is_usb_endpoint_stall_requested (EP_CCID_OUT))
    {
        if (Is_usb_setup_received ())
            usb_process_request ();
    }

    // MSC Compliance - Free BAD out receive during SCSI command

    while (Is_usb_out_received (EP_CCID_OUT))
    {
        Usb_ack_out_received_free (EP_CCID_OUT);
    }

    while (!Is_usb_in_ready (EP_CCID_IN))
    {
        if (!Is_usb_endpoint_enabled (EP_CCID_IN))
        {
            i = 0;  // todo USB Reset
        }
    }

    Usb_reset_endpoint_fifo_access (EP_CCID_IN);

    USB_Datalen_s32 = USB_CCID_data_st.CCID_datalen + 10;

    for (i = 0; i < USB_Datalen_s32; i++)
    {
        Usb_write_endpoint_data (EP_CCID_IN, 8, USB_CCID_data_st.USB_data[i]);
    }

    Usb_ack_in_ready_send (EP_CCID_IN);

    USB_Log_st.CCID_ReadCalls_u32++;
    USB_Log_st.CCID_BytesRead_u32 += USB_Datalen_s32;


    // MSC Compliance - Wait end of all transmitions on USB line
    while (0 != Usb_nb_busy_bank (EP_CCID_IN))
    {
        if (Is_usb_setup_received ())
            usb_process_request ();
    }
}
Esempio n. 7
0
//! usb_set_address.
//!
//! This function manages the SET ADDRESS request. When complete, the device
//! will filter the requests using the new address.
//!
//! @warning Code:xx bytes (function code length)
//!
//! @param none
//!
//! @return none
//!
void usb_set_address(void)
{
   Usb_configure_address(Usb_read_byte());

   Usb_ack_receive_setup();

   Usb_send_control_in();                    //!< send a ZLP for STATUS phase
   while(!Is_usb_in_ready());                //!< waits for status phase done
                                             //!< before using the new address
   Usb_enable_address();
}
Esempio n. 8
0
void sd_mmc_spi_read_multiple_sector_callback(const void *psector)
{
  U16 data_to_transfer = MMC_SECTOR_SIZE;

  while (data_to_transfer)
  {
    while (!Is_usb_in_ready(g_scsi_ep_ms_in));

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
    data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
                                             data_to_transfer, &psector);
    Usb_ack_in_ready_send(g_scsi_ep_ms_in);
  }
}
Esempio n. 9
0
//! @brief This function manages hid set idle request.
//!
//! @param Duration     When the upper byte of wValue is 0 (zero), the duration is indefinite else from 0.004 to 1.020 seconds
//! @param Report ID    0 the idle rate applies to all input reports, else only applies to the Report ID
//!
void usb_hid_set_idle (U8 u8_report_id, U8 u8_duration )
{
   U16 wInterface;
   
   // Get interface number to put in idle mode
   LSB(wInterface)=Usb_read_byte();
   MSB(wInterface)=Usb_read_byte();
   Usb_ack_receive_setup();
  
   g_u8_report_rate = u8_duration;
   
   Usb_send_control_in();
   while(!Is_usb_in_ready());
}
Esempio n. 10
0
//!
//! @brief USB Command Status Wrapper (CSW) management
//!
//! This function sends the status in relation with the last CBW.
//!
static void usb_mass_storage_csw(void)
{
  while (Is_usb_endpoint_stall_requested(EP_MS_IN))
  {
    if (Is_usb_setup_received()) usb_process_request();
  }

  while (Is_usb_endpoint_stall_requested(EP_MS_OUT))
  {
    if (Is_usb_setup_received()) usb_process_request();
  }

  // MSC Compliance - Free BAD out receive during SCSI command
  while( Is_usb_out_received(EP_MS_OUT) ) {
    Usb_ack_out_received_free(EP_MS_OUT);
  }

  while (!Is_usb_in_ready(EP_MS_IN));

  Usb_reset_endpoint_fifo_access(EP_MS_IN);

  //! Write CSW Signature
  Usb_write_endpoint_data(EP_MS_IN, 32, *(U32 *)&"USBS");

  //! Write stored CBW Tag
  Usb_write_endpoint_data(EP_MS_IN, 32, dCBWTag);

  //! Write data residual value
  Usb_write_endpoint_data(EP_MS_IN, 32,
                          usb_format_mcu_to_usb_data(32, g_scsi_data_remaining));

  //! Write command status
  Usb_write_endpoint_data(EP_MS_IN, 8, g_scsi_status);

  Usb_ack_in_ready_send(EP_MS_IN);

  // MSC Compliance - Wait end of all transmissions on USB line
  while( 0 != Usb_nb_busy_bank(EP_MS_IN) )
  {
    if (Is_usb_setup_received()) usb_process_request();
  }


  // Release the USB Mutex.
  if( true == xGiveUsbMutex )
  {
    x_supervisor_SemaphoreGive( xUSBMutex );
  }
}
//! usb_set_configuration.
//!
//! This function manages the SET CONFIGURATION request. If the selected
//! configuration is valid, this function call the usb_user_endpoint_init()
//! function that will configure the endpoints following the configuration
//! number.
//!
//! @warning Code:xx bytes (function code length)
//!
void usb_set_configuration( void )
{
U8 configuration_number;

   configuration_number = Usb_read_byte();

   // TODO: Verify configuration_number!
   Usb_ack_receive_setup();
   usb_configuration_nb = configuration_number;

   Usb_send_control_in();                    //!< send a ZLP for STATUS phase
   while(!Is_usb_in_ready());

   usb_user_endpoint_init(usb_configuration_nb);  //!< endpoint configuration
   Usb_set_configuration_action();
}
  //!
  //! @brief Entry point of the device HID task management
  //!
void device_hid_task(void)
{
  // First, check the device enumeration state
  if (!Is_device_enumerated()) {
    return;
  }

  if (Is_usb_in_ready(EP_KBD_IN)) {
    if (is_usb_hid_event()) {
      Usb_reset_endpoint_fifo_access(EP_KBD_IN);

      //! Write report
      Usb_write_endpoint_data(EP_KBD_IN, 8, key);
      Usb_ack_in_ready_send(EP_KBD_IN);
    }
  }
}
void at45dbx_read_multiple_sector_callback(const void *psector)
{
  U16 data_to_transfer = AT45DBX_SECTOR_SIZE;

  // Transfer read sector to the USB interface.
  while (data_to_transfer)
  {
    while (!Is_usb_in_ready(g_scsi_ep_ms_in))
    {
      if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in))
         return; // USB Reset
    }

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
    data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
                                             data_to_transfer, &psector);
    Usb_ack_in_ready_send(g_scsi_ep_ms_in);
  }
}
Esempio n. 14
0
void usb_hid_set_report_feature(void)
{

   Usb_ack_receive_setup();
   Usb_send_control_in();

   while(!Is_usb_receive_out());

   if(Usb_read_byte()==0x55)
      if(Usb_read_byte()==0xAA)
         if(Usb_read_byte()==0x55)
            if(Usb_read_byte()==0xAA)
            {
               jump_bootloader=1;
            }
   Usb_ack_receive_out();
   Usb_send_control_in();
   while(!Is_usb_in_ready());
}
Esempio n. 15
0
void sd_mmc_spi_read_multiple_sector_callback(const void *psector)
{
#ifdef USB_DEVICE_VENDOR_ID
   // USB Device Stack V2
   udi_msc_trans_block( true, (uint8_t*)psector, MMC_SECTOR_SIZE, NULL);
#else
  // USB Device Stack V1
  uint16_t data_to_transfer = MMC_SECTOR_SIZE;

  while (data_to_transfer)
  {
    while (!Is_usb_in_ready(g_scsi_ep_ms_in));

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
    data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
                                             data_to_transfer, &psector);
    Usb_ack_in_ready_send(g_scsi_ep_ms_in);
  }
#endif
}
//! usb_set_interface.
//!
//! TThis function manages the SET_INTERFACE request.
//!
//! @warning Code:xx bytes (function code length)
//!
void usb_set_interface (void)
{
	U8 alt_setting;
	U8 dummy;
	U8 interface;
	
	alt_setting = Usb_read_byte();
	dummy    = Usb_read_byte();
	interface = Usb_read_byte();
	
	if(usb_user_set_alt_interface(interface, alt_setting)) {
		Usb_ack_receive_setup();
		Usb_send_control_in();                    //!< send a ZLP for STATUS phase
		while(!Is_usb_in_ready());

		usb_endpoint_wait_for_receive_out();
		Usb_ack_receive_out();
	}

}
void USB_CCID_send_INT_Message (void)
{
    unsigned short Message_u16;
    int i, i1;
    /* todo while (Is_usb_endpoint_stall_requested(EP_CCID_IN)) { if (Is_usb_setup_received()) usb_process_request(); }

       while (Is_usb_endpoint_stall_requested(EP_CCID_OUT)) { if (Is_usb_setup_received()) usb_process_request(); }

       // MSC Compliance - Free BAD out receive during SCSI command while( Is_usb_out_received(EP_CCID_OUT) ) {
       Usb_ack_out_received_free(EP_CCID_OUT); } */
    while (!Is_usb_in_ready (EP_CCID_INT));

    Usb_reset_endpoint_fifo_access (EP_CCID_INT);

    Message_u16 = 0x5003;

    i = Usb_byte_count (EP_CCID_INT);

    Usb_write_endpoint_data (EP_CCID_INT, 16, Message_u16);

    i1 = Usb_byte_count (EP_CCID_INT);

    Usb_ack_in_ready_send (EP_CCID_INT);

    // MSC Compliance - Wait end of all transmitions on USB line
    for (i = 0; i < 100; i++)
    {
        if (0 != Usb_nb_busy_bank (EP_CCID_INT))
        {
            if (Is_usb_setup_received ())
                usb_process_request ();
        }
        else
        {
            break;
        }
    }

}
Bool sbc_inquiry (void)
{
    U8 allocation_length;

    DelayMs (2);

    // CMDT or EPVD bit is not 0 or PAGE or OPERATION CODE fields != 0x00.
    if ((g_scsi_command[1] & 0x03) || g_scsi_command[2])
    {
        sbc_lun_status_is_cdb_field ();
        return FALSE;
    }

    // Send standard INQUIRY data (bytes 0 to (allocation_length - 1)).
    allocation_length = min (g_scsi_command[4], sizeof (sbc_st_std_inquiry_data));
    if (allocation_length != 0)
    {
        while (!Is_usb_in_ready (g_scsi_ep_ms_in))
        {
            if (!Is_usb_endpoint_enabled (g_scsi_ep_ms_in))
                return FALSE;   // USB Reset
        }
        Usb_reset_endpoint_fifo_access (g_scsi_ep_ms_in);
        usb_write_ep_txpacket (g_scsi_ep_ms_in, &sbc_std_inquiry_data, allocation_length, NULL);
        Sbc_valid_write_usb (allocation_length);
        // MSC Compliance - Wait end of all transmitions on USB line, because a stall may be send after data
        while (0 != Usb_nb_busy_bank (EP_MS_IN));
    }
    sbc_lun_status_is_good ();

    if (allocation_length > g_scsi_command[4])  // Not enough space
    {
        return (FALSE);
    }

    return (TRUE);
}
Esempio n. 19
0
void device_mouse_hid_task(void)
#endif
{
#ifdef FREERTOS_USED
  portTickType xLastWakeTime;

  xLastWakeTime = xTaskGetTickCount();
  while (true)
  {
    vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DHID_MOUSE_PERIOD);

    // First, check the device enumeration state
    if (!Is_device_enumerated()) continue;
#else
    // First, check the device enumeration state
    if (!Is_device_enumerated()) return;
#endif  // FREERTOS_USED

    if( is_usb_mouse_event() )
    {
       if( Is_usb_in_ready(EP_HID_MOUSE_IN) )
       {
          Usb_reset_endpoint_fifo_access(EP_HID_MOUSE_IN);

          //! Write report
          Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_buttons);
          Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_x);
          Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_y);
          Usb_write_endpoint_data(EP_HID_MOUSE_IN, 8, u8_report_disp_wheel);

          Usb_ack_in_ready_send(EP_HID_MOUSE_IN);
       }
    }
#ifdef FREERTOS_USED
  }
#endif
}
Esempio n. 20
0
bool USB::canSend()
{
  Usb_select_endpoint(EP_TEMP_IN);
  return Is_usb_in_ready();
}
Esempio n. 21
0
void device_template_task(void)
#endif
{
  static U8 buf[EP_SIZE_TEMP2];

#ifdef FREERTOS_USED
  portTickType xLastWakeTime;

  xLastWakeTime = xTaskGetTickCount();
  while (true)
  {
    vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DTP_PERIOD);

    // First, check the device enumeration state
    if (!Is_device_enumerated()) continue;
#else
    // First, check the device enumeration state
    if (!Is_device_enumerated()) return;
#endif  // FREERTOS_USED

    // HERE STARTS THE USB DEVICE APPLICATIVE CODE
    // The example below just performs a loopback transmission/reception.
    // All data received with the OUT endpoint is stored in a RAM buffer and
    // sent back to the IN endpoint.

#if BOARD == EVK1100
    // For example, display Start-of-Frame counter on LEDs
    LED_Display_Field(LED_MONO0_GREEN |
                      LED_MONO1_GREEN |
                      LED_MONO2_GREEN |
                      LED_MONO3_GREEN,
                      sof_cnt >> 5);
#elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
    // For example, display Start-of-Frame counter on LEDs
    LED_Display_Field(LED0 |
                      LED1,
                      sof_cnt >> 5);
#else
  #error The display of the SOFs must be defined here.
#endif

    // If we receive something in the OUT endpoint, just store it in the RAM buffer
    if (Is_usb_out_received(EP_TEMP_OUT))
    {
      LED_On(LED_APPLI_1);
      Usb_reset_endpoint_fifo_access(EP_TEMP_OUT);
      data_length = Usb_byte_count(EP_TEMP_OUT);
      usb_read_ep_rxpacket(EP_TEMP_OUT, buf, data_length, NULL);
      Usb_ack_out_received_free(EP_TEMP_OUT);
      LED_Off(LED_APPLI_1);
    }

    // Load the IN endpoint with the contents of the RAM buffer
    if (data_length && Is_usb_in_ready(EP_TEMP_IN))
    {
      LED_On(LED_APPLI_0);
      Usb_reset_endpoint_fifo_access(EP_TEMP_IN);
      usb_write_ep_txpacket(EP_TEMP_IN, buf, data_length, NULL);
      data_length = 0;
      Usb_ack_in_ready_send(EP_TEMP_IN);
      LED_Off(LED_APPLI_0);
    }
#ifdef FREERTOS_USED
  }
#endif
}
void my_usb_ep1_int_action(void){
  Usb_select_endpoint(TX_EP);
  if(Is_usb_in_ready() && Is_usb_in_ready_interrupt_enabled()){
    my_uart_usb_send_to_endpoint();
  }
}
Esempio n. 23
0
void device_full_custom_task(void)
#endif
{
  U32  time=0;
  bool startup=true;

#ifdef FREERTOS_USED
  portTickType xLastWakeTime;

  xLastWakeTime = xTaskGetTickCount();
  while (true)
  {
    vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DFC_PERIOD);

    if( startup )
    {
       time+=configTSK_USB_DFC_PERIOD;
       #define STARTUP_LED_DELAY  100
       if     ( time== 1*STARTUP_LED_DELAY ) LED_On( LED_MONO0_GREEN );
       else if( time== 2*STARTUP_LED_DELAY ) LED_On( LED_MONO1_GREEN );
       else if( time== 3*STARTUP_LED_DELAY ) LED_On( LED_MONO2_GREEN );
       else if( time== 4*STARTUP_LED_DELAY ) LED_On( LED_MONO3_GREEN );
       else if( time== 5*STARTUP_LED_DELAY ) LED_Off( LED_MONO0_GREEN );
       else if( time== 6*STARTUP_LED_DELAY ) LED_Off( LED_MONO1_GREEN );
       else if( time== 7*STARTUP_LED_DELAY ) LED_Off( LED_MONO2_GREEN );
       else if( time== 8*STARTUP_LED_DELAY ) LED_Off( LED_MONO3_GREEN );
       else if( time== 9*STARTUP_LED_DELAY ) startup=false;
    }

    // First, check the device enumeration state
    if (!Is_device_enumerated()) continue;
#else
    // First, check the device enumeration state
    if (!Is_device_enumerated()) return;
#endif  // FREERTOS_USED

    if(Is_usb_out_received(EP_FC_OUT))
    {
       U32 nchar;
       Usb_reset_endpoint_fifo_access(EP_FC_OUT);
       memset(rxbuf, 0, RXBUF_SIZE);
       usb_read_ep_rxpacket(EP_FC_OUT, &rxbuf, RXBUF_SIZE, NULL);
       Usb_ack_out_received_free(EP_FC_OUT);
       //printf("Received %s\n\r", rxbuf);
       if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=temp") )
       {  // Temperature sensor
          nchar=build_answer(txbuf, "temp");
          b_temperature_get_value( txbuf+nchar );
          b_report_pending=true;
       }

       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=js") )
       {  // Joystick
          nchar=build_answer(txbuf, "js");
          b_joystick_get_value( txbuf+nchar );
          b_report_pending=true;
       }

       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb1") )
       {  // Push button 1
          nchar=build_answer(txbuf, "pb1");
          b_pushb1_get_value( txbuf+nchar );
          b_report_pending=true;
       }

       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb2") )
       {  // Push button 2
          nchar=build_answer(txbuf, "pb2");
          b_pushb2_get_value( txbuf+nchar );
          b_report_pending=true;
       }

#if BOARD == EVK1100
       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb3") )
       {  // Push button 3
          nchar=build_answer(txbuf, "pb3");
          sprintf( txbuf+nchar, "RELEASE\r\n");
          b_report_pending=true;
       }
#endif

       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=light") )
       {  // light
          U32 value;
          nchar=build_answer(txbuf, "light");
          b_light_get_value( txbuf+nchar, &value );
          e_ledm_refresh_intensity( value );
          b_report_pending=true;
       }


       else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm1") )
       {  // led1
          nchar=build_answer(txbuf, "ledm1");
          b_ledm1_get_value( txbuf+nchar );
          b_report_pending=true;
       }
       else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm2") )
       {  // led2
          nchar=build_answer(txbuf, "ledm2");
          b_ledm2_get_value( txbuf+nchar );
          b_report_pending=true;
       }
       else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm3") )
       {  // led3
          nchar=build_answer(txbuf, "ledm3");
          b_ledm3_get_value( txbuf+nchar );
          b_report_pending=true;
       }
       else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm4") )
       {  // led4
          nchar=build_answer(txbuf, "ledm4");
          b_ledm4_get_value( txbuf+nchar );
          b_report_pending=true;
       }


       else if( !strncmp((const char*)rxbuf, STR_SET_LEDM1, strlen(STR_SET_LEDM1)) )
       {  // led1
          nchar=build_answer(txbuf, "ledm1");
          e_ledm1_set_value(rxbuf+strlen(STR_SET_LEDM1), txbuf+nchar);
          b_report_pending=true;
       }
       else if( !strncmp((const char*)rxbuf, STR_SET_LEDM2, strlen(STR_SET_LEDM2)) )
       {  // led2
          nchar=build_answer(txbuf, "ledm2");
          e_ledm2_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
          b_report_pending=true;
       }
       else if( !strncmp((const char*)rxbuf, STR_SET_LEDM3, strlen(STR_SET_LEDM3)) )
       {  // led3
          nchar=build_answer(txbuf, "ledm3");
          e_ledm3_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
          b_report_pending=true;
       }
       else if( !strncmp((const char*)rxbuf, STR_SET_LEDM4, strlen(STR_SET_LEDM4)) )
       {  // led4
          nchar=build_answer(txbuf, "ledm4");
          e_ledm4_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
          b_report_pending=true;
       }


       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accx") )
       {  // accelerometer
          nchar=build_answer(txbuf, "accx");
          accelerometer_measure(0, txbuf+nchar);
          b_report_pending=true;
       }
       else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accy") )
       {  // accelerometer
          nchar=build_answer(txbuf, "accy");
          accelerometer_measure(1, txbuf+nchar);
          b_report_pending=true;
       }
    }

    if( b_report_pending && Is_usb_in_ready(EP_FC_IN) )
    {
       U8  data_to_transfer;
       char* ptr_cram=txbuf;

       //printf( "Sending %s", txbuf);
       #if 0
       Usb_reset_endpoint_fifo_access(EP_FC_IN);
       usb_write_ep_txpacket(EP_FC_IN, &txbuf, TXBUF_SIZE, NULL);
       Usb_ack_in_ready_send(EP_FC_IN);
       #endif

       data_to_transfer = strlen(txbuf);
       while (data_to_transfer)
       {
         while (!Is_usb_in_ready(EP_FC_IN));

         Usb_reset_endpoint_fifo_access(EP_FC_IN);
         data_to_transfer = usb_write_ep_txpacket(EP_FC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram);
         Usb_ack_in_ready_send(EP_FC_IN);
       }
       b_report_pending=false;
    }
#ifdef FREERTOS_USED
  }
#endif
}
// !
// ! @brief USB Command Status Wrapper (CSW) management
// !
// ! This function sends the status in relation with the last CBW.
// !
static void usb_mass_storage_csw (void)
{
    int i;
    /*
       i = 1; while (1 == i) { i = 0; if (Is_usb_endpoint_stall_requested(EP_MS_IN)) { i = 1; if (Is_usb_setup_received()) { usb_process_request(); }
       }

       if (Is_usb_endpoint_stall_requested(EP_MS_OUT)) { i = 1; if (Is_usb_setup_received()) { usb_process_request(); } } } */


    while (Is_usb_endpoint_stall_requested (EP_MS_IN))
    {
        if (Is_usb_setup_received ())
            usb_process_request ();
    }

    while (Is_usb_endpoint_stall_requested (EP_MS_OUT))
    {
        if (Is_usb_setup_received ())
            usb_process_request ();
    }


    // MSC Compliance - Free BAD out receiv during SCSI command
    while (Is_usb_out_received (EP_MS_OUT))
    {
        Usb_ack_out_received_free (EP_MS_OUT);
    }

    while (!Is_usb_in_ready (EP_MS_IN));
    /*
       // for (i=0;i<100000;i++) // Make break out { if (Is_usb_in_ready(EP_MS_IN)) { break; } } */
    Usb_reset_endpoint_fifo_access (EP_MS_IN);

    // ! Write CSW Signature
    Usb_write_endpoint_data (EP_MS_IN, 32, *(U32 *) & "USBS");

    // ! Write stored CBW Tag
    Usb_write_endpoint_data (EP_MS_IN, 32, dCBWTag);

    // ! Write data residual value
    Usb_write_endpoint_data (EP_MS_IN, 32, usb_format_mcu_to_usb_data (32, g_scsi_data_remaining));

    // ! Write command status
    Usb_write_endpoint_data (EP_MS_IN, 8, g_scsi_status);

    Usb_ack_in_ready_send (EP_MS_IN);

    // MSC Compliance - Wait end of all transmitions on USB line
    for (i = 0; i < 1000; i++)
    {
        if (0 != Usb_nb_busy_bank (EP_MS_IN))
        {
            if (Is_usb_setup_received ())
                usb_process_request ();
        }
        else
        {
            break;
        }
    }
    /*
       while( 0 != Usb_nb_busy_bank(EP_MS_IN) ) { if (Is_usb_setup_received()) usb_process_request(); } */
}
Esempio n. 25
0
//! usb_set_interface.
//!
//! TThis function manages the SET_INTERFACE request.
//!
//! @warning Code:xx bytes (function code length)
//!
//! @param none
//!
//! @return none
//!
void usb_set_interface (void)
{
  Usb_ack_receive_setup();
  Usb_send_control_in();                    //!< send a ZLP for STATUS phase
  while(!Is_usb_in_ready());
}
Esempio n. 26
0
static void usb_mass_storage_csw(void)
{
	volatile U32 timeoutTickCount = g_lifetimeHalfSecondTickCount + 6;

  while (Is_usb_endpoint_stall_requested(EP_MS_IN))
  {
	if (!Is_usb_endpoint_enabled(g_scsi_ep_ms_in)) { return; } // USB Reset
	if ((volatile U32)timeoutTickCount == (volatile U32)g_lifetimeHalfSecondTickCount) { return; }

    if (Is_usb_setup_received())
	{
		usb_process_request();
		  timeoutTickCount = (volatile U32)g_lifetimeHalfSecondTickCount + 6;
	}
  }

  timeoutTickCount = (volatile U32)g_lifetimeHalfSecondTickCount + 6;

  while (Is_usb_endpoint_stall_requested(EP_MS_OUT))
  {
	if (!Is_usb_endpoint_enabled(g_scsi_ep_ms_in)) { return; } // USB Reset
	if ((volatile U32)timeoutTickCount == (volatile U32)g_lifetimeHalfSecondTickCount) { return; }

    if (Is_usb_setup_received())
	{
		usb_process_request();
		  timeoutTickCount = (volatile U32)g_lifetimeHalfSecondTickCount + 6;
	}
  }

  // MSC Compliance - Free BAD out receive during SCSI command
  while( Is_usb_out_received(EP_MS_OUT) ) {
    Usb_ack_out_received_free(EP_MS_OUT);
  }

  timeoutTickCount = (volatile U32)g_lifetimeHalfSecondTickCount + 6;

  while (!Is_usb_in_ready(EP_MS_IN))
  {
	if (!Is_usb_endpoint_enabled(g_scsi_ep_ms_in)) { return; } // USB Reset
	if ((volatile U32)timeoutTickCount == (volatile U32)g_lifetimeHalfSecondTickCount) { return; }
  }

  Usb_reset_endpoint_fifo_access(EP_MS_IN);

  //! Write CSW Signature
  Usb_write_endpoint_data(EP_MS_IN, 32, *(uint32_t *)&"USBS");

  //! Write stored CBW Tag
  Usb_write_endpoint_data(EP_MS_IN, 32, dCBWTag);

  //! Write data residual value
  Usb_write_endpoint_data(EP_MS_IN, 32,
                          usb_format_mcu_to_usb_data(32, g_scsi_data_remaining));

  //! Write command status
  Usb_write_endpoint_data(EP_MS_IN, 8, g_scsi_status);

  Usb_ack_in_ready_send(EP_MS_IN);

  // MSC Compliance - Wait end of all transmissions on USB line
  while( 0 != Usb_nb_busy_bank(EP_MS_IN) )
  {
    if (Is_usb_setup_received()) usb_process_request();
  }
}