//!
//! @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, *(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();
  }
}
Exemple #2
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
}
Exemple #3
0
void adc_sample_sent_cb(void)
{
  uint32_t i;
  uint8_t  old_mic_buf_id=mic_buf_id;

  if (!b_microphone_pause && Is_usb_write_enabled(EP_AUDIO_IN) && audio_mixer_dacs_input(NULL, 0) )  // Endpoint buffer free ?
  {
    mic_frame_id++;
    if( mic_frame_id>=10 )
    {
      mic_frame_id=0;
      microphone[mic_buf_id].size = 45;
    }
    else
      microphone[mic_buf_id].size = 44;

    Usb_reset_endpoint_fifo_access(EP_AUDIO_IN);
    if(!mute)
    {
      for(i = 0; i < microphone[old_mic_buf_id].size; i++)
      {
          Usb_write_endpoint_data(EP_AUDIO_IN, 8, LSB(microphone[old_mic_buf_id].buffer[2 * i]));
          Usb_write_endpoint_data(EP_AUDIO_IN, 8, MSB(microphone[old_mic_buf_id].buffer[2 * i]));
      }
    }
    else
    {
      for(i = 0; i < 2*microphone[old_mic_buf_id].size; i++)
      {
          Usb_write_endpoint_data(EP_AUDIO_IN, 8, 0);
      }
    }
    Usb_ack_in_ready_send(EP_AUDIO_IN);

    audio_mixer_dacs_input(microphone[mic_buf_id].buffer, 45/*microphone[mic_buf_id].size*/);
    // Let's switch to the next buffer.
    mic_buf_id^=1;
  }
  else
    b_microphone_started=false;
}
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;
        }
    }

}
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
}
// !
// ! @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(); } */
}
Exemple #7
0
void device_audio_task(void)
#endif
{
#if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B)
  uint32_t  i;
#endif
  uint32_t  fifo_cnt;
  int  stream_status;

#ifdef FREERTOS_USED
  portTickType xLastWakeTime;
  xLastWakeTime = xTaskGetTickCount();
  LED_On(LED0);

  while (true)
  {
    vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DAUDIO_PERIOD);

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

    mmi_display();

#if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B)
    // Microphone emulation
    //
    if ( is_joystick_pressed() )
    {
       if (Is_usb_write_enabled(EP_AUDIO_IN))   // Endpoint buffer free ?
       {
          Usb_reset_endpoint_fifo_access(EP_AUDIO_IN);
          for( i=0 ; i<EP_SIZE_IN ; i++ )   // Fill endpoint with sample raw
          {
             if(mute==false)
             {
                uint8_t sample;
                sample = sample_sound[dat_sample_index++];
                LED_Set_Intensity(LED0, sample);
                Usb_write_endpoint_data(EP_AUDIO_IN, 8, sample);
                if (dat_sample_index >= SAMPLE_SOUND_LEN)
                {  dat_sample_index=0; }
             }
             else
             {
                LED_Set_Intensity(LED0, 0);
                Usb_write_endpoint_data(EP_AUDIO_IN, 8, 0x00);
             }
          }
          Usb_ack_in_ready_send(EP_AUDIO_IN);
       }
    }
#else
    // Handle input stream from microphone
    if( !b_microphone_started && (Is_usb_write_enabled(EP_AUDIO_IN)) && audio_mixer_dacs_input(NULL, 0) )
    {
      // Start ADC conversion. This will launch the IRL in background...
      mic_buf_id = 0;
      mic_frame_id=2;
      microphone[mic_buf_id].size=45;
      audio_mixer_dacs_input(microphone[0].buffer, 45 /*microphone[mic_buf_id].size*/);
      audio_mixer_dacs_input(microphone[1].buffer, 45 /*microphone[mic_buf_id].size*/);
      b_microphone_started=true;
    }
#endif



    // Handle incoming audio samples
    //
    if((Is_usb_out_received(EP_AUDIO_OUT) )
    /*&& (Is_usb_stall(EP_AUDIO_OUT)==false)*/)
    {
       stream_status = usb_stream_input(USB_STREAM_DEVICE, EP_AUDIO_OUT, &fifo_cnt);
       Usb_ack_out_received_free(EP_AUDIO_OUT);
       mmi_activity_display(false, fifo_cnt);
    }
#if USB_RESYNC_AUDIO_STREAM && (USB_RESYNC_AUDIO_STREAM==true)
    usb_stream_resync();
#endif

#ifdef FREERTOS_USED
  }
#endif
}
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();
  }
}
Exemple #9
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
}
Exemple #10
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
}