device_cdc_task.c File Reference


Detailed Description

Management of the USB device CDC task.

This file manages the USB device CDC task.

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

Definition in file device_cdc_task.c.

#include <stdio.h>
#include "usart.h"
#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "gpio.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "device_cdc_task.h"
#include "uart_usb_lib.h"

Go to the source code of this file.

Functions

void device_cdc_task (void *pvParameters)
 Entry point of the device CDC task management.
void device_cdc_task_init (void)
 This function initializes the hardware/software resources required for device CDC task.
void usb_sof_action (void)
 usb_sof_action

Variables

static volatile U16 sof_cnt


Function Documentation

void device_cdc_task ( void *  pvParameters  ) 

Entry point of the device CDC task management.

Definition at line 120 of file device_cdc_task.c.

References configTSK_USB_DCDC_PERIOD, NB_MS_BEFORE_FLUSH, sof_cnt, uart_usb_flush(), uart_usb_getchar(), uart_usb_putchar(), uart_usb_test_hit(), and uart_usb_tx_ready().

Referenced by device_cdc_task_init(), and main().

00124 {
00125   int c;
00126   static Bool startup=TRUE;
00127 
00128 #ifdef FREERTOS_USED
00129   portTickType xLastWakeTime;
00130   xLastWakeTime = xTaskGetTickCount();
00131 
00132   while (TRUE)
00133   {
00134     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DCDC_PERIOD);
00135 
00136     // First, check the device enumeration state
00137     if (!Is_device_enumerated()) continue;
00138 #else
00139     // First, check the device enumeration state
00140     if (!Is_device_enumerated()) return;
00141 #endif  // FREERTOS_USED
00142 
00143     if( startup )
00144     {
00145        printf("\r\nUSB DEVICE Communications Device Class demo.\r\n");
00146        startup=FALSE;
00147     }
00148 
00149     if( sof_cnt>=NB_MS_BEFORE_FLUSH )  //Flush buffer in Timeout
00150     {
00151        sof_cnt=0;
00152        uart_usb_flush();
00153     }
00154 
00155 #if BOARD == EVK1100 || BOARD == EVK1101
00156     if ( is_joystick_right() )
00157        printf("Joystick Right key pressed.\r\n");
00158 
00159     if ( is_joystick_left() )
00160        printf("Joystick Left key pressed.\r\n");
00161 
00162     if ( is_joystick_down() )
00163        printf("Joystick Down key pressed.\r\n");
00164 
00165     if ( is_joystick_up() )
00166        printf("Joystick Up key pressed.\r\n");
00167 
00168     if ( is_joystick_pressed() )
00169        printf("Joystick Select key pressed.\r\n");
00170 #endif
00171 #if BOARD == EVK1100 || BOARD == EVK1101 || BOARD == UC3C_EK    
00172     if (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0))
00173        printf("Button 0 key pressed.\r\n");
00174 
00175     if (!gpio_get_pin_value(GPIO_PUSH_BUTTON_1))
00176        printf("Button 1 key pressed.\r\n");
00177 #endif
00178 
00179     if (usart_test_hit(DBG_USART))    // Something on USART ?
00180     {
00181        if( uart_usb_tx_ready() )      // "USART"-USB free ?
00182        {
00183           if( USART_SUCCESS==usart_read_char(DBG_USART, &c) )
00184           {
00185              uart_usb_putchar(c);           // Loop back, USART to USB
00186              LED_Toggle(LED0);
00187           }
00188           else {
00189              usart_reset_status( DBG_USART );
00190           }
00191        }
00192     }
00193 
00194     if (uart_usb_test_hit())          // Something received from the USB ?
00195     {
00196        if (usart_tx_ready(DBG_USART)) // USART free ?
00197        {
00198           c= uart_usb_getchar();
00199           usart_write_char(DBG_USART, c);   // loop back USB to USART
00200           LED_Toggle(LED1);
00201        }
00202     }
00203 #ifdef FREERTOS_USED
00204   }
00205 #endif
00206 }

void device_cdc_task_init ( void   ) 

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

Definition at line 89 of file device_cdc_task.c.

References configTSK_USB_DCDC_NAME, configTSK_USB_DCDC_PRIORITY, configTSK_USB_DCDC_STACK_SIZE, device_cdc_task(), sof_cnt, and uart_usb_init().

Referenced by main().

00090 {
00091   sof_cnt   =0 ;
00092   uart_usb_init();
00093 
00094 #ifndef FREERTOS_USED
00095   #if USB_HOST_FEATURE == ENABLED
00096   // If both device and host features are enabled, check if device mode is engaged
00097   // (accessing the USB registers of a non-engaged mode, even with load operations,
00098   // may corrupt USB FIFO data).
00099   if (Is_usb_device())
00100   #endif  // USB_HOST_FEATURE == ENABLED
00101     Usb_enable_sof_interrupt();
00102 #endif  // FREERTOS_USED
00103 
00104 #ifdef FREERTOS_USED
00105   xTaskCreate(device_cdc_task,
00106               configTSK_USB_DCDC_NAME,
00107               configTSK_USB_DCDC_STACK_SIZE,
00108               NULL,
00109               configTSK_USB_DCDC_PRIORITY,
00110               NULL);
00111 
00112 #endif  // FREERTOS_USED
00113 }


Variable Documentation

volatile U16 sof_cnt [static]


Generated on Fri Feb 19 02:32:24 2010 for AVR32 - USB CDC Example by  doxygen 1.5.5