board.c 2.9 KB

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