cdc_task.c

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 //_____  I N C L U D E S ___________________________________________________
00018 
00019 #include "config.h"
00020 #include "conf_usb.h"
00021 #include "cdc_task.h"
00022 #include "lib_mcu\usb\usb_drv.h"
00023 #include "usb_descriptors.h"
00024 #include "modules\usb\device_chap9\usb_standard_request.h"
00025 #include "usb_specific_request.h"
00026 #include "lib_mcu/uart/uart_lib.h"
00027 #include "uart_usb_lib.h"
00028 #include <stdio.h>
00029 
00030 
00031 //_____ M A C R O S ________________________________________________________
00032 
00033 
00034 
00035 //_____ D E F I N I T I O N S ______________________________________________
00036 
00037 
00038 
00039 //_____ D E C L A R A T I O N S ____________________________________________
00040 
00041 
00042 volatile U8 cpt_sof;
00043 extern U8    rx_counter;
00044 extern U8    tx_counter;
00045 S_line_coding line_coding;
00046 
00047 
00056 void cdc_task_init(void)
00057 {
00058    uart_init();
00059    Leds_init();
00060    Joy_init();
00061    Hwb_button_init();
00062    Usb_enable_sof_interrupt();
00063 #ifdef AVRGCC
00064    fdevopen(uart_usb_putchar,uart_usb_getchar); //for printf redirection 
00065 #endif
00066 }
00067 
00068 
00069 
00077 void cdc_task(void)
00078 {
00079    if(Is_device_enumerated()) //Enumeration processs OK ?
00080    {
00081       if(cpt_sof>=NB_MS_BEFORE_FLUSH && tx_counter!=0 )  //Flush buffer in Timeout
00082       {
00083          cpt_sof=0;
00084          uart_usb_flush();
00085       }
00086       
00087       if (uart_test_hit())    //Something on USART ?
00088       {
00089          uart_usb_putchar(uart_getchar());   // Loop back, USART to USB
00090          Led0_toggle();
00091       }
00092    
00093       if (Uart_tx_ready())    //USART free ?
00094       {
00095          if (uart_usb_test_hit())   // Something received from the USB ?
00096          {
00097             while (rx_counter)
00098             {
00099                uart_putchar(uart_usb_getchar());   // loop back USB to USART
00100                Led3_toggle();
00101             }
00102          }
00103       }
00104 
00105       if ( cpt_sof>=REPEAT_KEY_PRESSED)   //Debounce joystick events
00106       {
00107          if (Is_joy_select())
00108          printf ("Select Pressed !\r\n");
00109 
00110          if (Is_joy_right())
00111          printf ("Right Pressed !\r\n");
00112    
00113          if (Is_joy_left())
00114          printf ("Left Pressed !\r\n");
00115 
00116          if (Is_joy_down())
00117          printf ("Down Pressed !\r\n");
00118 
00119          if (Is_joy_up())
00120          printf ("Up Pressed !\r\n");
00121 
00122          if(Is_hwb())
00123          printf("Hello from AT90USBXXX !\r\n");
00124       }
00125    }
00126 }
00127 
00128 
00129 
00141 void sof_action()
00142 {
00143    cpt_sof++;
00144 }

Generated on Fri Jun 15 14:15:32 2007 for Atmel by  doxygen 1.5.1-p1