Exemple #1
0
phmatrix
new_hmatrix(pccluster rc, pccluster cc)
{
    phmatrix hm = new hmatrix;
    hm = init_hmatrix(hm, rc, cc);
    return hm;
}
/*! \brief This is an example showing how to toggle a GPIO pin at high speed.
 */
int main(void)
{
  // Initialize domain clocks (CPU, HSB, PBA and PBB) to the max frequency available
  // without flash wait states.
  // Some of the registers in the GPIO module are mapped onto the CPU local bus.
  // To ensure maximum transfer speed and cycle determinism, any slaves being
  // addressed by the CPU on the local bus must be able to receive and transmit
  // data on the bus at CPU clock speeds. The consequences of this is that the
  // GPIO module has to run at the CPU clock frequency when local bus transfers
  // are being performed => we want fPBA = fCPU.
  clockfrequencies_configure();

  // initialize hmatrix bus
  init_hmatrix();

  // Enable the local bus interface for GPIO.
  gpio_local_init();

  // Enable the output driver of the example pin.
  // Note that the GPIO mode of pins is enabled by default after reset.
  gpio_local_enable_pin_output_driver(GPIO_PIN_EXAMPLE);

  // Toggle the example GPIO pin at high speed in a loop.
  while (1)
  {
    // Explicit loop unrolling allowing consecutive ST.W instructions without
    // loop overhead if compiler optimization is activated, except every 128
    // ST.W for the while loop.
#define INSERT_GPIO_LOCAL_TGL_GPIO_PIN(idx, pin) \
    gpio_local_tgl_gpio_pin(pin);
    MREPEAT(128, INSERT_GPIO_LOCAL_TGL_GPIO_PIN, GPIO_PIN_EXAMPLE)
#undef INSERT_GPIO_LOCAL_TGL_GPIO_PIN
  }
}
int __low_level_init(void)
#endif
{
    init_exceptions();
    init_hmatrix();
    init_heap();

    // EWAVR32: Request initialization of data segments.
    // GCC: Don't-care value.
    return 1;
}
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();
	board_init();
	ui_init();
	ui_powerdown();

#if UC3A3
	// Init Hmatrix bus   
	sysclk_enable_pbb_module(SYSCLK_HMATRIX);
	init_hmatrix();
#endif
#if (defined AT45DBX_MEM) && (AT45DBX_MEM == ENABLE)
	at45dbx_init();
#endif
#if ((defined SD_MMC_MCI_0_MEM) && (SD_MMC_MCI_0_MEM == ENABLE)) \
	|| ((defined SD_MMC_MCI_1_MEM) && (SD_MMC_MCI_1_MEM == ENABLE))
	// Initialize SD/MMC with MCI PB clock.
	sysclk_enable_pbb_module(SYSCLK_MCI);
	sysclk_enable_hsb_module(SYSCLK_DMACA);
	sd_mmc_mci_resources_init();
#endif

	// Start USB stack to authorize VBus monitoring
	udc_start();

	if (!udc_include_vbus_monitoring()) {
		// VBUS monitoring is not available on this product
		// thereby VBUS has to be considered as present
		main_vbus_action(true);
	}

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {

		sleepmgr_enter_sleep();
		if (main_b_msc_enable) {
         udi_msc_process_trans();
      }
	}
}
Exemple #5
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
    init_hmatrix();

    // Configure standard I/O streams as unbuffered.
#if (defined __GNUC__) && (defined __AVR32__)
    setbuf(stdin, NULL);
#endif
    setbuf(stdout, NULL);

#if (defined USB_RESYNC_METHOD) && (USB_RESYNC_METHOD == USB_RESYNC_METHOD_EXT_CLOCK_SYNTHESIZER)
    // Initialize the TWI using the internal RCOSC
    init_twi_CS2200(AVR32_PM_RCOSC_FREQUENCY);

    // Initialize the CS2200 and produce a default 11.2896 MHz frequency
    cs2200_setup(11289600, FOSC0);
