/** * @brief This function send nb_data pointed with *buf with the pipe number specified * * * @param pipe * @param nb_data * @param buf * @param handle call back function pointer * * @return status */ U8 host_send_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void(*handle)(U8 status, U16 nb_byte)) { U8 i; U8 *ptr_buf=buf; Host_select_pipe(pipe); if(it_pipe_str[pipe].enable==ENABLE) { return HOST_FALSE; } else { if(is_any_interrupt_pipe_active()==FALSE) { g_sav_int_sof_enable=Is_host_sof_interrupt_enabled(); Host_enable_sof_interrupt(); } it_pipe_str[pipe].enable=ENABLE; it_pipe_str[pipe].nb_byte_to_process=nb_data; it_pipe_str[pipe].nb_byte_processed=0; it_pipe_str[pipe].ptr_buf=buf; it_pipe_str[pipe].handle=handle; it_pipe_str[pipe].timeout=0; it_pipe_str[pipe].nak_timeout=NAK_SEND_TIMEOUT; it_pipe_str[pipe].nb_byte_on_going=0; Host_reset_pipe(pipe); Host_unfreeze_pipe(); // Prepare data to be sent i = Host_get_pipe_length(); if ( i > nb_data) // Pipe size> remaining data { i = nb_data; nb_data = 0; } else // Pipe size < remaining data { nb_data -= i; } it_pipe_str[pipe].nb_byte_on_going+=i; // Update nb data processed while (i!=0) // Load Pipe buffer { Host_write_byte(*ptr_buf++); i--; } private_sof_counter=0; // Reset the counter in SOF detection sub-routine it_pipe_str[pipe].timeout=0; // Refresh timeout counter Host_ack_out_sent(); Host_ack_stall(); Host_ack_nak_received(); Host_enable_stall_interrupt(); Host_enable_error_interrupt(); #if (NAK_TIMEOUT_ENABLE==ENABLE) Host_enable_nak_interrupt(); #endif Host_enable_transmit_interrupt(); Host_send_out(); // Send the USB frame return HOST_TRUE; } }
//! //! @brief This function sends nb_data bytes pointed to by ptr_buf on the specified pipe. //! //! @param pipe //! @param nb_data //! @param ptr_buf //! @param handler Call-back function pointer //! //! @return bool: Status //! bool host_send_data_interrupt(uint8_t pipe, uint16_t nb_data, const void *ptr_buf, Pipe_handler *handler) { bool sav_glob_int_en; if (it_pipe_str[pipe].enable) return false; if (!is_any_interrupt_pipe_active()) { g_sav_int_sof_enable = Is_host_sof_interrupt_enabled(); Host_enable_sof_interrupt(); } it_pipe_str[pipe].enable = true; it_pipe_str[pipe].nb_byte_to_process = nb_data; it_pipe_str[pipe].nb_byte_processed = 0; it_pipe_str[pipe].ptr_buf = (void *)ptr_buf; it_pipe_str[pipe].handler = handler; it_pipe_str[pipe].timeout = 0; it_pipe_str[pipe].nak_timeout = NAK_SEND_TIMEOUT; if ((sav_glob_int_en = cpu_irq_is_enabled())) cpu_irq_disable(); Host_reset_pipe(pipe); (void)Is_host_resetting_pipe(pipe); if (sav_glob_int_en) cpu_irq_enable(); Host_configure_pipe_token(pipe, TOKEN_OUT); Host_ack_out_ready(pipe); Host_unfreeze_pipe(pipe); // Prepare data to be sent Host_reset_pipe_fifo_access(pipe); it_pipe_str[pipe].nb_byte_on_going = nb_data - host_write_p_txpacket(pipe, ptr_buf, nb_data, NULL); private_sof_counter = 0; // Reset the counter in SOF detection subroutine it_pipe_str[pipe].timeout = 0; // Refresh time-out counter if ((sav_glob_int_en = cpu_irq_is_enabled())) cpu_irq_disable(); Host_ack_out_ready(pipe); Host_ack_stall(pipe); Host_ack_nak_received(pipe); (void)Is_host_nak_received(pipe); if (sav_glob_int_en) cpu_irq_enable(); Host_enable_stall_interrupt(pipe); Host_enable_pipe_error_interrupt(pipe); #if NAK_TIMEOUT_ENABLE == ENABLE Host_enable_nak_received_interrupt(pipe); #endif Host_enable_out_ready_interrupt(pipe); Host_enable_pipe_interrupt(pipe); Host_send_out(pipe); // Send the USB frame return true; }
//! //! @brief This function receives nb_data bytes pointed to by ptr_buf on the specified pipe. //! //! *nb_data is updated with the final number of data bytes received. //! //! @param pipe //! @param nb_data //! @param ptr_buf //! @param handler Call-back function pointer //! //! @return bool: Status //! bool host_get_data_interrupt(uint8_t pipe, uint16_t nb_data, void *ptr_buf, Pipe_handler *handler) { bool sav_glob_int_en; if (it_pipe_str[pipe].enable) return false; if (!is_any_interrupt_pipe_active()) { g_sav_int_sof_enable = Is_host_sof_interrupt_enabled(); Host_enable_sof_interrupt(); } it_pipe_str[pipe].enable = true; it_pipe_str[pipe].nb_byte_to_process = nb_data; it_pipe_str[pipe].nb_byte_processed = 0; it_pipe_str[pipe].ptr_buf = ptr_buf; it_pipe_str[pipe].handler = handler; it_pipe_str[pipe].timeout = 0; it_pipe_str[pipe].nak_timeout = NAK_RECEIVE_TIMEOUT; private_sof_counter = 0; // Reset the counter in SOF detection subroutine if ((sav_glob_int_en = cpu_irq_is_enabled())) cpu_irq_disable(); Host_reset_pipe(pipe); Host_ack_stall(pipe); Host_ack_nak_received(pipe); (void)Is_host_nak_received(pipe); if (sav_glob_int_en) cpu_irq_enable(); Host_enable_stall_interrupt(pipe); #if NAK_TIMEOUT_ENABLE == ENABLE Host_enable_nak_received_interrupt(pipe); #endif Host_enable_pipe_error_interrupt(pipe); Host_enable_in_received_interrupt(pipe); Host_enable_pipe_interrupt(pipe); Host_enable_continuous_in_mode(pipe); Host_configure_pipe_token(pipe, TOKEN_IN); Host_ack_in_received(pipe); Host_unfreeze_pipe(pipe); return true; }
/** * @brief This function receives nb_data pointed with *buf with the pipe number specified * * The nb_data parameter is passed as a U16 pointer, thus the data pointed by this pointer * is updated with the final number of data byte received. * * @param pipe * @param nb_data * @param buf * @param handle call back function pointer * * @return status */ U8 host_get_data_interrupt(U8 pipe, U16 nb_data, U8 *buf,void(*handle)(U8 status, U16 nb_byte)) { Host_select_pipe(pipe); if(it_pipe_str[pipe].enable==ENABLE) { return HOST_FALSE; } else { if(is_any_interrupt_pipe_active()==FALSE) { g_sav_int_sof_enable=Is_host_sof_interrupt_enabled(); Host_enable_sof_interrupt(); } it_pipe_str[pipe].enable=ENABLE; it_pipe_str[pipe].nb_byte_to_process=nb_data; it_pipe_str[pipe].nb_byte_processed=0; it_pipe_str[pipe].ptr_buf=buf; it_pipe_str[pipe].handle=handle; it_pipe_str[pipe].timeout=0; it_pipe_str[pipe].nak_timeout=NAK_RECEIVE_TIMEOUT; private_sof_counter=0; // Reset the counter in SOF detection sub-routine Host_reset_pipe(pipe); Host_enable_stall_interrupt(); #if (NAK_TIMEOUT_ENABLE==ENABLE) Host_enable_nak_interrupt(); #endif Host_enable_error_interrupt(); Host_enable_receive_interrupt(); Host_ack_stall(); Host_ack_nak_received(); Host_continuous_in_mode(); Host_set_token_in(); Host_ack_in_received(); Host_unfreeze_pipe(); return HOST_TRUE; } }