comparison chipsetsw/riviera/rvt/rvt_task.c @ 0:509db1a7b7b8

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