Пример #1
0
/*
 * Low-level initialization routine called during startup, before the main
 * function.
 * This version comes in replacement to the default one provided by Newlib.
 * Newlib's _init_startup only calls init_exceptions, but Newlib's exception
 * vectors are not compatible with the SCALL management in the current FreeRTOS
 * port. More low-level initializations are besides added here.
 */
void _init_startup(void)
{
	/* Import the Exception Vector Base Address. */
	extern void _evba;

	#if configHEAP_INIT
		extern void __heap_start__;
		extern void __heap_end__;
		BaseType_t *pxMem;
	#endif

	/* 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 configHEAP_INIT

		/* Initialize the heap used by malloc. */
		for( pxMem = &__heap_start__; pxMem < ( BaseType_t * )&__heap_end__; )
		{
			*pxMem++ = 0xA5A5A5A5;
		}

	#endif

	/* Give the used CPU clock frequency to Newlib, so it can work properly. */
	//set_cpu_hz( configCPU_CLOCK_HZ );
}
Пример #2
0
/*!
 * Setup a MPU entry
 * \param mpu_entry: pointer to mpu_entry_t with the MPU settings (base address, size, validity).
 * \param region_number: MPU entry region number (0..7).
 * \return int       MPU_SETUP_ENTRY_OK              if the setup succeeded
 *                   MPU_SETUP_ENTRY_INVALIDBASEADDR if the setup failed because the input base address is not aligned to the size of the region.
 *                   MPU_SETUP_ENTRY_INVALIDSIZE     if the setup failed because the input size is not one of the type eRegionSize.
 */
char set_mpu_entry(const mpu_entry_t *mpu_entry, unsigned int region_number)
{
  /* Set Address Register. */
  avr32_mpuar0_t ar;

  // Check the size: it must (be a power of 2) and (greater than or equal to 4kB) and (less than or equal to 4GB).
  // Based on Table 6.1 in doc32002 "AVR32UC Technical Reference Manual Complete".
  if( ( mpu_entry->size <= MPU_REGION_SIZE_LOWLIMIT_FORBIDDEN )
    ||( mpu_entry->size >= MPU_REGION_SIZE_HIGHLIMIT_FORBIDDEN ) )
    // ERROR: the input size is not of the type eRegionSize.
    return(MPU_SETUP_ENTRY_INVALIDSIZE);

  // Check the base address: it must be aligned to the size of the region.
  // This test is written carefully to also work for the 4-GB case.
  if(!Test_align(mpu_entry->addr, 2 << (U32)mpu_entry->size))
    // ERROR: the input base address is not aligned to the size of the region.
    return(MPU_SETUP_ENTRY_INVALIDBASEADDR);

  // Specify the 20 most significant bits of the start address.
  ar.base = mpu_entry->addr >> 12;
  // Size of this protected region; based on Table 5.1 in doc32000 (AVR32
  // Architecture Manual Complete).
  ar.size = mpu_entry->size;
  ar.v = mpu_entry->valid;

  /* Region entry */
  switch ( region_number & 0x7 )
  {
  default:
  case 0:
    Set_system_register(AVR32_MPUAR0, *((unsigned int *)&ar));
    break;
  case 1:
    Set_system_register(AVR32_MPUAR1, *((unsigned int *)&ar));
    break;
  case 2:
    Set_system_register(AVR32_MPUAR2, *((unsigned int *)&ar));
    break;
  case 3:
    Set_system_register(AVR32_MPUAR3, *((unsigned int *)&ar));
    break;
  case 4:
    Set_system_register(AVR32_MPUAR4, *((unsigned int *)&ar));
    break;
  case 5:
    Set_system_register(AVR32_MPUAR5, *((unsigned int *)&ar));
    break;
  case 6:
    Set_system_register(AVR32_MPUAR6, *((unsigned int *)&ar));
    break;
  case 7:
    Set_system_register(AVR32_MPUAR7, *((unsigned int *)&ar));
    break;
  }

  return(MPU_SETUP_ENTRY_OK);
}
Пример #3
0
/*
 * 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 vectors are not compatible with the SCALL management in the current
 * FreeRTOS port. More low-level initializations are besides added here.
 */
