board.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-11-24 WangHuachen the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <dfs_fs.h>
  13. #include "board.h"
  14. #include "drv_timer.h"
  15. #define ITERS_PER_USEC (XPAR_CPU_CORTEXR5_0_CPU_CLK_FREQ_HZ / 4000000)
  16. void rt_hw_us_delay(rt_uint32_t us)
  17. {
  18. __asm__ __volatile__ (
  19. "push {r0,r1,r3} \n"
  20. "mov r0, %[usec] \n"
  21. "mov r1, %[iter] \n"
  22. "1: \n"
  23. "mov r3, r1 \n"
  24. "2: \n"
  25. "subs r3, r3, #0x1\n"
  26. "bne 2b \n"
  27. "subs r0, r0, #0x1 \n"
  28. "bne 1b \n"
  29. "pop {r0,r1,r3} \n"
  30. ::[iter] "r" (ITERS_PER_USEC), [usec] "r" (us)
  31. );
  32. }
  33. #ifdef RT_USING_CONSOLE
  34. #include "drv_uart.h"
  35. void rt_hw_serial_putc(const char c)
  36. {
  37. UART_Registers *uart = (UART_Registers *)XPAR_PSU_UART_0_BASEADDR;
  38. if (c == '\n')
  39. rt_hw_serial_putc('\r');
  40. while ((uart->SR) & UART_SR_TXFULL);
  41. uart->FIFO = c;
  42. }
  43. void rt_hw_console_output(const char *str)
  44. {
  45. while (*str)
  46. {
  47. rt_hw_serial_putc(*str++);
  48. }
  49. }
  50. #endif
  51. /**
  52. * This function will initialize beaglebone board
  53. */
  54. void rt_hw_board_init(void)
  55. {
  56. /* initialize hardware interrupt */
  57. rt_hw_interrupt_init();
  58. /* initialize system heap */
  59. #ifdef RT_USING_HEAP
  60. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  61. #endif
  62. #ifdef RT_USING_COMPONENTS_INIT
  63. rt_components_board_init();
  64. #endif
  65. #ifdef RT_USING_CONSOLE
  66. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  67. #endif
  68. }