board.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * 2023-12-01 Raman Gopalan Initialize software I2C sub-system
  12. */
  13. #include <rtthread.h>
  14. #include "compiler.h"
  15. #include "pm.h"
  16. #include "gpio.h"
  17. #include "usart.h"
  18. #include "intc.h"
  19. #include "drv_uart.h"
  20. #include "drv_gpio.h"
  21. #include "drv_soft_i2c.h"
  22. /**
  23. * System tick interrupt handler.
  24. */
  25. static void rt_hw_timer_handler(void)
  26. {
  27. // Clears the interrupt request.
  28. Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
  29. rt_tick_increase();
  30. }
  31. /**
  32. * Initialize system clock and all peripherals.
  33. */
  34. static void peripherals_init(void)
  35. {
  36. /*
  37. * PM initialization: OSC0 = 12MHz XTAL, PLL0 = 60MHz System Clock
  38. */
  39. pm_freq_param_t pm_freq_param =
  40. {
  41. .cpu_f = FCPU,
  42. .pba_f = FPBA,
  43. .osc0_f = FOSC0,
  44. .osc0_startup = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC
  45. };
  46. pm_configure_clocks(&pm_freq_param);
  47. INTC_init_interrupts();
  48. }
  49. /**
  50. * Initialize CPU cycle counter for system tick.
  51. */
  52. static void cpu_counter_init(void)
  53. {
  54. INTC_register_interrupt(&rt_hw_timer_handler, AVR32_CORE_COMPARE_IRQ, AVR32_INTC_INT3);
  55. Set_system_register(AVR32_COMPARE, FCPU / RT_TICK_PER_SECOND);
  56. Set_system_register(AVR32_COUNT, 0);
  57. }
  58. void rt_hw_board_init(void)
  59. {
  60. Disable_global_interrupt();
  61. peripherals_init();
  62. cpu_counter_init();
  63. #ifdef RT_USING_COMPONENTS_INIT
  64. rt_components_board_init();
  65. #endif
  66. #ifdef RT_USING_SERIAL
  67. rt_hw_uart_init();
  68. #endif
  69. #ifdef RT_USING_PIN
  70. rt_hw_gpio_init();
  71. #endif
  72. #ifdef BSP_USING_SOFT_I2C
  73. rt_sw_i2c_init();
  74. #endif
  75. #ifdef RT_USING_CONSOLE
  76. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  77. #endif
  78. }