summaryrefslogtreecommitdiff
path: root/bsp/ls1cdev/applications/startup.c
blob: cb1025dec61097254ef1741bfce095588915cd47 (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
92
93
/*
 * File      : startup.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date                 Author         Notes
 * 2010-06-25     Bernard        first version
 * 2011-08-08     lgnq             modified for Loongson LS1B
 * 2015-07-06     chinesebear  modified for Loongson LS1C
 */

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

#include "board.h"
#define A_K0BASE		0x80000000

/**
 * @addtogroup Loongson LS1B
 */

/*@{*/

extern unsigned char __bss_end;

extern int rt_application_init(void);

extern void tlb_refill_exception(void);
extern void general_exception(void);
extern void irq_exception(void);
extern void rt_hw_cache_init(void);
extern void invalidate_writeback_dcache_all(void);
extern void invalidate_icache_all(void);

/**
 * This function will startup RT-Thread RTOS.
 */
void rtthread_startup(void)
{
    /* disable interrupt first */
    rt_hw_interrupt_disable();

    /* init cache */
    rt_hw_cache_init();
    /* init hardware interrupt */
    rt_hw_interrupt_init();

    /* copy vector */
    rt_memcpy((void *)A_K0BASE, tlb_refill_exception, 0x80);
    rt_memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x80);
    rt_memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x80);

    invalidate_writeback_dcache_all();
    invalidate_icache_all();

    /* init board */
    rt_hw_board_init();

    /* show version */
    rt_show_version();

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

    /* init scheduler system */
    rt_system_scheduler_init();

    /* initialize timer */
    rt_system_timer_init();

    /* initialize timer thread */
    rt_system_timer_thread_init();

    /* init idle thread */
    rt_thread_idle_init();

    /* init application */
    rt_application_init();

    /* start scheduler */
    rt_system_scheduler_start();

    /* never reach here */
    return;
}

/*@}*/