summaryrefslogtreecommitdiff
path: root/bsp/ht32/libraries/ht32_drivers/drv_common.c
blob: fe689d4728181ab7e9577bf2f9b558350c56a116 (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
/*
 * Copyright (c) 2006-2024, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-04-08     QT-one       first version
 */

#include <rtdbg.h>
#include "drv_common.h"
#ifdef RT_USING_SERIAL
    #include "drv_usart.h"
#endif

#ifdef RT_USING_FINSH
#include <finsh.h>
static void reboot(uint8_t argc, char **argv)
{
    rt_hw_cpu_reset();
}
MSH_CMD_EXPORT(reboot, Reboot System);
#endif /* RT_USING_FINSH */

/* SysTick configuration */
void rt_hw_systick_init(void)
{
    SYSTICK_ClockSourceConfig(SYSTICK_SRC_STCLK);
    SYSTICK_SetReloadValue(SystemCoreClock / 10 / RT_TICK_PER_SECOND);
    SYSTICK_IntConfig(ENABLE);
    SYSTICK_CounterCmd(SYSTICK_COUNTER_CLEAR);
    SYSTICK_CounterCmd(SYSTICK_COUNTER_ENABLE);
}

/* This is the timer interrupt service routine */
void SysTick_Handler(void)
{
    /* enter interrupt */
    rt_interrupt_enter();

    rt_tick_increase();

    /* leave interrupt */
    rt_interrupt_leave();
}

/* This function is executed in case of error occurrence */
void _Error_Handler(char *s, int num)
{
    /* User can add his own implementation to report the error return state */
    LOG_E("Error_Handler at file:%s num:%d", s, num);
    while (1)
    {
    }
}

/* This function will initial HT32 board */
void rt_hw_board_init(void)
{
    /* Configure the System clock */
    rt_hw_board_clock_init();

    /* Configure the SysTick */
    rt_hw_systick_init();

    /* heap initialization */
#ifdef RT_USING_HEAP
    rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif

    /* board underlying hardware initialization */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

    /* set the shell console output device */
#ifdef RT_USING_CONSOLE
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

}