board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-09-22 Bernard add board.h to this bsp
  9. * 2018-09-02 xuzhuoyi modify for TMS320F28379D version
  10. * 2022-06-21 guyunjie fix bugs in trap_rtosint and enable interrupt nesting
  11. * 2022-08-21 yuqi adding onboard devices initialization code
  12. */
  13. #include <rtthread.h>
  14. #include "board.h"
  15. #include "drv_sci.h"
  16. #include "drv_gpio.h"
  17. #include "F28x_Project.h"
  18. #ifndef RT_USING_SMP
  19. extern volatile rt_uint8_t rt_interrupt_nest;
  20. #endif
  21. extern rt_uint32_t rt_thread_switch_interrupt_flag;
  22. extern interrupt void rtosint_handler();
  23. /**
  24. * This is the timer interrupt service routine.
  25. *
  26. */
  27. interrupt void cpu_timer2_isr(void)
  28. {
  29. CpuTimer2Regs.TCR.all = 0xC000;
  30. rt_interrupt_enter();
  31. rt_tick_increase();
  32. rt_interrupt_leave();
  33. }
  34. extern interrupt void XINT1_Handler(void);
  35. extern interrupt void XINT2_Handler(void);
  36. /**
  37. * This function will initial TMS320F28379D board.
  38. */
  39. void rt_hw_board_init()
  40. {
  41. /* Configure the system clock @ 84 Mhz */
  42. InitSysCtrl();
  43. DINT;
  44. InitPieCtrl();
  45. IER = 0x0000;
  46. IFR = 0x0000;
  47. InitPieVectTable();
  48. #ifdef _FLASH
  49. memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);
  50. InitFlash();
  51. #endif
  52. EALLOW; // This is needed to write to EALLOW protected registers
  53. PieVectTable.TIMER2_INT = &cpu_timer2_isr;
  54. PieVectTable.RTOS_INT = &rtosint_handler;
  55. #ifdef BSP_USING_XINT1
  56. PieVectTable.XINT1_INT = &XINT1_Handler;
  57. #endif
  58. #ifdef BSP_USING_XINT2
  59. PieVectTable.XINT2_INT = &XINT2_Handler;
  60. #endif
  61. #ifdef BSP_USING_XINT3
  62. PieVectTable.XINT3_INT = &XINT3_Handler;
  63. #endif
  64. #ifdef BSP_USING_XINT4
  65. PieVectTable.XINT4_INT = &XINT4_Handler;
  66. #endif
  67. #ifdef BSP_USING_XINT5
  68. PieVectTable.XINT5_INT = &XINT5_Handler;
  69. #endif
  70. EDIS;
  71. InitCpuTimers();
  72. ConfigCpuTimer(&CpuTimer2, 200, 1000000 / RT_TICK_PER_SECOND);
  73. CpuTimer2Regs.TCR.all = 0x4000;
  74. IER |= M_INT14;
  75. IER |= M_INT1;
  76. #ifdef RT_USING_HEAP
  77. rt_system_heap_init(&__ebss_end, &(__heap_end));
  78. #endif
  79. #ifdef RT_USING_SERIAL
  80. rt_hw_sci_init();
  81. #endif
  82. #ifdef RT_USING_PIN
  83. rt_hw_pin_init();
  84. #endif
  85. #ifdef RT_USING_COMPONENTS_INIT
  86. rt_components_board_init();
  87. #endif
  88. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  89. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  90. #endif
  91. }
  92. int _args_main()
  93. {
  94. /* _args_main is the entry point called by _c_int00. We define it
  95. * here to override the one defined by the compiler in args_main.c */
  96. extern int rtthread_startup();
  97. /* startup RT-Thread RTOS */
  98. rtthread_startup();
  99. /* never reach here*/
  100. return 0;
  101. }