int _init_startup(void)
{
	/* Import the Exception Vector Base Address. */
	extern void _evba;

	#if configHEAP_INIT
		extern void __heap_start__;
		extern void __heap_end__;
		portBASE_TYPE *pxMem;
	#endif

	/* 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 configHEAP_INIT

		/* Initialize the heap used by malloc. */
		for( pxMem = &__heap_start__; pxMem < ( portBASE_TYPE * )&__heap_end__; )
		{
			*pxMem++ = 0xA5A5A5A5;
		}

	#endif

	/* Give the used PBA clock frequency to Newlib, so it can work properly. */
	set_cpu_hz( configPBA_CLOCK_HZ );

	/* Code section present if and only if the debug trace is activated. */
	#if configDBG
	{
		static const gpio_map_t DBG_USART_GPIO_MAP =
		{
			{ configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION },
			{ configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION }
		};

		/* Initialize the USART used for the debug trace with the configured parameters. */
		set_usart_base( ( void * ) configDBG_USART );
		gpio_enable_module( DBG_USART_GPIO_MAP,
		                    sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) );
		usart_init( configDBG_USART_BAUDRATE );
	}
	#endif

  // Don't-care value for GCC.
  return 1;
}
Пример #4
0
void wait_10_ms(void)
{
  Set_system_register(AVR32_COUNT, 0);
#if (defined AVR32_PM_RCOSC_FREQUENCY)
  while ((U32)Get_system_register(AVR32_COUNT) <
      (AVR32_PM_RCOSC_FREQUENCY * 10 + 999) / 1000);
#elif (defined AVR32_SCIF_RCOSC_FREQUENCY)
  while ((U32)Get_system_register(AVR32_COUNT) <
      (AVR32_SCIF_RCOSC_FREQUENCY * 10 + 999) / 1000);
#else
  #error Unknow RCOSC frequency value
#endif
}
Пример #5
0
static void prvScheduleFirstTick(void)
{
    unsigned long lCycles;

    lCycles = Get_system_register(AVR32_COUNT);
    lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ);
    // If lCycles ends up to be 0, make it 1 so that the COMPARE and exception
    // generation feature does not get disabled.
    if(0 == lCycles) {
        lCycles++;
    }
    Set_system_register(AVR32_COMPARE, lCycles);
}
Пример #6
0
/*!
 * Setup a Subregion
 * \param region_number: MPU entry region number (0..7).
 * \param pattern_select: bit-field for the 16 subregions: register A: '0' -- B: '1'
 */
void select_subregion(unsigned int region_number, unsigned int pattern_select)
{
  /* Region entry */
  switch ( region_number & 0x7 )
  {
  default:
  case 0: Set_system_register(AVR32_MPUPSR0, pattern_select );break;
  case 1: Set_system_register(AVR32_MPUPSR1, pattern_select );break;
  case 2: Set_system_register(AVR32_MPUPSR2, pattern_select );break;
  case 3: Set_system_register(AVR32_MPUPSR3, pattern_select );break;
  case 4: Set_system_register(AVR32_MPUPSR4, pattern_select );break;
  case 5: Set_system_register(AVR32_MPUPSR5, pattern_select );break;
  case 6: Set_system_register(AVR32_MPUPSR6, pattern_select );break;
  case 7: Set_system_register(AVR32_MPUPSR7, pattern_select );break;
  }
}
Пример #7
0
/*! \brief Initializes MCU exceptions.
 */
static void init_exceptions(void)
{
#if __GNUC__ && __AVR32__
    // Import the Exception Vector Base Address.
    extern void _evba;

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

    // Enable exceptions globally.
    Enable_global_exception();
}
Пример #8
0
/*! \brief 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.
 */