#endif

    // Initializes the MCU system clocks
    init_sys_clocks();

    // Initialize the TWI
    init_twi(FPBA_HZ);

    audio_mixer_enable_dacs(DEFAULT_DACS);
    audio_mixer_dacs_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                           DEFAULT_DAC_NUM_CHANNELS,
                           DEFAULT_DAC_BITS_PER_SAMPLE,
                           DEFAULT_DAC_SWAP_CHANNELS);

    // Initialize the display
    et024006_Init(  FCPU_HZ, FHSB_HZ);

    // Set Backlight
    gpio_set_gpio_pin(ET024006DHU_BL_PIN);

    // Clear the display
    et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE );

    // Display a logo.
    et024006_PutPixmap(avr32_logo, AVR32_LOGO_WIDTH, 0, 0
                       ,(ET024006_WIDTH - AVR32_LOGO_WIDTH)/2
                       ,(ET024006_HEIGHT - AVR32_LOGO_HEIGHT)/2, AVR32_LOGO_WIDTH, AVR32_LOGO_HEIGHT);

    et024006_PrintString(AUDIO_DEMO_STRING, (const unsigned char *)&FONT8x16, 30, 5, BLACK, -1);
    et024006_PrintString("Please plug the USB.", (const unsigned char *)&FONT8x8, 30, 30, BLACK, -1);

    // Initialize USB task
    usb_task_init();

    // Initialize Controller
    controller_init(FCPU_HZ, FHSB_HZ, FPBB_HZ, FPBA_HZ);

#if USB_DEVICE_FEATURE == true
    // Initialize device audio USB task
    device_audio_task_init();

    // Initialize the HID USB task
    device_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
    // Initialize host audio USB task
    host_audio_task_init();
#endif

#ifdef FREERTOS_USED
    // Start OS scheduler
    vTaskStartScheduler();
    portDBG_TRACE("FreeRTOS returned.");
    return 42;
#else
    // No OS here. Need to call each task in round-robin mode.
    while (true)
    {
        usb_task();
#if USB_DEVICE_FEATURE == true
        device_audio_task();
        device_hid_task();
#endif
#if USB_HOST_FEATURE == true
        host_audio_task();
#endif
    }
#endif  // FREERTOS_USED
}
Exemple #6
0
static void init_spi(void)
{
#if defined(WL_SPI)
        int i;
#endif
        

#if defined(AT45DBX_SPI)
        static const gpio_map_t AT45DBX_SPI_GPIO_MAP = {
                { AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION },
                { AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION },
                { AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION },
                { AT45DBX_SPI_NPCS2_PIN, AT45DBX_SPI_NPCS2_FUNCTION },
        };
#endif

        
#if defined(WL_SPI) 
	const gpio_map_t WL_SPI_GPIO_MAP = {
#if defined(WL_SPI_NPCS0)
            WL_SPI_NPCS0,
#endif
            WL_SPI_NPCS, WL_SPI_MISO, WL_SPI_MOSI, WL_SPI_SCK
        };
#endif

#if defined(WL_SPI) || defined(AT45DBX_SPI)
        spi_options_t spiOptions = {
                .modfdis = 1 /* only param used by spi_initMaster() */
        };
#endif

#if defined(AT45DBX_SPI)
        gpio_enable_module(AT45DBX_SPI_GPIO_MAP,
                           sizeof(AT45DBX_SPI_GPIO_MAP) /
                           sizeof(AT45DBX_SPI_GPIO_MAP[0]));
        spi_initMaster(AT45DBX_SPI, &spiOptions);
        spi_selectionMode(AT45DBX_SPI, 0, 0, 0);
#endif

#if defined(WL_SPI)
        /* same pins might be initialized twice here */
        gpio_enable_module(WL_SPI_GPIO_MAP,
                           sizeof(WL_SPI_GPIO_MAP) /
                           sizeof(WL_SPI_GPIO_MAP[0]));
        for (i = 0; i < sizeof(WL_SPI_GPIO_MAP)/sizeof(WL_SPI_GPIO_MAP[0]); i++)
                gpio_enable_pin_pull_up(WL_SPI_GPIO_MAP[i].pin);

        /* same SPI controller might be initialized again */
        spi_initMaster(&WL_SPI, &spiOptions);
        spi_selectionMode(&WL_SPI, 0, 0, 0);
#endif

#if defined(AT45DBX_SPI)
        spi_enable(AT45DBX_SPI);

        /* put up flash reset pin */
        gpio_set_gpio_pin(AT45DBX_CHIP_RESET);
#endif

#if defined(WL_SPI)
        spi_enable(&WL_SPI);
#endif
}


