//! //! @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); } }
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); }
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(); } }
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 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; }
//! @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); } }
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 (); } }
char uart_usb_getchar(void) { register char data_rx; while( !uart_usb_test_hit() ); data_rx=Usb_read_endpoint_data(RX_EP, 8); if( 0==Usb_byte_count(RX_EP) ) { Usb_ack_out_received_free(RX_EP); b_rx_new = TRUE; } return data_rx; }
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 ); } }
//! //! @brief Entry point of the device Audio task management //! void device_audio_task(void) { uint32_t fifo_cnt; // Handle incoming audio samples // if (Is_usb_out_received(EP_AUDIO_OUT)) { LED_On(LED0); usb_stream_input(USB_STREAM_DEVICE, EP_AUDIO_OUT, &fifo_cnt); Usb_ack_out_received_free(EP_AUDIO_OUT); LED_Off(LED0); } #if USB_RESYNC_AUDIO_STREAM && (USB_RESYNC_AUDIO_STREAM == true) usb_stream_resync(); #endif }
Bool uart_usb_test_hit(void) { if( Is_usb_out_received(RX_EP) ) { if( 0!=Usb_byte_count(RX_EP) ) { if( b_rx_new ) { Usb_reset_endpoint_fifo_access(RX_EP); b_rx_new = FALSE; } return TRUE; } Usb_ack_out_received_free(RX_EP); b_rx_new = TRUE; } return FALSE; }
bool uart_usb_test_hit(void) { if( Is_usb_out_received(RX_EP) ) { if( 0!=Usb_byte_count(RX_EP) ) { if( b_rx_new ) { Usb_reset_endpoint_fifo_access(RX_EP); b_rx_new = false; } return true; } Usb_ack_out_received_free(RX_EP); b_rx_new = true; } return false; }
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); } }
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 }
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 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 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(); } */ }
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(); } }