int _init_startup(void)
{
  // Import the Exception Vector Base Address.
  extern void _evba;

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

  // Enable exceptions.
  Enable_global_exception();

  // Initialize interrupt handling.
  INTC_init_interrupts();

  // Don't-care value for GCC.
  return 1;
}
Пример #9
0
static void prvScheduleNextTick(void)
{
    unsigned long lCycles, lCount;

    lCycles = Get_system_register(AVR32_COMPARE);
    lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ);
    // If lCycles ends up to be 0, make it 1 so that the COMPARE and exception
    // generation feature does not get disabled.
    if(0 == lCycles) {
        lCycles++;
    }
    lCount = Get_system_register(AVR32_COUNT);
    if( lCycles < lCount ) {
        // We missed a tick, recover for the next.
        lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ);
    }
    Set_system_register(AVR32_COMPARE, lCycles);
}
Пример #10
0
/*! \brief 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.
 */
int _init_startup(void)
{
  // Import the Exception Vector Base Address.
  extern void _evba;

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

  // Enable exceptions.
  Enable_global_exception();

  // Initialize interrupt handling.
  INTC_init_interrupts();

  // Initialize the USART used for the debug trace with the configured parameters.
  set_usart_base( ( void * ) DBG_USART );

  // Don't-care value for GCC.
  return 1;
}
Пример #11
0
/*!
 * Disable a MPU entry
 * \param region_number: MPU entry region number (0..7).
 * \param register_select: register A: '0' -- B: '1'
 */
void disable_mpu_entry(unsigned int region_number, unsigned int register_select)
{
  /* Set Address Register. */
  avr32_mpuar0_t ar;

  ar.base = 0;
  ar.size = 0;
  ar.v = 0;

  /* Region entry */
  switch ( region_number & 0x7 )
  {
  default:
  case 0:
    Set_system_register(AVR32_MPUAR0, *((unsigned int *)&ar));
    break;
  case 1:
    Set_system_register(AVR32_MPUAR1, *((unsigned int *)&ar));
    break;
  case 2:
    Set_system_register(AVR32_MPUAR2, *((unsigned int *)&ar));
    break;
  case 3:
    Set_system_register(AVR32_MPUAR3, *((unsigned int *)&ar));
    break;
  case 4:
    Set_system_register(AVR32_MPUAR4, *((unsigned int *)&ar));
    break;
  case 5:
    Set_system_register(AVR32_MPUAR5, *((unsigned int *)&ar));
    break;
  case 6:
    Set_system_register(AVR32_MPUAR6, *((unsigned int *)&ar));
    break;
  case 7:
    Set_system_register(AVR32_MPUAR7, *((unsigned int *)&ar));
    break;
  }
}
Пример #12
0
/*! \brief 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.
 */
int _init_startup(void)
{
  // Import the Exception Vector Base Address.
  extern void _evba;

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

  // Enable exceptions.
  Enable_global_exception();

  // Initialize interrupt handling.
  INTC_init_interrupts();

  // Give the used CPU clock frequency to Newlib, so it can work properly.
  set_cpu_hz(pcl_freq_param.pba_f);

  // Initialize the USART used for the debug trace with the configured parameters.
  set_usart_base( ( void * ) DBG_USART );

  // Don't-care value for GCC.
  return 1;
}
Пример #13
0
	__attribute__((__noinline__)) static void prvClearCcInt(void)
	{
		Set_system_register(AVR32_COMPARE, Get_system_register(AVR32_COMPARE));
	}
Пример #14
0
	static void prvScheduleFirstTick(void)
	{
		Set_system_register(AVR32_COMPARE, configCPU_CLOCK_HZ/configTICK_RATE_HZ);
		Set_system_register(AVR32_COUNT, 0);
	}
