FreeCalypso > hg > fc-tourmaline
comparison src/cs/layer1/dl1/dl1_com.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /* | |
2 * This module contains the LISR and HISR glue functions for L1 | |
3 * which used to be in the dl1_com module in the Leonardo version. | |
4 * The LoCosto source from which we got our L1 code no longer has a | |
5 * dl1_com.c module, and the ISR glue functions in question have been | |
6 * moved into csw-system/init_common/init.c - an incredibly messy C | |
7 * module that is mostly devoted to LoCosto BSP initialization. | |
8 * | |
9 * The present C code has been extracted from LoCosto's init.c, | |
10 * guided by the disassembly of dl1_com.obj from the Leonardo version. | |
11 */ | |
12 | |
13 /* Include Files */ | |
14 #include <assert.h> | |
15 #include <stdarg.h> | |
16 #include <stdio.h> | |
17 #include <stdlib.h> | |
18 #include <string.h> | |
19 | |
20 #include "nucleus.h" | |
21 | |
22 #include "l1_types.h" | |
23 #include "l1_confg.h" | |
24 #include "l1_const.h" | |
25 | |
26 #if TESTMODE | |
27 #include "l1tm_defty.h" | |
28 #endif // TESTMODE | |
29 | |
30 #if (AUDIO_TASK == 1) | |
31 #include "l1audio_const.h" | |
32 #include "l1audio_cust.h" | |
33 #include "l1audio_defty.h" | |
34 #endif // AUDIO_TASK | |
35 | |
36 #if (L1_GTT == 1) | |
37 #include "l1gtt_const.h" | |
38 #include "l1gtt_defty.h" | |
39 #endif | |
40 | |
41 #if (L1_MP3 == 1) | |
42 #include "l1mp3_defty.h" | |
43 #endif | |
44 | |
45 #if (L1_MIDI == 1) | |
46 #include "l1midi_defty.h" | |
47 #endif | |
48 | |
49 #if (L1_AAC == 1) | |
50 #include "l1aac_defty.h" | |
51 #endif | |
52 #if (L1_DYN_DSP_DWNLD == 1) | |
53 #include "l1_dyn_dwl_defty.h" | |
54 #endif | |
55 | |
56 #if (TRACE_TYPE == 4) | |
57 #include "l1_defty.h" | |
58 #endif | |
59 | |
60 #include "armio.h" | |
61 #include "timer.h" | |
62 | |
63 #include "iq.h" | |
64 #include "mem.h" | |
65 #include "clkm.h" | |
66 #include "inth.h" | |
67 | |
68 /* | |
69 * Timing monitor | |
70 */ | |
71 #if (TRACE_TYPE == 4) | |
72 extern T_L1A_L1S_COM l1a_l1s_com; | |
73 extern T_L1S_GLOBAL l1s; | |
74 UNSIGNED max_cpu, fn_max_cpu; | |
75 unsigned short layer_1_sync_end_time; | |
76 unsigned short max_cpu_flag; | |
77 #if (DSP >= 38) | |
78 // DSP CPU load measurement trace variables | |
79 UWORD32 dsp_max_cpu_load_trace_array[4]; | |
80 UWORD32 dsp_max_cpu_load_idle_frame; | |
81 unsigned short l1_dsp_cpu_load_trace_flag; | |
82 #endif | |
83 #endif | |
84 | |
85 #if (L1_EXT_AUDIO_MGT == 1) | |
86 NU_HISR EXT_AUDIO_MGT_hisr; | |
87 char FAR ext_audio_mgt_hisr_stack[500]; | |
88 extern void Cust_ext_audio_mgt_hisr(void); | |
89 #endif | |
90 | |
91 #if ( (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_AAC == 1) || (L1_DYN_DSP_DWNLD == 1) ) // equivalent to an API_HISR flag | |
92 extern void api_hisr(void); | |
93 #ifdef __GNUC__ | |
94 #define SECTION_ATTR __attribute__ ((section (".API_HISR_stack"))) | |
95 #else | |
96 #define SECTION_ATTR | |
97 #pragma DATA_SECTION (API_HISR_stack,"API_HISR_stack"); | |
98 #endif | |
99 char FAR API_HISR_stack[0x400] SECTION_ATTR; | |
100 #undef SECTION_ATTR | |
101 NU_HISR apiHISR; | |
102 #endif // (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_DYN_DSP_DWNLD == 1) | |
103 | |
104 #if (FF_L1_IT_DSP_USF == 1) || (FF_L1_IT_DSP_DTX == 1) | |
105 char FAR API_MODEM_HISR_stack[0x400]; // stack size to be tuned | |
106 NU_HISR api_modemHISR; | |
107 #endif // FF_L1_IT_DSP_USF | |
108 | |
109 /* | |
110 * HISR stack and semaphore needed by L1 | |
111 */ | |
112 #if (OP_L1_STANDALONE == 0) | |
113 #define LAYER_1_SYNC_STACK_SIZE 4000 /* matching Leonardo version */ | |
114 unsigned char layer_1_sync_stack[LAYER_1_SYNC_STACK_SIZE]; | |
115 #else | |
116 #if TESTMODE | |
117 char FAR layer_1_sync_stack[2600 /*3600*/]; // Frame interrupt task stack for EVA3 | |
118 #else | |
119 char FAR layer_1_sync_stack[1600 /* 2600 */]; // Frame interrupt task stack for EVA3 | |
120 #endif | |
121 #endif /* OP_L1_STANDALONE */ | |
122 | |
123 NU_HISR layer_1_sync_HISR; // Frame interrupt task stack for EVA3 | |
124 | |
125 /* forward declaration */ | |
126 void layer_1_sync_HISR_entry (void); | |
127 | |
128 /* | |
129 * l1_create_ISR | |
130 * | |
131 * Create L1 HISR. This function is called from l1_pei. | |
132 */ | |
133 void l1_create_ISR (void) | |
134 { | |
135 STATUS status; | |
136 | |
137 #if (OP_L1_STANDALONE == 0) | |
138 // Fill the entire stack with the pattern 0xFE | |
139 memset (layer_1_sync_stack, 0xFE, LAYER_1_SYNC_STACK_SIZE); | |
140 #endif | |
141 | |
142 status = NU_Create_HISR (&layer_1_sync_HISR, | |
143 "L1_HISR", | |
144 layer_1_sync_HISR_entry, | |
145 #if (OP_L1_STANDALONE == 0) | |
146 0, | |
147 layer_1_sync_stack, | |
148 LAYER_1_SYNC_STACK_SIZE); | |
149 #else | |
150 0, | |
151 layer_1_sync_stack, | |
152 sizeof(layer_1_sync_stack)); | |
153 #endif | |
154 | |
155 #if (L1_EXT_AUDIO_MGT) | |
156 // Create HISR for Ext MIDI activity | |
157 //================================== | |
158 status += NU_Create_HISR(&EXT_AUDIO_MGT_hisr, | |
159 "H_EXT_AUDIO_MGT", | |
160 Cust_ext_audio_mgt_hisr, | |
161 1, | |
162 ext_audio_mgt_hisr_stack, | |
163 sizeof(ext_audio_mgt_hisr_stack)); | |
164 #endif | |
165 | |
166 #if ( (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_AAC == 1) || (L1_DYN_DSP_DWNLD == 1) ) // equivalent to an API_HISR flag | |
167 status += NU_Create_HISR(&apiHISR, | |
168 "API_HISR", | |
169 api_hisr, | |
170 1, | |
171 API_HISR_stack, | |
172 sizeof(API_HISR_stack)); | |
173 #endif // (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_AAC == 1) || (L1_DYN_DSP_DWNLD == 1) | |
174 | |
175 #if (FF_L1_IT_DSP_USF == 1) || (FF_L1_IT_DSP_DTX == 1) // equivalent to an API_MODEM_HISR flag | |
176 // Create HISR for USF DSP interrupt !!!!. This HISR needs | |
177 // to have the highest priority since the USF status needs | |
178 // to be known before the next block starts. | |
179 //======================================================== | |
180 status += NU_Create_HISR(&api_modemHISR, | |
181 "MODEM", | |
182 api_modem_hisr, | |
183 0, | |
184 API_MODEM_HISR_stack, | |
185 sizeof(API_MODEM_HISR_stack)); | |
186 #endif | |
187 | |
188 assert (status == 0); | |
189 } | |
190 | |
191 /* | |
192 * The versions of TP_FrameIntHandler() and layer_1_sync_HISR_entry() | |
193 * in the TCS211 dl1_com.obj module contain CPU load measurement | |
194 * code. TI changed things for LoCosto, so we have to revert their | |
195 * changes and restore the TCS211 way. | |
196 */ | |
197 | |
198 #if (TRACE_TYPE == 4) | |
199 #define TIMER_RESET_VALUE (0xFFFF) | |
200 #define TICKS_PER_TDMA (1875) | |
201 #endif | |
202 | |
203 /*-------------------------------------------------------*/ | |
204 /* TP_FrameIntHandler() Low Interrupt service routine */ | |
205 /*-------------------------------------------------------*/ | |
206 /* Parameters : */ | |
207 /* Return : */ | |
208 /* Functionality : activate Hisr on each frame interrupt*/ | |
209 /*-------------------------------------------------------*/ | |
210 void TP_FrameIntHandler(void) | |
211 { | |
212 | |
213 #if (OP_L1_STANDALONE == 1) | |
214 | |
215 #if (TRACE_TYPE==1) | |
216 if (trace_info.current_config->l1_dyn_trace & 1<<L1_DYN_TRACE_L1S_CPU_LOAD) | |
217 { | |
218 TM_ResetTimer (2, 0xFFFF, 1, 0); | |
219 TM_StartTimer (2); | |
220 } | |
221 #endif | |
222 | |
223 #if (TRACE_TYPE==6) | |
224 TM_ResetTimer (2, 0xFFFF, 1, 0); | |
225 TM_StartTimer (2); | |
226 #endif | |
227 | |
228 #if (TRACE_TYPE==7) /* CPU_LOAD */ | |
229 l1_cpu_load_start(); | |
230 #endif | |
231 | |
232 #else | |
233 | |
234 #if (TRACE_TYPE == 4) && (TI_NUC_MONITOR != 1) | |
235 TM_ResetTimer (2, TIMER_RESET_VALUE, 1, 0); | |
236 TM_StartTimer (2); | |
237 #endif | |
238 | |
239 #if (TI_NUC_MONITOR == 1) | |
240 /* Copy LISR buffer in Log buffer each end of HISR */ | |
241 ti_nuc_monitor_tdma_action(); | |
242 #endif | |
243 | |
244 #if WCP_PROF == 1 | |
245 prf_LogFNSwitch(l1s.actual_time.fn_mod42432); | |
246 #endif | |
247 | |
248 #endif /* OP_L1_STANDALONE */ | |
249 | |
250 NU_Activate_HISR(&layer_1_sync_HISR); /* Activate HISR interrupt */ | |
251 | |
252 #if (OP_L1_STANDALONE == 0) | |
253 #if (WCP_PROF == 1) | |
254 #if (PRF_CALIBRATION == 1) | |
255 NU_Activate_HISR(&prf_CalibrationHISR); | |
256 #endif | |
257 #endif | |
258 #endif | |
259 | |
260 } | |
261 | |
262 /* | |
263 * layer_1_sync_HISR_entry | |
264 * | |
265 * HISR associated to layer 1 sync. | |
266 */ | |
267 | |
268 void layer_1_sync_HISR_entry (void) | |
269 { | |
270 /* automatic var for the CPU load measurement code below */ | |
271 #if (TRACE_TYPE == 4) | |
272 unsigned long cpu; | |
273 #endif | |
274 | |
275 // Call Synchronous Layer1 | |
276 hisr(); | |
277 | |
278 /* | |
279 * FreeCalypso: the following code has been reconstructed from | |
280 * the disassembly of the TCS211 binary object; it was found to be | |
281 * similar to the Trace_L1S_CPU_load() function in l1_trace.c | |
282 * which appears to have been only for (TRACE_TYPE == 1) originally. | |
283 */ | |
284 #if (TRACE_TYPE == 4) | |
285 layer_1_sync_end_time = TIMER_RESET_VALUE - TM_ReadTimer(2); | |
286 | |
287 cpu = (100 * layer_1_sync_end_time) / TICKS_PER_TDMA; | |
288 if (cpu > max_cpu) | |
289 { | |
290 max_cpu=cpu; | |
291 fn_max_cpu=l1s.actual_time.fn; | |
292 max_cpu_flag = 1; | |
293 /* | |
294 * TCS211 object has this bogus code here: | |
295 | |
296 if (some non-understood condition) { | |
297 static int i; | |
298 i++; // static var never used anywhere | |
299 max_cpu_flag = 1; | |
300 } | |
301 | |
302 * Because this bogus code does not change the result, | |
303 * I decided not to bother with reconstructing it. | |
304 */ | |
305 } | |
306 | |
307 if (((l1s.actual_time.fn%1326) == 0) && (max_cpu_flag == 0)) | |
308 max_cpu = 0; | |
309 #endif | |
310 } | |
311 | |
312 /* the following stub functions live in the dl1_com module per TCS211 */ | |
313 | |
314 void rx_tch_data (API *data_address, | |
315 UWORD8 channel_mode, | |
316 UWORD8 blk_seq_number) | |
317 { | |
318 } | |
319 | |
320 UWORD8 *tx_tch_data (void) | |
321 { | |
322 return(NULL); | |
323 } |