device_template_task.c File Reference

#include "config.h"
#include "conf_usb.h"
#include "device_template_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "lib_mcu/wdt/wdt_drv.h"

Include dependency graph for device_template_task.c:

Go to the source code of this file.

Functions

void device_template_task_init (void)
void device_template_task (void)
void sof_action ()

Variables

volatile U8 cpt_sof
U8 buf [256]
U8 rxok


Detailed Description

This file manages the high level application device task.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file device_template_task.c.


Function Documentation

void device_template_task_init ( void   ) 

This function initializes the hardware/software resources required for device application task.

Parameters:
none 
Returns:
none
/

Definition at line 78 of file device_template_task.c.

00079 {
00080    Joy_init();
00081    Hwb_button_init();
00082    Leds_init();
00083    cpt_sof=0;
00084    Usb_enable_sof_interrupt();
00085    rxok=FALSE;
00086 }

void device_template_task ( void   ) 

Entry point of the device application This function links the application with the USB bus.

Parameters:
none 
Returns:
none

Definition at line 95 of file device_template_task.c.

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 }


Variable Documentation

volatile U8 cpt_sof

Definition at line 62 of file device_template_task.c.

Referenced by device_template_task(), device_template_task_init(), and sof_action().

U8 buf[256]

Definition at line 64 of file device_template_task.c.

Referenced by device_template_task().

U8 rxok

Definition at line 65 of file device_template_task.c.

Referenced by device_template_task(), and device_template_task_init().


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