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 
19 #ifndef RT_USING_SMP
20 extern volatile rt_atomic_t rt_interrupt_nest;
21 #endif
22 
23 extern rt_uint32_t rt_thread_switch_interrupt_flag;
24 
25 extern interrupt void rtosint_handler();
26 
27 /**
28  * This is the timer interrupt service routine.
29  *
30  */
cpu_timer2_isr(void)31 interrupt void cpu_timer2_isr(void)
32 {
33     CpuTimer2Regs.TCR.all = 0xC000;
34 
35     rt_interrupt_enter();
36 
37     rt_tick_increase();
38 
39     rt_interrupt_leave();
40 }
41 
42 extern interrupt void XINT1_Handler(void);
43 extern interrupt void XINT2_Handler(void);
44 /**
45  * This function will initial TMS320F28379D board.
46  */
rt_hw_board_init()47 void rt_hw_board_init()
48 {
49     /* Configure the system clock @ 84 Mhz */
50     InitSysCtrl();
51 
52     DINT;
53     InitPieCtrl();
54 
55     IER = 0x0000;
56     IFR = 0x0000;
57 
58     InitPieVectTable();
59 
60 #ifdef _FLASH
61     memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);
62     InitFlash();
63 #endif
64     EALLOW;  // This is needed to write to EALLOW protected registers
65     PieVectTable.TIMER2_INT = &cpu_timer2_isr;
66     PieVectTable.RTOS_INT = &rtosint_handler;
67 
68 #ifdef BSP_USING_XINT1
69     PieVectTable.XINT1_INT = &XINT1_Handler;
70 #endif
71 #ifdef BSP_USING_XINT2
72     PieVectTable.XINT2_INT = &XINT2_Handler;
73 #endif
74 #ifdef BSP_USING_XINT3
75     PieVectTable.XINT3_INT = &XINT3_Handler;
76 #endif
77 #ifdef BSP_USING_XINT4
78     PieVectTable.XINT4_INT = &XINT4_Handler;
79 #endif
80 #ifdef BSP_USING_XINT5
81     PieVectTable.XINT5_INT = &XINT5_Handler;
82 #endif
83     EDIS;
84 
85     InitCpuTimers();
86     ConfigCpuTimer(&CpuTimer2, 200, 1000000 / RT_TICK_PER_SECOND);
87     CpuTimer2Regs.TCR.all = 0x4000;
88     IER |= M_INT14;
89     IER |= M_INT1;
90 
91 #ifdef RT_USING_HEAP
92     rt_system_heap_init(&__ebss_end, &(__heap_end));
93 #endif
94 
95 #ifdef RT_USING_SERIAL
96     rt_hw_sci_init();
97 #endif
98 
99 #ifdef RT_USING_PIN
100     rt_hw_pin_init();
101 #endif
102 
103 #ifdef RT_USING_COMPONENTS_INIT
104     rt_components_board_init();
105 #endif
106 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
107     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
108 #endif
109 }
110 
_args_main()111 int _args_main()
112 {
113     /* _args_main is the entry point called by _c_int00. We define it
114      * here to override the one defined by the compiler in args_main.c */
115 
116     extern int rtthread_startup();
117 
118     /* startup RT-Thread RTOS */
119     rtthread_startup();
120     /* never reach here*/
121     return 0;
122 }
123