board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-12-04 Jiaxun Yang Initial version
  9. */
  10. /**
  11. * @addtogroup mipssim
  12. */
  13. /*@{*/
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "mips_regs.h"
  17. #include "exception.h"
  18. #include "drv_uart.h"
  19. #define CPU_HZ (100 * 1000 * 1000)
  20. #define RT_HW_HEAP_END (0x80000000 + 64 * 1024 * 1024)
  21. extern unsigned char __bss_end;
  22. /**
  23. * this function will reset CPU
  24. *
  25. */
  26. void rt_hw_cpu_reset(void)
  27. {
  28. rt_kprintf("reboot system...\n");
  29. while (1);
  30. }
  31. /**
  32. * this function will shutdown CPU
  33. *
  34. */
  35. void rt_hw_cpu_shutdown(void)
  36. {
  37. rt_kprintf("shutdown...\n");
  38. while (1);
  39. }
  40. /**
  41. * This is the timer interrupt service routine.
  42. */
  43. void rt_hw_timer_handler(void)
  44. {
  45. unsigned int count;
  46. count = read_c0_compare();
  47. write_c0_compare(count);
  48. write_c0_count(0);
  49. /* increase a OS tick */
  50. rt_tick_increase();
  51. }
  52. /**
  53. * This function will initial OS timer
  54. */
  55. void rt_hw_timer_init(void)
  56. {
  57. write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
  58. write_c0_count(0);
  59. mips_unmask_cpu_irq(7);
  60. }
  61. /**
  62. * Board level initialization
  63. */
  64. void rt_hw_board_init(void)
  65. {
  66. rt_hw_exception_init();
  67. /* init hardware interrupt */
  68. rt_hw_interrupt_init();
  69. #ifdef RT_USING_FPU
  70. /* init hardware fpu */
  71. rt_hw_fpu_init();
  72. #endif
  73. #ifdef RT_USING_SERIAL
  74. /* init hardware UART device */
  75. rt_hw_uart_init();
  76. /* set console device */
  77. rt_console_set_device("uart");
  78. #endif
  79. #ifdef RT_USING_HEAP
  80. rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
  81. #endif
  82. /* init operating system timer */
  83. rt_hw_timer_init();
  84. #ifdef RT_USING_COMPONENTS_INIT
  85. rt_components_board_init();
  86. #endif
  87. rt_kprintf("Current SR: 0x%08x\n", read_c0_status());
  88. }
  89. /*@}*/