static void USB_CCID_GetDataFromUSB (void)
{
    int i;
    int USB_Datalen_s32;

    // Bool cbw_error;

    Usb_reset_endpoint_fifo_access (EP_CCID_OUT);

    // Get all data from USB
    USB_CCID_data_st.CCID_datalen = 0;

    while (Is_usb_out_received (EP_CCID_OUT))
    {
        Usb_reset_endpoint_fifo_access (EP_CCID_OUT);

        USB_Datalen_s32 = Usb_byte_count (EP_CCID_OUT);
        USB_Log_st.CCID_WriteCalls_u32++;
        USB_Log_st.CCID_BytesWrite_u32 += USB_Datalen_s32;

        // CI_TickLocalPrintf ("Get CCID USB block %3d byte - %3d\n",USB_Datalen_s32,USB_CCID_data_st.CCID_datalen);

        if (CCID_MAX_XFER_LENGTH <= USB_Datalen_s32 + USB_CCID_data_st.CCID_datalen)    // Check for oversize
        {
            CI_LocalPrintf ("*** CCID buffer to small %d ***\n", CCID_MAX_XFER_LENGTH);
            Usb_ack_out_received_free (EP_CCID_OUT);
            return;
        }

        for (i = 0; i < USB_Datalen_s32; i++)
        {
            USB_CCID_data_st.USB_data[USB_CCID_data_st.CCID_datalen] = Usb_read_endpoint_data (EP_CCID_OUT, 8);
            USB_CCID_data_st.CCID_datalen++;
        }

        Usb_ack_out_received_free (EP_CCID_OUT);
        DelayMs (1);
    }

    LED_RedOn ();

//    USB_CCID_Datalen_s32 = USB_CCID_data_st.CCID_datalen;

    USB_to_CRD_DispatchUSBMessage_v (&USB_CCID_data_st);

//    memset (USB_CCID_data_st.USB_data,0,USB_Datalen_s32);
    LED_RedOff ();

    // Usb_ack_out_received_free(EP_CCID_OUT);

}
//!
//! @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);
}
//******* Speaker control
void audio_speaker_set_mute(void)
{
   while(!Is_usb_control_out_received())
   {
     TASKS_SCHEDULE();
   }
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   b_speaker_mute=Usb_read_endpoint_data(EP_CONTROL, 8);
   audio_mixer_mute_audio(b_speaker_mute);

   if( b_speaker_mute )
   {
     audio_mixer_dacs_set_volume_direct((uint8_t)SPEAKER_VOL_MIN);
   }
   else
   {
     audio_mixer_dacs_set_volume_direct(s16_speaker_volume);
   }

   Usb_ack_control_out_received_free();
   Usb_ack_control_in_ready_send();  // send a ZLP
   while (!Is_usb_control_in_ready())
   {
     TASKS_SCHEDULE();
   }
}
void audio_speaker_set_volume(void)
{
   while(!Is_usb_control_out_received())
   {
     TASKS_SCHEDULE();
   }
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   LSB(s16_usb_speaker_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);
   MSB(s16_usb_speaker_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);

   // Convert USB range volume into the volume range of the application.
   s16_speaker_volume = volume_usb_to_appli(s16_usb_speaker_volume) ;

   Usb_ack_control_out_received_free();
   Usb_ack_control_in_ready_send();  // send a ZLP

   // Ensures good limits of the parameter
   s16_speaker_volume = min( s16_speaker_volume, SPEAKER_VOL_MAX);
   s16_speaker_volume = max( s16_speaker_volume, SPEAKER_VOL_MIN);
   audio_mixer_dacs_set_volume_direct(s16_speaker_volume);
   while (!Is_usb_control_in_ready())
   {
     TASKS_SCHEDULE();
   }
}
Bool sbc_read_capacity (void)
{
    U32 mem_size_nb_sector;

    switch (mem_read_capacity (usb_LUN, &mem_size_nb_sector))
    {
    case CTRL_GOOD:
        Usb_reset_endpoint_fifo_access (g_scsi_ep_ms_in);

        // Return nb block.
        Usb_write_endpoint_data (g_scsi_ep_ms_in, 32, sbc_format_mcu_to_scsi_data (32, mem_size_nb_sector));

        // Return block size (= 512 bytes).
        Usb_write_endpoint_data (g_scsi_ep_ms_in, 32, Sbc_format_mcu_to_scsi_data (32, 512));

        Sbc_valid_write_usb (SBC_READ_CAPACITY_LENGTH);
        sbc_lun_status_is_good ();
        return TRUE;

    case CTRL_NO_PRESENT:
        sbc_lun_status_is_not_present ();
        break;

    case CTRL_BUSY:
        sbc_lun_status_is_busy_or_change ();
        break;

    case CTRL_FAIL:
    default:
        sbc_lun_status_is_fail ();
        break;
    }
    return FALSE;
}
static void sbc_header_mode_sense (Bool b_sense_10, U8 u8_data_length)
{
    Usb_reset_endpoint_fifo_access (g_scsi_ep_ms_in);

    // Send data length.
    if (b_sense_10)
    {
        Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, 0);
    }
    Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, u8_data_length);

    // Send device type.
    Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, SBC_MEDIUM_TYPE);

    // Write protect status.
    Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, (mem_wr_protect (usb_LUN)) ? SBC_DEV_SPEC_PARAM_WR_PROTECT : SBC_DEV_SPEC_PARAM_WR_ENABLE);

    if (b_sense_10)
    {
        // Reserved.
        Usb_write_endpoint_data (g_scsi_ep_ms_in, 16, 0);
    }

    // Send block descriptor length.
    if (b_sense_10)
    {
        Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, 0);
    }
    Usb_write_endpoint_data (g_scsi_ep_ms_in, 8, SBC_BLOCK_DESCRIPTOR_LENGTH);
}
void sd_mmc_mci_write_multiple_sector_callback(void *psector)
{
#ifdef USB_DEVICE_VENDOR_ID
   // USB Device Stack V2
   udi_msc_trans_block( false, (uint8_t*)psector, SD_MMC_SECTOR_SIZE, NULL);
#else
  // USB Device Stack V1
  uint16_t data_to_transfer = SD_MMC_SECTOR_SIZE;

  // Transfer sector to write from the USB interface.
  while (data_to_transfer)
  {
    while (!Is_usb_out_received(g_scsi_ep_ms_out))
    {
      if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_out))
         return; // USB Reset
    }

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out);
    data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector,
                                            data_to_transfer, &psector);
    Usb_ack_out_received_free(g_scsi_ep_ms_out);
  }
