host_template_task.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of ATMEL may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00031  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 
00041 //_____  I N C L U D E S ___________________________________________________
00042 
00043 #include "config.h"
00044 #include "conf_usb.h"
00045 #include "host_template_task.h"
00046 #include "modules/usb/host_chap9/usb_host_task.h"
00047 #include "modules/usb/host_chap9/usb_host_enum.h"
00048 #include "lib_mcu/usb/usb_drv.h"
00049 #include "lib_mcu/uart/uart_lib.h"
00050 
00051 
00052 //_____ M A C R O S ________________________________________________________
00053 
00054 //_____ D E F I N I T I O N S ______________________________________________
00055 
00056 //_____ D E C L A R A T I O N S ____________________________________________
00057 
00058    U8 tab[64];
00059    U8 busy=FALSE;
00060    U8 pipe_out;
00061    U8 pipe_in;
00062    U8 pipe_interrupt_in;
00063 
00064 
00074 void host_template_task_init(void)
00075 {
00076    U8 i;
00077    for(i=0;i<sizeof(tab);i++)
00078    {
00079       tab[i]=i;
00080    }
00081    Leds_init();
00082    Joy_init();
00083    Hwb_button_init();
00084 }
00085 
00096 void host_template_task(void)
00097 {
00098    #if (USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE)
00099    U8 sta;
00100    #endif
00101    U16 *ptr_nb;
00102    U16 nb;
00103    U8 i;
00104 
00105    ptr_nb=&nb;
00106 
00107    // First check the host controller is in full operating mode with the B device attached
00108    // and enumerated
00109    if(Is_host_ready())
00110    {
00111       //Put here the code to do in host mode
00112 
00113       // New device connection (executed  only one time after device connection)
00114       if(Is_new_device_connection_event())
00115       {
00116          for(i=0;i<Get_nb_supported_interface();i++)
00117          {
00118             // First interface with two bulk IN/OUT pipes
00119             if(Get_class(i)==0x00 && Get_subclass(i)==0x00 && Get_protocol(i)==0x00)
00120             {
00121                //Get correct physical pipes associated to IN/OUT Endpoints
00122                if(Is_ep_addr_in(Get_ep_addr(i,0)))
00123                {  //Yes associate it to the IN pipe
00124                   pipe_in=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00125                   pipe_out=host_get_hwd_pipe_nb(Get_ep_addr(i,1));
00126                }
00127                else
00128                {  //No, invert...
00129                   pipe_in=host_get_hwd_pipe_nb(Get_ep_addr(i,1));
00130                   pipe_out=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00131                }
00132             }
00133             // Seconf interface with interrupt IN pipe
00134             if(Get_class(i)==0x00 && Get_subclass(i)==0x55 && Get_protocol(i)==0xAA)
00135             {
00136                pipe_interrupt_in=host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00137                Host_select_pipe(pipe_interrupt_in);
00138                Host_continuous_in_mode();
00139                Host_unfreeze_pipe();
00140             }
00141          }
00142       }
00143 
00144 
00145      // Firt interface (bulk IN/OUT) management
00146      // In polling mode
00147 #if (USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE)
00148       // The sample task sends 64 byte through pipe nb2...
00149       sta=host_send_data(pipe_out,64,tab);
00150 
00151       // And receives 64bytes from pipe nb 1...
00152       *ptr_nb=64;
00153       sta=host_get_data(pipe_in,ptr_nb,tab);
00154 #else
00155       // similar applicative task under interrupt mode...
00156       if (busy==FALSE)
00157       {
00158          busy=TRUE;
00159          host_send_data_interrupt(pipe_out,64,tab,call_back_template_1);
00160       }
00161 
00162 #endif
00163 
00164       // Second interface management (USB interrupt IN pipe)
00165       Host_select_pipe(pipe_interrupt_in);
00166       if(Is_host_in_received())
00167       {
00168          if(Is_host_stall()==FALSE)
00169          {
00170             i=Host_read_byte();
00171             Host_read_byte();
00172          }
00173          Host_ack_in_received(); Host_send_in();
00174       }
00175 
00176       // Here an example of an applicative request to go to USB suspend ...
00177       if(Is_hwb())
00178       {
00179          Host_request_suspend();
00180       }
00181    }
00182    // Here an applicative example of resume request...
00183    if(Is_host_suspended() && Is_btn_middle())
00184    {
00185       Host_request_resume();
00186    }
00187 
00188    //Device disconnection...
00189    if(Is_device_disconnection_event())
00190    {
00191       //Put here code to be executed upon device disconnection...
00192    }
00193 }
00194 
00195 void call_back_template_1(U8 status, U16 nb_byte)
00196 {
00197    if (status==PIPE_GOOD)
00198    {
00199       host_get_data_interrupt(pipe_in,64,tab,call_back_template_2);
00200    }
00201 
00202 }
00203 
00204 void call_back_template_2(U8 status, U16 nb_byte)
00205 {
00206    if (status==PIPE_GOOD)
00207    {
00208       busy=FALSE;
00209    }
00210 }

Generated on Mon Nov 3 10:08:23 2008 for ATMEL by  doxygen 1.5.3