summaryrefslogtreecommitdiff
path: root/bsp/core-v-mcu/core-v-cv32e40p/board/board.c
blob: de1d4d86c86fca9947893f3c6748b52debd176b3 (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
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-12-08     WangShun     the first version
 * 2022-12-13     WangShun     put the rt_system_heap_init in head
 */

#include <stdint.h>
#include <rthw.h>
#include <rtthread.h>
#include "udma_uart_driver.h"
#include "hal_udma_ctrl_reg_defs.h"
#include "hal_udma_uart_reg_defs.h"
#include "core-v-mcu-config.h"
#include "drv_usart.h"
#include "string.h"

extern void rt_systick_config(void);

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE (64*1024)
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
void *rt_heap_begin_get(void)
{
    return rt_heap;
}
void *rt_heap_end_get(void)
{
    return rt_heap + RT_HEAP_SIZE;
}
#endif

void rt_hw_board_init()
{
    /*Initialize heap first, or system_ Semaphore in init cannot be created*/
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
    rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
    /* System Clock Update */
    extern void system_init(void);
    system_init();
    /* System Tick Configuration */
    rt_systick_config();

    volatile uint32_t mtvec = 0;
    __asm volatile( "csrr %0, mtvec" : "=r"( mtvec ) );
    __asm volatile( "csrs mie, %0" :: "r"(0x880) );

    /* USART driver initialization is open by default */
#ifdef RT_USING_SERIAL
    rt_hw_usart_init();
#endif
#ifdef RT_USING_CONSOLE
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
    /* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif
}