usb_drv.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00015 
00016 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  *
00021  * 1. Redistributions of source code must retain the above copyright notice,
00022  * this list of conditions and the following disclaimer.
00023  *
00024  * 2. Redistributions in binary form must reproduce the above copyright notice,
00025  * this list of conditions and the following disclaimer in the documentation
00026  * and/or other materials provided with the distribution.
00027  *
00028  * 3. The name of ATMEL may not be used to endorse or promote products derived
00029  * from this software without specific prior written permission.
00030  *
00031  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00032  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00033  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00034  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00035  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00036  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00037  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00038  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00039  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00040  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041  */
00042 
00043 //_____ I N C L U D E S ____________________________________________________
00044 
00045 #include "config.h"
00046 #include "conf_usb.h"
00047 #include "usb_drv.h"
00048 
00049 //_____ M A C R O S ________________________________________________________
00050 
00051 //_____ D E C L A R A T I O N ______________________________________________
00052 
00053 
00054 
00065 U8 usb_config_ep(U8 config0, U8 config1)
00066 {
00067     Usb_enable_endpoint();
00068     UECFG0X = config0;
00069     UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00070     Usb_allocate_memory();
00071     return (Is_endpoint_configured());
00072 }
00073 
00085 U8 usb_select_enpoint_interrupt(void)
00086 {
00087 U8 interrupt_flags;
00088 U8 ep_num;
00089 
00090    ep_num = 0;
00091    interrupt_flags = Usb_interrupt_flags();
00092 
00093    while(ep_num < MAX_EP_NB)
00094    {
00095       if (interrupt_flags & 1)
00096       {
00097          return (ep_num);
00098       }
00099       else
00100       {
00101          ep_num++;
00102          interrupt_flags = interrupt_flags >> 1;
00103       }
00104    }
00105    return 0;
00106 }
00107 
00128 U8 usb_send_packet(U8 ep_num, U8* tbuf, U8 data_length)
00129 {
00130 U8 remaining_length;
00131 
00132    remaining_length = data_length;
00133    Usb_select_endpoint(ep_num);
00134    while(Is_usb_write_enabled() && (0 != remaining_length))
00135    {
00136       Usb_write_byte(*tbuf);
00137       remaining_length--;
00138       tbuf++;
00139    }
00140    return remaining_length;
00141 }
00142 
00163 U8 usb_read_packet(U8 ep_num, U8* rbuf, U8  data_length)
00164 {
00165 U8 remaining_length;
00166 
00167    remaining_length = data_length;
00168    Usb_select_endpoint(ep_num);
00169 
00170    while(Is_usb_read_enabled() && (0 != remaining_length))
00171    {
00172       *rbuf = Usb_read_byte();
00173       remaining_length--;
00174       rbuf++;
00175    }
00176    return remaining_length;
00177 }
00178 
00189 void usb_halt_endpoint (U8 ep_num)
00190 {
00191    Usb_select_endpoint(ep_num);
00192    Usb_enable_stall_handshake();
00193 }
00194 
00205 U8 usb_init_device (void)
00206 {
00207       Usb_select_endpoint(EP_CONTROL);
00208       if(!Is_usb_endpoint_enabled())
00209       {
00210          return usb_configure_endpoint(EP_CONTROL,    \
00211                                 TYPE_CONTROL,  \
00212                                 DIRECTION_OUT, \
00213                                 SIZE_32,       \
00214                                 ONE_BANK,      \
00215                                 NYET_DISABLED);
00216       }
00217    return FALSE;
00218 }
00219 
00220 
00221 

Generated on Mon May 5 15:57:55 2008 for ATMEL by  doxygen 1.5.1-p1