board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "ls2k1000.h"
  18. /**
  19. * this function will reset CPU
  20. *
  21. */
  22. void rt_hw_cpu_reset(void)
  23. {
  24. WDT_EN = 0x01;
  25. WDT_TIMER = 0x01;
  26. WDT_SET = 0x01;
  27. rt_kprintf("reboot system...\n");
  28. while (1);
  29. }
  30. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset cpu);
  31. /**
  32. * this function will shutdown CPU
  33. *
  34. */
  35. void rt_hw_cpu_shutdown(void)
  36. {
  37. PM1_STS &= 0xffffffff;
  38. PM1_CNT = 0x3c00;
  39. rt_kprintf("shutdown...\n");
  40. while (1);
  41. }
  42. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_shutdown, poweroff, shutdown cpu);
  43. /**
  44. * This is the timer interrupt service routine.
  45. */
  46. void rt_hw_timer_handler(void)
  47. {
  48. unsigned int count;
  49. count = read_c0_compare();
  50. write_c0_compare(count);
  51. write_c0_count(0);
  52. /* increase a OS tick */
  53. rt_tick_increase();
  54. }
  55. /**
  56. * This function will initial OS timer
  57. */
  58. void rt_hw_timer_init(void)
  59. {
  60. write_c0_compare(CPU_HZ / 2 / RT_TICK_PER_SECOND);
  61. write_c0_count(0);
  62. mips_unmask_cpu_irq(7);
  63. }
  64. /**
  65. * Board level initialization
  66. */
  67. void rt_hw_board_init(void)
  68. {
  69. rt_hw_exception_init();
  70. /* init hardware interrupt */
  71. rt_hw_interrupt_init();
  72. #ifdef RT_USING_FPU
  73. /* init hardware fpu */
  74. rt_hw_fpu_init();
  75. #endif
  76. #ifdef RT_USING_SERIAL
  77. /* init hardware UART device */
  78. rt_hw_uart_init();
  79. /* set console device */
  80. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  81. #endif
  82. #ifdef RT_USING_HEAP
  83. rt_system_heap_init((void *)RT_HW_HEAP_BEGIN, (void *)RT_HW_HEAP_END);
  84. #endif
  85. /* init operating system timer */
  86. rt_hw_timer_init();
  87. #ifdef RT_USING_COMPONENTS_INIT
  88. rt_components_board_init();
  89. #endif
  90. rt_kprintf("Current SR: 0x%08x\n", read_c0_status());
  91. }