board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-03-30 Kyle First version
  9. * 2023-10-13 Raman Gopalan Move UART specific code sections into the drv_uart files
  10. * 2023-10-20 Raman Gopalan Initialize GPIO sub-system
  11. */
  12. #include <rtthread.h>
  13. #include "compiler.h"
  14. #include "pm.h"
  15. #include "gpio.h"
  16. #include "usart.h"
  17. #include "intc.h"
  18. #include "drv_uart.h"
  19. #include "drv_gpio.h"
  20. /**
  21. * System tick interrupt handler.
  22. */
  23. static void rt_hw_timer_handler(void)
  24. {
  25. // Clears the interrupt request.
  26. Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
  27. rt_tick_increase();
  28. }
  29. /**
  30. * Initialize system clock and all peripherals.
  31. */
  32. static void peripherals_init(void)
  33. {
  34. /*
  35. * PM initialization: OSC0 = 12MHz XTAL, PLL0 = 60MHz System Clock
  36. */
  37. pm_freq_param_t pm_freq_param =
  38. {
  39. .cpu_f = FCPU,
  40. .pba_f = FPBA,
  41. .osc0_f = FOSC0,
  42. .osc0_startup = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC
  43. };
  44. pm_configure_clocks(&pm_freq_param);
  45. INTC_init_interrupts();
  46. }
  47. /**
  48. * Initialize CPU cycle counter for system tick.
  49. */
  50. static void cpu_counter_init(void)
  51. {
  52. INTC_register_interrupt(&rt_hw_timer_handler, AVR32_CORE_COMPARE_IRQ, AVR32_INTC_INT3);
  53. Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
  54. Set_system_register(AVR32_COUNT, 0);
  55. }
  56. void rt_hw_board_init(void)
  57. {
  58. Disable_global_interrupt();
  59. peripherals_init();
  60. cpu_counter_init();
  61. #ifdef RT_USING_COMPONENTS_INIT
  62. rt_components_board_init();
  63. #endif
  64. #ifdef RT_USING_SERIAL
  65. rt_hw_uart_init();
  66. #endif
  67. #ifdef RT_USING_PIN
  68. rt_hw_gpio_init();
  69. #endif
  70. #ifdef RT_USING_CONSOLE
  71. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  72. #endif
  73. }