static void init_rs232(void)
{
#ifndef NO_SERIAL
#if defined(BOARD_RS232_0)
        const gpio_map_t BOARD_RS232_0_GPIO_MAP = {
                BOARD_RS232_0_TX,
                BOARD_RS232_0_RX,
#if defined(BOARD_RS232_0_RTS) && defined (BOARD_RS232_0_CTS)
                BOARD_RS232_0_RTS,
                BOARD_RS232_0_CTS
#endif
                
        };
#endif

#if defined(BOARD_RS232_1)
        const gpio_map_t BOARD_RS232_1_GPIO_MAP = {
                BOARD_RS232_1_TX,
                BOARD_RS232_1_RX
#if defined(BOARD_RS232_1_RTS) && defined (BOARD_RS232_1_CTS)
                BOARD_RS232_1_RTS,
                BOARD_RS232_1_CTS
#endif
        };
#endif

#if defined(BOARD_RS232_0)
	gpio_enable_module(BOARD_RS232_0_GPIO_MAP,
                           sizeof(BOARD_RS232_0_GPIO_MAP) / 
                           sizeof(BOARD_RS232_0_GPIO_MAP[0]));
#endif

#if defined(BOARD_RS232_1)
	gpio_enable_module(BOARD_RS232_1_GPIO_MAP,
                           sizeof(BOARD_RS232_1_GPIO_MAP) / 
                           sizeof(BOARD_RS232_1_GPIO_MAP[0]));
#endif
#endif /* NO_SERIAL */
}

static void init_printk(void)
{
#ifndef NO_SERIAL
#if defined(CONFIG_CONSOLE_PORT)
	const usart_options_t usart_options = {
		.baudrate = 57600,
		.charlength = 8,
		.paritytype = USART_NO_PARITY,
		.stopbits = USART_1_STOPBIT,
		.channelmode = USART_NORMAL_CHMODE
	};
	usart_init_rs232(&CONFIG_CONSOLE_PORT, &usart_options, FPBA_HZ);
#endif
#endif /* NO_SERIAL */
}

