board.c 1.9 KB
Newer Older
1
/*
mysterywolf's avatar
mysterywolf 已提交
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
3 4 5 6 7 8 9 10
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-04-29     supperthomas first version
 *
 */
S
supperthomas 已提交
11 12
#include <rtthread.h>
#include <rthw.h>
13
#include <nrfx_systick.h>
S
supperthomas 已提交
14

15 16
#include "board.h"
#include "drv_uart.h"
17
#include <nrfx_clock.h>
S
supperthomas 已提交
18

19 20 21 22 23
/**
 * This is the timer interrupt service routine.
 *
 */
void SysTick_Handler(void)
S
supperthomas 已提交
24
{
25
    /* enter interrupt */
S
supperthomas 已提交
26 27
    rt_interrupt_enter();

28 29
    rt_tick_increase();

S
supperthomas 已提交
30 31 32
    /* leave interrupt */
    rt_interrupt_leave();
}
33 34 35

static void clk_event_handler(nrfx_clock_evt_type_t event){}

36 37
void SysTick_Configuration(void)
{
38 39 40
    nrfx_clock_init(clk_event_handler);
    nrfx_clock_enable();
    nrfx_clock_lfclk_start();
41 42 43 44 45 46 47 48
    /* Set interrupt priority */
    NVIC_SetPriority(SysTick_IRQn, 0xf);

    /* Configure SysTick to interrupt at the requested rate. */
    nrf_systick_load_set(SystemCoreClock / RT_TICK_PER_SECOND);
    nrf_systick_val_clear();
    nrf_systick_csr_set(NRF_SYSTICK_CSR_CLKSOURCE_CPU | NRF_SYSTICK_CSR_TICKINT_ENABLE
                        | NRF_SYSTICK_CSR_ENABLE);
49

50
}
S
supperthomas 已提交
51 52 53 54


void rt_hw_board_init(void)
{
55
    rt_hw_interrupt_enable(0);
S
supperthomas 已提交
56 57

    SysTick_Configuration();
58

59 60 61
#if defined(RT_USING_HEAP)
    rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
62

63
#ifdef RT_USING_SERIAL
S
supperthomas 已提交
64
    rt_hw_uart_init();
65
#endif
S
supperthomas 已提交
66 67 68 69 70 71 72 73

#ifdef RT_USING_CONSOLE
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88
#ifdef BSP_USING_SOFTDEVICE
    extern uint32_t  Image$$RW_IRAM1$$Base;
    uint32_t const *const m_ram_start  = &Image$$RW_IRAM1$$Base;
    if ((uint32_t)m_ram_start == 0x20000000)
    {
        rt_kprintf("\r\n using softdevice the RAM couldn't be %p,please use the templete from package\r\n", m_ram_start);
        while (1);
    }
    else
    {
        rt_kprintf("\r\n using softdevice the RAM at %p\r\n", m_ram_start);
    }
#endif

S
supperthomas 已提交
89 90
}