rt-thread-official/bsp/raspberry-pi/raspi4-32/driver/board.c

95 lines
2.5 KiB
C
Raw Normal View History

2020-05-25 17:30:05 +08:00
/*
2021-03-14 12:58:10 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2020-05-25 17:30:05 +08:00
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-04-16 bigmagic first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
#include "drv_uart.h"
#include "cp15.h"
#include "mmu.h"
2020-11-26 11:20:13 +08:00
#include "mbox.h"
2020-05-25 17:30:05 +08:00
struct mem_desc platform_mem_desc[] = {
{0x0, 0x6400000, 0x0, NORMAL_MEM},
2020-10-30 18:12:30 +08:00
{0x8000000, 0x8800000, 0x8000000, DEVICE_MEM}, //mbox msg
2020-11-27 14:30:25 +08:00
{0x0E000000, 0x0EE00000, 0x0E000000, DEVICE_MEM}, //framebuffer
2021-03-14 12:58:10 +08:00
{0x0F400000, 0x0FA00000, 0x0F400000, DEVICE_MEM}, //dsi_touch
2020-10-30 18:12:30 +08:00
{0xFD500000, 0xFDA00000, 0xFD500000, DEVICE_MEM}, //gmac
2020-12-02 10:09:27 +08:00
{0xFE000000, 0xFF000000, 0xFE000000, DEVICE_MEM}, //peripheral
2020-10-27 12:46:50 +08:00
{0xFF800000, 0xFFA00000, 0xFF800000, DEVICE_MEM} //gic
2020-05-25 17:30:05 +08:00
};
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
void rt_hw_timer_isr(int vector, void *parameter)
{
ARM_TIMER_IRQCLR = 0;
rt_tick_increase();
}
void rt_hw_timer_init(void)
{
2020-11-26 11:20:13 +08:00
rt_uint32_t apb_clock = 0;
rt_uint32_t timer_clock = 1000000;
2020-05-25 17:30:05 +08:00
/* timer_clock = apb_clock/(pre_divider + 1) */
2020-11-26 11:20:13 +08:00
apb_clock = bcm271x_mbox_clock_get_rate(CORE_CLK_ID);
ARM_TIMER_PREDIV = (apb_clock/timer_clock - 1);
2020-05-25 17:30:05 +08:00
ARM_TIMER_RELOAD = 0;
ARM_TIMER_LOAD = 0;
ARM_TIMER_IRQCLR = 0;
ARM_TIMER_CTRL = 0;
2020-11-26 11:20:13 +08:00
ARM_TIMER_RELOAD = 1000000/RT_TICK_PER_SECOND;
ARM_TIMER_LOAD = 1000000/RT_TICK_PER_SECOND;
2020-05-25 17:30:05 +08:00
/* 23-bit counter, enable interrupt, enable timer */
ARM_TIMER_CTRL = (1 << 1) | (1 << 5) | (1 << 7);
2020-11-26 11:20:13 +08:00
rt_hw_interrupt_install(ARM_TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
rt_hw_interrupt_umask(ARM_TIMER_IRQ);
2020-05-25 17:30:05 +08:00
}
void idle_wfi(void)
{
asm volatile ("wfi");
}
/**
2021-03-14 12:58:10 +08:00
* Initialize the Hardware related stuffs. Called from rtthread_startup()
2020-05-25 17:30:05 +08:00
* after interrupt disabled.
*/
void rt_hw_board_init(void)
{
/* initialize hardware interrupt */
rt_hw_interrupt_init();
/* initialize uart */
rt_hw_uart_init(); // driver/drv_uart.c
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
2020-05-25 17:30:05 +08:00
/* set console device */
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
2020-05-25 17:30:05 +08:00
#ifdef RT_USING_HEAP
/* initialize memory system */
rt_kprintf("heap: 0x%08x - 0x%08x\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
/* initialize timer for os tick */
rt_hw_timer_init();
rt_thread_idle_sethook(idle_wfi);
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}