Пример #1
0
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
}
Пример #2
0
//!
//! @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 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);
    }
}
//! @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);
   }
}
Пример #5
0
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);
  }
}
Пример #6
0
void cdc_receiving(void) {		// return: Anzahl empfangener Bytes im Fifo
  int bytes_rx, bytes_left;
#if USB_DEVICE_FEATURE == ENABLED && USB_HOST_FEATURE == ENABLED
   usb_task();
#elif USB_DEVICE_FEATURE == ENABLED
   usb_device_task();
#elif USB_HOST_FEATURE == ENABLED
   usb_host_task();
#endif
  if ( usb_connected && Is_usb_out_received(RX_EP) ) {
    bytes_rx = Usb_byte_count(RX_EP);
    if ((bytes_rx > 0)&&(bytes_rx < cdc_rxleft)) {
      bytes_left = CDC_RXBUFFERSIZE-cdc_wrpos;
      Usb_reset_endpoint_fifo_access(RX_EP);
      if (bytes_rx <= bytes_left) {	// Normalfall: kein Wrap
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_rx, NULL);
      } else {
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer+cdc_wrpos, bytes_left, NULL);
        usb_read_ep_rxpacket(RX_EP, (void *)cdc_rxbuffer, bytes_rx-bytes_left, NULL);
      }
      cdc_wrpos = (cdc_wrpos+bytes_rx)%CDC_RXBUFFERSIZE;
      // End copy in own fifo
      cdc_rxidle_pos = cdc_sof_counter + cdc_timeoutval;
      cdc_timeout_enabled = (cdc_timeoutval>0)&&(cdc_timeout_fct!=NULL);
    } // fi copy received
    Usb_ack_out_received_free(RX_EP);	// moved outside of if-con
  } else if (cdc_timeout_enabled) {
    if ((int)(cdc_sof_counter - cdc_rxidle_pos) >= 0) {
      cdc_timeout_fct(cdc_rxlen);
      cdc_timeout_enabled = FALSE;
    }
  } // esle fi to
  // chain-tx (>64 byte):
  if (cdc_txbuffer_len > 0) {
    cdc_transmit(cdc_txbuffer, cdc_txbuffer_len);
  } // fi
}
void at45dbx_write_multiple_sector_callback(void *psector)
{
  U16 data_to_transfer = AT45DBX_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);
  }
}
Пример #8
0
void sd_mmc_spi_write_multiple_sector_callback(void *psector)
{
#ifdef USB_DEVICE_VENDOR_ID
   // USB Device Stack V2
   udi_msc_trans_block( false, (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_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);
  }
#endif
}
//!
//! @brief This function takes the stream coming from the selected USB pipe and sends
//! it to the DAC driver. Moreover, it ensures that both input and output stream
//! keep synchronized by adding or deleting samples.
//!
//! @param side          USB_STREAM_HOST for USB host, USB_STREAM_DEVICE for device.
//! @param pipe_in       Number of the addressed pipe/endpoint
//! @param pFifoCount    (return parameter) NULL or pointer to the number of used buffers at this time
//!
//! @return              status: (USB_STREAM_STATUS_OK, USB_STREAM_STATUS_NOT_SYNCHRONIZED,
//!                      USB_STREAM_STATUS_SPEED_UP, USB_STREAM_STATUS_SLOW_DOWN, USB_STREAM_STATUS_BUFFER_OVERFLOW)
//!
int usb_stream_input(usb_stream_side_t side, uint8_t pipe_in, uint32_t* pFifoCount)
{
   uint16_t      fifo_used_cnt;
   uint16_t      byte_count=0;
   uint32_t      i;
   UnionPtr pswap;
   UnionPtr buffer;

   // We comes here since we have received something. Let's increase the internal
   // activity counter.
   usb_stream_cnt++;

   fifo_used_cnt=usb_stream_fifo_get_used_room();
   if (pFifoCount)
      *pFifoCount = fifo_used_cnt;

   // usb_stream_fifo_get_free_room()
   if( USB_STREAM_BUFFER_NUMBER-fifo_used_cnt==0 )
   {  // Fatal error: even with the synchro mechanism acting, we are in a case in which the
      // buffers are full.
      usb_stream_context->synchronized = false;
      usb_stream_context->status = USB_STREAM_ERROR_NOT_SYNCHRONIZED;
      return usb_stream_context->status;
   }

   pswap.s8ptr  =
   buffer.s8ptr = usb_stream_fifo_get_buffer(usb_stream_context->wr_id);

#if USB_HOST_FEATURE == true
   if( side==USB_STREAM_HOST )
   {
      byte_count=Host_byte_count(pipe_in);
   }
#endif
#if USB_DEVICE_FEATURE == true
   if( side==USB_STREAM_DEVICE )
   {
      byte_count=Usb_byte_count(pipe_in);
   }
#endif
  if( byte_count==0 )
  {
     if( cpu_is_timeout(&broken_stream_timer) ) {
        usb_stream_context->status = USB_STREAM_ERROR_BROKEN_STREAM;
     } else {
        usb_stream_context->status = USB_STREAM_ERROR_NO_DATA;
     }
     return usb_stream_context->status;
  }
  else
  {
    // reset time out detection
    cpu_set_timeout(cpu_ms_2_cy(BROKEN_STREAM_TIMER, FCPU_HZ), &broken_stream_timer);
  }

#if USB_HOST_FEATURE == true
   if( side==USB_STREAM_HOST )
   {
      Host_reset_pipe_fifo_access(pipe_in);
      host_read_p_rxpacket(pipe_in, (void*)buffer.s8ptr, byte_count, NULL);
	 }
#endif
#if USB_DEVICE_FEATURE == true
   if( side==USB_STREAM_DEVICE )
	 {
      Usb_reset_endpoint_fifo_access(pipe_in);
      usb_read_ep_rxpacket(pipe_in, (void*)buffer.s8ptr, byte_count, NULL);
	}
#endif

   usb_stream_context->status = USB_STREAM_ERROR_NONE;

   if( byte_count > USB_STREAM_REAL_BUFFER_SIZE )
   {
      byte_count = USB_STREAM_REAL_BUFFER_SIZE;
      usb_stream_context->status = USB_STREAM_ERROR_OVERFLOW;
   }

   // Swap samples since they are coming from the USB world.
   if( usb_stream_context->bits_per_sample==16 )
      for( i=0 ; i<byte_count/(16/8) ; i++ )
         pswap.s16ptr[i] = swap16(pswap.s16ptr[i]);

   else if( usb_stream_context->bits_per_sample==32 )
      for( i=0 ; i<byte_count/(32/8) ; i++ )
         pswap.s32ptr[i] = swap32(pswap.s32ptr[i]);

   //for( i=0 ; i<byte_count/2 ; i++ )
   //   printf("0x%04hx ", pswap[i]);
   //printf("\r\n");

   usb_stream_fifo_push(byte_count);
   fifo_used_cnt++;

   if( !usb_stream_context->synchronized )
   {
      usb_stream_context->status = USB_STREAM_ERROR_NOT_SYNCHRONIZED;

      if( fifo_used_cnt>=(USB_STREAM_BUFFER_NUMBER/2) )
      {  // We have enough buffers to start the playback.
         void* buffer;
         uint16_t   size;

         // CS2200
         cs2200_freq_clk_out(_32_BITS_RATIO(usb_stream_resync_frequency, CS2200_FREF));
         usb_stream_resync_step = PPM(usb_stream_resync_frequency, USB_STREAM_RESYNC_PPM_STEPS);
         usb_stream_resync_freq_ofst = usb_stream_resync_frequency;
         usb_stream_resync_ppm_ofst = 0;
         usb_stream_resync_last_room = fifo_used_cnt;
#define TIMER_USB_RESYNC_CORRECTION  320
         cpu_set_timeout( cpu_ms_2_cy(TIMER_USB_RESYNC_CORRECTION, FCPU_HZ), &usb_resync_timer );

         usb_stream_context->synchronized=true;
         usb_stream_fifo_get(&buffer, &size);
         audio_mixer_dacs_output_direct(buffer, size/(usb_stream_context->channel_count*usb_stream_context->bits_per_sample/8));

         // Fill also the reload stage of the PDCA.
         usb_stream_fifo_pull();
         usb_stream_fifo_get(&buffer, &size);
         audio_mixer_dacs_output_direct(buffer, size/(usb_stream_context->channel_count*usb_stream_context->bits_per_sample/8));
      }
   }

   return usb_stream_context->status;
}
Пример #10
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
}
Пример #11
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
}