#endif
}
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
}
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 USB Command Block Wrapper (CBW) management
//!
//! This function decodes the CBW command and stores the SCSI command.
//!
static void usb_mass_storage_cbw(void)
{
  bool cbw_error;

  Usb_reset_endpoint_fifo_access(EP_MS_OUT);

  //! Check if dCBWSignature is correct
  cbw_error = (Usb_read_endpoint_data(EP_MS_OUT, 32) != *(U32 *)&"USBC");

  //! Store CBW Tag to be repeated in CSW
  dCBWTag = Usb_read_endpoint_data(EP_MS_OUT, 32);

  g_scsi_data_remaining = Usb_read_endpoint_data(EP_MS_OUT, 32);
  g_scsi_data_remaining = usb_format_usb_to_mcu_data(32, g_scsi_data_remaining);

  //! if (bmCBWFlags.bit7 == 1) {direction = IN;}
  if (Usb_read_endpoint_data(EP_MS_OUT, 8))
  {
    ms_endpoint = EP_MS_IN;
    if (cbw_error)
    {
      Usb_ack_out_received_free(EP_MS_OUT);
      Usb_enable_stall_handshake(EP_MS_IN);
      return;
    }
  }
  else
  {
    ms_endpoint = EP_MS_OUT;
    if (cbw_error)
    {
      Usb_enable_stall_handshake(EP_MS_OUT);
      Usb_ack_out_received_free(EP_MS_OUT);
      return;
    }
  }

  usb_LUN = Usb_read_endpoint_data(EP_MS_OUT, 8);

  if (!ms_multiple_drive)
  {
    usb_LUN = get_cur_lun();
  }

  //! Dummy CBWCBLength read
  Usb_read_endpoint_data(EP_MS_OUT, 8);

  //! Store scsi_command
  usb_read_ep_rxpacket(EP_MS_OUT, g_scsi_command, sizeof(g_scsi_command), NULL);

  Usb_ack_out_received_free(EP_MS_OUT);

  // Take the USB Mutex(i.e. we're allowed to perform a ms cmd).
  /* if( ( pdFALSE == ( xGiveUsbMutex = x_supervisor_SemaphoreTake( xUSBMutex, 0 ) ) ) || ( !scsi_decode_command() && g_scsi_data_remaining ) ) */
  if( ( pdFALSE == (xGiveUsbMutex = x_supervisor_SemaphoreTake( xUSBMutex, 0 ) ) )
      || ( !scsi_decode_command() && g_scsi_data_remaining ) )
  {
    Usb_enable_stall_handshake(ms_endpoint);
  }
}
//! @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);
   }
}
// !
// ! @brief USB Command Block Wrapper (CBW) management
// !
// ! This function decodes the CBW command and stores the SCSI command.
// !
static void usb_mass_storage_cbw (void)
{
    Bool cbw_error;

    Usb_reset_endpoint_fifo_access (EP_MS_OUT);

    // ! Check if dCBWSignature is correct
    cbw_error = (Usb_read_endpoint_data (EP_MS_OUT, 32) != *(U32 *) & "USBC");

    // ! Store CBW Tag to be repeated in CSW
    dCBWTag = Usb_read_endpoint_data (EP_MS_OUT, 32);

    g_scsi_data_remaining = Usb_read_endpoint_data (EP_MS_OUT, 32);
    g_scsi_data_remaining = usb_format_usb_to_mcu_data (32, g_scsi_data_remaining);

    /* Show the remaining bytes { U8 Text_u8[20]; CI_StringOut (" - "); itoa ((S32)g_scsi_data_remaining,Text_u8); CI_StringOut (Text_u8);
       CI_StringOut (" - "); } */
    // ! if (bmCBWFlags.bit7 == 1) {direction = IN;}
    if (Usb_read_endpoint_data (EP_MS_OUT, 8))
    {
        ms_endpoint = EP_MS_IN;
        if (cbw_error)
        {
            Usb_ack_out_received_free (EP_MS_OUT);
            Usb_enable_stall_handshake (EP_MS_IN);
            return;
        }
    }
    else
    {
        ms_endpoint = EP_MS_OUT;
        if (cbw_error)
        {
            Usb_enable_stall_handshake (EP_MS_OUT);
            Usb_ack_out_received_free (EP_MS_OUT);
            return;
        }
    }

    usb_LUN = Usb_read_endpoint_data (EP_MS_OUT, 8);

    if (!ms_multiple_drive)
    {
        usb_LUN = get_cur_lun ();
    }

    // ! Dummy CBWCBLength read
    Usb_read_endpoint_data (EP_MS_OUT, 8);

    // ! Store scsi_command
    usb_read_ep_rxpacket (EP_MS_OUT, g_scsi_command, sizeof (g_scsi_command), NULL);

    Usb_ack_out_received_free (EP_MS_OUT);

    if (!scsi_decode_command ())
    {
        Usb_enable_stall_handshake (ms_endpoint);
    }
}
Beispiel #13
0
void cdc_flushrx(void) {		// löscht den Inhalt des Rx
  if (usb_connected) {
    Usb_reset_endpoint_fifo_access(RX_EP);
    Usb_ack_out_received_free(RX_EP);
  }
  cdc_rdpos = cdc_wrpos;
//  cdc_rxfifo_empty = TRUE;
}
Beispiel #14
0
void cdc_transmit(const char *data, int len) {
  if (usb_connected) {
    if (Is_usb_write_enabled(TX_EP)) {
      Usb_reset_endpoint_fifo_access(TX_EP);
      cdc_txbuffer_len = usb_write_ep_txpacket(TX_EP, data, len, (const void **)&cdc_txbuffer);
      Usb_ack_in_ready_send(TX_EP);
    } // fi TX_EP empty
  }
}
Beispiel #15
0
//! This function is called by the standard USB read request function when
//! the USB request is not supported. This function returns true when the
//! request is processed. This function returns false if the request is not
//! supported. In this case, a STALL handshake will be automatically
//! sent by the standard USB read request function.
//!
bool usb_user_read_request(U8 type, U8 request)
{
  Usb_read_endpoint_data(EP_CONTROL, 8); // string_type
  Usb_read_endpoint_data(EP_CONTROL, 8); // descriptor_type

  switch (request)
  {
#if( EVK1101_CTRL_PANEL_PID==EVK1101_CTRL_PANEL_DEMO_HID_MS_PID )
  case MASS_STORAGE_RESET:
    Usb_ack_setup_received_free();
    Usb_ack_control_in_ready_send();
    return true;

  case GET_MAX_LUN:
    Usb_ack_setup_received_free();
    Usb_reset_endpoint_fifo_access(EP_CONTROL);
    Usb_write_endpoint_data(EP_CONTROL, 8, get_nb_lun() - 1);
    Usb_ack_control_in_ready_send();
    while (!Is_usb_control_in_ready());

    while(!Is_usb_control_out_received());
    Usb_ack_control_out_received_free();
    ms_multiple_drive = true;
    return true;
#endif

  /*
  case HID_SET_REPORT:
    switch (descriptor_type)
    {
    case HID_REPORT_OUTPUT:
      Usb_ack_setup_received_free();
      while (!Is_usb_control_out_received());
      Usb_ack_control_out_received_free();
      Usb_ack_control_in_ready_send();
      while (!Is_usb_control_in_ready());
      return true;

    default:
      break;
    }
    break;

  case HID_SET_IDLE:
    Usb_ack_setup_received_free();
    Usb_ack_control_in_ready_send();
    while (!Is_usb_control_in_ready());
    return true;
*/

  default:
    break;
  }

  return false;
}
//! @brief Get data report from Host
//!
void hid_report_out(void)
{
  int led_number;
  int led_state;

   if(Is_usb_out_received(EP_HID_GENERIC_OUT))
   {
      Usb_reset_endpoint_fifo_access(EP_HID_GENERIC_OUT);
      memset(rxbuf, 0, RXBUF_SIZE);
      usb_read_ep_rxpacket(EP_HID_GENERIC_OUT, &rxbuf, RXBUF_SIZE, NULL);
      Usb_ack_out_received_free(EP_HID_GENERIC_OUT);
      // The Data has been read and stored in rxbuf

      led_state      = rxbuf[0]&0x0F; // RepportOUT[0] is LEDS value
      led_number     = rxbuf[1]&0x0F;
      switch (led_number)
      {
         case 1:
            if(led_state)
            {   gpio_clr_gpio_pin(LED0_GPIO);   }
            else { gpio_set_gpio_pin(LED0_GPIO);}
            break;
         case 2:
            if(led_state)
            {   gpio_clr_gpio_pin(LED1_GPIO);   }
            else { gpio_set_gpio_pin(LED1_GPIO);}
            break;
         case 3:
            if(led_state)
            {   gpio_clr_gpio_pin(LED2_GPIO);   }
            else { gpio_set_gpio_pin(LED2_GPIO);}
            break;
         case 4:
            if(led_state)
            {   gpio_clr_gpio_pin(LED3_GPIO);   }
            else { gpio_set_gpio_pin(LED3_GPIO);}
            break;
      }

   }

   //** Check if we received DFU mode command from host
   if(jump_bootloader)
   {
      uint32_t volatile tempo;
      gpio_set_gpio_pin(LED0_GPIO);
      gpio_set_gpio_pin(LED1_GPIO);
      gpio_set_gpio_pin(LED2_GPIO);
      gpio_set_gpio_pin(LED3_GPIO);
      Usb_detach();                          // Detach actual generic HID application
      for(tempo=0;tempo<70000;tempo++);      // Wait some time before
      //start_boot();                          // Jumping to bootloader
      while(1);
   }
}
//! This function is called by the standard USB read request function when
//! the USB request is not supported. This function returns true when the
//! request is processed. This function returns false if the request is not
//! supported. In this case, a STALL handshake will be automatically
//! sent by the standard USB read request function.
//!
bool usb_user_read_request(uint8_t type, uint8_t request)
{
   uint16_t wInterface;
   uint8_t wValue_msb;
   uint8_t wValue_lsb;

   wValue_lsb = Usb_read_endpoint_data(EP_CONTROL, 8);
   wValue_msb = Usb_read_endpoint_data(EP_CONTROL, 8);

   //** Specific request from Class MassStorage
   if( USB_SETUP_SET_CLASS_INTER == type )
   {
      switch( request )
      {
         case MASS_STORAGE_RESET:
         // wValue must be 0
         // wIndex = Interface
         if( (0!=wValue_lsb) || (0!=wValue_msb) )
            break;
         wInterface=Usb_read_endpoint_data(EP_CONTROL, 16);
         if( INTERFACE_NB != wInterface )
            break;
         Usb_ack_setup_received_free();
         Usb_ack_control_in_ready_send();
         return true;
      }
   }
   if( USB_SETUP_GET_CLASS_INTER == type )
   {
      switch( request )
      {
         case GET_MAX_LUN:
         // wValue must be 0
         // wIndex = Interface
         if( (0!=wValue_lsb) || (0!=wValue_msb) )
            break;
         wInterface=Usb_read_endpoint_data(EP_CONTROL, 16);
         if( INTERFACE_NB != wInterface )
            break;
         Usb_ack_setup_received_free();
         Usb_reset_endpoint_fifo_access(EP_CONTROL);
         Usb_write_endpoint_data(EP_CONTROL, 8, get_nb_lun() - 1);
         Usb_ack_control_in_ready_send();
         while (!Is_usb_control_in_ready());

         while(!Is_usb_control_out_received());
         Usb_ack_control_out_received_free();

         ms_multiple_drive = true;
         return true;
      }
   }

   return false;
}
Beispiel #18
0
//! This function manages the HID Get_Descriptor request.
//!
static void hid_get_descriptor(U8 size_of_report, const U8* p_usb_hid_report)
{
  bool  zlp;
  U16   wIndex;
  U16   wLength;

  zlp = false;                                              /* no zero length packet */

  data_to_transfer = size_of_report;
  pbuffer          = p_usb_hid_report;

  wIndex = Usb_read_endpoint_data(EP_CONTROL, 16);
  wIndex = usb_format_usb_to_mcu_data(16, wIndex);
  wLength = Usb_read_endpoint_data(EP_CONTROL, 16);
  wLength = usb_format_usb_to_mcu_data(16, wLength);
  Usb_ack_setup_received_free();                          //!< clear the setup received flag

  if (wLength > data_to_transfer)
  {
    zlp = !(data_to_transfer % EP_CONTROL_LENGTH);  //!< zero length packet condition
  }
  else
  {
    data_to_transfer = wLength; //!< send only requested number of data bytes
  }

  Usb_ack_nak_out(EP_CONTROL);

  while (data_to_transfer && (!Is_usb_nak_out(EP_CONTROL)))
  {
    while( !Is_usb_control_in_ready() && !Is_usb_nak_out(EP_CONTROL) );

    if( Is_usb_nak_out(EP_CONTROL) )
       break;    // don't clear the flag now, it will be cleared after

    Usb_reset_endpoint_fifo_access(EP_CONTROL);
    data_to_transfer = usb_write_ep_txpacket(EP_CONTROL, pbuffer,
                                             data_to_transfer, &pbuffer);
    if( Is_usb_nak_out(EP_CONTROL) )
       break;
    else
       Usb_ack_control_in_ready_send();  //!< Send data until necessary
  }

  if ( zlp && (!Is_usb_nak_out(EP_CONTROL)) )
  {
    while (!Is_usb_control_in_ready());
    Usb_ack_control_in_ready_send();
  }

  while (!(Is_usb_nak_out(EP_CONTROL)));
  Usb_ack_nak_out(EP_CONTROL);
  while (!Is_usb_control_out_received());
  Usb_ack_control_out_received_free();
}
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 ();
    }
}
Beispiel #20
0
//! This function manages the GET CONFIGURATION request. The current
//! configuration number is returned.
//!
void usb_get_configuration(void)
{
  Usb_ack_setup_received_free();

  Usb_reset_endpoint_fifo_access(EP_CONTROL);
  Usb_write_endpoint_data(EP_CONTROL, 8, usb_configuration_nb);
  Usb_ack_control_in_ready_send();

  while (!Is_usb_control_out_received());
  Usb_ack_control_out_received_free();
}
void audio_micro_get_vol_res(void)
{
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, MICRO_VOL_RES));
   Usb_ack_control_in_ready_send();
   while(!Is_usb_control_out_received()) // send a ZLP
   {
     TASKS_SCHEDULE();
   }
   Usb_ack_control_out_received_free();
}
void audio_micro_get_mute(void)
{
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   Usb_write_endpoint_data(EP_CONTROL, 8, b_micro_mute);
   Usb_ack_control_in_ready_send();
   while(!Is_usb_control_out_received()) // send a ZLP
   {
     TASKS_SCHEDULE();
   }
   Usb_ack_control_out_received_free();
}
void audio_speaker_get_vol_max(void)
{
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, USB_SPEAKER_VOL_MAX));
   Usb_ack_control_in_ready_send();
   while(!Is_usb_control_out_received()) // send a ZLP
   {
     TASKS_SCHEDULE();
   }
   Usb_ack_control_out_received_free();
}
// Functions that manage characters output through USB
//
Bool uart_usb_tx_ready(void)
{
  if( Is_usb_write_enabled(TX_EP) )
  {
      if( b_tx_new )
      {
         Usb_reset_endpoint_fifo_access(TX_EP);
         b_tx_new = FALSE;
      }
      return TRUE;
  }
  return FALSE;
}
Beispiel #25
0
// Functions that manage characters output through USB
//
bool uart_usb_tx_ready(void)
{
  if( Is_usb_write_enabled(TX_EP) )
  {
      if( b_tx_new )
      {
         Usb_reset_endpoint_fifo_access(TX_EP);
         b_tx_new = false;
      }
      return true;
  }
  return false;
}
Beispiel #26
0
//! This function manages the GET STATUS request. The device, interface or
//! endpoint status is returned.
//!
void usb_get_status(void)
{
  U8 wIndex;

  switch (bmRequestType)
  {
  case REQUEST_DEVICE_STATUS:
    Usb_ack_setup_received_free();
    Usb_reset_endpoint_fifo_access(EP_CONTROL);
    Usb_write_endpoint_data(EP_CONTROL, 8, device_status);
    break;

  case REQUEST_INTERFACE_STATUS:
    Usb_ack_setup_received_free();
    Usb_reset_endpoint_fifo_access(EP_CONTROL);
    Usb_write_endpoint_data(EP_CONTROL, 8, INTERFACE_STATUS);
    break;

  case REQUEST_ENDPOINT_STATUS:
    Usb_read_endpoint_data(EP_CONTROL, 16); //!< dummy read (wValue)
    wIndex = Usb_read_endpoint_data(EP_CONTROL, 8);
    wIndex = Get_desc_ep_nbr(wIndex);
    Usb_ack_setup_received_free();
    Usb_reset_endpoint_fifo_access(EP_CONTROL);
    Usb_write_endpoint_data(EP_CONTROL, 8, Is_usb_endpoint_stall_requested(wIndex) );
    break;

  default:
    Usb_enable_stall_handshake(EP_CONTROL);
    Usb_ack_setup_received_free();
    return;
  }

  Usb_write_endpoint_data(EP_CONTROL, 8, 0x00);
  Usb_ack_control_in_ready_send();

  while (!Is_usb_control_out_received());
  Usb_ack_control_out_received_free();
}
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);
  }
}
void sd_mmc_spi_write_multiple_sector_callback(void *psector)
{
  U16 data_to_transfer = MMC_SECTOR_SIZE;

  while (data_to_transfer)
  {
    while (!Is_usb_out_received(g_scsi_ep_ms_out));

    Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out);
    data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector,
                                            data_to_transfer, &psector);
    Usb_ack_out_received_free(g_scsi_ep_ms_out);
  }
}
//!
//! @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 );
  }
}
//******* Micro control
void audio_micro_set_mute(void)
{
   while(!Is_usb_control_out_received())
   {
     TASKS_SCHEDULE();
   }
   Usb_reset_endpoint_fifo_access(EP_CONTROL);
   b_micro_mute=Usb_read_endpoint_data(EP_CONTROL, 8);
   Usb_ack_control_out_received_free();
   Usb_ack_control_in_ready_send();  // send a ZLP
   while (!Is_usb_control_in_ready())
   {
     TASKS_SCHEDULE();
   }
}