Пример #15
0
int _init_startup(void)
{
	/* Import the Exception Vector Base Address. */
	extern void _evba;

	#if configHEAP_INIT
		extern void __heap_start__;
		extern void __heap_end__;
		portBASE_TYPE *pxMem;
	#endif

	/* 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 configHEAP_INIT

		/* Initialize the heap used by malloc. */
		for( pxMem = &__heap_start__; pxMem < ( portBASE_TYPE * )&__heap_end__; )
		{
			*pxMem++ = 0xA5A5A5A5;
		}

	#endif

	/* Code section present if and only if the debug trace is activated. */
	#if configDBG
	{
		static const gpio_map_t DBG_USART_GPIO_MAP =
		{
			{ configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION },
			{ configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION }
		};

		static const usart_options_t DBG_USART_OPTIONS =
		{
			.baudrate = configDBG_USART_BAUDRATE,
			.charlength = 8,
			.paritytype = USART_NO_PARITY,
			.stopbits = USART_1_STOPBIT,
			.channelmode = USART_NORMAL_CHMODE
		};

		/* Initialize the USART used for the debug trace with the configured parameters. */
		extern volatile avr32_usart_t *volatile stdio_usart_base;
		stdio_usart_base = configDBG_USART;
		gpio_enable_module( DBG_USART_GPIO_MAP,
		                    sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) );
		usart_init_rs232(configDBG_USART, &DBG_USART_OPTIONS, configPBA_CLOCK_HZ);
	}
	#endif

  // Don't-care value for GCC.
  return 1;
}
/*-----------------------------------------------------------*/

/*
 * malloc, realloc and free are meant to be called through respectively
 * pvPortMalloc, pvPortRealloc and vPortFree.
 * The latter functions call the former ones from within sections where tasks
 * are suspended, so the latter functions are task-safe. __malloc_lock and
 * __malloc_unlock use the same mechanism to also keep the former functions
 * task-safe as they may be called directly from Newlib's functions.
 * However, all these functions are interrupt-unsafe and SHALL THEREFORE NOT BE
 * CALLED FROM WITHIN AN INTERRUPT, because __malloc_lock and __malloc_unlock do
 * not call portENTER_CRITICAL and portEXIT_CRITICAL in order not to disable
 * interrupts during memory allocation management as this may be a very time-
 * consuming process.
 */

/*
 * Lock routine called by Newlib on malloc / realloc / free entry to guarantee a
 * safe section as memory allocation management uses global data.
 * See the aforementioned details.
 */
void __malloc_lock(struct _reent *ptr);
void __malloc_lock(struct _reent *ptr)
{
	vTaskSuspendAll();
}

/*
 * Unlock routine called by Newlib on malloc / realloc / free exit to guarantee
 * a safe section as memory allocation management uses global data.
 * See the aforementioned details.
 */
void __malloc_unlock(struct _reent *ptr);
void __malloc_unlock(struct _reent *ptr)
{
	xTaskResumeAll();
}
/*-----------------------------------------------------------*/

/* Added as there is no such function in FreeRTOS. */
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn;

	vTaskSuspendAll();
	{
		pvReturn = realloc( pv, xWantedSize );
	}
	xTaskResumeAll();

	return pvReturn;
}
Пример #16
0
	static void prvClearCcInt(void)
	{
		Set_system_register(AVR32_COMPARE, Get_system_register(AVR32_COMPARE));
	}
Пример #17
0
static void init_exceptions(void)
{
	extern void _evba;
	Set_system_register(AVR32_EVBA, (int)&_evba);
	Enable_global_exception();
}
Пример #18
0
/*!
 * Control of the MPU control register MPUCR: disable MPUCR
 */
void disable_mpu(void)
{
  Set_system_register(AVR32_MPUCR, 0);
}
Пример #19
0
/*!
 * Control of the MPU control register MPUCR: enable MPUCR
 */
void enable_mpu(void)
{
  Set_system_register(AVR32_MPUCR, AVR32_MPUCR_E_MASK);
}
Пример #20
0
/*!
 * Setup a register A and B
 * \param region_number: MPU entry region number (0..7).
 * \param register_select: register A: '0' -- B: '1'
 * \param right_access: R/W/X see doc32002.pdf (Table 5-3. Access permissions implied by the APn bits)
 */
