#include "config.h"
#include "conf_usb.h"
#include "modules/usb/usb_task.h"
#include "usb_host_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "lib_mcu/pll/pll_drv.h"
#include "modules/usb/host_chap9/usb_host_enum.h"
#include "modules/usb/host_chap9/usb_host_hub.h"
Go to the source code of this file.
Defines | |
#define | Usb_id_transition_action() |
#define | Host_device_disconnection_action() |
#define | Host_device_connection_action() |
#define | Host_sof_action() |
#define | Host_suspend_action() |
#define | Host_hwup_action() |
#define | Host_device_not_supported_action() |
#define | Host_device_class_not_supported_action() |
#define | Host_device_supported_action() |
#define | Host_device_error_action() |
#define | LOG_STR_CODE(str) |
Functions | |
void | usb_host_task_init (void) |
void | usb_host_task (void) |
U8 | host_send_data (U8 pipe, U16 nb_data, U8 *buf) |
U8 | host_get_data (U8 pipe, U16 *nb_data, U8 *buf) |
void | reset_it_pipe_str (void) |
U8 | is_any_interrupt_pipe_active (void) |
U8 | host_get_data_interrupt (U8 pipe, U16 nb_data, U8 *buf, void(*handle)(U8 status, U16 nb_byte)) |
U8 | host_send_data_interrupt (U8 pipe, U16 nb_data, U8 *buf, void(*handle)(U8 status, U16 nb_byte)) |
__interrupt void | usb_pipe_interrupt () |
Variables | |
volatile S_pipe_int | it_pipe_str [MAX_EP_NB] |
volatile U8 | pipe_nb_save |
U8 | g_sav_int_sof_enable |
U8 | device_state |
Public : U8 device_state Its value represent the current state of the device connected to the usb host controller Value can be:
| |
S_usb_setup_data | usb_request |
For control requests management over pipe 0. | |
U8 | data_stage [SIZEOF_DATA_STAGE] |
Public : U8 data_stage[SIZEOF_DATA_STAGE]; Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process Its contains the device descriptors received. | |
U8 | device_status |
U8 | request_resume = FALSE |
U8 | force_enumeration = FALSE |
U8 | new_device_connected = 0 |
static U16 | c |
static U8 | i |
static U8 | j |
volatile U8 | hub_interrupt_sof = 0 |
U8 | saved_device |
Definition in file usb_host_task.c.
#define Usb_id_transition_action | ( | ) |
Definition at line 81 of file usb_host_task.c.
#define Host_device_disconnection_action | ( | ) |
Definition at line 84 of file usb_host_task.c.
#define Host_device_connection_action | ( | ) |
Definition at line 87 of file usb_host_task.c.
#define Host_sof_action | ( | ) |
Definition at line 90 of file usb_host_task.c.
#define Host_suspend_action | ( | ) |
Definition at line 93 of file usb_host_task.c.
#define Host_hwup_action | ( | ) |
Definition at line 96 of file usb_host_task.c.
#define Host_device_not_supported_action | ( | ) |
Definition at line 99 of file usb_host_task.c.
#define Host_device_class_not_supported_action | ( | ) |
Definition at line 102 of file usb_host_task.c.
#define Host_device_supported_action | ( | ) |
Definition at line 105 of file usb_host_task.c.
#define Host_device_error_action | ( | ) |
Definition at line 108 of file usb_host_task.c.
#define LOG_STR_CODE | ( | str | ) |
Definition at line 115 of file usb_host_task.c.
Referenced by usb_general_interrupt(), and usb_host_task().
__interrupt void usb_pipe_interrupt | ( | ) |
USB pipe interrupt subroutine
none |
Definition at line 1119 of file usb_host_task.c.
References DISABLE, S_pipe_int::enable, FALSE, g_sav_int_sof_enable, S_pipe_int::handle, Host_ack_all_errors, Host_ack_in_received, Host_ack_nak_received, Host_ack_out_sent, Host_byte_counter, Host_disable_sof_interrupt, Host_error_status, Host_freeze_pipe, Host_get_pipe_length, Host_get_pipe_type, Host_get_selected_pipe, Host_read_byte, Host_select_pipe, Host_send_in, Host_send_out, Host_stop_pipe_interrupt, Host_unfreeze_pipe, Host_write_byte, i, is_any_interrupt_pipe_active(), Is_host_in_received, Is_host_nak_received, Is_host_out_sent, Is_host_pipe_error, Is_host_stall, NAK_RECEIVE_TIMEOUT, NAK_SEND_TIMEOUT, S_pipe_int::nak_timeout, S_pipe_int::nb_byte_on_going, S_pipe_int::nb_byte_processed, S_pipe_int::nb_byte_to_process, PIPE_GOOD, PIPE_NAK_TIMEOUT, pipe_nb_save, PIPE_STALL, private_sof_counter, S_pipe_int::ptr_buf, S_pipe_int::status, S_pipe_int::timeout, TRUE, TYPE_INTERRUPT, and usb_get_nb_pipe_interrupt().
01121 { 01122 U8 pipe_nb; 01123 U8 *ptr_buf; 01124 void (*fct_handle)(U8 status,U16 nb_byte); 01125 U16 n; 01126 U8 i; 01127 U8 do_call_back=FALSE; 01128 01129 pipe_nb_save = Host_get_selected_pipe(); // Important! Save here working pipe number 01130 pipe_nb=usb_get_nb_pipe_interrupt(); // work with the correct pipe number that generates the interrupt 01131 Host_select_pipe(pipe_nb); // Select this pipe 01132 fct_handle=*(it_pipe_str[pipe_nb].handle); 01133 01134 // Now try to detect what event generate an interrupt... 01135 01136 if (Is_host_pipe_error()) // Any error ? 01137 { 01138 it_pipe_str[pipe_nb].status = Host_error_status(); 01139 it_pipe_str[pipe_nb].enable=DISABLE; 01140 Host_stop_pipe_interrupt(pipe_nb); 01141 Host_ack_all_errors(); 01142 do_call_back=TRUE; 01143 goto usb_pipe_interrupt_end; 01144 } 01145 01146 if (Is_host_stall()) // Stall handshake received ? 01147 { 01148 it_pipe_str[pipe_nb].status=PIPE_STALL; 01149 it_pipe_str[pipe_nb].enable=DISABLE; 01150 Host_stop_pipe_interrupt(pipe_nb); 01151 do_call_back=TRUE; 01152 goto usb_pipe_interrupt_end; 01153 } 01154 01155 #if (NAK_TIMEOUT_ENABLE==ENABLE) 01156 if (Is_host_nak_received()) // NAK ? 01157 { 01158 Host_ack_nak_received(); 01159 // check if number of NAK timeout error occurs (not for interrupt type pipe) 01160 if((--it_pipe_str[pipe_nb].nak_timeout==0) && (Host_get_pipe_type()!=TYPE_INTERRUPT)) 01161 { 01162 it_pipe_str[pipe_nb].status=PIPE_NAK_TIMEOUT; 01163 it_pipe_str[pipe_nb].enable=DISABLE; 01164 Host_stop_pipe_interrupt(pipe_nb); 01165 do_call_back=TRUE; 01166 goto usb_pipe_interrupt_end; 01167 } 01168 } 01169 #endif 01170 01171 if (Is_host_in_received()) // Pipe IN reception ? 01172 { 01173 ptr_buf=it_pipe_str[pipe_nb].ptr_buf+it_pipe_str[pipe_nb].nb_byte_processed; // Build pointer to data buffer 01174 n=it_pipe_str[pipe_nb].nb_byte_to_process-it_pipe_str[pipe_nb].nb_byte_processed; // Remaining data bytes 01175 Host_freeze_pipe(); 01176 if (Host_byte_counter()<=n) 01177 { 01178 if ((Host_byte_counter() < n)&&(Host_byte_counter()<Host_get_pipe_length())) //Received less than remaining, but less than pipe capacity 01179 //TODO: error code 01180 { 01181 n=0; 01182 } 01183 else 01184 { 01185 n-=Host_byte_counter(); 01186 } 01187 it_pipe_str[pipe_nb].nb_byte_processed+=Host_byte_counter(); // Update nb of byte received 01188 for (i=Host_byte_counter();i;i--) 01189 { *ptr_buf=Host_read_byte(); ptr_buf++;} 01190 } 01191 else // more bytes received than expected 01192 { // TODO error code management 01193 it_pipe_str[pipe_nb].nb_byte_processed+=n; 01194 for (i=n;i;i--) // Byte number limited to the initial request (limit tab over pb) 01195 { *ptr_buf=Host_read_byte(); ptr_buf++;} 01196 n=0; 01197 } 01198 Host_ack_in_received(); 01199 if(n>0) //still something to process 01200 { 01201 Host_unfreeze_pipe(); // Request another IN transfer 01202 Host_send_in(); 01203 private_sof_counter=0; // Reset the counter in SOF detection sub-routine 01204 it_pipe_str[pipe_nb].timeout=0; // Reset timeout 01205 it_pipe_str[pipe_nb].nak_timeout=NAK_RECEIVE_TIMEOUT; 01206 01207 } 01208 else //end of transfer 01209 { 01210 it_pipe_str[pipe_nb].enable=DISABLE; 01211 it_pipe_str[pipe_nb].status=PIPE_GOOD; 01212 Host_stop_pipe_interrupt(pipe_nb); 01213 do_call_back=TRUE; 01214 } 01215 } 01216 01217 if(Is_host_out_sent()) // Pipe OUT sent ? 01218 { 01219 Host_ack_out_sent(); 01220 it_pipe_str[pipe_nb].nb_byte_processed+=it_pipe_str[pipe_nb].nb_byte_on_going; 01221 it_pipe_str[pipe_nb].nb_byte_on_going=0; 01222 ptr_buf=it_pipe_str[pipe_nb].ptr_buf+it_pipe_str[pipe_nb].nb_byte_processed; // Build pointer to data buffer 01223 n=it_pipe_str[pipe_nb].nb_byte_to_process-it_pipe_str[pipe_nb].nb_byte_processed; // Remaining data bytes 01224 if(n>0) // Still data to process... 01225 { 01226 Host_unfreeze_pipe(); 01227 // Prepare data to be sent 01228 i = Host_get_pipe_length(); 01229 if ( i > n) // Pipe size> remaining data 01230 { 01231 i = n; 01232 n = 0; 01233 } 01234 else // Pipe size < remaining data 01235 { n -= i; } 01236 it_pipe_str[pipe_nb].nb_byte_on_going+=i; // Update nb data processed 01237 while (i!=0) // Load Pipe buffer 01238 { 01239 Host_write_byte(*ptr_buf++); i--; 01240 } 01241 private_sof_counter=0; // Reset the counter in SOF detection sub-routine 01242 it_pipe_str[pipe_nb].timeout=0; // Refresh timeout counter 01243 it_pipe_str[pipe_nb].nak_timeout=NAK_SEND_TIMEOUT; 01244 Host_send_out(); // Send the USB frame 01245 } 01246 else //n==0 Transfer is finished 01247 { 01248 it_pipe_str[pipe_nb].enable=DISABLE; // Tranfer end 01249 it_pipe_str[pipe_nb].status=PIPE_GOOD; // Status OK 01250 Host_stop_pipe_interrupt(pipe_nb); 01251 do_call_back=TRUE; 01252 } 01253 } 01254 01255 usb_pipe_interrupt_end: 01256 Host_select_pipe(pipe_nb_save); // Restore pipe number !!!! 01257 if (is_any_interrupt_pipe_active()==FALSE) // If no more transfer is armed 01258 { 01259 if (g_sav_int_sof_enable==FALSE) 01260 { 01261 Host_disable_sof_interrupt(); 01262 } 01263 } 01264 if(do_call_back) // Any callback functions to perform ? 01265 { 01266 fct_handle(it_pipe_str[pipe_nb].status,it_pipe_str[pipe_nb].nb_byte_processed); 01267 } 01268 }
volatile S_pipe_int it_pipe_str[MAX_EP_NB] |
Definition at line 129 of file usb_host_task.c.
volatile U8 pipe_nb_save |
Definition at line 131 of file usb_host_task.c.
Referenced by host_get_data_interrupt(), host_send_data_interrupt(), usb_general_interrupt(), and usb_pipe_interrupt().
Definition at line 174 of file usb_host_task.c.
Referenced by host_check_class(), host_check_VID_PID(), host_send_control(), host_send_data(), uart_getchar(), and usb_host_task().
Definition at line 178 of file usb_host_task.c.
Referenced by device_template_task(), host_auto_configure_endpoint(), host_disable_all_pipe(), host_get_data(), host_get_hwd_pipe_nb(), host_send_data_interrupt(), host_template_task(), host_template_task_init(), init_usb_tree(), is_any_interrupt_pipe_active(), remove_device_entry(), reset_it_pipe_str(), usb_general_interrupt(), usb_get_nb_pipe_interrupt(), usb_host_task(), and usb_pipe_interrupt().
Definition at line 178 of file usb_host_task.c.
Referenced by host_get_hwd_pipe_nb(), remove_device_entry(), and usb_host_task().
volatile U8 hub_interrupt_sof = 0 |
Definition at line 179 of file usb_host_task.c.
Referenced by usb_general_interrupt(), and usb_host_task().