rt-thread/bsp/hifive1/drivers/board.c

93 lines
2.3 KiB
C
Raw Normal View History

2018-05-30 22:17:25 +08:00
/*
* File : board.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <interrupt.h>
#include <rthw.h>
#include <board.h>
#include <platform.h>
#include <encoding.h>
#include <interrupt.h>
extern void use_default_clocks(void);
extern void use_pll(int refsel, int bypass, int r, int f, int q);
#define TICK_COUNT (2 * RTC_FREQ / RT_TICK_PER_SECOND)
#define MTIME (*((volatile uint64_t *)(CLINT_CTRL_ADDR + CLINT_MTIME)))
#define MTIMECMP (*((volatile uint64_t *)(CLINT_CTRL_ADDR + CLINT_MTIMECMP)))
/* system tick interrupt */
void handle_m_time_interrupt()
{
MTIMECMP = MTIME + TICK_COUNT;
rt_tick_increase();
}
/* fixed misaligned bug for qemu */
void *__wrap_memset(void *s, int c, size_t n)
{
return rt_memset(s, c, n);
}
static void rt_hw_clock_init(void)
{
use_default_clocks();
use_pll(0, 0, 1, 31, 1);
}
static void rt_hw_timer_init(void)
{
MTIMECMP = MTIME + TICK_COUNT;
/* enable timer interrupt*/
set_csr(mie, MIP_MTIP);
}
void rt_hw_board_init(void)
{
/* initialize the system clock */
rt_hw_clock_init();
/* initialize hardware interrupt */
rt_hw_interrupt_init();
/* initialize timer0 */
rt_hw_timer_init();
#ifdef RT_USING_HEAP
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
return;
}