host_template_task.c File Reference


Detailed Description

Management of the USB high-level applicative host task.

This file manages the USB high-level applicative host task.

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

Definition in file host_template_task.c.

#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "usb_host_enum.h"
#include "usb_host_task.h"
#include "host_template_task.h"

Go to the source code of this file.

Defines

#define LED_APPLI_0   LED2
#define LED_APPLI_1   LED3

Functions

void host_get_data_callback (Status_t status, U16 nb_byte)
void host_send_data_callback (Status_t status, U16 nb_byte)
void host_sof_action (void)
 host_sof_action
void host_template_task (void *pvParameters)
 High-level host applicative task entry point Put here the code of your host application.
void host_template_task_init (void)
 This function initializes the high-level host application.

Variables

static U8 buf [64]
static volatile U8 busy
static U8 pipe_in
static U8 pipe_out
static U16 sof_cnt
volatile Bool tpl_new_device_connected


Define Documentation

#define LED_APPLI_0   LED2

Definition at line 75 of file host_template_task.c.

#define LED_APPLI_1   LED3

Definition at line 76 of file host_template_task.c.


Function Documentation

void host_get_data_callback ( Status_t  status,
U16  nb_byte 
)

Definition at line 259 of file host_template_task.c.

References busy, host_get_data_callback, and PIPE_GOOD.

00260 {
00261   if (status == PIPE_GOOD)
00262   {
00263     busy = FALSE;
00264   }
00265 }

void host_send_data_callback ( Status_t  status,
U16  nb_byte 
)

Definition at line 248 of file host_template_task.c.

References buf, host_get_data_callback, host_get_data_interrupt(), host_send_data_callback, LED_APPLI_1, PIPE_GOOD, and pipe_in.

00249 {
00250   if (status == PIPE_GOOD)
00251   {
00252     LED_On(LED_APPLI_1);
00253     host_get_data_interrupt(pipe_in, sizeof(buf), buf, host_get_data_callback);
00254     LED_Off(LED_APPLI_1);
00255   }
00256 }

void host_template_task ( void *  pvParameters  ) 

High-level host applicative task entry point Put here the code of your host application.

The sample code just sends and receives 64 bytes from IN and OUT pipes.

Definition at line 131 of file host_template_task.c.

References buf, busy, configTSK_USB_HTP_PERIOD, Get_class, Get_ep_pipe, Get_nb_supported_interface, host_get_data(), Host_request_resume, Host_request_suspend, host_send_data(), host_send_data_callback, host_send_data_interrupt(), host_set_feature_remote_wakeup, Is_ep_in, Is_host_ready, Is_host_suspended, LED_APPLI_0, LED_APPLI_1, pipe_in, pipe_out, sof_cnt, and tpl_new_device_connected.

Referenced by host_template_task_init(), and main().

