board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * 2009-01-05 Bernard first implementation
  9. * 2018-03-15 flyingcys add amebaz
  10. */
  11. #include <rtl8710b.h>
  12. #include <stdint.h>
  13. #include "board.h"
  14. #include "drv_uart.h"
  15. #ifdef __ICCARM__
  16. #pragma section="HEAP"
  17. #define HEAP_BEGIN (__segment_end("HEAP"))
  18. #elif defined(__GNUC__)
  19. extern int __rtt_heap_start;
  20. #define HEAP_BEGIN (&__rtt_heap_start)
  21. #else
  22. #error "not support toolchain!!!"
  23. #endif
  24. #define HEAP_END (0x1002FFFF)
  25. #ifdef __GNUC__
  26. void __wrap_rtl_printf(const char *fmt, ...)
  27. {
  28. va_list args;
  29. rt_size_t length;
  30. static char rt_log_buf[RT_CONSOLEBUF_SIZE];
  31. va_start(args, fmt);
  32. /* the return value of vsnprintf is the number of bytes that would be
  33. * written to buffer had if the size of the buffer been sufficiently
  34. * large excluding the terminating null byte. If the output string
  35. * would be larger than the rt_log_buf, we have to adjust the output
  36. * length. */
  37. length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
  38. if (length > RT_CONSOLEBUF_SIZE - 1)
  39. length = RT_CONSOLEBUF_SIZE - 1;
  40. rt_kprintf("%s", rt_log_buf);
  41. va_end(args);
  42. }
  43. #endif
  44. /**
  45. * This is the timer interrupt service routine.
  46. *
  47. */
  48. void SysTick_Handler(void)
  49. {
  50. /* enter interrupt */
  51. rt_interrupt_enter();
  52. rt_tick_increase();
  53. /* leave interrupt */
  54. rt_interrupt_leave();
  55. }
  56. uint32_t SysTick_Config(uint32_t ticks)
  57. {
  58. if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
  59. SysTick->LOAD = ticks - 1; /* set reload register */
  60. NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
  61. SysTick->VAL = 0; /* Load the SysTick Counter Value */
  62. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  63. SysTick_CTRL_TICKINT_Msk |
  64. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  65. return (0); /* Function successful */
  66. }
  67. /**
  68. * This function will initial board.
  69. */
  70. void rt_hw_board_init(void)
  71. {
  72. extern uint32_t SystemCoreClock;
  73. SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
  74. #ifdef RT_USING_HEAP
  75. rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  76. #endif
  77. #ifdef RT_USING_COMPONENTS_INIT
  78. rt_components_board_init();
  79. #endif
  80. #ifdef RT_USING_CONSOLE
  81. rt_hw_uart_init();
  82. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  83. #endif
  84. }
  85. /*@}*/