board.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * 2022/12/25 flyingcys first version
  9. * 2023/01/17 chushicheng add pin and i2c
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "board.h"
  14. #include "drv_uart.h"
  15. static void sipeed_bl_sys_enabe_jtag(int cpuid)
  16. {
  17. GLB_GPIO_Cfg_Type gpio_cfg;
  18. gpio_cfg.drive = 0;
  19. gpio_cfg.smtCtrl = 1;
  20. gpio_cfg.pullType = GPIO_PULL_NONE;
  21. gpio_cfg.gpioMode = GPIO_MODE_AF;
  22. switch (cpuid) {
  23. case 0: {
  24. gpio_cfg.gpioFun = GPIO_FUN_JTAG_M0;
  25. } break;
  26. case 1: {
  27. gpio_cfg.gpioFun = GPIO_FUN_JTAG_D0;
  28. } break;
  29. default: {
  30. } break;
  31. }
  32. gpio_cfg.gpioPin = GLB_GPIO_PIN_0;
  33. GLB_GPIO_Init(&gpio_cfg);
  34. gpio_cfg.gpioPin = GLB_GPIO_PIN_1;
  35. GLB_GPIO_Init(&gpio_cfg);
  36. gpio_cfg.gpioPin = GLB_GPIO_PIN_2;
  37. GLB_GPIO_Init(&gpio_cfg);
  38. gpio_cfg.gpioPin = GLB_GPIO_PIN_3;
  39. GLB_GPIO_Init(&gpio_cfg);
  40. }
  41. static void cmd_jtag_m0(void)
  42. {
  43. sipeed_bl_sys_enabe_jtag(0);
  44. }
  45. static void cmd_jtag_cpu0(void)
  46. {
  47. sipeed_bl_sys_enabe_jtag(1);
  48. }
  49. /* This is the timer interrupt service routine. */
  50. static void mtime_handler(void)
  51. {
  52. rt_tick_increase();
  53. csi_coret_config(CPU_Get_MTimer_Clock() / RT_TICK_PER_SECOND, MTIME_IRQn);
  54. }
  55. void rt_hw_board_init(void)
  56. {
  57. bl_sys_lowlevel_init();
  58. csi_coret_config(CPU_Get_MTimer_Clock() / RT_TICK_PER_SECOND, MTIME_IRQn);
  59. bl_irq_register(MTIME_IRQn, mtime_handler);
  60. bl_irq_enable(MTIME_IRQn);
  61. #ifdef RT_USING_HEAP
  62. /* initialize memory system */
  63. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  64. #endif
  65. /* GPIO driver initialization is open by default */
  66. #ifdef RT_USING_PIN
  67. rt_hw_pin_init();
  68. #endif
  69. /* I2C driver initialization is open by default */
  70. #ifdef RT_USING_I2C
  71. rt_hw_i2c_init();
  72. #endif
  73. /* UART driver initialization is open by default */
  74. #ifdef RT_USING_SERIAL
  75. rt_hw_uart_init();
  76. #endif
  77. /* Set the shell console output device */
  78. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  79. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  80. #endif
  81. #ifdef RT_USING_COMPONENTS_INIT
  82. rt_components_board_init();
  83. #endif
  84. #ifdef BSP_USING_JTAG_M0
  85. cmd_jtag_m0();
  86. #endif
  87. }
  88. void rt_hw_cpu_reset(void)
  89. {
  90. bl_sys_reset_por();
  91. while(1);
  92. }
  93. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);