summaryrefslogtreecommitdiff
path: root/bsp/nxp/mcx/mcxc/frdm-mcxc162/board/board.c
blob: 76de70a5c85fe7f247d4c7ec36e5f53323288257 (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
/*
 * Copyright (c) 2006-2026, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

#include "board.h"
#include "pin_mux.h"

void SysTick_Handler(void)
{
    rt_interrupt_enter();
    rt_tick_increase();
    rt_interrupt_leave();
}

void rt_hw_board_init(void)
{
    BOARD_InitBootPins();
    BOARD_InitBootClocks();

    SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
    NVIC_SetPriority(PendSV_IRQn, (1U << __NVIC_PRIO_BITS) - 1U);

#ifdef RT_USING_HEAP
    rt_system_heap_init(HEAP_BEGIN, HEAP_END);
#endif

#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
}

void rt_hw_us_delay(rt_uint32_t us)
{
    uint32_t cycles = SystemCoreClock / 1000000U * us;
    uint32_t start = SysTick->VAL;
    uint32_t elapsed = 0;
    uint32_t reload = SysTick->LOAD + 1U;

    while (elapsed < cycles)
    {
        uint32_t now = SysTick->VAL;
        elapsed += (start >= now) ? (start - now) : (start + reload - now);
        start = now;
    }
}

void rt_hw_cpu_reset(void)
{
    NVIC_SystemReset();
}