board.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-09-15 QiuYi the first version
  9. * 2006-10-10 Bernard add hardware related of finsh
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <bsp.h>
  14. /**
  15. * @addtogroup QEMU
  16. */
  17. /*@{*/
  18. static void rt_timer_handler(int vector, void* param)
  19. {
  20. rt_tick_increase();
  21. }
  22. #ifdef RT_USING_HOOK
  23. static void idle_hook(void)
  24. {
  25. asm volatile("sti; hlt": : :"memory");
  26. }
  27. #endif
  28. /**
  29. * This function will init QEMU
  30. *
  31. */
  32. void rt_hw_board_init(void)
  33. {
  34. /* initialize 8253 clock to interrupt 1000 times/sec */
  35. outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
  36. outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) % 256);
  37. outb(IO_TIMER1, TIMER_DIV(RT_TICK_PER_SECOND) / 256);
  38. /* install interrupt handler */
  39. rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL, "tick");
  40. rt_hw_interrupt_umask(INTTIMER0);
  41. #ifdef RT_USING_HOOK
  42. rt_thread_idle_sethook(idle_hook);
  43. #endif
  44. }
  45. void restart(void)
  46. {
  47. outb(KBSTATP, 0xFE); /* pulse reset low */
  48. while(1);
  49. }
  50. #ifdef RT_USING_FINSH
  51. #include <finsh.h>
  52. FINSH_FUNCTION_EXPORT(restart, reboot PC)
  53. void reboot(void)
  54. {
  55. restart();
  56. }
  57. FINSH_FUNCTION_EXPORT(reboot, reboot PC)
  58. #endif
  59. /*@}*/