comparison riviera/rvt/rvt_task.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
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 /*
424 rvf_send_trace("Ser RX", 6, rvf_get_tick_count(),
425 RV_TRACE_LEVEL_DEBUG_HIGH, RVT_USE_ID);
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 // Read and destuff the UART RX FIFO and fill inBuffer with received
440 // bytes
441 bytesRead = SER_tr_ReadNBytes (SER_LAYER_1,
442 (char *) (inBuffer + total_bytesRead),
443 sizeof (inBuffer) - total_bytesRead,
444 &eof);
445
446 // Check for the header. Hence, get the sendee
447 if ((rcv_state == RVT_WAIT_FOR_HEADER) && \
448 (bytesRead) && \
449 !(total_bytesRead))
450 {
451 if ((inBuffer[0] >= RVT_RV_HEADER) &&
452 (inBuffer[0] <= RVT_KEEPALIVE_HEADER))
453 {
454 UINT8 idtab = 0;
455
456 // Search for the ID in the table
457 for (idtab = 0;
458 rvt_user_db[idtab].user_id != RVT_INVALID_HEADER;
459 idtab++)
460 {
461 if (rvt_user_db[idtab].user_id == inBuffer[0])
462 {
463 rx_callback_func =
464 rvt_user_db[idtab].rx_callback_func;
465 break;
466 }
467 }
468 rcv_state = RVT_WAIT_FOR_DATA;
469 }
470 }
471
472 // Update the total number of bytes read,
473 // regarding the current frame
474 total_bytesRead += bytesRead;
475
476 // Call the corresponding callback function when a complete message
477 // is received (eof odd)
478 if (eof & 0x01)
479 {
480 // Invoke the callback function
481 if (rx_callback_func != NULL)
482 {
483 rx_callback_func ((T_RVT_BUFFER) (inBuffer + 1),
484 total_bytesRead - 1);
485 rx_callback_func = NULL;
486 }
487
488 // Wait for the next frame to come
489 rcv_state = RVT_WAIT_FOR_HEADER;
490 total_bytesRead = 0;
491 }
492
493 // inBuffer may be full due to some synchro lost problems
494 else if (total_bytesRead == sizeof (inBuffer))
495 {
496 // If still waiting for the header, discard received characters
497 // and reset static variables for the next frame to come
498 if (rcv_state == RVT_WAIT_FOR_HEADER)
499 {
500 total_bytesRead = 0;
501 break;
502 }
503
504 // Just discard characters received as payload
505 total_bytesRead = sizeof (inBuffer[0]);
506 }
507
508 // Proceed with the next concatenated frame whether more bytes left
509 if (eof > 1)
510 {
511 continue;
512 }
513 break;
514 }
515 #else
516
517 // Read the UART RX FIFO and fill inBuffer with received bytes
518 bytesRead = SER_tr_ReadNChars (SER_LAYER_1,
519 (char *) inBuffer,
520 sizeof (inBuffer));
521
522 // Invoke the Testmode callback function : this is the only one able,
523 // for the moment, to send an external command !! WARNING : This
524 // should be the same name than the one already registered in
525 // create_RVtasks.c.
526 tm_receive ((T_RVT_BUFFER) inBuffer, bytesRead);
527 #endif
528 }
529
530
531
532 /******************************************************************************/
533 /* */
534 /* Function Name: rvt_activate_RX_HISR */
535 /* */
536 /* Purpose: This function is called when an RX interrupt occurs. */
537 /* */
538 /* Input Parameters: */
539 /* None. */
540 /* */
541 /* Output Parameters: */
542 /* None. */
543 /* */
544 /* Global Parameters: */
545 /* None. */
546 /* */
547 /* Note: */
548 /* None. */
549 /* */
550 /******************************************************************************/
551 void rvt_activate_RX_HISR (void)
552 {
553 NU_Activate_HISR (&TI_rcv_HISR);
554 }