usb_drv.c File Reference

,vThis file contains the USB driver routines. More...

#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

,vThis file contains the USB driver routines.

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.

Version:
1.4 at90usb162-cdc-1_0_1
Id
usb_drv.c,v 1.4 2006/09/06 12:59:42 rletendu Exp
Todo:
Bug:

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 39 of file usb_drv.c.

References ALLOC, Is_endpoint_configured, Usb_allocate_memory, and Usb_enable_endpoint.

00040 {
00041     Usb_enable_endpoint();
00042     UECFG0X = config0;
00043     UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00044     Usb_allocate_memory();
00045     return (Is_endpoint_configured());
00046 }

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 59 of file usb_drv.c.

References ep_num, MAX_EP_NB, and Usb_interrupt_flags.

00060 {
00061 U8 interrupt_flags;
00062 U8 ep_num;
00063 
00064    ep_num = 0;
00065    interrupt_flags = Usb_interrupt_flags();
00066 
00067    while(ep_num < MAX_EP_NB)
00068    {
00069       if (interrupt_flags & 1)
00070       {
00071          return (ep_num);
00072       }
00073       else
00074       {
00075          ep_num++;
00076          interrupt_flags = interrupt_flags >> 1;
00077       }
00078    }
00079    return 0;
00080 }

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 102 of file usb_drv.c.

References Is_usb_write_enabled, Usb_select_endpoint, and Usb_write_byte.

00103 {
00104 U8 remaining_length;
00105 
00106    remaining_length = data_length;
00107    Usb_select_endpoint(ep_num);
00108    while(Is_usb_write_enabled() && (0 != remaining_length))
00109    {
00110       Usb_write_byte(*tbuf);
00111       remaining_length--;
00112       tbuf++;
00113    }
00114    return remaining_length;
00115 }

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 137 of file usb_drv.c.

References Is_usb_read_enabled, Usb_read_byte, and Usb_select_endpoint.

00138 {
00139 U8 remaining_length;
00140 
00141    remaining_length = data_length;
00142    Usb_select_endpoint(ep_num);
00143 
00144    while(Is_usb_read_enabled() && (0 != remaining_length))
00145    {
00146       *rbuf = Usb_read_byte();
00147       remaining_length--;
00148       rbuf++;
00149    }
00150    return remaining_length;
00151 }

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 163 of file usb_drv.c.

References Usb_enable_stall_handshake, and Usb_select_endpoint.

00164 {
00165    Usb_select_endpoint(ep_num);
00166    Usb_enable_stall_handshake();
00167 }

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 179 of file usb_drv.c.

References DIRECTION_OUT, EP_CONTROL, FALSE, Is_usb_endpoint_enabled, NYET_DISABLED, ONE_BANK, SIZE_32, TYPE_CONTROL, usb_configure_endpoint, and Usb_select_endpoint.

Referenced by usb_general_interrupt(), and usb_start_device().

00180 {
00181       Usb_select_endpoint(EP_CONTROL);
00182       if(!Is_usb_endpoint_enabled())
00183       {
00184          return usb_configure_endpoint(EP_CONTROL,    \
00185                                 TYPE_CONTROL,  \
00186                                 DIRECTION_OUT, \
00187                                 SIZE_32,       \
00188                                 ONE_BANK,      \
00189                                 NYET_DISABLED);
00190       }
00191    return FALSE;
00192 }


Generated on Fri Jun 15 14:15:49 2007 for Atmel by  doxygen 1.5.1-p1