00135 {
00136 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE
00137   Status_t sta;
00138   U16 nb;
00139 #endif
00140   U8 i;
00141 
00142 #ifdef FREERTOS_USED
00143   portTickType xLastWakeTime;
00144 
00145   xLastWakeTime = xTaskGetTickCount();
00146   while (TRUE)
00147   {
00148     vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HTP_PERIOD);
00149 
00150 #endif  // FREERTOS_USED
00151     // First, check the host controller is in full operating mode with the
00152     // B-device attached and enumerated
00153     if (Is_host_ready())
00154     {
00155       // Put here the code to execute in host mode
00156 
00157 #if BOARD == EVK1100
00158       // For example, display Start-of-Frame counter on LEDs
00159       LED_Display_Field(LED_MONO0_GREEN |
00160                         LED_MONO1_GREEN |
00161                         LED_MONO2_GREEN |
00162                         LED_MONO3_GREEN,
00163                         sof_cnt >> 5);
00164 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
00165       // For example, display Start-of-Frame counter on LEDs
00166       LED_Display_Field(LED0 |
00167                         LED1,
00168                         sof_cnt >> 5);
00169 #else
00170   #error The display of the SOFs must be defined here.
00171 #endif
00172 
00173       // New device connection (executed only once after device connection)
00174       if (tpl_new_device_connected)
00175       {
00176         tpl_new_device_connected = FALSE;
00177 
00178 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00179         // No more pipe interrupt transfer pending
00180         busy = FALSE;
00181 #endif
00182 
00183         // For all supported interfaces
00184         for (i = 0; i < Get_nb_supported_interface(); i++)
00185         {
00186           // If vendor-specific class
00187           if (Get_class(i) == VENDOR_CLASS)
00188           {
00189             // Get correct physical pipes associated with IN/OUT endpoints
00190             if (Is_ep_in(i, 0))
00191             { // Yes, associate it with the IN pipe
00192               pipe_in = Get_ep_pipe(i, 0);
00193               pipe_out = Get_ep_pipe(i, 1);
00194             }
00195             else
00196             { // No, invert...
00197               pipe_in = Get_ep_pipe(i, 1);
00198               pipe_out = Get_ep_pipe(i, 0);
00199             }
00200             break;
00201           }
00202         }
00203       }
00204 
00205 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE
00206       // The sample task sends 64 bytes through OUT pipe
00207       LED_On(LED_APPLI_0);
00208       sta = host_send_data(pipe_out, sizeof(buf), buf);
00209       LED_Off(LED_APPLI_0);
00210 
00211       // And receives 64 bytes from IN pipe
00212       nb = sizeof(buf);
00213       LED_On(LED_APPLI_1);
00214       sta = host_get_data(pipe_in, &nb, buf);
00215       LED_Off(LED_APPLI_1);
00216 #else
00217       // Similar applicative task under interrupt mode...
00218       if (!busy)
00219       {
00220         busy = TRUE;
00221         LED_On(LED_APPLI_0);
00222         host_send_data_interrupt(pipe_out, sizeof(buf), buf, host_send_data_callback);
00223         LED_Off(LED_APPLI_0);
00224       }
00225 #endif
00226 
00227       // Here is an example of an applicative request to go to USB suspend ...
00228       if (FALSE/* applicative conditions */)
00229       {
00230         host_set_feature_remote_wakeup();
00231         Host_request_suspend();
00232       }
00233     }
00234 
00235     // Here an applicative example of resume request...
00236     if (Is_host_suspended()/* && applicative conditions */)
00237     {
00238       Host_request_resume();
00239     }
00240 #ifdef FREERTOS_USED
00241   }
00242 #endif
00243 }

void host_template_task_init ( void   ) 

This function initializes the high-level host application.

Here initialize specific hardware resources requirements.

Definition at line 102 of file host_template_task.c.

References buf, busy, configTSK_USB_HTP_NAME, configTSK_USB_HTP_PRIORITY, configTSK_USB_HTP_STACK_SIZE, host_template_task(), sof_cnt, and tpl_new_device_connected.

Referenced by main().

00103 {
00104   U8 i;
00105 
00106   sof_cnt = 0;
00107   for (i = 0; i < sizeof(buf); i++) buf[i] = i;
00108 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00109   busy = FALSE;
00110 #endif
00111   tpl_new_device_connected = FALSE;
00112 
00113 #ifdef FREERTOS_USED
00114   xTaskCreate(host_template_task,
00115               configTSK_USB_HTP_NAME,
00116               configTSK_USB_HTP_STACK_SIZE,
00117               NULL,
00118               configTSK_USB_HTP_PRIORITY,
00119               NULL);
00120 #endif  // FREERTOS_USED
00121 }


Variable Documentation

U8 buf[64] [static]

volatile U8 busy [static]

U8 pipe_in [static]

Definition at line 88 of file host_template_task.c.

Referenced by host_send_data_callback(), and host_template_task().

U8 pipe_out [static]

Definition at line 89 of file host_template_task.c.

Referenced by host_template_task().

U16 sof_cnt [static]

Definition at line 87 of file host_template_task.c.


Generated on Fri Feb 19 02:27:50 2010 for AVR32 - USB Enumeration Example by  doxygen 1.5.5