void set_access_permissions(unsigned int region_number, unsigned int register_select, unsigned int right_access)
{
  avr32_mpuapra_t mpu_regA;
  avr32_mpuaprb_t mpu_regB;

  *(U32 *)&mpu_regA = (U32) Get_system_register(AVR32_MPUAPRA);
  *(U32 *)&mpu_regB = (U32) Get_system_register(AVR32_MPUAPRB);

  /* Region entry */
  if (register_select==0) //Register A
  {
    switch ( region_number & 0x7 )
    {
    default:
    case 0:
      mpu_regA.ap0 = (right_access);
      break;
    case 1:
      mpu_regA.ap1  = (right_access);
      break;
    case 2:
      mpu_regA.ap2  = (right_access);
      break;
    case 3:
      mpu_regA.ap3  = (right_access);
      break;
    case 4:
      mpu_regA.ap4  = (right_access);
      break;
    case 5:
      mpu_regA.ap5  = (right_access);
      break;
    case 6:
      mpu_regA.ap6  = (right_access);
      break;
    case 7:
      mpu_regA.ap7  = (right_access);
      break;
    }
    /* Set permissions */
    Set_system_register(AVR32_MPUAPRA, *((unsigned int *)&mpu_regA));
  }
  else //Register B
  {
    switch ( region_number & 0x7 )
    {
    default:
    case 0:
      mpu_regB.ap0 = (right_access);
      break;
    case 1:
      mpu_regB.ap1  = (right_access);
      break;
    case 2:
      mpu_regB.ap2  = (right_access);
      break;
    case 3:
      mpu_regB.ap3  = (right_access);
      break;
    case 4:
      mpu_regB.ap4  = (right_access);
      break;
    case 5:
      mpu_regB.ap5  = (right_access);
      break;
    case 6:
      mpu_regB.ap6  = (right_access);
      break;
    case 7:
      mpu_regB.ap7  = (right_access);
      break;
    }
    /* Set permissions */
    Set_system_register(AVR32_MPUAPRB, *((unsigned int *)&mpu_regB));
  }
}
Пример #21
0
/**
 * \internal
 * \brief Init EVBA address. This operation may or may not have been done by the
 * C startup process.
 */
static __inline__ void INTC_init_evba(void)
{
  Set_system_register(AVR32_EVBA, (int32_t)&_evba );
}
Пример #22
0
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;
}
Пример #23
0
/*! \brief Initializes STDIO.
 */
static void init_stdio(void)
{
#if (defined __GNUC__) && (defined __AVR32__)

    static const gpio_map_t STDIO_USART_GPIO_MAP =
    {
        {STDIO_USART_RX_PIN, STDIO_USART_RX_FUNCTION},
        {STDIO_USART_TX_PIN, STDIO_USART_TX_FUNCTION}
    };

    // Initialize the USART used for STDIO.
    set_usart_base((void *)STDIO_USART);
    gpio_enable_module(STDIO_USART_GPIO_MAP,
                       sizeof(STDIO_USART_GPIO_MAP) / sizeof(STDIO_USART_GPIO_MAP[0]));
    usart_init(STDIO_USART_BAUDRATE);

#elif (defined __ICCAVR32__)

    static const gpio_map_t STDIO_USART_GPIO_MAP =
    {
        {STDIO_USART_RX_PIN, STDIO_USART_RX_FUNCTION},
        {STDIO_USART_TX_PIN, STDIO_USART_TX_FUNCTION}
    };

    static const usart_options_t STDIO_USART_OPTIONS =
    {
        .baudrate     = STDIO_USART_BAUDRATE,
        .charlength   = 8,
        .paritytype   = USART_NO_PARITY,
        .stopbits     = USART_1_STOPBIT,
        .channelmode  = USART_NORMAL_CHMODE
    };

    // Initialize the USART used for STDIO.
    extern volatile avr32_usart_t *volatile stdio_usart_base;
    stdio_usart_base = STDIO_USART;
    gpio_enable_module(STDIO_USART_GPIO_MAP,
                       sizeof(STDIO_USART_GPIO_MAP) / sizeof(STDIO_USART_GPIO_MAP[0]));
    usart_init_rs232(STDIO_USART, &STDIO_USART_OPTIONS, FPBA_HZ);

#endif
}


