board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. */
  12. #include <rtthread.h>
  13. #include "board.h"
  14. #include "drv_sci.h"
  15. #include "F28x_Project.h"
  16. #ifndef RT_USING_SMP
  17. extern volatile rt_uint8_t rt_interrupt_nest;
  18. #endif
  19. extern rt_uint32_t rt_thread_switch_interrupt_flag;
  20. extern interrupt void RTOSINT_Handler();
  21. void trap_rtosint()
  22. {
  23. if(rt_thread_switch_interrupt_flag)
  24. {
  25. /* only do pendsv at the end of the last level of interrupt nesting,
  26. * so that threads do not preempt any isrs. */
  27. if(rt_interrupt_nest == 1)
  28. {
  29. /* rt_interrupt_leave_hook is called before rt_interrupt_nest --
  30. * in rt_interrupt_leave. We need to do this manually here to indicate
  31. * that all isrs have been cleared before we switch to thread. */
  32. rt_interrupt_nest --;
  33. asm(" trap #16");
  34. /* increment rt_interrupt_nest to compensate for the previous decrement. */
  35. rt_interrupt_nest ++;
  36. }
  37. }
  38. }
  39. /**
  40. * This is the timer interrupt service routine.
  41. *
  42. */
  43. interrupt void cpu_timer2_isr(void)
  44. {
  45. CpuTimer2Regs.TCR.all = 0xC000;
  46. ALLOW_ISR_PREEMPT();
  47. /* enter interrupt */
  48. rt_interrupt_enter();
  49. rt_tick_increase();
  50. /* leave interrupt */
  51. rt_interrupt_leave();
  52. }
  53. /**
  54. * This function will initial TMS320F28379D board.
  55. */
  56. void rt_hw_board_init()
  57. {
  58. /* Configure the system clock @ 84 Mhz */
  59. InitSysCtrl();
  60. DINT;
  61. InitPieCtrl();
  62. IER = 0x0000;
  63. IFR = 0x0000;
  64. InitPieVectTable();
  65. EALLOW; // This is needed to write to EALLOW protected registers
  66. PieVectTable.TIMER2_INT = &cpu_timer2_isr;
  67. PieVectTable.RTOS_INT = &RTOSINT_Handler;
  68. EDIS;
  69. InitCpuTimers();
  70. ConfigCpuTimer(&CpuTimer2, 200, 1000000 / RT_TICK_PER_SECOND);
  71. CpuTimer2Regs.TCR.all = 0x4000;
  72. IER |= M_INT14;
  73. #ifdef RT_USING_HEAP
  74. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  75. #endif
  76. rt_hw_sci_init();
  77. #ifdef RT_USING_COMPONENTS_INIT
  78. rt_components_board_init();
  79. #endif
  80. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  81. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  82. #endif
  83. /*this hook may cause problem for reasons unknown*/
  84. rt_interrupt_leave_sethook((void (*)(void))trap_rtosint);
  85. }