cdc_example.c File Reference


Detailed Description

Main file of the USB CDC example.

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

Definition in file cdc_example.c.

#include "nlao_cpu.h"
#include "nlao_usart.h"
#include "compiler.h"
#include "board.h"
#include "print_funcs.h"
#include "intc.h"
#include "power_clocks_lib.h"
#include "cdc_example.h"
#include "conf_usb.h"
#include "usb_task.h"
#include "device_cdc_task.h"
#include "host_cdc_task.h"
#include <stdio.h>

Go to the source code of this file.

Functions

int _init_startup (void)
 Low-level initialization routine called during startup, before the main function.
int main (void)
 Main function. Execution starts here.

Variables

System Clock Frequencies
pcl_freq_param_t pcl_freq_param


Function Documentation

int _init_startup ( void   ) 

Low-level initialization routine called during startup, before the main function.

This version comes in replacement to the default one provided by the Newlib add-ons library. Newlib add-ons' _init_startup only calls init_exceptions, but Newlib add-ons' exception and interrupt vectors are defined in the same section and Newlib add-ons' interrupt vectors are not compatible with the interrupt management of the INTC module. More low-level initializations are besides added here.

Definition at line 257 of file cdc_example.c.

00258 {
00259   // Import the Exception Vector Base Address.
00260   extern void _evba;
00261 
00262   // Load the Exception Vector Base Address in the corresponding system register.
00263   Set_system_register(AVR32_EVBA, (int)&_evba);
00264 
00265   // Enable exceptions.
00266   Enable_global_exception();
00267 
00268   // Initialize interrupt handling.
00269   INTC_init_interrupts();
00270 
00271   // Initialize the USART used for the debug trace with the configured parameters.
00272   set_usart_base( ( void * ) DBG_USART );
00273 
00274   // Don't-care value for GCC.
00275   return 1;
00276 }

int main ( void   ) 

Main function. Execution starts here.

Return values:
42 Fatal error.

Definition at line 308 of file cdc_example.c.

References device_cdc_task(), device_cdc_task_init(), host_cdc_task(), host_cdc_task_init(), and pcl_freq_param.

00309 {
00310   // Configure system clocks.
00311   if (pcl_configure_clocks(&pcl_freq_param) != PASS)
00312     return 42;
00313 
00314   // Initialize usart comm
00315   init_dbg_rs232(pcl_freq_param.pba_f);
00316 
00317 #ifndef FREERTOS_USED
00318 # if __GNUC__
00319   // Give the used CPU clock frequency to Newlib, so it can work properly.
00320   set_cpu_hz(pcl_freq_param.pba_f);
00321 # endif
00322 #endif
00323 
00324   // Initialize USB clock.
00325   pcl_configure_usb_clock();
00326 
00327   // Initialize USB task
00328   usb_task_init();
00329 
00330   // Display a welcome banner on USART
00331   printf("                                                       ......       ......     \r\n");
00332   printf("       IIIIII  IIIII        IIII   IIIIIIIIIII      IIIIIIIIIII. .IIIIIIIIII.  \r\n");
00333   printf("      IIIIIII   IIIII      IIIII  IIIIIIIIIIIII     IIIIIIIIIIII..IIIIIIIIIII. \r\n");
00334   printf("     IIIIIIIII  IIIII     IIIII   IIIII   IIIII     I.      IIIII.:.     IIIII \r\n");
00335   printf("     IIII IIIII  IIIII    IIII   IIIII    IIIII            .IIII.        IIIII \r\n");
00336   printf("    IIIII  IIII   IIII   IIIII  IIIIIIIIIIIIII         IIIIIIII          IIII. \r\n");
00337   printf("    IIII   IIIII  IIIII IIIII   IIIIIIIIIIIII          IIIIIIII.       .IIII:  \r\n");
00338   printf("   IIIII    IIIII  IIIIIIIII   IIIIIIIIIII                 .IIIII     IIIII.   \r\n");
00339   printf("  IIIIIIIIIIIIIII   IIIIIIII   IIIII IIIII                  .IIII   .IIII:     \r\n");
00340   printf("  IIIIIIIIIIIIIIII  IIIIIII   IIIII   IIII         II:.    .IIIII .IIIII.      \r\n");
00341   printf(" IIIII        IIIII  IIIIII  IIIII    IIIII        IIIIIIIIIIIII.IIIIIIIIIIIIII\r\n");
00342   printf(" IIIII        IIIII  IIIII   IIIII    IIIII        :IIIIIIIIII.  IIIIIIIIIIIIII\r\n");
00343   printf("                      III                                                      \r\n");
00344   printf("                       II                                                      \r\n");
00345 
00346 #if USB_DEVICE_FEATURE == ENABLED
00347   // Initialize device CDC USB task
00348   device_cdc_task_init();
00349 #endif
00350 #if USB_HOST_FEATURE == ENABLED
00351   // Initialize host CDC USB task
00352   host_cdc_task_init();
00353 #endif
00354 
00355 #ifdef FREERTOS_USED
00356   // Start OS scheduler
00357   vTaskStartScheduler();
00358   portDBG_TRACE("FreeRTOS returned.");
00359   return 42;
00360 #else
00361   // No OS here. Need to call each task in round-robin mode.
00362   while (TRUE)
00363   {
00364     usb_task();
00365   #if USB_DEVICE_FEATURE == ENABLED
00366     device_cdc_task();
00367   #endif
00368   #if USB_HOST_FEATURE == ENABLED
00369     host_cdc_task();
00370   #endif
00371   }
00372 #endif  // FREERTOS_USED
00373 }


Variable Documentation

pcl_freq_param_t pcl_freq_param

Initial value:

{
  .cpu_f        = APPLI_CPU_SPEED,
  .pba_f        = APPLI_PBA_SPEED,
  .osc0_f       = FOSC0,
  .osc0_startup = OSC0_STARTUP
}

Definition at line 232 of file cdc_example.c.

Referenced by cdc_set_line_coding(), and main().


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