board.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-28 flybreak first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdio.h>
  13. #include "board.h"
  14. #include "hardware/structs/systick.h"
  15. void isr_systick(void)
  16. {
  17. /* enter interrupt */
  18. rt_interrupt_enter();
  19. rt_tick_increase();
  20. /* leave interrupt */
  21. rt_interrupt_leave();
  22. }
  23. uint32_t systick_config(uint32_t ticks)
  24. {
  25. if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS)
  26. {
  27. return (1UL); /* Reload value impossible */
  28. }
  29. mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
  30. mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS |
  31. M0PLUS_SYST_CSR_TICKINT_BITS |
  32. M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
  33. return (0UL); /* Function successful */
  34. }
  35. void rt_hw_board_init()
  36. {
  37. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  38. alarm_pool_init_default();
  39. // Start and end points of the constructor list,
  40. // defined by the linker script.
  41. extern void (*__init_array_start)();
  42. extern void (*__init_array_end)();
  43. // Call each function in the list.
  44. // We have to take the address of the symbols, as __init_array_start *is*
  45. // the first function pointer, not the address of it.
  46. for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p) {
  47. (*p)();
  48. }
  49. /* Configure the SysTick */
  50. systick_config(frequency_count_khz(CLOCKS_FC0_SRC_VALUE_ROSC_CLKSRC)*10000/RT_TICK_PER_SECOND);
  51. stdio_init_all();
  52. rt_hw_uart_init();
  53. #ifdef RT_USING_CONSOLE
  54. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  55. #endif
  56. }