usb_drv.c File Reference

#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.


Detailed Description

This file contains the USB driver routines.

This file contains the USB driver routines.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file usb_drv.c.


Function Documentation

U8 usb_config_ep ( U8  config0,
U8  config1 
)

usb_configure_endpoint.

This function configures an endpoint with the selected type.

Parameters:
config0 
config1 
Returns:
Is_endpoint_configured.

Definition at line 68 of file usb_drv.c.

00069 {
00070     Usb_enable_endpoint();
00071     UECFG0X = config0;
00072     UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00073     Usb_allocate_memory();
00074     return (Is_endpoint_configured());
00075 }

U8 usb_select_enpoint_interrupt ( void   ) 

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.

Parameters:
none 
Returns:
endpoint number.

Definition at line 88 of file usb_drv.c.

00089 {
00090 U8 interrupt_flags;
00091 U8 ep_num;
00092 
00093    ep_num = 0;
00094    interrupt_flags = Usb_interrupt_flags();
00095 
00096    while(ep_num < MAX_EP_NB)
00097    {
00098       if (interrupt_flags & 1)
00099       {
00100          return (ep_num);
00101       }
00102       else
00103       {
00104          ep_num++;
00105          interrupt_flags = interrupt_flags >> 1;
00106       }
00107    }
00108    return 0;
00109 }

U8 usb_send_packet ( U8  ep_num,
U8 tbuf,
U8  data_length 
)

usb_send_packet.

This function moves the data pointed by tbuf to the selected endpoint fifo and sends it through the USB.

Parameters:
ep_num number of the addressed endpoint
*tbuf address of the first data to send
data_length number of bytes to send
Returns:
address of the next U8 to send.
Example: usb_send_packet(3,&first_data,0x20); // send packet on the endpoint #3 while(!(Usb_tx_complete)); // wait packet ACK'ed by the Host Usb_clear_tx_complete(); // acknowledge the transmit

Note: tbuf is incremented of 'data_length'.

Definition at line 131 of file usb_drv.c.

00132 {
00133 U8 remaining_length;
00134 
00135    remaining_length = data_length;
00136    Usb_select_endpoint(ep_num);
00137    while(Is_usb_write_enabled() && (0 != remaining_length))
00138    {
00139       Usb_write_byte(*tbuf);
00140       remaining_length--;
00141       tbuf++;
00142    }
00143    return remaining_length;
00144 }

U8 usb_read_packet ( U8  ep_num,
U8 rbuf,
U8  data_length 
)

usb_read_packet.

This function moves the data stored in the selected endpoint fifo to the address specified by *rbuf.

Parameters:
ep_num number of the addressed endpoint
*rbuf aaddress of the first data to write with the USB data
data_length number of bytes to read
Returns:
address of the next U8 to send.
Example: while(!(Usb_rx_complete)); // wait new packet received usb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4 Usb_clear_rx(); // acknowledge the transmit

Note: rbuf is incremented of 'data_length'.

Definition at line 166 of file usb_drv.c.

00167 {
00168 U8 remaining_length;
00169 
00170    remaining_length = data_length;
00171    Usb_select_endpoint(ep_num);
00172 
00173    while(Is_usb_read_enabled() && (0 != remaining_length))
00174    {
00175       *rbuf = Usb_read_byte();
00176       remaining_length--;
00177       rbuf++;
00178    }
00179    return remaining_length;
00180 }

void usb_halt_endpoint ( U8  ep_num  ) 

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.

Parameters:
ep_num number of the addressed endpoint
Returns:
none

Definition at line 192 of file usb_drv.c.

00193 {
00194    Usb_select_endpoint(ep_num);
00195    Usb_enable_stall_handshake();
00196 }

U8 usb_init_device ( void   ) 

usb_init_device.

This function initializes the USB device controller and configures the Default Control Endpoint.

Parameters:
none 
Returns:
status

Definition at line 208 of file usb_drv.c.

Referenced by usb_general_interrupt(), and usb_start_device().

00209 {
00210       Usb_select_endpoint(EP_CONTROL);
00211       if(!Is_usb_endpoint_enabled())
00212       {
00213 #if (USB_LOW_SPEED_DEVICE==DISABLE)
00214          return usb_configure_endpoint(EP_CONTROL,    \
00215                                 TYPE_CONTROL,  \
00216                                 DIRECTION_OUT, \
00217                                 SIZE_32,       \
00218                                 ONE_BANK,      \
00219                                 NYET_DISABLED);
00220 #else
00221          return usb_configure_endpoint(EP_CONTROL,    \
00222                                 TYPE_CONTROL,  \
00223                                 DIRECTION_OUT, \
00224                                 SIZE_8,       \
00225                                 ONE_BANK,      \
00226                                 NYET_DISABLED);
00227 
00228 #endif         
00229       }
00230    return FALSE;
00231 }

Here is the caller graph for this function:


Generated on Fri Sep 11 14:46:07 2009 for ATMEL by  doxygen 1.5.3