#include "config.h"
#include "conf_usb.h"
#include "usb_drv.h"
Include dependency graph for usb_drv.c:
Go to the source code of this file.
Functions | |
U8 | usb_config_ep (U8 config0, U8 config1) |
usb_configure_endpoint. | |
U8 | usb_select_enpoint_interrupt (void) |
usb_select_endpoint_interrupt. | |
U8 | usb_send_packet (U8 ep_num, U8 *tbuf, U8 data_length) |
usb_send_packet. | |
U8 | usb_read_packet (U8 ep_num, U8 *rbuf, U8 data_length) |
usb_read_packet. | |
void | usb_halt_endpoint (U8 ep_num) |
usb_halt_endpoint. | |
U8 | usb_init_device (void) |
usb_init_device. | |
U8 | host_config_pipe (U8 config0, U8 config1) |
usb_configure_pipe. | |
U8 | host_determine_pipe_size (U16 size) |
host_determine_pipe_size. | |
void | host_disable_all_pipe (void) |
host_disable_all_pipe. |
Copyright (c) 2006 Atmel.
Use of this program is subject to Atmel's End User License Agreement. Please read file license.txt for copyright notice.
This file contains the USB driver routines.
Definition in file usb_drv.c.
|
usb_configure_endpoint. This function configures an endpoint with the selected type.
Definition at line 43 of file usb_drv.c. References ALLOC, Is_endpoint_configured, UECFG0X, UECFG1X, Usb_allocate_memory, and Usb_enable_endpoint. 00044 { 00045 Usb_enable_endpoint(); 00046 UECFG0X = config0; 00047 UECFG1X = (UECFG1X & (1<<ALLOC)) | config1; 00048 Usb_allocate_memory(); 00049 return (Is_endpoint_configured()); 00050 }
|
|
usb_select_endpoint_interrupt. This function select the endpoint where an event occurs and returns the number of this endpoint. If no event occurs on the endpoints, this function returns 0.
Definition at line 63 of file usb_drv.c. References ep_num, and Usb_interrupt_flags. 00064 { 00065 U8 interrupt_flags; 00066 U8 ep_num; 00067 00068 ep_num = 0; 00069 interrupt_flags = Usb_interrupt_flags(); 00070 00071 while(ep_num < 9) 00072 { 00073 if (interrupt_flags & 1) 00074 { 00075 return (ep_num); 00076 } 00077 else 00078 { 00079 ep_num++; 00080 interrupt_flags = interrupt_flags >> 1; 00081 } 00082 } 00083 return 0; 00084 }
|
|
usb_send_packet. This function moves the data pointed by tbuf to the selected endpoint fifo and sends it through the USB.
Note: tbuf is incremented of 'data_length'. Definition at line 106 of file usb_drv.c. References Is_usb_write_enabled, Usb_select_endpoint, and Usb_write_byte. 00107 { 00108 U8 remaining_length; 00109 00110 remaining_length = data_length; 00111 Usb_select_endpoint(ep_num); 00112 while(Is_usb_write_enabled() && (0 != remaining_length)) 00113 { 00114 Usb_write_byte(*tbuf); 00115 remaining_length--; 00116 tbuf++; 00117 } 00118 return remaining_length; 00119 }
|
|
usb_read_packet. This function moves the data stored in the selected endpoint fifo to the address specified by *rbuf.
Note: rbuf is incremented of 'data_length'. Definition at line 141 of file usb_drv.c. References Is_usb_read_enabled, Usb_read_byte, and Usb_select_endpoint. 00142 { 00143 U8 remaining_length; 00144 00145 remaining_length = data_length; 00146 Usb_select_endpoint(ep_num); 00147 00148 while(Is_usb_read_enabled() && (0 != remaining_length)) 00149 { 00150 *rbuf = Usb_read_byte(); 00151 remaining_length--; 00152 rbuf++; 00153 } 00154 return remaining_length; 00155 }
|
|
usb_halt_endpoint. This function sends a STALL handshake for the next Host request. A STALL handshake will be send for each next request untill a SETUP or a Clear Halt Feature occurs for this endpoint.
Definition at line 167 of file usb_drv.c. References Usb_enable_stall_handshake, and Usb_select_endpoint. 00168 { 00169 Usb_select_endpoint(ep_num); 00170 Usb_enable_stall_handshake(); 00171 }
|
|
usb_init_device. This function initializes the USB device controller and configures the Default Control Endpoint.
Definition at line 183 of file usb_drv.c. References DIRECTION_OUT, EP_CONTROL, FALSE, Is_usb_endpoint_enabled, Is_usb_id_device, NYET_DISABLED, ONE_BANK, SIZE_64, TYPE_CONTROL, usb_configure_endpoint, Usb_select_device, and Usb_select_endpoint. Referenced by usb_general_interrupt(), and usb_start_device(). 00184 { 00185 Usb_select_device(); 00186 if(Is_usb_id_device()) 00187 { 00188 Usb_select_endpoint(EP_CONTROL); 00189 if(!Is_usb_endpoint_enabled()) 00190 { 00191 return usb_configure_endpoint(EP_CONTROL, \ 00192 TYPE_CONTROL, \ 00193 DIRECTION_OUT, \ 00194 SIZE_64, \ 00195 ONE_BANK, \ 00196 NYET_DISABLED); 00197 } 00198 } 00199 return FALSE; 00200 }
|
|
usb_configure_pipe. This function configures a pipe with the selected type.
Definition at line 219 of file usb_drv.c. References Host_allocate_memory, Host_enable_pipe, Is_pipe_configured, UPCFG0X, and UPCFG1X. 00220 { 00221 Host_enable_pipe(); 00222 UPCFG0X = config0; 00223 UPCFG1X = config1; 00224 Host_allocate_memory(); 00225 return (Is_pipe_configured()); 00226 }
|
|
host_determine_pipe_size. This function returns the size configuration register value according to the endpint size detected inthe device enumeration process.
Definition at line 235 of file usb_drv.c. References SIZE_1024, SIZE_128, SIZE_16, SIZE_256, SIZE_32, SIZE_512, SIZE_64, and SIZE_8. 00236 { 00237 if(size <= 8 ) {return (SIZE_8 );} 00238 else if(size <= 16 ) {return (SIZE_16 );} 00239 else if(size <= 32 ) {return (SIZE_32 );} 00240 else if(size <= 64 ) {return (SIZE_64 );} 00241 else if(size <= 128) {return (SIZE_128 );} 00242 else if(size <= 256) {return (SIZE_256 );} 00243 else if(size <= 512) {return (SIZE_512 );} 00244 else {return (SIZE_1024);} 00245 00246 }
|
|
host_disable_all_pipe. This function disable all pipes for the host controller Usefull to execute upon device disconnection.
Definition at line 255 of file usb_drv.c. References Host_disable_pipe, Host_reset_pipe, Host_select_pipe, and Host_unallocate_memory. Referenced by usb_general_interrupt(). 00256 { 00257 U8 i; 00258 for (i=0;i<7;i++) 00259 { 00260 Host_reset_pipe(i); 00261 Host_select_pipe(i); 00262 Host_unallocate_memory(); 00263 Host_disable_pipe(); 00264 } 00265 00266 }
|