cdc_task.c File Reference

#include "config.h"
#include "conf_usb.h"
#include "cdc_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu/uart/uart_lib.h"
#include "uart_usb_lib.h"
#include <stdio.h>

Include dependency graph for cdc_task.c:

Go to the source code of this file.

Functions

void cdc_task_init (void)
void cdc_task (void)
void sof_action ()
__interrupt void usart_receive_interrupt ()

Variables

volatile U8 cpt_sof
U8 rx_counter
U8 tx_counter
volatile U8 usb_request_break_generation
S_line_coding line_coding
S_line_status line_status
S_serial_state serial_state
volatile U8 rs2usb [10]


Detailed Description

This file manages the CDC task.

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

Definition in file cdc_task.c.


Function Documentation

void cdc_task_init ( void   ) 

This function initializes the hardware ressources required for CDC demo.

Parameters:
none 
Returns:
none
/

Definition at line 94 of file cdc_task.c.

References Hwb_button_init, Joy_init, Leds_init, Uart_enable_it_rx, uart_init(), uart_usb_getchar(), uart_usb_putchar, and Usb_enable_sof_interrupt.

00095 {
00096    uart_init();
00097    Uart_enable_it_rx();
00098    Leds_init();
00099    Joy_init();
00100    Hwb_button_init();
00101    Usb_enable_sof_interrupt();
00102 #ifdef __GNUC__
00103    fdevopen((int (*)(char, FILE*))(uart_usb_putchar),(int (*)(FILE*))uart_usb_getchar); //for printf redirection
00104 #endif
00105 }

Here is the call graph for this function:

void cdc_task ( void   ) 

Entry point of the uart cdc management This function links the uart and the USB bus.

Parameters:
none 
Returns:
none

Definition at line 114 of file cdc_task.c.

References S_serial_state::bDCD, S_serial_state::bDSR, cdc_update_serial_state(), cpt_sof, S_line_status::DTR, FALSE, Is_btn_left, Is_btn_middle, Is_device_enumerated, Is_joy_down, Is_joy_left, Is_joy_right, Is_joy_up, Led2_toggle, Led3_toggle, REPEAT_KEY_PRESSED, rx_counter, RX_EP, TRUE, TX_EP, uart_putchar(), Uart_tx_ready, uart_usb_getchar(), uart_usb_test_hit(), Usb_disable_in_ready_interrupt, Usb_enable_in_ready_interrupt, Usb_enable_receive_out_interrupt, usb_request_break_generation, and Usb_select_endpoint.

00115 {
00116 #ifdef CHECK_CDC_MAX_SPEED
00117    if( Is_device_enumerated() && line_status.DTR ) //Enumeration processs OK and COM port openned ?
00118    {
00119      if( !b_interrupt_init )
00120      {
00121         b_interrupt_init = TRUE;
00122         Usb_select_endpoint(RX_EP);
00123         Usb_enable_receive_out_interrupt();
00124      }
00125      if (Is_joy_down())
00126      {
00127         Usb_select_endpoint(TX_EP);
00128         Usb_enable_in_ready_interrupt();
00129      }else{
00130         Usb_select_endpoint(TX_EP);
00131         Usb_disable_in_ready_interrupt();
00132      }
00133    }
00134 #else
00135    if(Is_device_enumerated() && line_status.DTR) //Enumeration processs OK and COM port openned ?
00136    {
00137       if (Uart_tx_ready())    //USART free ?
00138       {
00139          if (uart_usb_test_hit())   // Something received from the USB ?
00140          {
00141              while (rx_counter)
00142             {
00143                uart_putchar(uart_usb_getchar());   // loop back USB to USART
00144                Led3_toggle();
00145             }
00146          }
00147       }
00148 
00149       if ( cpt_sof>=REPEAT_KEY_PRESSED)   //Debounce joystick events
00150       {
00151          if (Is_btn_middle()){
00152             printf ("Select Pressed !\r\n");
00153          }
00154          if (Is_joy_right()) {
00155             printf ("Right Pressed !\r\n");
00156             serial_state.bDCD = TRUE;
00157          }
00158          else
00159             serial_state.bDCD = FALSE;
00160 
00161          if (Is_joy_left()) {
00162             printf ("Left Pressed !\r\n");
00163             serial_state.bDSR = TRUE;
00164          }
00165          else
00166             serial_state.bDSR = FALSE;
00167 
00168          if (Is_joy_down())
00169          printf ("Down Pressed !\r\n");
00170 
00171          if (Is_joy_up())
00172          printf ("Up Pressed !\r\n");
00173 
00174          if(Is_btn_left())
00175          printf("Hello from AT90USBXXX !\r\n");
00176          
00177          cdc_update_serial_state();
00178       }
00179 
00180       if(usb_request_break_generation==TRUE)
00181       {
00182          usb_request_break_generation=FALSE;
00183          Led2_toggle();
00184       }
00185    }
00186 #endif
00187 }

Here is the call graph for this function:

__interrupt void usart_receive_interrupt (  ) 

Uart Receive interrupt subroutine

Parameters:
none 
Returns:
none

Definition at line 215 of file cdc_task.c.

References FALSE, Is_device_enumerated, Is_usb_write_enabled, rs2usb, TX_EP, Uart_get_byte, Uart_rx_ready, uart_usb_send_buffer(), Usb_get_selected_endpoint, and Usb_select_endpoint.

00217 {
00218    U8 i=0;
00219    U8 save_ep;
00220    
00221    if(Is_device_enumerated()) 
00222    {
00223       save_ep=Usb_get_selected_endpoint();   
00224       Usb_select_endpoint(TX_EP);
00225       do 
00226       {
00227          if(Uart_rx_ready())
00228          {
00229             rs2usb[i]=Uart_get_byte();
00230             i++;
00231          }
00232       }while(Is_usb_write_enabled()==FALSE );
00233       uart_usb_send_buffer((U8*)&rs2usb,i);
00234       Usb_select_endpoint(save_ep);
00235    }
00236 }

Here is the call graph for this function:


Variable Documentation

volatile U8 cpt_sof

Definition at line 70 of file cdc_task.c.

Referenced by cdc_task(), and sof_action().

U8 rx_counter

Definition at line 57 of file uart_usb_lib.c.

Referenced by cdc_task(), uart_usb_getchar(), uart_usb_init(), and uart_usb_test_hit().

U8 tx_counter

volatile U8 usb_request_break_generation

Definition at line 77 of file usb_specific_request.c.

Referenced by cdc_send_break(), and cdc_task().

S_line_coding line_coding

Definition at line 75 of file cdc_task.c.

S_line_status line_status

Definition at line 76 of file cdc_task.c.

S_serial_state serial_state

Definition at line 77 of file cdc_task.c.

volatile U8 rs2usb[10]

Definition at line 79 of file cdc_task.c.

Referenced by usart_receive_interrupt().


Generated on Mon Sep 14 13:51:27 2009 for ATMEL by  doxygen 1.5.3