device_template_task.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 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  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 //_____  I N C L U D E S ___________________________________________________
00045 
00046 #include "config.h"
00047 #include "conf_usb.h"
00048 #include "device_template_task.h"
00049 #include "lib_mcu/usb/usb_drv.h"
00050 #include "usb_descriptors.h"
00051 #include "modules/usb/device_chap9/usb_standard_request.h"
00052 #include "lib_mcu/wdt/wdt_drv.h"
00053 
00054 
00055 //_____ M A C R O S ________________________________________________________
00056 
00057 
00058 //_____ D E F I N I T I O N S ______________________________________________
00059 
00060 
00061 
00062 //_____ D E C L A R A T I O N S ____________________________________________
00063 
00064 
00065 volatile U8 cpt_sof;
00066 
00067 U8 buf[256];
00068 U8 rxok;
00069 
00070 
00081 void device_template_task_init(void)
00082 {
00083    Joy_init();
00084    Hwb_button_init();
00085    Leds_init();
00086    cpt_sof=0;
00087    Usb_enable_sof_interrupt();
00088    rxok=FALSE;
00089 }
00090 
00098 void device_template_task(void)
00099 {
00100    U8 i;
00101    U8 *ptr;
00102    static U8 dummy_data;
00103 
00104    //.. FIRST CHECK THE DEVICE ENUMERATION STATE
00105    if (Is_device_enumerated())
00106    {
00107       //.. HERE START THE USB DEVICE APPLICATIVE CODE
00108       //.. The example bellow just perform a loop back transmition/reception
00109       //.. All data received wth the OUT endpoint are store in a ram buffer and
00110       //.. send back to the IN endpoint
00111 
00112       //.. For example, blink a led with start of frame counter
00113       if(cpt_sof>0x7F)
00114       {  Led0_on(); }
00115       else { Led0_off();}
00116 
00117       //.. First interface management
00118       //.. Select the OUT endpoint declared in descriptors
00119       //.. load the endpoint with the content of a ram buffer for example
00120       Usb_select_endpoint(EP_TEMP_OUT);
00121       if ( Is_usb_receive_out())
00122       {
00123          ptr=buf;
00124          for(i=Usb_byte_counter();i;i--)
00125          {
00126             *ptr++=Usb_read_byte();
00127          }
00128          Usb_ack_receive_out();
00129          rxok=TRUE;
00130       }
00131       //.. First interface management (cont)
00132       //.. Select the IN endpoint declared in descriptors
00133       //.. If we receive something, just store in the ram buffer
00134       Usb_select_endpoint(EP_TEMP_IN);
00135       if ( Is_usb_read_control_enabled()&&(rxok==TRUE))
00136       {
00137          ptr=buf;
00138          for(i=0;i<EP_IN_LENGTH_TEMP1;i++)
00139          Usb_write_byte(*ptr++);
00140          Usb_ack_in_ready();
00141          rxok=FALSE;
00142       }
00143 
00144       //.. Second interface management (interrupt IN endpoint)
00145       //.. Just Send dummy data bytes
00146       Usb_select_endpoint(EP_TEMP_INT_IN);    // Select this enpoint
00147       if (Is_usb_write_enabled())             // Check data can be loaded
00148       {                                       // And load dummy data...
00149          Usb_write_byte(dummy_data);
00150          Usb_write_byte(dummy_data+1);
00151          Usb_write_byte(dummy_data+2);
00152          Usb_write_byte(dummy_data+3);
00153          Usb_ack_in_ready();
00154          dummy_data+=4;
00155       }
00156    }
00157 }
00158 
00159 
00169 void sof_action()
00170 {
00171    cpt_sof++;
00172 }

Generated on Fri Sep 11 15:02:34 2009 for ATMEL by  doxygen 1.5.3