board.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2020, Shenzhen Academy of Aerospace Technology
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2020-10-16 Dystopia the first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <finsh.h>
  17. #include "board.h"
  18. #include <interrupt.h>
  19. extern int __bss_end;
  20. static void rt_hw_timer_isr(int vector, void* param)
  21. {
  22. rt_tick_increase();
  23. /* timer interrupt cleared by hardware */
  24. }
  25. int rt_hw_timer_init(void)
  26. {
  27. unsigned int counter = 1000000 / RT_TICK_PER_SECOND;
  28. volatile struct lregs *regs = (struct lregs*)PREGS;
  29. regs->scalercnt = CPU_FREQ / 1000000 - 1;
  30. regs->scalerload = CPU_FREQ / 1000000 - 1;
  31. regs->timercnt2 = counter - 1;
  32. regs->timerload2 = counter - 1;
  33. rt_hw_interrupt_install(TIMER2_TT, rt_hw_timer_isr, RT_NULL, "tick");
  34. rt_hw_interrupt_umask(TIMER2_TT);
  35. /* start timer */
  36. regs->timerctrl2 = 0x7;
  37. return 0;
  38. }
  39. INIT_BOARD_EXPORT(rt_hw_timer_init);
  40. /**
  41. * This function will initialize beaglebone board
  42. */
  43. void rt_hw_board_init(void)
  44. {
  45. rt_system_heap_init((void*)&__bss_end, (void*)&__bss_end + 0x01000000);
  46. rt_components_board_init();
  47. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  48. }