rt-thread-official/bsp/avr32uc3b0/board.c

98 lines
2.4 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
* Copyright (c) 2006-2021, 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
*/
#include <rtthread.h>
#include "compiler.h"
#include "pm.h"
#include "gpio.h"
#include "usart.h"
#include "intc.h"
#include "serial.h"
#define FOSC0 12000000
#define FCPU 60000000
#define FHSB FCPU
#define FPBA FCPU
#define FPBB FCPU
2013-01-08 22:40:58 +08:00
extern void rt_hw_serial_isr(void);
extern void rt_hw_usart_init(void);
/**
* 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);
2013-01-08 22:40:58 +08:00
/*
* USART1 initialization
*/
gpio_enable_module_pin(AVR32_USART1_TXD_0_1_PIN, AVR32_USART1_TXD_0_1_FUNCTION);
gpio_enable_module_pin(AVR32_USART1_RXD_0_1_PIN, AVR32_USART1_RXD_0_1_FUNCTION);
static const usart_options_t usartOptions = {
.baudrate = 115200,
.charlength = 8,
.paritytype = USART_NO_PARITY,
.stopbits = USART_1_STOPBIT,
.channelmode = USART_NORMAL_CHMODE
};
usart_init_rs232(&AVR32_USART1, &usartOptions, FCPU);
2013-01-08 22:40:58 +08:00
INTC_init_interrupts();
INTC_register_interrupt(&rt_hw_serial_isr, AVR32_USART1_IRQ, AVR32_INTC_INT0);
AVR32_USART1.ier = AVR32_USART_IER_RXRDY_MASK;
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)
{
extern struct rt_device _rt_usart_device;
extern struct avr32_serial_device uart;
2013-01-08 22:40:58 +08:00
Disable_global_interrupt();
2013-01-08 22:40:58 +08:00
peripherals_init();
cpu_counter_init();
2013-01-08 22:40:58 +08:00
rt_hw_serial_register(&_rt_usart_device, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, &uart);
rt_console_set_device("uart1");
2013-01-08 22:40:58 +08:00
}