board.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2020, Shenzhen Academy of Aerospace Technology
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-10-16 Dystopia the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <finsh.h>
  13. #include "board.h"
  14. #include <interrupt.h>
  15. extern int __bss_end;
  16. static void rt_hw_timer_isr(int vector, void *param)
  17. {
  18. rt_tick_increase();
  19. /* timer interrupt cleared by hardware */
  20. }
  21. int rt_hw_timer_init(void)
  22. {
  23. unsigned int counter = 1000000 / RT_TICK_PER_SECOND;
  24. volatile struct lregs *regs = (struct lregs *)PREGS;
  25. regs->scalercnt = CPU_FREQ / 1000000 - 1;
  26. regs->scalerload = CPU_FREQ / 1000000 - 1;
  27. regs->timercnt2 = counter - 1;
  28. regs->timerload2 = counter - 1;
  29. rt_hw_interrupt_install(TIMER2_TT, rt_hw_timer_isr, RT_NULL, "tick");
  30. rt_hw_interrupt_umask(TIMER2_TT);
  31. /* start timer */
  32. regs->timerctrl2 = 0x7;
  33. return 0;
  34. }
  35. INIT_BOARD_EXPORT(rt_hw_timer_init);
  36. /**
  37. * This function will initialize beaglebone board
  38. */
  39. void rt_hw_board_init(void)
  40. {
  41. rt_system_heap_init((void *)&__bss_end, (unsigned char *)&__bss_end + 0x01000000);
  42. rt_components_board_init();
  43. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  44. }