device_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 "device_template_task.h"
00046 #include "lib_mcu/usb/usb_drv.h"
00047 #include "usb_descriptors.h"
00048 #include "modules/usb/device_chap9/usb_standard_request.h"
00049 #include "lib_mcu/wdt/wdt_drv.h"
00050 
00051 
00052 //_____ M A C R O S ________________________________________________________
00053 
00054 
00055 //_____ D E F I N I T I O N S ______________________________________________
00056 
00057 
00058 
00059 //_____ D E C L A R A T I O N S ____________________________________________
00060 
00061 
00062 volatile U8 cpt_sof;
00063 
00064 U8 buf[256];
00065 U8 rxok;
00066 
00067 
00078 void device_template_task_init(void)
00079 {
00080    Joy_init();
00081    Hwb_button_init();
00082    Leds_init();
00083    cpt_sof=0;
00084    Usb_enable_sof_interrupt();
00085    rxok=FALSE;
00086 }
00087 
00095 void device_template_task(void)
00096 {
00097    U8 i;
00098    U8 *ptr;
00099    static U8 dummy_data;
00100 
00101    //.. FIRST CHECK THE DEVICE ENUMERATION STATE
00102    if (Is_device_enumerated())
00103    {
00104       //.. HERE START THE USB DEVICE APPLICATIVE CODE
00105       //.. The example bellow just perform a loop back transmition/reception
00106       //.. All data received wth the OUT endpoint are store in a ram buffer and
00107       //.. send back to the IN endpoint
00108 
00109       //.. For example, blink a led with start of frame counter
00110       if(cpt_sof>0x7F)
00111       {  Led0_on(); }
00112       else { Led0_off();}
00113 
00114       //.. First interface management
00115       //.. Select the OUT endpoint declared in descriptors
00116       //.. load the endpoint with the content of a ram buffer for example
00117       Usb_select_endpoint(EP_TEMP_OUT);
00118       if ( Is_usb_receive_out())
00119       {
00120          ptr=buf;
00121          for(i=Usb_byte_counter();i;i--)
00122          {
00123             *ptr++=Usb_read_byte();
00124          }
00125          Usb_ack_receive_out();
00126          rxok=TRUE;
00127       }
00128       //.. First interface management (cont)
00129       //.. Select the IN endpoint declared in descriptors
00130       //.. If we receive something, just store in the ram buffer
00131       Usb_select_endpoint(EP_TEMP_IN);
00132       if ( Is_usb_read_control_enabled()&&(rxok==TRUE))
00133       {
00134          ptr=buf;
00135          for(i=0;i<EP_IN_LENGTH_TEMP1;i++)
00136          Usb_write_byte(*ptr++);
00137          Usb_ack_in_ready();
00138          rxok=FALSE;
00139       }
00140 
00141       //.. Second interface management (interrupt IN endpoint)
00142       //.. Just Send dummy data bytes
00143       Usb_select_endpoint(EP_TEMP_INT_IN);    // Select this enpoint
00144       if (Is_usb_write_enabled())             // Check data can be loaded
00145       {                                       // And load dummy data...
00146          Usb_write_byte(dummy_data);
00147          Usb_write_byte(dummy_data+1);
00148          Usb_write_byte(dummy_data+2);
00149          Usb_write_byte(dummy_data+3);
00150          Usb_ack_in_ready();
00151          dummy_data+=4;
00152       }
00153    }
00154 }
00155 
00156 
00166 void sof_action()
00167 {
00168    cpt_sof++;
00169 }

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