comparison src/cs/layer1/dl1/dl1_com.c @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children d2074d1102e0
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
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 #pragma DATA_SECTION (API_HISR_stack,"API_HISR_stack");
94 char FAR API_HISR_stack[0x400];
95 NU_HISR apiHISR;
96 #endif // (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_DYN_DSP_DWNLD == 1)
97
98 #if (FF_L1_IT_DSP_USF == 1) || (FF_L1_IT_DSP_DTX == 1)
99 char FAR API_MODEM_HISR_stack[0x400]; // stack size to be tuned
100 NU_HISR api_modemHISR;
101 #endif // FF_L1_IT_DSP_USF
102
103 /*
104 * HISR stack and semaphore needed by L1
105 */
106 #if (OP_L1_STANDALONE == 0)
107 #define LAYER_1_SYNC_STACK_SIZE 4000 /* matching Leonardo version */
108 unsigned char layer_1_sync_stack[LAYER_1_SYNC_STACK_SIZE];
109 #else
110 #if TESTMODE
111 char FAR layer_1_sync_stack[2600 /*3600*/]; // Frame interrupt task stack for EVA3
112 #else
113 char FAR layer_1_sync_stack[1600 /* 2600 */]; // Frame interrupt task stack for EVA3
114 #endif
115 #endif /* OP_L1_STANDALONE */
116
117 NU_HISR layer_1_sync_HISR; // Frame interrupt task stack for EVA3
118
119 /* forward declaration */
120 void layer_1_sync_HISR_entry (void);
121
122 /*
123 * l1_create_ISR
124 *
125 * Create L1 HISR. This function is called from l1_pei.
126 */
127 void l1_create_ISR (void)
128 {
129 STATUS status;
130
131 #if (OP_L1_STANDALONE == 0)
132 // Fill the entire stack with the pattern 0xFE
133 memset (layer_1_sync_stack, 0xFE, LAYER_1_SYNC_STACK_SIZE);
134 #endif
135
136 status = NU_Create_HISR (&layer_1_sync_HISR,
137 "L1_HISR",
138 layer_1_sync_HISR_entry,
139 #if (OP_L1_STANDALONE == 0)
140 0,
141 layer_1_sync_stack,
142 LAYER_1_SYNC_STACK_SIZE);
143 #else
144 0,
145 layer_1_sync_stack,
146 sizeof(layer_1_sync_stack));
147 #endif
148
149 #if (L1_EXT_AUDIO_MGT)
150 // Create HISR for Ext MIDI activity
151 //==================================
152 status += NU_Create_HISR(&EXT_AUDIO_MGT_hisr,
153 "H_EXT_AUDIO_MGT",
154 Cust_ext_audio_mgt_hisr,
155 1,
156 ext_audio_mgt_hisr_stack,
157 sizeof(ext_audio_mgt_hisr_stack));
158 #endif
159
160 #if ( (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_AAC == 1) || (L1_DYN_DSP_DWNLD == 1) ) // equivalent to an API_HISR flag
161 status += NU_Create_HISR(&apiHISR,
162 "API_HISR",
163 api_hisr,
164 1,
165 API_HISR_stack,
166 sizeof(API_HISR_stack));
167 #endif // (L1_MP3 == 1) || (L1_MIDI == 1) || (L1_AAC == 1) || (L1_DYN_DSP_DWNLD == 1)
168
169 #if (FF_L1_IT_DSP_USF == 1) || (FF_L1_IT_DSP_DTX == 1) // equivalent to an API_MODEM_HISR flag
170 // Create HISR for USF DSP interrupt !!!!. This HISR needs
171 // to have the highest priority since the USF status needs
172 // to be known before the next block starts.
173 //========================================================
174 status += NU_Create_HISR(&api_modemHISR,
175 "MODEM",
176 api_modem_hisr,
177 0,
178 API_MODEM_HISR_stack,
179 sizeof(API_MODEM_HISR_stack));
180 #endif
181
182 assert (status == 0);
183 }
184
185 /*
186 * The versions of TP_FrameIntHandler() and layer_1_sync_HISR_entry()
187 * in the TCS211 dl1_com.obj module contain CPU load measurement
188 * code. TI changed things for LoCosto, so we have to revert their
189 * changes and restore the TCS211 way.
190 */
191
192 #if (TRACE_TYPE == 4)
193 #define TIMER_RESET_VALUE (0xFFFF)
194 #define TICKS_PER_TDMA (1875)
195 #endif
196
197 /*-------------------------------------------------------*/
198 /* TP_FrameIntHandler() Low Interrupt service routine */
199 /*-------------------------------------------------------*/
200 /* Parameters : */
201 /* Return : */
202 /* Functionality : activate Hisr on each frame interrupt*/
203 /*-------------------------------------------------------*/
204 void TP_FrameIntHandler(void)
205 {
206
207 #if (OP_L1_STANDALONE == 1)
208
209 #if (TRACE_TYPE==1)
210 if (trace_info.current_config->l1_dyn_trace & 1<<L1_DYN_TRACE_L1S_CPU_LOAD)
211 {
212 TM_ResetTimer (2, 0xFFFF, 1, 0);
213 TM_StartTimer (2);
214 }
215 #endif
216
217 #if (TRACE_TYPE==6)
218 TM_ResetTimer (2, 0xFFFF, 1, 0);
219 TM_StartTimer (2);
220 #endif
221
222 #if (TRACE_TYPE==7) /* CPU_LOAD */
223 l1_cpu_load_start();
224 #endif
225
226 #else
227
228 #if (TRACE_TYPE == 4) && (TI_NUC_MONITOR != 1)
229 TM_ResetTimer (2, TIMER_RESET_VALUE, 1, 0);
230 TM_StartTimer (2);
231 #endif
232
233 #if (TI_NUC_MONITOR == 1)
234 /* Copy LISR buffer in Log buffer each end of HISR */
235 ti_nuc_monitor_tdma_action();
236 #endif
237
238 #if WCP_PROF == 1
239 prf_LogFNSwitch(l1s.actual_time.fn_mod42432);
240 #endif
241
242 #endif /* OP_L1_STANDALONE */
243
244 NU_Activate_HISR(&layer_1_sync_HISR); /* Activate HISR interrupt */
245
246 #if (OP_L1_STANDALONE == 0)
247 #if (WCP_PROF == 1)
248 #if (PRF_CALIBRATION == 1)
249 NU_Activate_HISR(&prf_CalibrationHISR);
250 #endif
251 #endif
252 #endif
253
254 }
255
256 /*
257 * layer_1_sync_HISR_entry
258 *
259 * HISR associated to layer 1 sync.
260 */
261
262 void layer_1_sync_HISR_entry (void)
263 {
264 /* automatic var for the CPU load measurement code below */
265 #if (TRACE_TYPE == 4)
266 unsigned long cpu;
267 #endif
268
269 // Call Synchronous Layer1
270 hisr();
271
272 /*
273 * FreeCalypso: the following code has been reconstructed from
274 * the disassembly of the TCS211 binary object; it was found to be
275 * similar to the Trace_L1S_CPU_load() function in l1_trace.c
276 * which appears to have been only for (TRACE_TYPE == 1) originally.
277 */
278 #if (TRACE_TYPE == 4)
279 layer_1_sync_end_time = TIMER_RESET_VALUE - TM_ReadTimer(2);
280
281 cpu = (100 * layer_1_sync_end_time) / TICKS_PER_TDMA;
282 if (cpu > max_cpu)
283 {
284 max_cpu=cpu;
285 fn_max_cpu=l1s.actual_time.fn;
286 max_cpu_flag = 1;
287 /*
288 * TCS211 object has this bogus code here:
289
290 if (some non-understood condition) {
291 static int i;
292 i++; // static var never used anywhere
293 max_cpu_flag = 1;
294 }
295
296 * Because this bogus code does not change the result,
297 * I decided not to bother with reconstructing it.
298 */
299 }
300
301 if (((l1s.actual_time.fn%1326) == 0) && (max_cpu_flag == 0))
302 max_cpu = 0;
303 #endif
304 }
305
306 /* the following stub functions live in the dl1_com module per TCS211 */
307
308 void rx_tch_data (API *data_address,
309 UWORD8 channel_mode,
310 UWORD8 blk_seq_number)
311 {
312 }
313
314 UWORD8 *tx_tch_data (void)
315 {
316 return(NULL);
317 }