void board_init(void)
{
        
    init_exceptions();
    init_hmatrix();
    init_sys_clocks();
    init_interrupts();

    init_rs232();
    init_printk();
        
#ifdef WITH_SDRAM
    sdramc_init(FHSB_HZ);
#endif
    init_spi();
}
Exemple #7
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  uint32_t iter=0;
  uint32_t cs2200_out_freq=11289600;
  static bool b_sweep_up=true;
  static uint32_t freq_step=0;

  // USART options.
  static usart_serial_options_t USART_SERIAL_OPTIONS =
  {
    .baudrate     = USART_SERIAL_EXAMPLE_BAUDRATE,
    .charlength   = USART_SERIAL_CHAR_LENGTH,
    .paritytype   = USART_SERIAL_PARITY,
    .stopbits     = USART_SERIAL_STOP_BIT
  };

  // Initialize the TWI using the internal RCOSC
  init_twi(AVR32_PM_RCOSC_FREQUENCY);

  // Initialize the CS2200 and produce a default frequency.
  cs2200_setup(11289600, FOSC0);

  sysclk_init();

  // Initialize the board.
  // The board-specific conf_board.h file contains the configuration of the board
  // initialization.
  board_init();

  // Initialize the TWI
  init_twi(sysclk_get_pba_hz());

  // Initialize Serial Interface using Stdio Library
  stdio_serial_init(USART_SERIAL_EXAMPLE,&USART_SERIAL_OPTIONS);

  // Initialize the HMatrix.
  init_hmatrix();

  print_dbg("\r\nCS2200 Example\r\n");

  // Generate a 12.288 MHz frequency out of the CS2200.
  print_dbg("Output 12.288 MHz\r\n");
  cs2200_freq_clk_out(_32_BITS_RATIO(12288000, FOSC0));
  cpu_delay_ms( 10000, sysclk_get_cpu_hz());

  // Generate a 11.2896 MHz frequency out of the CS2200.
  print_dbg("Output 11.2896 MHz\r\n");
  cs2200_freq_clk_out(_32_BITS_RATIO(cs2200_out_freq, FOSC0));
  cpu_delay_ms( 10000, sysclk_get_cpu_hz());

  print_dbg("Sweep from 11.2896 MHz steps of 100 PPM\r\n");
  freq_step = PPM(cs2200_out_freq, 100);

  while(1)
  {
    uint32_t ratio;

    if(b_sweep_up)
    {
      if( iter<=10 )
      {
        print_dbg("Add 100 PPM\r\n");
        iter++;
        cs2200_out_freq += freq_step;
        ratio = _32_BITS_RATIO(cs2200_out_freq, FOSC0);
        cs2200_freq_clk_adjust((uint16_t)ratio);
        cpu_delay_ms( 1000, sysclk_get_cpu_hz());
        while( twi_is_busy() );
      }
      else
        b_sweep_up=false;
    }

    if(!b_sweep_up)
    {
      if( iter>0 )
      {
        print_dbg("Sub 100 PPM\r\n");
        iter--;
        cs2200_out_freq -= freq_step;
        ratio = _32_BITS_RATIO(cs2200_out_freq, FOSC0);
        cs2200_freq_clk_adjust((uint16_t)ratio);
        cpu_delay_ms( 1000, sysclk_get_cpu_hz());
        while( twi_is_busy() );
      }
      else
        b_sweep_up=true;
    }
  }
}
Exemple #8
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
  U32 n_sector = 0;
  U32 card_size; // Unit is in sector.
  U32 bench_start_sector;
  U16 i = 0;
  U16 j = 0;
  t_cpu_time timer;
  Ctrl_status status;

  // Set CPU and PBA clock
  if( PM_FREQ_STATUS_FAIL==pm_configure_clocks(&pm_freq_param) )
     return 42;

  // Initialize HMatrix
  init_hmatrix();

  // Initialize debug RS232 with PBA clock
  init_dbg_rs232(pm_freq_param.pba_f);

  // Start test
  print_dbg("\r\nInitialize SD/MMC driver");

  // Initialize SD/MMC driver resources: GPIO, SDIO and SD/MMC.
  sd_mmc_mci_resources_init();

  // Wait for a card to be inserted
  #if (BOARD == EVK1104)
    #if EXAMPLE_SD_SLOT == SD_SLOT_8BITS
    print_dbg("\r\nInsert a MMC/SD card into the SD/MMC 8bits slot...");
    #elif EXAMPLE_SD_SLOT == SD_SLOT_4BITS
    print_dbg("\r\nInsert a MMC/SD card into the SD/MMC 4bits slot...");
    #else
    # error SD_SLOT not supported
    #endif
    while (!sd_mmc_mci_mem_check(EXAMPLE_SD_SLOT));
  #else
  # error Board not supported
  #endif

  print_dbg("Card detected!\r\n");

  // Read Card capacity
  sd_mmc_mci_read_capacity(EXAMPLE_SD_SLOT, &card_size);
  print_dbg("\r\nCapacity = ");
  print_dbg_ulong(card_size*512);
  print_dbg(" Bytes\r\n");



  // Read the first sector number 0 of the card
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in);
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  // Display the ram_buffer content
  print_dbg("\r\nFirst sector of the card:\r\n");
  for (i=0;i<(512);i++)
  {
    print_dbg_char_hex(buffer_in[i]);
    j++;
    if (j%32==0)
      print_dbg("\r\n"), j=0;
    else if (j%4==0)
      print_dbg(" ");
  }



  // Write some patterns in the first sector number 0 of the card
  print_dbg("Testing write.\r\n");
  if( !test_sd_mmc_write(0) ) return -1;
  if( !test_sd_mmc_write(1) ) return -1;
  if( !test_sd_mmc_write(2) ) return -1;
  if( !test_sd_mmc_write(3) ) return -1;


  // Bench single-block read operations without DMA
  //
  print_dbg("Benching single-block read (without DMA). Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block read operations with DMA
  //
  print_dbg("Benching single-block read (with DMA).    Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block read operations without DMA
  //
  print_dbg("Benching multi-block read  (without DMA). Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_multiple_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block read operations with DMA
  //
  print_dbg("Benching multi-block read  (with DMA).    Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_multiple_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block write operations without DMA
  //
  print_dbg("Benching single-block write (without DMA). Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block write operations with DMA
  //
  print_dbg("Benching single-block write (with DMA).    Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block write operations without DMA
  //
  print_dbg("Benching multi-block write  (without DMA). Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_multiple_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block write operations with DMA
  //
  print_dbg("Benching multi-block write  (with DMA).    Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_multiple_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));

  return 0;
}
/*! \brief The main function.
 *
 */
int main(void)
{
  aes_config_t      AesConf;        // AES config structure
  int               i;
  static const gpio_map_t USART_GPIO_MAP =      // USART GPIO map
  {
    {DMACA_AES_EVAL_USART_RX_PIN, DMACA_AES_EVAL_USART_RX_FUNCTION},
    {DMACA_AES_EVAL_USART_TX_PIN, DMACA_AES_EVAL_USART_TX_FUNCTION}
  };
  static const usart_options_t USART_OPTIONS =  // USART options.
  {
    .baudrate     = DMACA_AES_EVAL_USART_BAUDRATE,
    .charlength   = 8,
    .paritytype   = USART_NO_PARITY,
    .stopbits     = USART_1_STOPBIT,
    .channelmode  = USART_NORMAL_CHMODE
  };


#if BOARD == EVK1104
  if( PM_FREQ_STATUS_FAIL==pm_configure_clocks(&pm_freq_param) )
    while(1);
#endif

  init_hmatrix();

  // Assign GPIO to USART.
  gpio_enable_module(USART_GPIO_MAP,
                     sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

  // Initialize USART in RS232 mode.
  usart_init_rs232(DMACA_AES_EVAL_USART, &USART_OPTIONS, DMACA_AES_EVAL_CPU_FREQ);
  print(DMACA_AES_EVAL_USART, "\x1B[2J\x1B[H.: Using the AES with the DMACA at ");
  print_ulong(DMACA_AES_EVAL_USART, DMACA_AES_EVAL_CPU_FREQ);
  print(DMACA_AES_EVAL_USART, "Hz :.\r\n\r\n");

  //****************************************************************************
  //               CIPHER IN DMA MODE: RAM -> AES -> RAM
  //  - 256bit cryptographic key
  //  - CBC cipher mode
  //  - No counter measures
  //****************************************************************************

  // Init the input array.
  for(i=0; i<DMACA_AES_EVAL_BUF_SIZE; i+=DMACA_AES_EVAL_REFBUF_SIZE)
  {
    memcpy(InputData+i, RefInputData, DMACA_AES_EVAL_REFBUF_SIZE*sizeof(unsigned int));
  }

  //====================
  // Configure the AES.
  //====================
  AesConf.ProcessingMode = AES_PMODE_CIPHER;  // Cipher
  AesConf.ProcessingDelay = 0;                // No delay: best performance
  AesConf.StartMode = AES_START_MODE_DMA;     // DMA mode
  AesConf.KeySize = AES_KEY_SIZE_256;         // 256bit cryptographic key
  AesConf.OpMode = AES_CBC_MODE;              // CBC cipher mode
  AesConf.LodMode = 0;                        // LODMODE == 0 : the end of the
  // encryption is notified by the DMACA transfer complete interrupt. The output
  // is available in the OutputData[] buffer.
  AesConf.CFBSize = 0;                        // Don't-care because we're using the CBC mode.
  AesConf.CounterMeasureMask = 0;             // Disable all counter measures.
  aes_configure(&AVR32_AES, &AesConf);


  //****************************************************************************
  //  - input of 16 32bit words in CPUSRAM
  //  - output of 16 32bit words in CPUSRAM
  //****************************************************************************
  print(DMACA_AES_EVAL_USART, "\r\n---------------------------------------------------\r\n");
  print(DMACA_AES_EVAL_USART, "------ Cipher in DMA Mode: CPUSRAM -> AES -> CPUSRAM ------\r\n");
  print(DMACA_AES_EVAL_USART, "       - 256bit cryptographic key\r\n");
  print(DMACA_AES_EVAL_USART, "       - CBC cipher mode\r\n");
  print(DMACA_AES_EVAL_USART, "       - No counter measures\r\n");
  print(DMACA_AES_EVAL_USART, "       - input of 16 32bit words in CPUSRAM\r\n");
  print(DMACA_AES_EVAL_USART, "       - output of 16 32bit words in CPUSRAM\r\n");
  print(DMACA_AES_EVAL_USART, "---------------------------------------------------\r\n");

  test_ram_aes_ram(16, (unsigned int *)InputData, (unsigned int *)OutputData);
  gpio_clr_gpio_pin(DMACA_AES_EVAL_LED1);

  //****************************************************************************
  //  - input of 256 32bit words in CPUSRAM
  //  - output of 256 32bit words in CPUSRAM
  //****************************************************************************
  print(DMACA_AES_EVAL_USART, "\r\n---------------------------------------------------\r\n");
  print(DMACA_AES_EVAL_USART, "------ Cipher in DMA Mode: CPUSRAM -> AES -> CPUSRAM ------\r\n");
  print(DMACA_AES_EVAL_USART, "       - 256bit cryptographic key\r\n");
  print(DMACA_AES_EVAL_USART, "       - CBC cipher mode\r\n");
  print(DMACA_AES_EVAL_USART, "       - No counter measures\r\n");
  print(DMACA_AES_EVAL_USART, "       - input of 256 32bit words in CPUSRAM\r\n");
  print(DMACA_AES_EVAL_USART, "       - output of 256 32bit words in CPUSRAM\r\n");
  print(DMACA_AES_EVAL_USART, "---------------------------------------------------\r\n");

  test_ram_aes_ram(256, (unsigned int *)InputData, (unsigned int *)OutputData);
  gpio_clr_gpio_pin(DMACA_AES_EVAL_LED2);

  //****************************************************************************
  //  - input of 256 32bit words in HSBSRAM0
  //  - output of 256 32bit words in HSBSRAM1
  //****************************************************************************
  print(DMACA_AES_EVAL_USART, "\r\n---------------------------------------------------\r\n");
  print(DMACA_AES_EVAL_USART, "------ Cipher in DMA Mode: HSBSRAM0 -> AES -> HSBSRAM1 ------\r\n");
  print(DMACA_AES_EVAL_USART, "       - 256bit cryptographic key\r\n");
  print(DMACA_AES_EVAL_USART, "       - CBC cipher mode\r\n");
  print(DMACA_AES_EVAL_USART, "       - No counter measures\r\n");
  print(DMACA_AES_EVAL_USART, "       - Input of 256 32bit words in HSBSRAM0\r\n");
  print(DMACA_AES_EVAL_USART, "       - Output of 256 32bit words in HSBSRAM1\r\n");
  print(DMACA_AES_EVAL_USART, "---------------------------------------------------\r\n");

  // Set the Src and Dst array addresses to respectively HSBSRAM0 & HSBRAM1.
  pSrcData_HsbSram = (unsigned int *)AVR32_INTRAM0_ADDRESS;
  pDstData_HsbSram = (unsigned int *)AVR32_INTRAM1_ADDRESS;

  // Init the input array.
  for(i=0; i<DMACA_AES_EVAL_BUF_SIZE; i+=DMACA_AES_EVAL_REFBUF_SIZE)
  {
    memcpy(pSrcData_HsbSram+i, RefInputData, DMACA_AES_EVAL_REFBUF_SIZE*sizeof(unsigned int));
  }

  test_ram_aes_ram(256, pSrcData_HsbSram, (unsigned int *)pDstData_HsbSram);
  gpio_clr_gpio_pin(DMACA_AES_EVAL_LED3);
  print(DMACA_AES_EVAL_USART, "\r\nDone!");

  // End of tests: go to sleep.
  SLEEP(AVR32_PM_SMODE_STATIC);
  while (true);
}
int main (void)
{
    pcl_freq_param_t local_pcl_freq_param;

    /*
       USART_Int_Test ();

       return (0); */

    // Configure system clocks.
    local_pcl_freq_param = pcl_freq_param;

    if (pcl_configure_clocks (&local_pcl_freq_param) != PASS)
    {
        return 42;
    }

    /* Load the Exception Vector Base Address in the corresponding system register. */
    Set_system_register (AVR32_EVBA, (int) &_evba);

    /* Enable exceptions. */
    ENABLE_ALL_EXCEPTIONS ();

    /* Initialize interrupt handling. */
    INTC_init_interrupts ();

#if ((defined SD_MMC_MCI_0_MEM) && (SD_MMC_MCI_0_MEM == ENABLE)) || ((defined SD_MMC_MCI_1_MEM) && (SD_MMC_MCI_1_MEM == ENABLE))
    sd_mmc_mci_resources_init ();
#endif


#ifdef FREERTOS_USED
    if (!ctrl_access_init ())
    {
        return 42;
    }
#endif // FREERTOS_USED

    // Init Hmatrix bus
    init_hmatrix ();

    // Initialize USB clock.
    pcl_configure_usb_clock ();

    /*
       SmartCard_test (); return 42;

       Test_ALL_Pins ();

       Test_MCI_Pins ();

       Test_LEDs_Pins ();

       TestUart0 ();

       while (1); return (0); */

#ifdef TIME_MEASURING_ENABLE
    TIME_MEASURING_Init ();
#endif


    // For debugging
    BUFFERED_SIO_Init ();

#ifdef INTERPRETER_ENABLE
    IDF_task_init ();
#endif

    // Internal work task - FAT Access
    IW_task_init ();

    // Initialize USB tasks.
    usb_task_init ();




#if USB_DEVICE_FEATURE == ENABLED
#ifdef  USB_MSD
    device_mass_storage_task_init ();
#endif // USB_MSD
#endif


    // CCID_Test_task_init ();
#ifdef  USB_CCID
    USB_CCID_task_init ();
#endif

    DFU_DisableFirmwareUpdate ();   // Stick always starts in application mode

     /**/
        // Protect bootloader
#ifdef STICK_20_A_MUSTER_PROD   //
        flashc_set_bootloader_protected_size (0x2000);
//        flashc_activate_security_bit ();    // Debugging disabled, only chip erase works (bootloader is save) , AES storage keys and setup
                                        // are erased
        flashc_lock_external_privileged_fetch (TRUE);     // Disable external instruction fetch
#endif

    // DFU_FirmwareResetUserpage ();


    // Set BOD33 detection reset to 3.06 Volt
    pm_bod33_ResetDisable ();
    pm_bod33_set_level (AVR32_PM_BOD33_LEVEL_306_VOLT);
    pm_bod33_ResetEnable ();

    // ushell_task_init(pcl_freq_param.pba_f);


    // Create the semaphore
    vSemaphoreCreateBinary (AES_semphr);


    // Wait for the semaphore
    while (!xSemaphoreTake (AES_semphr, portMAX_DELAY));

    // Release the semaphore in order to start a new device/host task
    portBASE_TYPE task_woken = pdFALSE;
/*
    taskENTER_CRITICAL ();
    xSemaphoreGiveFromISR (AES_semphr, &task_woken);
    taskEXIT_CRITICAL ();
*/
    taskENTER_CRITICAL ();
    xSemaphoreGive (AES_semphr);
    taskEXIT_CRITICAL ();


    // Start stick
    vTaskStartScheduler ();

    // It never gets to this point
    return 42;
}