FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/riviera/rvt/rvt_task.c @ 143:afceeeb2cba1
Our nuc-fw is destined to become gsm-fw, so I went ahead and did the big hg mv
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 12 Nov 2013 05:35:48 +0000 |
parents | nuc-fw/riviera/rvt/rvt_task.c@3b5c3f3646fb |
children | 4b53bd08f345 |
comparison
equal
deleted
inserted
replaced
142:15d5977390c2 | 143:afceeeb2cba1 |
---|---|
1 /************************************************************************** | |
2 * | |
3 * rvt_task.c | |
4 * | |
5 * This contains the core of the Trace task. | |
6 * | |
7 * (C) Texas Instruments, all rights reserved | |
8 * | |
9 * Version number : 0.1 | |
10 * | |
11 * History : 0.1 (7/5/2000) - Created | |
12 * | |
13 * Date : 7/5/2000 | |
14 * | |
15 * Author : Guido Pagana | |
16 * | |
17 * Update : Pascal Puel | |
18 * : David Lamy-Charrier (changes for Riviera 1.6) | |
19 * | |
20 ***************************************************************************/ | |
21 | |
22 #include "../../include/config.h" | |
23 | |
24 #include "../rv/general.h" | |
25 #include "../rv/rv_general.h" | |
26 #include "../rvf/rvf_api.h" | |
27 #include "rvt_gen.h" | |
28 #include "rvt_def_i.h" | |
29 #include "rvt_env.h" | |
30 #include "rvt_env_i.h" | |
31 #include "../rvm/rvm_use_id_list.h" | |
32 | |
33 #include "../../serial/serialswitch.h" | |
34 | |
35 #include "../../nucleus/nucleus.h" | |
36 | |
37 #include <string.h> | |
38 | |
39 extern NU_HISR TI_rcv_HISR; | |
40 | |
41 /* Time (in milliseconds) between two consecutive 'System Time' messages */ | |
42 #define RVT_ALIVE_POLLING_TIME (RVF_MS_TO_TICKS (20000)) | |
43 | |
44 #define RVT_WAIT_FOR_HEADER (1) | |
45 #define RVT_WAIT_FOR_DATA (2) | |
46 | |
47 | |
48 /********************************************************************************/ | |
49 /* */ | |
50 /* Function Name: rvt_task_core */ | |
51 /* */ | |
52 /* Purpose: Core of Trace task. */ | |
53 /* */ | |
54 /* Input Parameters: */ | |
55 /* None. */ | |
56 /* */ | |
57 /* Output Parameters: */ | |
58 /* None. */ | |
59 /* */ | |
60 /* Global Parameters: */ | |
61 /* None. */ | |
62 /* */ | |
63 /* Note: */ | |
64 /* None. */ | |
65 /* */ | |
66 /********************************************************************************/ | |
67 T_RVM_RETURN rvt_task_core (void) | |
68 { | |
69 UINT16 event = 0; | |
70 UINT32 nb_bytes_sent = 0; | |
71 | |
72 #ifdef FRAMING_PROTOCOL | |
73 | |
74 // Request for the level of filtering, as well as the 32-bit | |
75 // mask related to the software entities to be monitored. | |
76 { | |
77 UINT8 trace_level_request[] = {RVM_INVALID_USE_ID, 0, 0, 0, 0, | |
78 (RV_TRACE_LEVEL_ERROR - 1), 0, 0, 0, 0}; | |
79 | |
80 // Note that the level is defined as invalid | |
81 trace_level_request[0] = (char) rv_trace_user_id; | |
82 | |
83 // Transmit an 'empty' message | |
84 nb_bytes_sent = 0; | |
85 while (nb_bytes_sent < sizeof (trace_level_request)) | |
86 { | |
87 nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1, | |
88 trace_level_request + nb_bytes_sent, | |
89 sizeof (trace_level_request) - | |
90 nb_bytes_sent); | |
91 } | |
92 } | |
93 | |
94 // Start the 'Alive Polling Timer' | |
95 #if (OP_WCP == 0) | |
96 rvf_start_timer (RVF_TIMER_0, | |
97 RVT_ALIVE_POLLING_TIME, | |
98 TRUE); | |
99 #endif | |
100 | |
101 for (; ; ) | |
102 { | |
103 // Infinite wait on 'Trace Task' mailbox or timer events | |
104 event = rvf_wait ((1 << RVT_TRACE_MAILBOX) | (RVF_TIMER_0_EVT_MASK), | |
105 0); | |
106 | |
107 // Check for some messages lost | |
108 if (((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) | |
109 && (p_rvt_lost_msg)) | |
110 { | |
111 INT8 count = 0; | |
112 UINT8 lost_msg_length = RVT_HDR_LENGTH + RVT_LOST_MSG_LENGTH; | |
113 UINT32 lost_msg_cpt = rvt_lost_msg_cpt.overall_value; | |
114 | |
115 // Append with the number of messages lost | |
116 rvt_lost_msg_cpt.overall_value = 0; | |
117 for (count = 0; | |
118 count < RVT_HEX_VALUE_LENGTH; | |
119 count++) | |
120 { | |
121 p_rvt_lost_msg[lost_msg_length + count] = | |
122 Num2Char[(UINT8) ((lost_msg_cpt << (count << 2)) >> 28)]; | |
123 } | |
124 lost_msg_length += RVT_HEX_VALUE_LENGTH; | |
125 | |
126 // Send message to the UART with byte stuffing | |
127 nb_bytes_sent = 0; | |
128 while (nb_bytes_sent < lost_msg_length) | |
129 { | |
130 nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1, | |
131 (UINT8 *) p_rvt_lost_msg + nb_bytes_sent, | |
132 lost_msg_length - nb_bytes_sent); | |
133 } | |
134 | |
135 } // End of if ((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) | |
136 | |
137 if (event & EVENT_MASK (RVT_TRACE_MAILBOX)) | |
138 { | |
139 T_RV_HDR *msg = NULL; | |
140 | |
141 // Read the message from the mailbox | |
142 if ((msg = (T_RV_HDR *) rvf_read_mbox (RVT_TRACE_MAILBOX)) | |
143 != NULL) | |
144 { | |
145 if (msg->msg_id == RVT_TRACE_RQST_ID) | |
146 { | |
147 UINT8 msg_format = 0; | |
148 UINT32 msg_length = 0; | |
149 | |
150 // Get the length | |
151 msg_length = ((T_RVT_TRACE_RQST *) msg)->msg_length; | |
152 | |
153 // Get the format | |
154 msg_format = ((T_RVT_TRACE_RQST *) msg)->format; | |
155 | |
156 // Copy the 'User ID' | |
157 ((UINT8 *) msg + RVT_HEADER_SIZE - 1)[0] = | |
158 ((T_RVT_TRACE_RQST *) msg)->user_id; | |
159 msg_length++; | |
160 | |
161 switch (msg_format) | |
162 { | |
163 case RVT_ASCII_FORMAT: | |
164 { | |
165 // Send message to the UART without byte stuffing | |
166 nb_bytes_sent = 0; | |
167 while (nb_bytes_sent < msg_length) | |
168 { | |
169 nb_bytes_sent += SER_tr_EncapsulateNChars | |
170 (SER_LAYER_1, | |
171 (char *) msg + RVT_HEADER_SIZE - 1 + | |
172 nb_bytes_sent, | |
173 msg_length - nb_bytes_sent); | |
174 } | |
175 break; | |
176 } | |
177 case RVT_BINARY_FORMAT: | |
178 { | |
179 // Send message to the UART with byte stuffing | |
180 nb_bytes_sent = 0; | |
181 while (nb_bytes_sent < msg_length) | |
182 { | |
183 nb_bytes_sent += SER_tr_WriteNBytes | |
184 (SER_LAYER_1, | |
185 (UINT8 *) msg + RVT_HEADER_SIZE | |
186 - 1 + nb_bytes_sent, | |
187 msg_length - nb_bytes_sent); | |
188 } | |
189 break; | |
190 } | |
191 default: | |
192 { | |
193 // Increment the number of messages lost. | |
194 // Is the buffer corrupted? | |
195 (rvt_lost_msg_cpt.bit_mask).count++; | |
196 (rvt_lost_msg_cpt.bit_mask).unknown_format = 1; | |
197 break; | |
198 } | |
199 } | |
200 | |
201 // Deallocate the buffer | |
202 rvf_free_buf (msg); | |
203 | |
204 } // End of if (msg->msg_id == RVT_TRACE_RQST_ID) | |
205 else | |
206 { | |
207 // Increment the number of messages lost. Is the buffer | |
208 // corrupted? | |
209 (rvt_lost_msg_cpt.bit_mask).count++; | |
210 (rvt_lost_msg_cpt.bit_mask).unknown_request = 1; | |
211 } | |
212 | |
213 } // End of if (msg != NULL) | |
214 else | |
215 { | |
216 // Increment the number of messages lost. Is the buffer | |
217 // corrupted? | |
218 (rvt_lost_msg_cpt.bit_mask).count++; | |
219 (rvt_lost_msg_cpt.bit_mask).message_empty = 1; | |
220 } | |
221 | |
222 } // End of if (event & EVENT_MASK (RVT_TRACE_MAILBOX)) | |
223 | |
224 if ((event & (RVF_TIMER_0_EVT_MASK)) && (p_rvt_sys_time)) | |
225 { | |
226 UINT8 count = 0; | |
227 UINT8 sys_time_length = RVT_HDR_LENGTH + RVT_SYS_TIME_LENGTH; | |
228 UINT32 current_time = rvf_get_tick_count (); | |
229 | |
230 // Append with the system time | |
231 for (count = 0; | |
232 count < RVT_HEX_VALUE_LENGTH; | |
233 count++) | |
234 { | |
235 p_rvt_sys_time[sys_time_length + count] = | |
236 Num2Char[(UINT8) ((current_time << (count << 2)) >> 28)]; | |
237 } | |
238 sys_time_length += RVT_HEX_VALUE_LENGTH; | |
239 | |
240 // Send message to the UART with byte stuffing | |
241 nb_bytes_sent = 0; | |
242 while (nb_bytes_sent < sys_time_length) | |
243 { | |
244 nb_bytes_sent += SER_tr_WriteNBytes (SER_LAYER_1, | |
245 (UINT8 *) p_rvt_sys_time + nb_bytes_sent, | |
246 sys_time_length - nb_bytes_sent); | |
247 } | |
248 | |
249 } // End of if (event & (RVF_TIMER_0_EVT_MASK)) | |
250 //freecalypso_lldbg_intinfo(); | |
251 } | |
252 | |
253 #else | |
254 | |
255 // Start the 'Alive Polling Timer' | |
256 #if (OP_WCP == 0) | |
257 rvf_start_timer (RVF_TIMER_0, | |
258 RVT_ALIVE_POLLING_TIME, | |
259 TRUE); | |
260 #endif | |
261 | |
262 for (; | |
263 ; | |
264 ) | |
265 { | |
266 // Infinite wait on 'Trace Task' mailbox or timer events | |
267 event = rvf_wait ((1 << RVT_TRACE_MAILBOX) | (RVF_TIMER_0_EVT_MASK), | |
268 0); | |
269 | |
270 // Check for some messages lost | |
271 if (((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) && (p_rvt_lost_msg)) | |
272 { | |
273 INT8 count = 0; | |
274 UINT8 lost_msg_length = RVT_LOST_MSG_LENGTH; | |
275 UINT32 lost_msg_cpt = rvt_lost_msg_cpt.overall_value; | |
276 | |
277 // Append with the number of messages lost | |
278 rvt_lost_msg_cpt.overall_value = 0; | |
279 for (count = 0; | |
280 count < RVT_HEX_VALUE_LENGTH; | |
281 count ++) | |
282 { | |
283 p_rvt_lost_msg[lost_msg_length + count] = Num2Char[(UINT8) ((lost_msg_cpt << (count << 2)) >> 28)]; | |
284 } | |
285 rvt_lost_msg_length += RVT_HEX_VALUE_LENGTH; | |
286 | |
287 // Append with the '\n' and '\r' characters for the hyper terminal | |
288 p_rvt_lost_msg[lost_msg_length++] = '\n'; | |
289 p_rvt_lost_msg[lost_msg_length++] = '\r'; | |
290 | |
291 // Send the message to the UART without byte stuffing | |
292 nb_bytes_sent = 0; | |
293 while (nb_bytes_sent < lost_msg_length) | |
294 { | |
295 nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1, | |
296 (UINT8 *) p_rvt_lost_msg + nb_bytes_sent, | |
297 lost_msg_length - nb_bytes_sent); | |
298 } | |
299 | |
300 } // End of if ((rvt_lost_msg_cpt.bit_mask).count >= RVT_MAX_LOST_TRACE_MSG) | |
301 | |
302 if (event & EVENT_MASK (RVT_TRACE_MAILBOX)) | |
303 { | |
304 T_RV_HDR *msg = NULL; | |
305 | |
306 // Read the message from the mailbox | |
307 if ((msg = (T_RV_HDR *) rvf_read_mbox (RVT_TRACE_MAILBOX)) != NULL) | |
308 { | |
309 if (msg->msg_id == RVT_TRACE_RQST_ID) | |
310 { | |
311 UINT32 msg_length = 0; | |
312 | |
313 // Get the length | |
314 msg_length = ((T_RVT_TRACE_RQST *) msg)->msg_length; | |
315 | |
316 // Send message to the UART without byte stuffing | |
317 nb_bytes_sent = 0; | |
318 while (nb_bytes_sent < msg_length) | |
319 { | |
320 nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1, | |
321 msg + RVT_HEADER_SIZE + nb_bytes_sent, | |
322 msg_length - nb_bytes_sent); | |
323 } | |
324 | |
325 // Append with the '\n' and '\r' characters for the hyper terminal | |
326 msg_length = 0; | |
327 msg[msg_length++] = '\n'; | |
328 msg[msg_length++] = '\r'; | |
329 | |
330 // Send message to the UART without byte stuffing | |
331 nb_bytes_sent = 0; | |
332 while (nb_bytes_sent < msg_length) | |
333 { | |
334 nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1, | |
335 msg + nb_bytes_sent, | |
336 msg_length - nb_bytes_sent); | |
337 } | |
338 | |
339 // Deallocate the buffer | |
340 rvf_free_buf (msg); | |
341 | |
342 } // End of if (msg->msg_id == RVT_TRACE_RQST_ID) | |
343 | |
344 else | |
345 { | |
346 // Increment the number of messages lost. Is the buffer | |
347 // corrupted? | |
348 (rvt_lost_msg_cpt.bit_mask).count++; | |
349 (rvt_lost_msg_cpt.bit_mask).unknown_request = 1; | |
350 } | |
351 | |
352 } // End of if (msg != NULL) | |
353 | |
354 else | |
355 { | |
356 // Increment the number of messages lost. Is the buffer | |
357 // corrupted? | |
358 (rvt_lost_msg_cpt.bit_mask).count++; | |
359 (rvt_lost_msg_cpt.bit_mask).message_empty = 1; | |
360 } | |
361 | |
362 } // End of if (event & EVENT_MASK (RVT_TRACE_MAILBOX)) | |
363 | |
364 if ((event & (RVF_TIMER_0_EVT_MASK)) && (p_rvt_sys_time)) | |
365 { | |
366 UINT8 count = 0; | |
367 UINT8 sys_time_length = RVT_SYS_TIME_LENGTH; | |
368 UINT32 current_time = rvf_get_tick_count (); | |
369 | |
370 // Append with the system time | |
371 for (count = 0; | |
372 count < RVT_HEX_VALUE_LENGTH; | |
373 count++) | |
374 { | |
375 p_rvt_sys_time[sys_time_length + count] = Num2Char[(UINT8) ((current_time << (count << 2)) >> 28)]; | |
376 } | |
377 sys_time_length += RVT_HEX_VALUE_LENGTH; | |
378 | |
379 // Append with the '\n' and '\r' characters for the hyper terminal | |
380 p_rvt_sys_time[sys_time_length++] = '\n'; | |
381 p_rvt_sys_time[sys_time_length++] = '\r'; | |
382 | |
383 // Send message to the UART without byte stuffing | |
384 nb_bytes_sent = 0; | |
385 while (nb_bytes_sent < sys_time_length) | |
386 { | |
387 nb_bytes_sent += SER_tr_WriteNChars (SER_LAYER_1, | |
388 (UINT8 *) p_rvt_sys_time + nb_bytes_sent, | |
389 sys_time_length - nb_bytes_sent); | |
390 } | |
391 | |
392 } // End of if (event & (RVF_TIMER_0_EVT_MASK)) | |
393 } | |
394 #endif | |
395 } | |
396 | |
397 | |
398 /********************************************************************************/ | |
399 /* */ | |
400 /* Function Name: rvt_RX_process */ | |
401 /* */ | |
402 /* Purpose: This function is called when characters are received */ | |
403 /* on the serial port on receive HISR. */ | |
404 /* */ | |
405 /* Input Parameters: */ | |
406 /* None. */ | |
407 /* */ | |
408 /* Output Parameters: */ | |
409 /* None. */ | |
410 /* */ | |
411 /* Global Parameters: */ | |
412 /* None. */ | |
413 /* */ | |
414 /* Note: */ | |
415 /* None. */ | |
416 /* */ | |
417 /********************************************************************************/ | |
418 void rvt_RX_process (void) | |
419 { | |
420 UINT32 bytesRead; | |
421 static UINT8 inBuffer[255]; | |
422 | |
423 rvf_send_trace("Ser RX", 6, rvf_get_tick_count(), | |
424 RV_TRACE_LEVEL_DEBUG_HIGH, RVT_USE_ID); | |
425 /* | |
426 freecalypso_raw_dbgout("*Ser_RX"); | |
427 freecalypso_lldbg_intinfo(); | |
428 */ | |
429 | |
430 #ifdef FRAMING_PROTOCOL | |
431 BOOL eof = 0; | |
432 static UINT8 rcv_state = RVT_WAIT_FOR_HEADER; | |
433 static UINT32 total_bytesRead = 0; | |
434 static RVT_CALLBACK_FUNC rx_callback_func = NULL; | |
435 | |
436 // Get all bytes from the UART RX FIFO | |
437 for (; | |
438 ; | |
439 ) | |
440 { | |
441 // Read and destuff the UART RX FIFO and fill inBuffer with received | |
442 // bytes | |
443 bytesRead = SER_tr_ReadNBytes (SER_LAYER_1, | |
444 (char *) (inBuffer + total_bytesRead), | |
445 sizeof (inBuffer) - total_bytesRead, | |
446 &eof); | |
447 | |
448 // Check for the header. Hence, get the sendee | |
449 if ((rcv_state == RVT_WAIT_FOR_HEADER) && \ | |
450 (bytesRead) && \ | |
451 !(total_bytesRead)) | |
452 { | |
453 if ((inBuffer[0] == RVT_RV_HEADER) || \ | |
454 (inBuffer[0] == RVT_L1_HEADER) || \ | |
455 (inBuffer[0] == RVT_L23_HEADER) || \ | |
456 (inBuffer[0] == RVT_TM_HEADER) || \ | |
457 (inBuffer[0] == RVT_RNET_HEADER) || \ | |
458 (inBuffer[0] == RVT_PROF_HEADER) || \ | |
459 (inBuffer[0] == RVT_GTTBACK_HEADER) || \ | |
460 (inBuffer[0] == RVT_OTHER_HEADER)) | |
461 { | |
462 UINT8 idtab = 0; | |
463 | |
464 // Search for the ID in the table | |
465 for (idtab = 0; | |
466 rvt_user_db[idtab].user_id != RVT_INVALID_HEADER; | |
467 idtab++) | |
468 { | |
469 if (rvt_user_db[idtab].user_id == inBuffer[0]) | |
470 { | |
471 rx_callback_func = rvt_user_db[idtab].rx_callback_func; | |
472 break; | |
473 } | |
474 } | |
475 rcv_state = RVT_WAIT_FOR_DATA; | |
476 } | |
477 } | |
478 | |
479 // Update the total number of bytes read, regarding the current frame | |
480 total_bytesRead += bytesRead; | |
481 | |
482 // Call the corresponding callback function when a complete message is | |
483 // received (eof odd) | |
484 if (eof & 0x01) | |
485 { | |
486 // Invoke the callback function | |
487 if (rx_callback_func != NULL) | |
488 { | |
489 rx_callback_func ((T_RVT_BUFFER) (inBuffer + 1), | |
490 total_bytesRead - 1); | |
491 rx_callback_func = NULL; | |
492 } | |
493 | |
494 // Wait for the next frame to come | |
495 rcv_state = RVT_WAIT_FOR_HEADER; | |
496 total_bytesRead = 0; | |
497 } | |
498 | |
499 // inBuffer may be full due to some synchro lost problems | |
500 else if (total_bytesRead == sizeof (inBuffer)) | |
501 { | |
502 // If still waiting for the header, discard received characters and | |
503 // reset static variables for the next frame to come | |
504 if (rcv_state == RVT_WAIT_FOR_HEADER) | |
505 { | |
506 total_bytesRead = 0; | |
507 break; | |
508 } | |
509 | |
510 // Just discard characters received as payload | |
511 total_bytesRead = sizeof (inBuffer[0]); | |
512 } | |
513 | |
514 // Proceed with the next concatenated frame whether more bytes left | |
515 if (eof > 1) | |
516 { | |
517 continue; | |
518 } | |
519 break; | |
520 } | |
521 #else | |
522 | |
523 // Read the UART RX FIFO and fill inBuffer with received bytes | |
524 bytesRead = SER_tr_ReadNChars (SER_LAYER_1, | |
525 (char *) inBuffer, | |
526 sizeof (inBuffer)); | |
527 | |
528 // Invoke the Testmode callback function : this is the only one able, | |
529 // for the moment, to send an external command !! WARNING : This | |
530 // should be the same name than the one already registered in | |
531 // create_RVtasks.c. | |
532 tm_receive ((T_RVT_BUFFER) inBuffer, | |
533 bytesRead); | |
534 #endif | |
535 } | |
536 | |
537 | |
538 | |
539 /********************************************************************************/ | |
540 /* */ | |
541 /* Function Name: rvt_activate_RX_HISR */ | |
542 /* */ | |
543 /* Purpose: This function is called when an RX interrupt occurs. */ | |
544 /* */ | |
545 /* Input Parameters: */ | |
546 /* None. */ | |
547 /* */ | |
548 /* Output Parameters: */ | |
549 /* None. */ | |
550 /* */ | |
551 /* Global Parameters: */ | |
552 /* None. */ | |
553 /* */ | |
554 /* Note: */ | |
555 /* None. */ | |
556 /* */ | |
557 /********************************************************************************/ | |
558 void rvt_activate_RX_HISR (void) | |
559 { | |
560 NU_Activate_HISR (&TI_rcv_HISR); | |
561 } |