rt-thread/bsp/avr32uc3b0/board.c

85 lines
1.8 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
* Date Author Notes
* 2010-03-30 Kyle First version
* 2023-10-13 Raman Gopalan Move UART specific code sections into the drv_uart files
* 2023-10-20 Raman Gopalan Initialize GPIO sub-system
2013-01-08 22:40:58 +08:00
*/
#include <rtthread.h>
#include "compiler.h"
#include "pm.h"
#include "gpio.h"
#include "usart.h"
#include "intc.h"
#include "drv_uart.h"
#include "drv_gpio.h"
2013-01-08 22:40:58 +08:00
/**
* System tick interrupt handler.
2013-01-08 22:40:58 +08:00
*/
static void rt_hw_timer_handler(void)
{
// Clears the interrupt request.
Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
2013-01-08 22:40:58 +08:00
rt_tick_increase();
2013-01-08 22:40:58 +08:00
}
/**
* Initialize system clock and all peripherals.
2013-01-08 22:40:58 +08:00
*/
static void peripherals_init(void)
{
/*
* PM initialization: OSC0 = 12MHz XTAL, PLL0 = 60MHz System Clock
*/
pm_freq_param_t pm_freq_param =
{
.cpu_f = FCPU,
.pba_f = FPBA,
.osc0_f = FOSC0,
.osc0_startup = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC
};
pm_configure_clocks(&pm_freq_param);
INTC_init_interrupts();
2013-01-08 22:40:58 +08:00
}
/**
* Initialize CPU cycle counter for system tick.
2013-01-08 22:40:58 +08:00
*/
static void cpu_counter_init(void)
{
INTC_register_interrupt(&rt_hw_timer_handler, AVR32_CORE_COMPARE_IRQ, AVR32_INTC_INT3);
Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
Set_system_register(AVR32_COUNT, 0);
2013-01-08 22:40:58 +08:00
}
void rt_hw_board_init(void)
{
Disable_global_interrupt();
2013-01-08 22:40:58 +08:00
peripherals_init();
cpu_counter_init();
2013-01-08 22:40:58 +08:00
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#ifdef RT_USING_SERIAL
rt_hw_uart_init();
#endif
#ifdef RT_USING_PIN
rt_hw_gpio_init();
#endif
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
2013-01-08 22:40:58 +08:00
}