board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-04-05 bigmagic Initial version
  9. */
  10. #include <rtthread.h>
  11. #include <rthw.h>
  12. #include "mips_regs.h"
  13. #include "mips_fpu.h"
  14. #include "exception.h"
  15. #include "drv_uart.h"
  16. #include "board.h"
  17. /**
  18. * this function will reset CPU
  19. *
  20. */
  21. void rt_hw_cpu_reset(void)
  22. {
  23. WDT_EN = 0x01;
  24. WDT_TIMER = 0x01;
  25. WDT_SET = 0x01;
  26. rt_kprintf("reboot system...\n");
  27. while (1);
  28. }
  29. /**
  30. * this function will shutdown CPU
  31. *
  32. */
  33. void rt_hw_cpu_shutdown(void)
  34. {
  35. PM1_STS &= 0xffffffff;
  36. PM1_CNT = 0x3c00;
  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*)RT_HW_HEAP_BEGIN, (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. }