summaryrefslogtreecommitdiff
path: root/bsp/mipssim/drivers/board.c
blob: 9c295f0a28da09b6af3aa05089eddb1446577e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (c) 2006-2019, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-12-04     Jiaxun Yang  Initial version
 */

/**
 * @addtogroup mipssim
 */

/*@{*/

#include <rtthread.h>
#include <rthw.h>

#include "mips_regs.h"
#include "exception.h"
#include "drv_uart.h"

#define CPU_HZ	(100 * 1000 * 1000)
#define RT_HW_HEAP_END	(0x80000000 + 64 * 1024 * 1024)

extern unsigned char __bss_end;

/**
 * This is the timer interrupt service routine.
 */
void rt_hw_timer_handler(void)
{
    unsigned int count;

    count = read_c0_compare();
    write_c0_compare(count);
    write_c0_count(0);
    /* increase a OS tick */
    rt_tick_increase();
}

/**
 * This function will initial OS timer
 */
void rt_hw_timer_init(void)
{
    write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
    write_c0_count(0);
    mips_unmask_cpu_irq(7);
}

/**
 * Board level initialization
 */
void rt_hw_board_init(void)
{
    rt_hw_exception_init();

    /* init hardware interrupt */
    rt_hw_interrupt_init();

    #ifdef RT_USING_FPU
    /* init hardware fpu */
    rt_hw_fpu_init();
    #endif

#ifdef RT_USING_SERIAL
    /* init hardware UART device */
    rt_hw_uart_init();
    /* set console device */
    rt_console_set_device("uart");
#endif

#ifdef RT_USING_HEAP
    rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
#endif

    /* init operating system timer */
    rt_hw_timer_init();


#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

    rt_kprintf("Current SR: 0x%08x\n", read_c0_status());

}

/*@}*/