comparison src/cs/riviera/rvt/ti_profiler/ti_profiler.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 * ti_profiler.c : contains ti profiling module function *
3 * *
4 * *
5 * Author: Philippe Martinez *
6 * *
7 * version: 1.0 *
8 * *
9 * Date: 07/16/2001 *
10 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved *
11 ************************************************************************************/
12
13 #include "config/debug.cfg"
14
15 #if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
16
17 /*-------------------------------------------------------*/
18 /* include files */
19 /*-------------------------------------------------------*/
20
21 #include <string.h>
22
23 #include "main/sys_types.h"
24
25 #include "nucleus.h"
26 #if (TI_NUC_MONITOR == 1)
27 #include "qu_defs.h"
28 #include "tc_defs.h"
29 #endif
30
31 #include "rvf/rvf_api.h"
32 #include "rvt/rvt_gen.h"
33 #include "rvt/rvt_def_i.h"
34
35 #include "mem.h"
36 #include "iq.h"
37
38 #include "rvt/ti_profiler/ti_profiler.h"
39
40 #include "timer.h"
41 #include "inth.h"
42
43 /*-------------------------------------------------------*/
44 /* Global instances */
45 /*-------------------------------------------------------*/
46
47 // task variable instance
48 T_RVF_MB_ID prof_mb_id;
49 T_RVT_USER_ID prof_trace_id;
50 T_RVF_ADDR_ID prof_addr_id;
51
52 /*-------------------------------------------------------*/
53 /* internal prototypes */
54 /*-------------------------------------------------------*/
55
56 void ti_prf_init( void );
57 T_RV_RET ti_prf_core(void);
58 void ti_profiler_trace_rx_callback( T_RVT_BUFFER trace_msg, UINT16 trace_msg_size );
59 #if (L1_TRACER == 1)
60 extern void SendTraces(char *s);
61 #endif
62
63 #endif
64
65
66 #if (TI_PROFILER == 1)
67
68 /*-------------------------------------------------------*/
69 /* Global instances */
70 /*-------------------------------------------------------*/
71
72 // Internal state of profiling
73 T_PROFILER_STATE profiler_state = PROFILER_STOPPED;
74
75
76 // Buffer that contains the Profiling samples.
77 // Structure (SYS_UWORD32 buffer):
78 // C_OP_CODE_TDMA_BEGIN
79 // PC Samples ......
80 // C_OP_CODE_TDMA_END
81 // ......
82 // C_OP_CODE_TDMA_BEGIN
83 // PC Samples ......
84 // C_OP_CODE_TDMA_END
85
86 SYS_UWORD32 pr_buffer[PR_BUFFER_SIZE];
87 // pointer on pr_buffer
88 SYS_UWORD32 pos_pr_buffer = 0;
89 SYS_UWORD32 pr_buffer_length = PR_BUFFER_SIZE;
90
91 T_PROFILER_BUFFER_STATE ti_profiler_buffer_state = LOGGING;
92 T_PROFILER_HANDLER ti_profiler_active = NOT_ACTIVE;
93
94 // hisr variable instance
95 NU_HISR ti_profiler_cb;
96 SYS_UWORD8 ti_profiler_hisr_stack[500];
97
98 // Event variables
99 // NO_SLEEP_EVENT
100 SYS_UWORD32 ti_profiler_nb_sleep_call = 0;
101 SYS_UWORD32 ti_profiler_nb_sleep_counter_ref = 0;
102
103 T_PROFILER_EVENTS ti_profiler_event_state = NO_EVENT;
104
105 /*-------------------------------------------------------*/
106 /* internal prototypes */
107 /*-------------------------------------------------------*/
108
109 void ti_profiler_start( BOOL enable );
110 void ti_profiler_handler( SYS_UWORD32 programCounter );
111 void ti_profiler_freeze( void );
112 void ti_profiler_unfreeze( void );
113 void ti_profiler_tdma_action( void );
114 void ti_profiler_init_profiler_module( void );
115 void ti_profiler_hisr( void );
116
117 void l1_profiler_open( void );
118 void l1_profiler_close( void );
119 void l1_profiler_flush( void );
120
121 /*-------------------------------------------------------*/
122 /* external prototypes */
123 /*-------------------------------------------------------*/
124
125 SYS_UWORD32 l1_get_next_absolute_fn( void );
126
127 /*-------------------------------------------------------*/
128 /* ti_profiler_start() */
129 /*-------------------------------------------------------*/
130 /* */
131 /* Description: Start or Stop the timer */
132 /* ------------ */
133 /* parameters */
134 /* enable = 1 => Unmask + start the timer 1 */
135 /* Initialize buffer. */
136 /* enable = 0 => mask + stop the timer 1 */
137 /* Close Buffer. */
138 /*-------------------------------------------------------*/
139
140 void ti_profiler_start( BOOL enable )
141 {
142 if( enable )
143 {
144 TM_EnableTimer( PR_TIMER_NUM );
145 IQ_Unmask( IQ_TIM1 );
146 IQ_InitLevel( IQ_TIM1, FIQ, 0, 1 );
147
148 TM_ResetTimer( PR_TIMER_NUM, PR_TIMER_RESET_VALUE, 1, 0 );
149 TM_StartTimer( PR_TIMER_NUM );
150 }
151 else
152 {
153 IQ_Mask( IQ_TIM1 );
154 IQ_InitLevel( IQ_TIM1, 0, 0, 1 );
155 TM_StopTimer( PR_TIMER_NUM );
156 }
157 } // ti_profiler_start
158
159
160 /*-------------------------------------------------------*/
161 /* ti_profiler_handler() */
162 /*-------------------------------------------------------*/
163 /* */
164 /* Description: */
165 /* ------------ */
166 /* Store the Program counter in a static buffer */
167 /* If buffer is full, deactivate the profiling and */
168 /* activate the ti_profiler_hisr(); */
169 /*-------------------------------------------------------*/
170
171 void ti_profiler_handler( SYS_UWORD32 programCounter )
172 {
173
174 // Store the program Counter in log buffer
175 pr_buffer[ pos_pr_buffer++ ] = programCounter;
176
177 } // ti_profiler_handler
178
179
180 /*-------------------------------------------------------*/
181 /* ti_profiler_freeze() ti_profiler_unfreeze() */
182 /*-------------------------------------------------------*/
183 /* */
184 /* Description: */
185 /* ------------ */
186 /* Function to suspend/resume the profiling */
187 /*-------------------------------------------------------*/
188
189 void ti_profiler_freeze()
190 {
191 TM_StopTimer( PR_TIMER_NUM );
192 } // ti_profiler_freeze
193
194 void ti_profiler_unfreeze()
195 {
196 TM_StartTimer( PR_TIMER_NUM );
197 } // ti_profiler_unfreeze
198
199 /*-------------------------------------------------------*/
200 /* ti_profiler_init_profiler_module() */
201 /*-------------------------------------------------------*/
202 /* */
203 /* Description: Initialize profiling task and hisr */
204 /* ------------ */
205 /* Note : this init will changed */
206 /* */
207 /*-------------------------------------------------------*/
208
209 void ti_profiler_init_profiler_module( void )
210 {
211 // Fill the entire stack with the pattern 0xFE
212 memset( ti_profiler_hisr_stack, 0xFE, sizeof( ti_profiler_hisr_stack ) );
213
214 // Create the HISR which is called from power interrupts
215 NU_Create_HISR( &ti_profiler_cb,
216 "TI PROF",
217 ti_profiler_hisr,
218 2,
219 ti_profiler_hisr_stack,
220 sizeof( ti_profiler_hisr_stack ) ); // lowest prty
221
222 } // ti_profiler_init_profiler_module
223
224
225 /*-------------------------------------------------------*/
226 /* ti_profiler_hisr() High Interrupt service routine */
227 /*-------------------------------------------------------*/
228 /* */
229 /* Description: */
230 /* ------------ */
231 /* This hisr stands as relay for the profiler LISR. */
232 /* It sends a message to the profiler task to start the */
233 /* buffer extraction. */
234 /*-------------------------------------------------------*/
235
236 void ti_profiler_hisr( void )
237 {
238 T_PROFILER_MSG * msg;
239
240 //send a message to the ti profiler task
241 if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
242 {
243 msg->msg_id = TI_PROFILER_OUTPUT_BUFFER;
244 rvf_send_msg( prof_addr_id, msg );
245 }
246 } // ti_profiler_hisr
247
248 /*-------------------------------------------------------*/
249 /* ti_profiler_tdma_action() */
250 /*-------------------------------------------------------*/
251 /* */
252 /* Description: */
253 /* ------------ */
254 /* */
255 /* */
256 /*-------------------------------------------------------*/
257
258 void ti_profiler_tdma_action(void)
259 {
260
261 switch( profiler_state )
262 {
263 case PROFILER_RUNNING :
264 {
265 SYS_UWORD8 output_buffer_condition = 0;
266
267 // suspend the profiler
268 //ti_profiler_freeze();
269 ti_profiler_start( FALSE );
270
271 if( ti_profiler_event_state == NO_SLEEP_EVENT )
272 {
273 // Need to reach the event to output the buffer
274 if( ti_profiler_nb_sleep_call++ >= ti_profiler_nb_sleep_counter_ref )
275 {
276 output_buffer_condition = 1;
277 ti_profiler_nb_sleep_call = 0;
278 // ti_profiler_buffer_state = FLUSH;
279 } // End if
280 }
281 else
282 {
283 output_buffer_condition = 1;
284 } // End if
285
286
287 // Check if buffer threshold reached
288 if( pos_pr_buffer >= PR_BUFFER_THRESHOLD )
289 {
290 // change the status of the buffer
291 ti_profiler_buffer_state = LOGGING;
292
293 // Insert the End of Buffer OP code
294 pr_buffer[ pos_pr_buffer++ ] = C_OP_CODE_END_BUFFER;
295
296 // Specifie used length of buffer in SYS_UWORD32
297 pr_buffer_length = pos_pr_buffer;
298
299 if( output_buffer_condition == 1 )
300 {
301 // Change profiler state to freezed
302 profiler_state = PROFILER_FREEZED;
303
304 // Activate the hisr in order to start the buffer output
305 NU_Activate_HISR( &ti_profiler_cb );
306 }
307 else
308 {
309 // insert TDMA begin OP Code
310 pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;
311 pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;
312 // Insert current fn
313 pr_buffer[ 2 ] = l1_get_next_absolute_fn();
314
315 // initialize buffer pointer
316 pos_pr_buffer = 3;
317
318 ti_profiler_start( TRUE );
319 } // End if
320
321 }
322 else
323 {
324 // insert OP Code begining of TDMA
325 pr_buffer[pos_pr_buffer++] = C_OP_CODE_TDMA_BEGIN;
326 // Insert current fn
327 pr_buffer[pos_pr_buffer++] = l1_get_next_absolute_fn();
328
329 // resume profiler
330 //ti_profiler_unfreeze();
331 ti_profiler_start( TRUE );
332 } // End if
333
334
335 break;
336 } // PROFILER_RUNNING
337
338 case PROFILER_TO_BE_RAN :
339 {
340 // insert TDMA begin OP Code
341 pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;
342 pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;
343 // Insert current fn
344 pr_buffer[ 2 ] = l1_get_next_absolute_fn();
345
346 // initialize buffer pointer
347 pos_pr_buffer = 3;
348 // start the profiler
349 profiler_state = PROFILER_RUNNING;
350
351 // start the profiler
352 ti_profiler_start( TRUE );
353
354 break;
355 } // PROFILER_TO_BE_RAN
356
357 case PROFILER_TO_BE_STOPPED :
358 {
359 // stop the profiler
360 ti_profiler_start( FALSE );
361
362 // Insert End Buffer Op Code.
363 pr_buffer[pos_pr_buffer++] = C_OP_CODE_END_BUFFER;
364 profiler_state = PROFILER_STOPPED;
365
366 // Activate the hisr in order to start the buffer output
367 NU_Activate_HISR( &ti_profiler_cb );
368
369 // Returns to inactive
370 ti_profiler_active = NOT_ACTIVE;
371
372 break;
373 } // PROFILER_TO_BE_STOPPED
374
375 case PROFILER_TO_BE_UNFREEZED :
376 {
377 // Init profiling buffer
378 // insert TDMA begin OP Code
379 pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;
380 pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;
381 // Insert current fn
382 pr_buffer[ 2 ] = l1_get_next_absolute_fn();
383
384 // initialize buffer pointer
385 pos_pr_buffer = 3;
386 // Insert the TDMA Start Op Code
387 profiler_state = PROFILER_RUNNING;
388
389 // resume profiler
390 //ti_profiler_unfreeze();
391 ti_profiler_start( TRUE );
392
393 break;
394 } // PROFILER_TO_BE_UNFREEZED
395
396 default :
397 {
398 // nothing to do
399 break;
400 } // default
401
402 } // End switch
403
404 } // ti_profiler_tdma_action
405
406 /*-------------------------------------------------------*/
407 /* ti_profiler_open() */
408 /*-------------------------------------------------------*/
409 /* */
410 /* Description: */
411 /* ------------ */
412 /* Start the profiling on the next TDMA occurence */
413 /* */
414 /*-------------------------------------------------------*/
415
416 void ti_profiler_open( void )
417 {
418 if( ti_profiler_active == NOT_ACTIVE )
419 {
420
421 } // End if
422 } // ti_profiler_open
423
424 /*-------------------------------------------------------*/
425 /* ti_profiler_close() */
426 /*-------------------------------------------------------*/
427 /* */
428 /* Description: */
429 /* ------------ */
430 /* Stop the profiling on the next TDMA occurence */
431 /* */
432 /*-------------------------------------------------------*/
433
434 void ti_profiler_close( void )
435 {
436 if( ti_profiler_active == NOT_ACTIVE )
437 {
438 l1_profiler_close();
439 } // End if
440 } // ti_profiler_close
441
442 /*-------------------------------------------------------*/
443 /* l1_profiler_flush() */
444 /*-------------------------------------------------------*/
445 /* */
446 /* Description: */
447 /* ------------ */
448 /* freeze the profiling and flush the current profiling */
449 /* buffer. Profiling will restart after output of the */
450 /* buffer. */
451 /*-------------------------------------------------------*/
452
453 void ti_profiler_flush( void )
454 {
455 if( ti_profiler_active == NOT_ACTIVE )
456 {
457 l1_profiler_flush();
458 } // End if
459 } // ti_profiler_flush
460
461 // To be used only TI internal modules
462
463 /*-------------------------------------------------------*/
464 /* ti_profiler_open() */
465 /*-------------------------------------------------------*/
466 /* */
467 /* Description: */
468 /* ------------ */
469 /* Start the profiling on the next TDMA occurence */
470 /* */
471 /*-------------------------------------------------------*/
472
473 void l1_profiler_open( void )
474 {
475
476 if( ti_profiler_active != NOT_ACTIVE )
477 {
478 // stop profiler timer
479 ti_profiler_start( FALSE );
480 // go to idle
481 profiler_state = PROFILER_STOPPED;
482 } // Endif
483
484 // insert TDMA begin OP Code
485 pr_buffer[ 0 ] = C_OP_CODE_BEGIN_BUFFER;
486 pr_buffer[ 1 ] = C_OP_CODE_TDMA_BEGIN;
487
488 // Insert current fn
489 pr_buffer[ 2 ] = l1_get_next_absolute_fn();
490
491 // initialize buffer pointer
492 pos_pr_buffer = 3;
493
494 // change state of profiler
495 profiler_state = PROFILER_TO_BE_RAN;
496
497 } // ti_profiler_open
498
499 /*-------------------------------------------------------*/
500 /* ti_profiler_close() */
501 /*-------------------------------------------------------*/
502 /* */
503 /* Description: */
504 /* ------------ */
505 /* Stop the profiling on the next TDMA occurence */
506 /* */
507 /*-------------------------------------------------------*/
508
509 void l1_profiler_close( void )
510 {
511 // stop the profiler
512 ti_profiler_start( FALSE );
513
514 // Insert TDMA_BOUNDARY Op Code.
515 pr_buffer[pos_pr_buffer++] = C_OP_CODE_END_BUFFER;
516 profiler_state = PROFILER_STOPPED;
517
518 // Activate the hisr in order to start the buffer output
519 NU_Activate_HISR( &ti_profiler_cb );
520
521 } // ti_profiler_close
522
523 /*-------------------------------------------------------*/
524 /* l1_profiler_flush() */
525 /*-------------------------------------------------------*/
526 /* */
527 /* Description: */
528 /* ------------ */
529 /* freeze the profiling and flush the current profiling */
530 /* buffer. Profiling will restart after output of the */
531 /* buffer. */
532 /*-------------------------------------------------------*/
533
534 void l1_profiler_flush( void )
535 {
536 ti_profiler_buffer_state = FLUSH;
537 } // ti_profiler_flush
538
539 #endif // PROFILER
540
541 #if (TI_NUC_MONITOR == 1)
542
543 /*-------------------------------------------------------*/
544 /* Global instances */
545 /*-------------------------------------------------------*/
546 // management of monitoring buffer
547
548 // Internal state of nucleus monitoring
549
550 T_NUC_MONITOR_STATE ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
551
552 // pointers on current buffer
553 SYS_UWORD8* ti_nuc_monitor_current_buffer = NULL;
554 SYS_UWORD8 ti_nuc_monitor_current_position = 0;
555
556 // Create static doubled bufferised LISR buffers (max 10 LISR by TDMA)
557 SYS_UWORD8 ti_nuc_monitor_LISR_Buffer[C_NUC_LISR_BUF_PG_NB][C_NUC_MAX_LISR];
558 SYS_UWORD8 ti_nuc_monitor_LISR_current_page = 0;
559 SYS_UWORD8 ti_nuc_monitor_LISR_current_pos = 0;
560 SYS_UWORD8 ti_nuc_monitor_LISR_next_page = 0;
561 SYS_UWORD8 ti_nuc_monitor_LISR_next_pos = 0;
562
563 // Create static doubled bufferised LISR buffers (max 10 LISR by TDMA)
564 SYS_UWORD8 ti_nuc_monitor_Thread_Buffer[C_NUC_THREAD_BUF_PG_NB][C_NUC_MAX_THREAD];
565 SYS_UWORD8 ti_nuc_monitor_Thread_current_page = 0;
566 SYS_UWORD8 ti_nuc_monitor_Thread_current_pos = 0;
567 SYS_UWORD8 ti_nuc_monitor_Thread_next_page = 0;
568 SYS_UWORD8 ti_nuc_monitor_Thread_next_pos = 0;
569
570 // hisr variable instance
571 NU_HISR ti_nuc_monitor_cb;
572 SYS_UWORD8 ti_nuc_monitor_hisr_stack[ 500 ];
573
574 // Array that store the ID <-> pointer of the Nucleus Components
575 //SYS_UWORD32* ti_nuc_monitor_thread_id[ NUC_MONITOR_MAX_ID ];
576 SYS_UWORD32 ti_nuc_monitor_thread_id[ NUC_MONITOR_MAX_ID ];
577 SYS_UWORD8 ti_nuc_monitor_thread_pos = 0;
578
579 //SYS_UWORD32* ti_nuc_monitor_queue_id[ NUC_MONITOR_MAX_ID ];
580 SYS_UWORD32 ti_nuc_monitor_queue_id[ NUC_MONITOR_MAX_ID ];
581 SYS_UWORD8 ti_nuc_monitor_queue_pos = 0;
582
583 // LISR IRQ value
584 SYS_UWORD8 IRQ_value;
585
586 // Indicates the nucleus monitor part to switch Thread buffer page
587 SYS_UWORD8 ti_nuc_monitor_change_thread_page = 0;
588
589 // Indicates that the IDLE mode has been reached
590 // (to be reset in LISR or Thread monitor function)
591 SYS_UWORD8 ti_nuc_monitor_idle_reached = 0;
592
593 // debug
594 SYS_UWORD32 ti_nuc_monitor_lost_messages = 0;
595
596 /*-------------------------------------------------------*/
597 /* internal prototypes */
598 /*-------------------------------------------------------*/
599
600 void ti_nuc_monitor_tdma_action( void );
601 void ti_nuc_monitor_init_module( void );
602 void ti_nuc_monitor_hisr( void );
603 void ti_nuc_monitor_check_ID_buffer( void );
604 void ti_nuc_monitor_LISR_log( void );
605 void ti_nuc_monitor_LISR_log_end( void );
606 void ti_nuc_monitor_Thread_log( void );
607 void ti_nuc_monitor_Queue_log( SYS_UWORD32* queue_pointer, SYS_UWORD8 status, SYS_UWORD8 Direction );
608 void ti_nuc_monitor_sleep( void );
609
610 T_RVT_RET ti_nuc_monitor_mem_alloc(T_RVT_USER_ID user_id,
611 T_RVT_MSG_LG buffer_lenght,
612 T_RVT_BUFFER * buff);
613
614 /*-------------------------------------------------------*/
615 /* external prototypes */
616 /*-------------------------------------------------------*/
617
618 extern SYS_UWORD16 l1_get_actual_fn_mod42432( void );
619 extern SYS_UWORD32* TCD_Current_Thread;
620
621 /*-------------------------------------------------------*/
622 /* ti_nuc_monitor_init_module() */
623 /*-------------------------------------------------------*/
624 /* */
625 /* Description: Initialize hisr */
626 /* ------------ */
627 /* Create hisr and initialize thread/queue structures. */
628 /* */
629 /*-------------------------------------------------------*/
630
631 void ti_nuc_monitor_init_module( void )
632 {
633 SYS_UWORD8 i;
634
635 // Fill the entire stack with the pattern 0xFE
636 memset( ti_nuc_monitor_hisr_stack, 0xFE, sizeof( ti_nuc_monitor_hisr_stack ) );
637
638 // Create the HISR
639 NU_Create_HISR( &ti_nuc_monitor_cb,
640 "TI MON",
641 ti_nuc_monitor_hisr,
642 2,
643 ti_nuc_monitor_hisr_stack,
644 sizeof( ti_nuc_monitor_hisr_stack ) ); // lowest prty
645
646 } // ti_nuc_monitor_init_module
647
648
649 /*-------------------------------------------------------*/
650 /* ti_nuc_monitor_hisr() High Interrupt service routine */
651 /*-------------------------------------------------------*/
652 /* */
653 /* Description: */
654 /* ------------ */
655 /* It sends a message to the profiler task to start the */
656 /* buffer extraction. */
657 /*-------------------------------------------------------*/
658
659 void ti_nuc_monitor_hisr( void )
660 {
661 SYS_UWORD8 remaining_bytes;
662 SYS_UWORD16 fn;
663 T_PROFILER_MSG *msg;
664 SYS_UWORD8 i;
665
666 // Allocate a buffer first time
667 if(( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN ) ||
668 ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STARTED ))
669 {
670 if((ti_nuc_monitor_mem_alloc (prof_trace_id,
671 NUC_MONITOR_BUFFER_SIZE,
672 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
673 == RVT_OK)
674 {
675
676 ti_nuc_monitor_current_position = 0;
677
678 // Insert the interrupt OP Code (0x00 0x00 0x00)
679 if( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN )
680 {
681 for( i=0; i < 3; i++)
682 {
683 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = 0x00;
684 } // End for
685 } // Endif
686
687 // Reset intermediate buffer pointers
688 ti_nuc_monitor_Thread_current_pos = 0;
689 ti_nuc_monitor_LISR_current_pos = 0;
690 }
691 else
692 {
693 return;
694 } // End if
695
696 // Write FN OP CODE : (0x00 | xx)
697
698 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
699 (SYS_UWORD8) ( C_OP_CODE_FN_LOG );
700
701 // Insert the fn%42432
702 fn = l1_get_actual_fn_mod42432();
703
704 // insert LSB
705 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
706 (SYS_UWORD8) (fn & 0x00ff);
707
708 // insert MSB
709 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
710 (SYS_UWORD8) ((fn & 0xff00) >> 8);
711
712 ti_nuc_monitor_state = NUC_MONITOR_RUNNING;
713
714 return;
715 } // End if
716
717 // Copy the LISR and Thread buffer into current buffer.
718
719 // - LISR array
720
721 // Check the number of byte remaining in the current
722 // log buffer vs LISR buffer.
723
724 remaining_bytes = NUC_MONITOR_BUFFER_SIZE - ti_nuc_monitor_current_position;
725
726 if( remaining_bytes > ti_nuc_monitor_LISR_next_pos )
727 {
728 // Copy ti_nuc_monitor_LISR_next_pos bytes to Nucleus log buffer
729
730 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
731 &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ 0 ],
732 ti_nuc_monitor_LISR_next_pos);
733
734 ti_nuc_monitor_current_position += ti_nuc_monitor_LISR_next_pos;
735
736 }
737 else
738 {
739
740 // Copy remaining_bytes bytes to Nucleus log buffer
741
742 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
743 &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ 0 ],
744 remaining_bytes);
745
746 ti_nuc_monitor_current_position += remaining_bytes;
747
748 // Send current buffer
749
750 // send a message to the ti profiler task
751
752 if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
753 {
754 msg->msg_id = TI_NUC_MONITOR_OUTPUT_BUFFER;
755 msg->p_buffer = ti_nuc_monitor_current_buffer;
756 msg->buffer_size = ti_nuc_monitor_current_position;
757
758 ti_nuc_monitor_current_position = 0;
759
760 if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
761 {
762 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
763 return;
764 } // End if
765 }
766 else
767 {
768 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
769 return;
770 } // End if
771
772 // Change Nucleus log buffer
773
774 if((ti_nuc_monitor_mem_alloc (prof_trace_id,
775 NUC_MONITOR_BUFFER_SIZE,
776 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
777 != RVT_OK)
778 {
779 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
780 return;
781 } // End if
782
783 // Copy remaining_bytes bytes to Nucleus log buffer
784 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
785 &ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_next_page ][ remaining_bytes ],
786 ( ti_nuc_monitor_LISR_next_pos - remaining_bytes ));
787
788 ti_nuc_monitor_current_position += ( ti_nuc_monitor_LISR_next_pos - remaining_bytes );
789
790 } // End if
791
792 // - Thread Array
793
794 // Check the number of byte remaining in the current
795 // log buffer vs Thread buffer.
796
797 remaining_bytes = NUC_MONITOR_BUFFER_SIZE - ti_nuc_monitor_current_position;
798
799 if( remaining_bytes > ti_nuc_monitor_Thread_next_pos )
800 {
801 // Copy ti_nuc_monitor_Thread_next_pos bytes to Nucleus log buffer
802
803 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
804 &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ 0 ],
805 ti_nuc_monitor_Thread_next_pos);
806
807 ti_nuc_monitor_current_position += ti_nuc_monitor_Thread_next_pos;
808
809 }
810 else
811 {
812
813 // Copy remaining_bytes bytes to Nucleus log buffer
814
815 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
816 &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ 0 ],
817 remaining_bytes);
818
819 ti_nuc_monitor_current_position += remaining_bytes;
820
821 // Send current buffer
822
823 // send a message to the ti profiler task
824
825 if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
826 {
827 msg->msg_id = TI_NUC_MONITOR_OUTPUT_BUFFER;
828 msg->p_buffer = ti_nuc_monitor_current_buffer;
829 msg->buffer_size = ti_nuc_monitor_current_position;
830
831 ti_nuc_monitor_current_position = 0;
832
833 if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
834 {
835 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
836 return;
837 } // End if
838 }
839 else
840 {
841 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
842 return;
843 } // End if
844
845 // Change Nucleus log buffer
846
847 if((ti_nuc_monitor_mem_alloc (prof_trace_id,
848 NUC_MONITOR_BUFFER_SIZE,
849 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
850 != RVT_OK)
851 {
852 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
853 return;
854 } // End if
855
856 // Copy remaining_bytes bytes to Nucleus log buffer
857 memcpy( &ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position ],
858 &ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_next_page ][ remaining_bytes ],
859 ( ti_nuc_monitor_Thread_next_pos - remaining_bytes ));
860
861 ti_nuc_monitor_current_position += ( ti_nuc_monitor_Thread_next_pos - remaining_bytes );
862
863 } // End if
864
865 // Exit if monitoring must be stopped
866
867 if( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STOP )
868 {
869 ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
870 return;
871 } // End if
872
873 // Insert actual Frame number
874
875 // Check if enough space in current buffer
876 if( ti_nuc_monitor_current_position >= (NUC_MONITOR_BUFFER_SIZE - 3) )
877 {
878 // send a message to the ti profiler task
879
880 if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
881 {
882 msg->msg_id = TI_NUC_MONITOR_OUTPUT_BUFFER;
883 msg->p_buffer = ti_nuc_monitor_current_buffer;
884 msg->buffer_size = ti_nuc_monitor_current_position;
885
886 ti_nuc_monitor_current_position = 0;
887
888 if( rvf_send_msg( prof_addr_id, msg ) != RV_OK )
889 {
890 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
891 return;
892 } // End if
893 }
894 else
895 {
896 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
897 return;
898 } // End if
899
900 // Change Nucleus log buffer
901
902 if((ti_nuc_monitor_mem_alloc (prof_trace_id,
903 NUC_MONITOR_BUFFER_SIZE,
904 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
905 != RVT_OK)
906 {
907 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_RUN;
908 return;
909 } // End if
910 } // End if
911
912 // Write FN OP CODE : (0x00 | xx)
913
914 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
915 (SYS_UWORD8) ( C_OP_CODE_FN_LOG );
916
917 // Insert the fn%42432
918 fn = l1_get_actual_fn_mod42432();
919
920 // insert LSB
921 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
922 (SYS_UWORD8) (fn & 0x00ff);
923
924 // insert MSB
925 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
926 (SYS_UWORD8) ((fn & 0xff00) >> 8);
927
928 } // ti_nuc_monitor_hisr
929
930 /*-------------------------------------------------------*/
931 /* ti_nuc_monitor_check_ID_buffer() */
932 /*-------------------------------------------------------*/
933 /* */
934 /* Description: */
935 /* ------------ */
936 /* During the Thread/Queue ID -> names buffer */
937 /* transmission, change current buffer. */
938 /* Send the full buffer and allocate a new one. */
939 /*-------------------------------------------------------*/
940
941 void ti_nuc_monitor_check_ID_buffer( void )
942 {
943 // Reset pointer
944 ti_nuc_monitor_current_position = 0;
945
946 // Send a message to the Riviera Tracer to Output the current buffer.
947 if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) ti_nuc_monitor_current_buffer,
948 prof_trace_id,
949 NUC_MONITOR_BUFFER_SIZE, // Length in bytes
950 RVT_BINARY_FORMAT ) != RVT_OK )
951 {
952 // code to insert a breakpoint if failed.
953 ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
954 } // End if
955
956
957 // Allocate one buffer.
958 do
959 {
960 ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
961
962 if ((ti_nuc_monitor_mem_alloc (prof_trace_id,
963 NUC_MONITOR_BUFFER_SIZE,
964 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
965 != RVT_OK)
966 {
967 ti_nuc_monitor_state = NUC_MONITOR_WAITING;
968 } // End if
969 } while (ti_nuc_monitor_state == NUC_MONITOR_WAITING);
970
971 } // ti_nuc_monitor_check_ID_buffer
972
973 /*-------------------------------------------------------*/
974 /* ti_nuc_monitor_tdma_action() */
975 /*-------------------------------------------------------*/
976 /* */
977 /* Description: */
978 /* ------------ */
979 /* this function activate the HISR monitor */
980 /*-------------------------------------------------------*/
981
982 void ti_nuc_monitor_tdma_action( void )
983 {
984
985 if(( ti_nuc_monitor_state == NUC_MONITOR_RUNNING ) ||
986 ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_RUN ) ||
987 ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STOP ) ||
988 ( ti_nuc_monitor_state == NUC_MONITOR_TO_BE_STARTED ))
989 {
990
991 // Activate the hisr in order to start the buffer fill
992 NU_Activate_HISR( &ti_nuc_monitor_cb );
993
994 } // End if
995
996 } // ti_nuc_monitor_tdma_action
997
998 /*-------------------------------------------------------*/
999 /* ti_nuc_monitor_LISR_log() */
1000 /*-------------------------------------------------------*/
1001 /* */
1002 /* Description: */
1003 /* ------------ */
1004 /* This function permits to include the LISR IRQ and */
1005 /* timer value in the LISR log buffer */
1006 /* Warning : To save cpu, no overflow check is done */
1007 /*-------------------------------------------------------*/
1008
1009 void ti_nuc_monitor_LISR_log( void )
1010 {
1011 SYS_UWORD16 timer_value;
1012
1013 if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
1014 {
1015
1016 // Exit Idle mode if reached
1017
1018 ti_nuc_monitor_idle_reached = 0;
1019
1020 IRQ_value = (SYS_UWORD8) ((* (volatile SYS_UWORD16 *) INTH_B_IRQ_REG) & 0x001f);
1021
1022 // Write LISR OP CODE and IRQ : (0xC0 | IRQ)
1023
1024 ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
1025 [ ti_nuc_monitor_LISR_current_pos ] =
1026 (SYS_UWORD8) (C_OP_CODE_LISR_FLAG | IRQ_value);
1027
1028 // Write the timer value
1029
1030 timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
1031
1032 // insert LSB
1033
1034 ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
1035 [ ti_nuc_monitor_LISR_current_pos + 1 ] =
1036 (SYS_UWORD8) (timer_value & 0x00ff);
1037
1038 // insert MSB
1039
1040 ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
1041 [ ti_nuc_monitor_LISR_current_pos + 2 ] =
1042 (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
1043
1044 ti_nuc_monitor_LISR_current_pos += 3;
1045
1046 } // End if
1047
1048 } // ti_nuc_monitor_LISR_log
1049
1050 /*-------------------------------------------------------*/
1051 /* ti_nuc_monitor_LISR_log_end() */
1052 /*-------------------------------------------------------*/
1053 /* */
1054 /* Description: */
1055 /* ------------ */
1056 /* This function permits to include the LISR end */
1057 /* timer value in the LISR log buffer */
1058 /* Warning : To save cpu, no overflow check is done */
1059 /*-------------------------------------------------------*/
1060
1061 void ti_nuc_monitor_LISR_log_end( void )
1062 {
1063 SYS_UWORD16 timer_value;
1064
1065 if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
1066 {
1067 // Write the timer value
1068
1069 timer_value = TM_ReadTimer(2);
1070
1071 // insert LSB
1072
1073 ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
1074 [ ti_nuc_monitor_LISR_current_pos ] =
1075 (SYS_UWORD8) (timer_value & 0x00ff);
1076
1077 // insert MSB
1078
1079 ti_nuc_monitor_LISR_Buffer[ ti_nuc_monitor_LISR_current_page ]
1080 [ ti_nuc_monitor_LISR_current_pos + 1 ] =
1081 (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
1082
1083 ti_nuc_monitor_LISR_current_pos += 2;
1084
1085 // Switch LISR & thread buffer page if IRQ4 (TDMA)
1086 if( IRQ_value == 4 )
1087 {
1088 // copy current to next
1089 ti_nuc_monitor_LISR_next_pos = ti_nuc_monitor_LISR_current_pos;
1090 ti_nuc_monitor_LISR_next_page = ti_nuc_monitor_LISR_current_page;
1091
1092 // instead of changing the Thread page here, set a boolean
1093 ti_nuc_monitor_change_thread_page = 1;
1094
1095 //ti_nuc_monitor_Thread_next_pos = ti_nuc_monitor_Thread_current_pos;
1096 //ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
1097
1098 // Reset current pointer
1099 ti_nuc_monitor_LISR_current_pos = 0;
1100 //ti_nuc_monitor_Thread_current_pos = 0;
1101
1102 // Change page
1103 if( ti_nuc_monitor_LISR_current_page == 0 )
1104 {
1105 ti_nuc_monitor_LISR_current_page = 1;
1106 // ti_nuc_monitor_Thread_current_page = 1;
1107 }
1108 else
1109 {
1110 ti_nuc_monitor_LISR_current_page = 0;
1111 // ti_nuc_monitor_Thread_current_page = 0;
1112 } // End if
1113
1114 // reset IRQ_value
1115 IRQ_value = 0;
1116
1117 // reset timer
1118 TM_ResetTimer (2, 0xFFFF, 1, 0);
1119 TM_StartTimer (2);
1120
1121 // Doesn't work
1122 // * (volatile SYS_UWORD16 *) TIMER2_LOAD_TIM = 0xFFFF;
1123 // * (volatile SYS_UWORD16 *) TIMER2_CNTL = 0x0003;
1124
1125 } // End if
1126
1127 } // End if
1128
1129 } // ti_nuc_monitor_LISR_log_end
1130
1131 /*-------------------------------------------------------*/
1132 /* ti_nuc_monitor_Thread_log() */
1133 /*-------------------------------------------------------*/
1134 /* */
1135 /* Description: */
1136 /* ------------ */
1137 /* This function permits to include the Thread and */
1138 /* timer value in the log buffer */
1139 /*-------------------------------------------------------*/
1140
1141 void ti_nuc_monitor_Thread_log( void )
1142 {
1143 SYS_UWORD16 timer_value;
1144 SYS_UWORD8 i;
1145
1146 if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
1147 {
1148
1149 // Exit Idle mode if reached
1150
1151 ti_nuc_monitor_idle_reached = 0;
1152
1153 // Check if page must be changed
1154 if( ti_nuc_monitor_change_thread_page == 1 )
1155 {
1156
1157 ti_nuc_monitor_change_thread_page = 0;
1158
1159 // copy current to next
1160 ti_nuc_monitor_Thread_next_pos = ti_nuc_monitor_Thread_current_pos;
1161 ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
1162
1163 // Reset current pointer
1164 ti_nuc_monitor_Thread_current_pos = 0;
1165
1166 // Change page
1167 if( ti_nuc_monitor_Thread_current_page == 0 )
1168 {
1169 ti_nuc_monitor_Thread_current_page = 1;
1170 }
1171 else
1172 {
1173 ti_nuc_monitor_Thread_current_page = 0;
1174 } // End if
1175
1176 } // End if
1177
1178 // Search the ID considering the Nucleus_Current_thread Pointer
1179
1180 for( i = 0; i < ti_nuc_monitor_thread_pos ; i++ )
1181 {
1182 if( ti_nuc_monitor_thread_id[ i ] == (SYS_UWORD32) TCD_Current_Thread )
1183 {
1184 // insert the OP Code Thread | ID
1185 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1186 [ ti_nuc_monitor_Thread_current_pos ] =
1187 (SYS_UWORD8) (C_OP_CODE_THREAD_FLAG | i);
1188 // exit loop
1189 break;
1190 } // End if
1191 } // End for
1192
1193 // Write the timer value
1194
1195 timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
1196
1197 // insert LSB
1198
1199 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1200 [ ti_nuc_monitor_Thread_current_pos + 1 ] =
1201 (SYS_UWORD8) (timer_value & 0x00ff);
1202
1203 // insert MSB
1204
1205 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1206 [ ti_nuc_monitor_Thread_current_pos + 2 ] =
1207 (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
1208
1209 ti_nuc_monitor_Thread_current_pos += 3;
1210
1211 } // End if
1212
1213 } // ti_nuc_monitor_Thread_log
1214
1215 /*-------------------------------------------------------*/
1216 /* ti_nuc_monitor_Queue_log() */
1217 /*-------------------------------------------------------*/
1218 /* */
1219 /* Description: */
1220 /* ------------ */
1221 /* This function permits to include the Queue ID and */
1222 /* status value in the log buffer */
1223 /* Direction = 0 => Send message */
1224 /* Direction = 1 => Receive message */
1225 /* status = 0 => OK */
1226 /* status = 1 => Queue full */
1227 /*-------------------------------------------------------*/
1228
1229 void ti_nuc_monitor_Queue_log( SYS_UWORD32* queue_pointer, SYS_UWORD8 status, SYS_UWORD8 Direction )
1230 {
1231 SYS_UWORD8 status_word;
1232 SYS_UWORD8 i;
1233
1234
1235
1236 if( ti_nuc_monitor_state == NUC_MONITOR_RUNNING )
1237 {
1238
1239 // Exit Idle mode if reached
1240
1241 ti_nuc_monitor_idle_reached = 0;
1242
1243 // Check if page must be changed
1244 if( ti_nuc_monitor_change_thread_page == 1 )
1245 {
1246
1247 ti_nuc_monitor_change_thread_page = 0;
1248
1249 // copy current to next
1250 ti_nuc_monitor_Thread_next_pos = ti_nuc_monitor_Thread_current_pos;
1251 ti_nuc_monitor_Thread_next_page = ti_nuc_monitor_Thread_current_page;
1252
1253 // Reset current pointer
1254 ti_nuc_monitor_Thread_current_pos = 0;
1255
1256 // Change page
1257 if( ti_nuc_monitor_Thread_current_page == 0 )
1258 {
1259 ti_nuc_monitor_Thread_current_page = 1;
1260 }
1261 else
1262 {
1263 ti_nuc_monitor_Thread_current_page = 0;
1264 } // End if
1265
1266 } // End if
1267
1268 // Search the ID considering the Nucleus_Current_thread Pointer
1269 for( i = 0; i < ti_nuc_monitor_queue_pos ; i++ )
1270 {
1271 if( ti_nuc_monitor_queue_id[ i ] == (SYS_UWORD32) queue_pointer)
1272 {
1273 // insert the OP Code Thread | ID
1274 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1275 [ ti_nuc_monitor_Thread_current_pos ] =
1276 (SYS_UWORD8) (C_OP_CODE_QUEUE_FLAG | i);
1277
1278 // exit loop
1279 break;
1280
1281 } // End if
1282 } // End for
1283
1284 // Write the status value and Receive/send flag
1285
1286 status_word = (Direction << 8) | (status << 7) | i; // Direction | Status | ID
1287
1288 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1289 [ ti_nuc_monitor_Thread_current_pos + 1 ] =
1290 (SYS_UWORD8) (status_word);
1291
1292 ti_nuc_monitor_Thread_current_pos += 2;
1293
1294 } // End if
1295
1296 } // ti_nuc_monitor_Queue_log
1297
1298
1299
1300 /*-------------------------------------------------------*/
1301 /* ti_nuc_monitor_sleep() */
1302 /*-------------------------------------------------------*/
1303 /* */
1304 /* Description: */
1305 /* ------------ */
1306 /* This function permits to include the sleep and */
1307 /* timer value in the log buffer */
1308 /*-------------------------------------------------------*/
1309
1310 void ti_nuc_monitor_sleep( void )
1311 {
1312
1313 SYS_UWORD16 timer_value;
1314 SYS_UWORD8 i;
1315
1316 if(( ti_nuc_monitor_state == NUC_MONITOR_RUNNING ) &&
1317 ( ti_nuc_monitor_idle_reached == 0 ))
1318 {
1319
1320 ti_nuc_monitor_idle_reached = 1;
1321
1322 // insert the OP Code Thread | ID
1323 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1324 [ ti_nuc_monitor_Thread_current_pos ] =
1325 (SYS_UWORD8) (0xBF);
1326
1327 // Write the timer value
1328
1329 timer_value = TM_ReadTimer(2); // (* (SYS_UWORD16 *) TIMER2_READ_TIM)
1330
1331 // insert LSB
1332
1333 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1334 [ ti_nuc_monitor_Thread_current_pos + 1 ] =
1335 (SYS_UWORD8) (timer_value & 0x00ff);
1336
1337 // insert MSB
1338
1339 ti_nuc_monitor_Thread_Buffer[ ti_nuc_monitor_Thread_current_page ]
1340 [ ti_nuc_monitor_Thread_current_pos + 2 ] =
1341 (SYS_UWORD8) ((timer_value & 0xff00) >> 8);
1342
1343 ti_nuc_monitor_Thread_current_pos += 3;
1344 } // End if
1345
1346 } // ti_nuc_monitor_sleep
1347
1348 // -------------- RVT Copied function --------------------------------
1349 // --- Modified Memory Bank ----
1350
1351 /********************************************************************************/
1352 /* */
1353 /* Function Name: ti_nuc_monitor_mem_alloc */
1354 /* */
1355 /* Purpose: this function creates a memory bank for the profiler task*/
1356 /* */
1357 /* Input Parameters: */
1358 /* refer to t_rvt_type.h */
1359 /* */
1360 /* Output Parameters: */
1361 /* refer to t_rvt_type.h */
1362 /* */
1363 /* Global Parameters: */
1364 /* None. */
1365 /* */
1366 /* Note: */
1367 /* None. */
1368 /* */
1369 /********************************************************************************/
1370
1371
1372 T_RVT_RET ti_nuc_monitor_mem_alloc(T_RVT_USER_ID user_id, T_RVT_MSG_LG buffer_lenght, T_RVT_BUFFER * buff)
1373 {
1374 T_RVF_MB_STATUS return_value;
1375
1376 return_value = rvf_get_buf (prof_mb_id, (UINT32) buffer_lenght + RVT_HEADER_SIZE, (T_RVF_BUFFER**) buff);
1377
1378 if (return_value == RVF_RED)
1379 {
1380 *buff = NULL;
1381 return RVT_MEMORY_ERR;
1382 }
1383 else
1384 {
1385 *buff = *buff + RVT_HEADER_SIZE;
1386 return RVT_OK;
1387 }
1388 } // ti_nuc_monitor_mem_alloc
1389
1390 // -------------------------------------------------------------------
1391
1392 #endif // TI_NUC_MONITOR
1393
1394 #if (TI_PROFILER == 1) || (TI_NUC_MONITOR == 1)
1395
1396 /*-------------------------------------------------------*/
1397 /* ti_prf_init() */
1398 /*-------------------------------------------------------*/
1399 /* */
1400 /* Description: Initialize profiling hisrs */
1401 /* ------------ */
1402 /* Register the profiling to rvt */
1403 /* */
1404 /*-------------------------------------------------------*/
1405
1406 void ti_prf_init( void )
1407 {
1408 #if (TI_PROFILER == 1)
1409 ti_profiler_init_profiler_module();
1410 #endif
1411 #if (TI_NUC_MONITOR == 1)
1412 ti_nuc_monitor_init_module();
1413 #endif
1414 // Register to Trace task module
1415 rvt_register_id( "PROF", &prof_trace_id, ti_profiler_trace_rx_callback );
1416
1417 } // ti_prf_init
1418
1419 /*-------------------------------------------------------*/
1420 /* ti_prf_core() */
1421 /*-------------------------------------------------------*/
1422 /* */
1423 /* Description: */
1424 /* ------------ */
1425 /* this function : */
1426 /* - start the profiler on PC side message reception */
1427 /* - stop the profiler on PC side message reception */
1428 /* - cut the profiler buffer less than 256 bytes */
1429 /* messages to rvt */
1430 /* */
1431 /*-------------------------------------------------------*/
1432
1433 T_RV_RET ti_prf_core(void)
1434 {
1435
1436 SYS_UWORD16 i = 0;
1437
1438 SYS_UWORD16 event;
1439 SYS_UWORD16 message_length;
1440 T_PROFILER_MSG *msg;
1441
1442 while( INFINITE_LOOP )
1443 {
1444
1445 // Suspend the task on empty queue
1446 event = rvf_wait( RVF_TASK_MBOX_0_EVT_MASK, 0 );
1447 msg = ( T_PROFILER_MSG* ) rvf_read_mbox( RVF_TASK_MBOX_0 );
1448
1449 // Check the msg ID code
1450 switch( msg->msg_id )
1451 {
1452
1453 #if (TI_PROFILER == 1)
1454 case TI_PROFILER_OUTPUT_BUFFER :
1455 // Cut the buffer in small element to be sent to
1456 // PC by the RVT.
1457 {
1458 message_length = TRACE_MESSAGE_SIZE;
1459 pos_pr_buffer = 0;
1460
1461 // loop until end of buffer
1462 while( pos_pr_buffer < pr_buffer_length )
1463 {
1464 // Update message length for next loop turn
1465 if ( pos_pr_buffer <= ( pr_buffer_length - TRACE_MESSAGE_SIZE ) )
1466 {
1467 message_length = TRACE_MESSAGE_SIZE;
1468 }
1469 else
1470 {
1471 message_length = pr_buffer_length - pos_pr_buffer;
1472 }
1473
1474 if( rvt_send_trace_cpy( ( T_RVT_BUFFER ) &pr_buffer[ pos_pr_buffer ],
1475 prof_trace_id,
1476 message_length * 4, // Length in bytes
1477 RVT_BINARY_FORMAT ) == RVT_OK )
1478 {
1479 // Update pr_buffer pointer
1480 pos_pr_buffer += message_length;
1481
1482 } // End if
1483
1484 } // End while
1485
1486 // Restart the profiling at vitam aeternam unless stop command received.
1487 if( profiler_state == PROFILER_FREEZED )
1488 {
1489 profiler_state = PROFILER_TO_BE_UNFREEZED;
1490 } // End if
1491
1492 break;
1493 } // TI_PROFILER_OUTPUT_BUFFER
1494
1495 case TI_PROFILER_START_PROFILING :
1496 {
1497 #if (L1_TRACER == 1)
1498 SendTraces("TI_PROF: msg TI_PROFILER_START\n\r");
1499 #endif
1500
1501 ti_profiler_event_state = (T_PROFILER_EVENTS) (msg->event_number);
1502
1503 if( ti_profiler_event_state == NO_SLEEP_EVENT )
1504 {
1505 ti_profiler_nb_sleep_counter_ref = msg->arg1; // nb_tdma
1506 } // End if
1507
1508 // Source of Activation
1509 ti_profiler_active = ACTIVE_BY_HOST;
1510
1511 // change state of profiler
1512 profiler_state = PROFILER_TO_BE_RAN;
1513
1514 break;
1515 } // TI_PROFILER_START_PROFILING
1516
1517 case TI_PROFILER_END_PROFILING :
1518 {
1519 #if (L1_TRACER == 1)
1520 SendTraces("TI_PROF: msg TI_PROFILER_STOP\n\r");
1521 #endif
1522
1523 profiler_state = PROFILER_TO_BE_STOPPED;
1524 break;
1525 } // TI_PROFILER_END_PROFILING
1526
1527 #endif
1528
1529 #if (TI_NUC_MONITOR == 1)
1530
1531 case TI_NUC_MONITOR_START :
1532 {
1533 SYS_UWORD8 i = 0;
1534 SYS_UWORD8 j = 0;
1535 #if (L1_TRACER == 1)
1536 SendTraces("TI_PROF: msg TI_NUC_MONITOR_START\n\r");
1537 #endif
1538
1539 if( ti_nuc_monitor_state == NUC_MONITOR_STOPPED )
1540 {
1541
1542 // Output the task and queues create info.
1543 // buffer format is following :
1544 // C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
1545 // < Thread ID0 > | (1 byte)
1546 // < Thread name > | (8 bytes)
1547 // < Thread ID1 > | (1 byte)
1548 // < Thread name > | (8 bytes)
1549 // ..............
1550 // C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
1551 // < Queue ID0 > | (1 byte)
1552 // < Queue name > | (8 bytes)
1553 // < Queue ID1 > | (1 byte)
1554 // < Queue name > | (8 bytes)
1555 // ..............
1556 // C_OP_CODE_NUC_MON_THREAD_IDS | (1 byte)
1557
1558 // Allocate one buffer.
1559
1560 while ((ti_nuc_monitor_mem_alloc (prof_trace_id,
1561 NUC_MONITOR_BUFFER_SIZE,
1562 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
1563 != RVT_OK);
1564
1565
1566 // Output the ID (thread and Queue array)
1567
1568 ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
1569
1570 // Output the Thread IDs and corresponding Thread name.
1571
1572 for( i = 0 ; i < ti_nuc_monitor_thread_pos ; i++ )
1573 {
1574 // distinghuish Task and HISR
1575 if( (( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_id == TC_HISR_ID)
1576 {
1577 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = (0x80 | i); // ID
1578 }
1579 else
1580 {
1581 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = i; // ID
1582 } // End if
1583
1584 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1585 {
1586 ti_nuc_monitor_check_ID_buffer();
1587 } // End if
1588
1589 // Write task priority
1590 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
1591 (SYS_UWORD8) ((( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_priority);
1592
1593 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1594 {
1595 ti_nuc_monitor_check_ID_buffer();
1596 } // End if
1597
1598 // Write name in the Log buffer.
1599 for( j = 0 ; j < NU_MAX_NAME ; j++ )
1600 {
1601 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
1602 (SYS_UWORD8) ((( TC_TCB * ) ( ti_nuc_monitor_thread_id[ i ]))->tc_name[ j ]); // Thread_name
1603 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1604 {
1605 ti_nuc_monitor_check_ID_buffer();
1606 } // End if
1607 } // End for
1608
1609 } // End for
1610
1611 // Output the ID (thread and Queue array)
1612 if( ti_nuc_monitor_queue_pos != 0 )
1613 {
1614 ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
1615
1616 // Output the Queue IDs and corresponding Queue name.
1617
1618 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1619 {
1620 ti_nuc_monitor_check_ID_buffer();
1621 } // End if
1622
1623 for( i = 0 ; i < ti_nuc_monitor_queue_pos ; i++ )
1624 {
1625 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] = i; // ID
1626
1627 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1628 {
1629 ti_nuc_monitor_check_ID_buffer();
1630 } // End if
1631
1632 // Write name in the Log buffer.
1633 for( j = 0 ; j < NU_MAX_NAME ; j++ )
1634 {
1635 ti_nuc_monitor_current_buffer[ ti_nuc_monitor_current_position++ ] =
1636 (SYS_UWORD8) ((( QU_QCB * ) ( ti_nuc_monitor_queue_id[ i ] ))->qu_name[ j ]); // Thread_name
1637 if( ti_nuc_monitor_current_position >= NUC_MONITOR_BUFFER_SIZE )
1638 {
1639 ti_nuc_monitor_check_ID_buffer();
1640 } // End if
1641 } // End for
1642
1643 } // End for
1644 } // End if
1645
1646 // Insert end op code (same as begin op code)
1647
1648 ti_nuc_monitor_current_buffer[ti_nuc_monitor_current_position++] = C_OP_CODE_NUC_MON_THREAD_IDS;
1649
1650 // flush the last buffer.
1651
1652 // Send a message to the Riviera Tracer to Output the current buffer.
1653 if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) ti_nuc_monitor_current_buffer,
1654 prof_trace_id,
1655 ti_nuc_monitor_current_position, // Length in bytes
1656 RVT_BINARY_FORMAT ) != RVT_OK )
1657 {
1658 // Code to insert break point.
1659 ti_nuc_monitor_state = NUC_MONITOR_STOPPED;
1660 } // End if
1661
1662 // Configuration buffer has been logged out.
1663
1664 /*
1665 ** Allocate a buffer for Nucleus profiling
1666 */
1667
1668 while ((ti_nuc_monitor_mem_alloc (prof_trace_id,
1669 NUC_MONITOR_BUFFER_SIZE,
1670 (T_RVT_BUFFER*) &ti_nuc_monitor_current_buffer))
1671 != RVT_OK);
1672
1673 // reset the current pointer.
1674 ti_nuc_monitor_current_position = 0;
1675
1676 // Set the new Monitoring state.
1677 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_STARTED;
1678 } // End if
1679
1680 break;
1681
1682 } // TI_NUC_MONITOR_START
1683
1684 case TI_NUC_MONITOR_OUTPUT_BUFFER :
1685 {
1686 // The buffer is output only if it is full.
1687
1688 // Send a message to the Riviera Tracer to Output the current buffer.
1689 if( rvt_send_trace_no_cpy( ( T_RVT_BUFFER ) msg->p_buffer,
1690 prof_trace_id,
1691 msg->buffer_size, // Length in bytes
1692 RVT_BINARY_FORMAT ) != RVT_OK )
1693 {
1694 // increment lost messages variable
1695 ti_nuc_monitor_lost_messages++;
1696 } // End if
1697
1698 break;
1699
1700 } // TI_NUC_MONITOR_OUTPUT_BUFFER
1701
1702 case TI_NUC_MONITOR_STOP :
1703 {
1704 #if (L1_TRACER == 1)
1705 SendTraces("TI_PROF: msg TI_NUC_MONITOR_STOP\n\r");
1706 #endif
1707
1708 ti_nuc_monitor_state = NUC_MONITOR_TO_BE_STOP;
1709
1710 break;
1711
1712 } // TI_NUC_MONITOR_STOP
1713
1714 #endif
1715
1716 default :
1717 {
1718 #if (L1_TRACER == 1)
1719 SendTraces("TI_PROF: msg default\n\r");
1720 #endif
1721
1722 break;
1723 } // default
1724
1725 } // End switch
1726
1727
1728 // Free the msg alloc
1729 rvf_free_buf( msg );
1730
1731 } // End while ( INFINITE_LOOP )
1732
1733 } // ti_profiler_task
1734
1735
1736 /*-------------------------------------------------------*/
1737 /* ti_profiler_trace_rx_callback() */
1738 /*-------------------------------------------------------*/
1739 /* */
1740 /* Description: */
1741 /* ------------ */
1742 /* callback function called when the trace */
1743 /* module receives a msg for the profiler */
1744 /* or the nucleus monitor. */
1745 /* */
1746 /*-------------------------------------------------------*/
1747
1748 void ti_profiler_trace_rx_callback(T_RVT_BUFFER trace_msg, UINT16 trace_msg_size)
1749 {
1750 T_PROFILER_MSG * msg;
1751
1752 // send a message to the ti profiler received from Rvt
1753 if( rvf_get_buf( prof_mb_id, sizeof( T_PROFILER_MSG ), ( T_RVF_BUFFER** ) &msg ) == RVF_GREEN )
1754 {
1755 /*
1756 if( trace_msg[0] == 1 )
1757 msg->msg_id = TI_PROFILER_START_PROFILING;
1758 else if ( trace_msg[0] == 0 )
1759 msg->msg_id = TI_PROFILER_END_PROFILING;
1760 else if ( trace_msg[0] == 2 )
1761 msg->msg_id = TI_NUC_MONITOR_START;
1762 else if ( trace_msg[0] == 3 )
1763 msg->msg_id = TI_NUC_MONITOR_STOP;
1764 */
1765 msg->msg_id = ((T_PROFILER_MSG_UART*) trace_msg)->msg_id;
1766 msg->event_number = ((T_PROFILER_MSG_UART*) trace_msg)->event_number;
1767 msg->arg1 = ((T_PROFILER_MSG_UART*) trace_msg)->arg1;
1768
1769 rvf_send_msg( prof_addr_id, msg );
1770 }
1771
1772 } // ti_profiler_trace_rx_callback
1773
1774 #endif // NUC_MONITOR || PROFILER
1775