#if (defined __GNUC__)

/*! \brief 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.
 */
int _init_startup(void)
{
    // Import the Exception Vector Base Address.
    extern void _evba;

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

    // Enable exceptions.
    Enable_global_exception();

    // Initialize interrupt handling.
    irq_initialize_vectors();
    cpu_irq_enable();

    init_stdio();

    // Don't-care value for GCC.
    return 1;
}

#elif (defined __ICCAVR32__)

/*! \brief Low-level initialization routine called during startup, before the
 *         main function.
 */
int __low_level_init(void)
{
    // Enable exceptions.
    Enable_global_exception();

    // Initialize interrupt handling.
    irq_initialize_vectors();
    cpu_irq_enable();

    init_stdio();

    // Request initialization of data segments.
    return 1;
}
Пример #24
0
/*
 * Low-level initialization routine called during startup, before the main
 * function.
 * This version comes in replacement to the default one provided by Newlib.
 * Newlib's _init_startup only calls init_exceptions, but Newlib's exception
 * vectors are not compatible with the SCALL management in the current FreeRTOS
 * port. More low-level initializations are besides added here.
 */
void _init_startup(void)
{
	/* Import the Exception Vector Base Address. */
	extern void _evba;

	#if configHEAP_INIT
		extern void __heap_start__;
		extern void __heap_end__;
		portBASE_TYPE *pxMem;
	#endif

	/* 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 configHEAP_INIT

		/* Initialize the heap used by malloc. */
		for( pxMem = &__heap_start__; pxMem < ( portBASE_TYPE * )&__heap_end__; )
		{
			*pxMem++ = 0xA5A5A5A5;
		}

	#endif

	/* Give the used CPU clock frequency to Newlib, so it can work properly. */
	set_cpu_hz( configCPU_CLOCK_HZ );
	
    // Input and output parameters when initializing PM clocks using pm_configure_clocks().
	pm_freq_param_t clkParams = {
		configCPU_CLOCK_HZ, // unsigned long cpu_f;
		configPBA_CLOCK_HZ, // unsigned long pba_f; ! PBA frequency (input/output argument).
		FOSC0, // unsigned long osc0_f; ! Oscillator 0's external crystal(or external clock) frequency (board dependant) (input argument).
		OSC0_STARTUP // unsigned long osc0_startup; ! Oscillator 0's external crystal(or external clock) startup time: AVR32_PM_OSCCTRL0_STARTUP_x_RCOSC (input argument).
	};

	pm_configure_clocks(&clkParams);
    
	/* Code section present if and only if the debug trace is activated. */
	#if configDBG
	{
		static const gpio_map_t DBG_USART_GPIO_MAP =
		{
			{ configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION },
			{ configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION }
		};

		/* Initialize the USART used for the debug trace with the configured parameters. */
		set_usart_base( ( void * ) configDBG_USART );
		gpio_enable_module( DBG_USART_GPIO_MAP,
		                    sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) );
		usart_init( configDBG_USART_BAUDRATE );
    
        /*const usart_options_t USART_OPTIONS =
        {
            configDBG_USART_BAUDRATE,	// baudrate
            8, 					        // charlength
            USART_NO_PARITY, 	        // paritytype
            USART_1_STOPBIT, 	        // stopbits
            USART_NORMAL_CHMODE         // channelmode
        };
        
        usart_init_rs232(configDBG_USART, &USART_OPTIONS, configPBA_CLOCK_HZ);*/
	}
	#endif
}