board.c 2.8 KB

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