-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvntrUtil.c
executable file
·1795 lines (1439 loc) · 45.2 KB
/
vntrUtil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
// FILE NAME: vntrUtil.c
//
// DESCRIPTION: This file contains utility routines for the transrating
// library module
//
// DOCUMENT REF: VNC Software coding guidelines
//
// NOTES: -
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Standard include files:
//-----------------------------------------------------------------------------
//
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <csl_timerhal.h>
#include <stdarg.h>
#include <csl_timer.h>
#include <assert.h>
#include <csl_cache.h>
#include <csl_gpiohal.h>
//-----------------------------------------------------------------------------
// Project include files:
//-----------------------------------------------------------------------------
//
#include "vntrShellDefs.h"
#include "vntrUtil.h"
#include "vntrCmdMsg.h"
#include "vntrMuxEngine.h"
#include "vntrIoBufs.h"
#include "vntrDemux.h"
//-----------------------------------------------------------------------------
// Types and defines:
//-----------------------------------------------------------------------------
//
#define USE_DATA_SECTION 0 // FOR DMA TEST
//#define VERBOSE_PROFILING
#define TIMER_BUFFER_SIZE 10000
#define DBG_TIME_LEN (28) // Max length of time string
#define DBG_MAX_LINE_LEN (256) // Max output line length
#define DBG_FORMAT_LEN (128) // Max length of the format string
#define MEASURE_PERIOD (5) // Num secs to check/report min idle usage
#define MIN_CPU_IDLE_PERCENT (10) // Threshold to report error to host
typedef struct
{
UInt32* pBuf; // buffer start address
UInt32 size; // size in bytes of buffer
UInt32 writePosition; // offset in bytes from start
UInt16 wrap; // 1 if buffer has wrapped
UInt16 reserved;
}
DebugCtrl_t, *pDebugCtrl_t;
// profiling
typedef struct
{
UInt32 start;
UInt32 total;
} ContextMeasure_t;
typedef struct
{
ContextMeasure_t context[MAX_CONTEXTS];
UInt32 prev;
UInt32 curr;
} ContextCtrl_t;
char* gTaskStrs[MAX_CONTEXTS] =
{
"IDLE ",
"SHELL",
"CORE ",
"MUX "
};
//-----------------------------------------------------------------------------
// Global data:
//-----------------------------------------------------------------------------
//
extern UInt32 gInputLost;
extern void vectors();
extern UInt32 gCpuMeasure;
extern TIMER_Handle gTimer2Handle ;
UInt32 gElapsedTime = 0;
UInt32 vcc=0, acc=0;
//UInt32 total_time = 0;
TIMER_Handle gTimer2Handle = Null;
volatile UInt32 gTimerSecs = 0;
UInt32 gTimerCnt = 0;
UInt32 gIdleCnt = 0xffffffff;
unsigned int ptimer0_cnt = 0;
extern int gRxCnt;
extern int gTxCnt;
extern int gRxRptCnt;
extern int gRxMisCnt;
extern int gDspId;
//static int gDataSeed0 = 0x100 ;
static char gTimeBuf[DBG_TIME_LEN+1];
static char gFormatBuf[DBG_MAX_LINE_LEN];
static char gLineBuf[DBG_MAX_LINE_LEN+1];
static char logStuffing[7][9] = {
{0x0A,0x00},
{0x20,0x0A,0x00},
{0x20,0x20,0x0A,0x00},
{0x20,0x20,0x20,0x0A,0x00},
{0x20,0x20,0x20,0x20,0x0A,0x00},
{0x20,0x20,0x20,0x20,0x20,0x0A,0x00},
{0x20,0x20,0x20,0x20,0x20,0x20,0x0A,0x00}
};
static int gTimer2Init = 0;
static UInt32 gUtilDbgMessageLevel = DBG_INFO;
static int gUtilInit = False;
static pDebugCtrl_t gpDebugCtrl;
#pragma DATA_SECTION (dbg_ctl, ".shell_dbg_ctl");
static unsigned char dbg_ctl[sizeof(DebugCtrl_t)];
static pDebugCtrl_t gpDebugCtrl ;
#pragma DATA_SECTION (dbgBuffer, ".shell_dbg_buffer");
static unsigned char dbgBuffer[DEBUG_BUFFER_SIZE];
#if USE_DATA_SECTION
#pragma DATA_SECTION (dmaBuf, ".dma_buffer_ptr");
static unsigned char dmaBuf[0x100000];
#endif
static ContextCtrl_t gContextCtrl;
static UInt32 gMeasurePeriod = MEASURE_PERIOD;
static UInt32 gMinCpuThreshold = MIN_CPU_IDLE_PERCENT;
static float gMinIdleUsage = 0xffffffff;
//-----------------------------------------------------------------------------
// Internal Prototypes:
//-----------------------------------------------------------------------------
//
static int UtilPrn(char* line);
static int TimeStampFormat(char* pTimeBuf, size_t bufsize);
//-----------------------------------------------------------------------------
// Exported functions:
//-----------------------------------------------------------------------------
//
void reset_timer0();
unsigned int print_timer0();
extern void vntrCleanPmcDmaInputStack();
void DataReceive(int channelId,int* pPattern);
void DataSend(int channelId,int senderId,int destId,int* pPattern);
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilInit
//
// DESCRIPTION:
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
void vntrUtilInit(int initdebug)
{
gUtilInit = True;
if (initdebug)
{
gpDebugCtrl = (pDebugCtrl_t)dbg_ctl;
gpDebugCtrl->pBuf = (UInt32*)dbgBuffer;
memset(dbgBuffer,0,DEBUG_BUFFER_SIZE);
gpDebugCtrl->writePosition = 0;
gpDebugCtrl->size = DEBUG_BUFFER_SIZE;
gpDebugCtrl->wrap = 0;
gpDebugCtrl->reserved = 0;
}
// Reset profiling
vntrUtilContextReset();
}
//-----------------------------------------------------------------------------
// FUNCTION: vntrTimer1Isr
//
// DESCRIPTION: Interrupt service routine for timer1 of the DM642
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
UInt32 timer1_heartbeat=0;
interrupt void vntrTimer1Isr()
{
Uint32 gie;
gie = IRQ_globalDisable();
#if 0 //TRACE_DETAIL
if (timer1_heartbeat++%36000 == 0) // every 10mns
TRACE1(DBG_INFO,"t1_heartbeat %08x\n", timer1_heartbeat);
#endif
// Call main MUX function
#if MUX
CONTEXT_SWITCH(CONTEXT_MUX);
vntrMuxFieldInterrupt();
CONTEXT_SWITCH(CONTEXT_PREV);
#endif
IRQ_globalRestore(gie);
}
//-----------------------------------------------------------------------------
// FUNCTION: vntrTimer2Isr
//
// DESCRIPTION: Interrupt service routine for timer2 of the DM642
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
UInt32 timer2_heartbeat=0;
interrupt void vntrTimer2Isr()
{
Uint32 gie;
gie = IRQ_globalDisable();
#if 0 //TRACE_DETAIL
if (timer2_heartbeat++%600 == 0) // every 10mns
TRACE1(DBG_INFO,"t2_heartbeat %08x\n", timer2_heartbeat);
#endif
gTimerSecs++;
gElapsedTime++;
if (gCpuMeasure)
{
vntrUtilContextCheck();
vntrUtilContextReset();
}
TIMER_setCount(gTimer2Handle,0);
IRQ_globalRestore(gie);
}
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilInitTimer0
//
// DESCRIPTION: This function initialises timer 0 on the DM642, this timer is
// intended to be used for profiling purpose
// RETURN:
//
// NOTES: The counter register increments every cycle*8, cycle = 1/DSP
// clock value (600MHz, 720MHz, ..). It will return to 0 when it
// reaches the value set in the periode register
// At 600MHz, the counter increments every 8/600000 = 13.3333ns
// Will return to 0 every 0xffffffff*13.33ns # 57sec.
//-----------------------------------------------------------------------------
void vntrUtilInitTimer0()
{
char* p;
p = (char*)_TIMER_CTL0_ADDR;
*(int*)p = 0x000002C0;
p = (char*)_TIMER_PRD0_ADDR; // Timer period register
*(int*)p = 0xffffffff;
p = (char*)_TIMER_CNT0_ADDR; // Timer counter register
*(int*)p = 0x00000000; // reset to 0
ptimer0_cnt = *(int*)p;
}
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilInitTimer1
//
// DESCRIPTION: This function initialises timer 1 on the DM642, this timer is
// intended to generate a field interrupt
// RETURN:
//
// NOTES: The counter register increments every cycle*8, cycle = 1/DSP
// clock value (600MHz, 720MHz, ..).
//-----------------------------------------------------------------------------
#if 1
void vntrUtilInitTimer1()
{
char* p;
// *********** Init Timer1 interrupt **********
IRQ_nmiDisable();
IRQ_globalDisable();
//Point to the IRQ vector table
IRQ_setVecs(vectors);
IRQ_map(IRQ_EVT_TINT1,15);
//Reset the TIMER1 INT event
IRQ_reset(IRQ_EVT_TINT1);
IRQ_enable(IRQ_EVT_TINT1);
p = (char*)_TIMER_CTL1_ADDR;
*(int*)p = _TIMER_CTL_GO_MASK|_TIMER_CTL_HLD_MASK|_TIMER_CTL_CLKSRC_MASK; //0x000002C0;
p = (char*)_TIMER_PRD1_ADDR; // Timer period register
#if TEST_PAL
*(int*)p = (isPAL) ? TIMER1_RELOAD_PAL : TIMER1_RELOAD;
TRACE2(DBG_INFO,"Timer 1 reload is %d. Cpu freq id %d\n",*(int*)p,cpuFreq);
#else
*(int*)p = TIMER1_RELOAD;
TRACE2(DBG_INFO,"Timer 1 reload is %d. Cpu freq id %d\n",TIMER1_RELOAD,cpuFreq);
#endif
p = (char*)_TIMER_CNT1_ADDR; // Timer counter register
*(int*)p = 0x00000000; // reset to 0
// Enable interrupts when everything is intialized
IRQ_globalEnable();
IRQ_nmiEnable();
}
#endif
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilInitTimer2
//
// DESCRIPTION: This function initialises timer 0 on the DM642, this timer is
// intended to be used for profiling purpose
// RETURN:
//
// NOTES:
//-----------------------------------------------------------------------------
#if 1
void vntrUtilInitTimer2()
{
TIMER_Config timerConfig;
timerConfig.ctl = 0x2c0;
timerConfig.prd = TIMER2_RELOAD;
timerConfig.cnt = 0;
if (gTimer2Init)
{
TRACE0(DBG_WARN,"Timer2 already init!\n");
return;
}
gTimer2Handle = TIMER_open(TIMER_DEV2,TIMER_OPEN_RESET);
if (gTimer2Handle == INV)
{
TRACE0(DBG_ERR,"Timer2 open failed!\n");
return;
}
TIMER_config(gTimer2Handle, &timerConfig);
IRQ_nmiDisable();
IRQ_globalDisable();
IRQ_setVecs(vectors);
//Map DSPINT event to physical interrupt number
IRQ_map(IRQ_EVT_TINT2, 10);
IRQ_reset(IRQ_EVT_TINT2);
IRQ_enable(IRQ_EVT_TINT2);
// Enable interrupts when everything is intialized
IRQ_globalEnable();
IRQ_nmiEnable();
TRACE1(DBG_INFO,"timer 2 init! reload = %d\n",TIMER2_RELOAD);
gTimer2Init = 1;
}
#endif
/*
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilContextSwitch
//
// DESCRIPTION: Call when entering into new Code area
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
*/
void vntrUtilContextSwitch(int nextContext)
{
UInt32 end;
UInt32 start;
UInt32 idx;
// Calculate timer ticks on exit of current Context
idx = gContextCtrl.curr;
start = gContextCtrl.context[idx].start;
end = TIMER_getCount(gTimer2Handle);
if (end >= start)
gContextCtrl.context[idx].total += ((end - start));
else
// Handle wrap
gContextCtrl.context[idx].total += (TIMER2_RELOAD - start + end);
if (gContextCtrl.context[idx].total > (cpuFreq>>3))
{
// Not sure why but ig is 1 timer
TRACE4(DBG_VERB,"Context total overflow [%d] - %d %d %d\n",
idx,gContextCtrl.context[idx].total,start,end);
gContextCtrl.context[idx].total-=(cpuFreq>>3);
}
// Determine next context
if (nextContext == CONTEXT_PREV)
{
gContextCtrl.curr = gContextCtrl.prev;
}
else
{
gContextCtrl.prev = gContextCtrl.curr;
gContextCtrl.curr = (UInt32)nextContext;
}
// Store current timer ticks
idx = gContextCtrl.curr;
gContextCtrl.context[idx].start = TIMER_getCount(gTimer2Handle);
}
/*
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilContextReset
//
// DESCRIPTION: Call to reset measurements
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
*/
void vntrUtilContextReset(void)
{
memset((void*)&gContextCtrl, 0, sizeof(gContextCtrl));
gContextCtrl.context[CONTEXT_IDLE].start = TIMER_getCount(gTimer2Handle);
}
/*
//-----------------------------------------------------------------------------
// FUNCTION: vntrUtilContextCheck
//
// DESCRIPTION: Call to print results
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
*/
void vntrUtilContextCheck(void)
{
UInt32 idx;
UInt32 total=0;
float cpuUsage;
if (gTimerSecs < 15)
return;
vntrUtilContextSwitch(CONTEXT_IDLE);
#ifdef VERBOSE_PROFILING
TRACE0(DBG_INFO, "Task Measurements: \n");
#endif
for (idx = 0; idx < MAX_CONTEXTS; idx++)
{
gContextCtrl.context[idx].total <<= 3;
cpuUsage = gContextCtrl.context[idx].total/(float)(cpuFreq/100);
// Watch idle/available cpu
if (idx == CONTEXT_IDLE && cpuUsage < gMinIdleUsage)
gMinIdleUsage = cpuUsage;
#ifdef VERBOSE_PROFILING
TRACE3(DBG_INFO,"%s : %9d (%4f %%)\n",
gTaskStrs[idx],
gContextCtrl.context[idx].total,
cpuUsage);
#endif
#ifdef EXCEL_PROFILING
vntmUtilPrn(DBG_MOD_ID,DBG_INFO,"%16d",
gContextCtrl.context[idx].total);
#endif
total += gContextCtrl.context[idx].total;
}
#ifdef EXCEL_PROFILING
vntmUtilPrn(DBG_MOD_ID,DBG_INFO,"\n");
#endif
#ifdef VERBOSE_PROFILING
// TRACE0(DBG_INFO, "-------------------\n");
// TRACE1(DBG_INFO,"Total: %d\n\n",total);
#endif
if (gTimerSecs > gMeasurePeriod
&& gTimerSecs % gMeasurePeriod == 0)
{
if (gMinIdleUsage < gMinCpuThreshold)
{
TRACE1(DBG_INFO,"Reporting CPU overload, Min Idle = %f %%\n", gMinIdleUsage);
#if MSG
// vntrMsgSend(MSG_ERROR, MSG_ERR_CPU, 0);
#endif
}
gMinIdleUsage = 0xffffffff;
}
}
//-----------------------------------------------------------------------------
// FUNCTION: set_timer
//
// DESCRIPTION: This function sets timer1 of the DM642 to the specified value
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
void set_timer1(int value)
{
char* p;
p = (char*)_TIMER_CNT1_ADDR;
*(int*)p = value;
}
//-----------------------------------------------------------------------------
// FUNCTION: get_timer1
//
// DESCRIPTION: This function gets the counter value of timer1 of the DM642
//
// RETURN: None
//
// NOTES:
//-----------------------------------------------------------------------------
unsigned int get_timer1()
{
char* p;
p = (char*)_TIMER_CNT1_ADDR; // Timer counter register
return ( *(int*)p );
}
//-----------------------------------------------------------------------------
// FUNCTION: DMA_In_Out_Test
//
// DESCRIPTION: This function passes input direct to output.
//
// RETURN: void:
//
// NOTES: AKA passthru mode
//
//----------------------------------------------------------------------------
int prdma=0;
extern UInt32 gDspNum;
UInt8 gdmabuff[50000];
#define DMA_TEST_BUFFER_SIZE 0x40000
extern int gTransfer_started;
#define INTER_DSP_DMA_TEST 1
extern unsigned char test_dma[];
volatile char txfr_done[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
void DMA_In_Out_Test()
{
UInt32 contigDataAvailable, contigSpaceAvailable, data, dataToProcess;
UInt32 total_data_received=0, total_data_sent=0, data_to_send;
UInt8 *pdmabuff;
UInt8 *psource;
volatile UInt8* dmaTestBuffer = (volatile UInt8*)test_dma;
UInt8 dmaPattern = 0;
int i;
UInt32 dest;
prdma = 0;
pdmabuff = &gdmabuff[0];
dataToProcess = 0;
TRACE2(DBG_INFO,"In DMA_In_Out_Test() ap state is %d buffer %08x\n",ApStateGet(), pdmabuff);
for (i=0; i<DMA_TEST_BUFFER_SIZE; i++)
{
dmaTestBuffer[i]=0x55;
}
while(ApStateGet() == AP_STATE_RUNNING)
{
#if 1
data = 0;
if ( (contigDataAvailable=GetInstreamContigDataAvail()) >= MAX_MSG)
{
// Put data in intermediate buffer
if (contigDataAvailable > MAX_MSG)
contigDataAvailable = MAX_MSG;
dataToProcess += contigDataAvailable;
assert(contigDataAvailable < 50000);
if ( (prdma%100)==0 || prdma<10)
{
TRACE3(DBG_INFO,"memcpy %08x %08x %i\n",pdmabuff, *instream_rdpt
, contigDataAvailable);
}
psource = (UInt8*)*instream_rdpt;
memcpy(pdmabuff,psource,contigDataAvailable);
if ( (prdma%100)==0 || prdma<10)
{
prdma++;
TRACE2(DBG_INFO,"R %i %i\n",contigDataAvailable,prdma);
}
//testMpegPacketLoss((char*)buffer, contigDataAvailable);
total_data_received += contigDataAvailable;
// Update instream buffer read pointer
InstreamUpdateRdPtr(contigDataAvailable);
data = contigDataAvailable;
}
// ****************************
// Now copy in outstream buffer
// ****************************
while(data && (ApStateGet()==AP_STATE_RUNNING) )
{
contigSpaceAvailable = GetOutstreamContigSpaceAvail();
if(contigSpaceAvailable >= data)
{
data_to_send = data;
data = 0;
}
else
{
data_to_send = contigSpaceAvailable;
data -= contigSpaceAvailable;
}
total_data_sent += data_to_send;
if ( !((*outstream_wrpt>=OUTSTREAM_BUFF_ADDR) && (*outstream_wrpt<OUTSTREAM_BUFF_END_ADDR)) )
{
TRACE0(DBG_INFO,"outstream_wrpt out of range,stop\n")
IRQ_globalDisable();
for ( ; ; );
}
if ( (prdma%100)==0 || prdma<10)
{
TRACE3(DBG_INFO,"memcpy %08x %08x %i\n",*outstream_wrpt, pdmabuff
, data_to_send);
}
memcpy((char*)*outstream_wrpt,pdmabuff,data_to_send);
if ( (prdma%100)==0 || prdma<10)
{
prdma++;
TRACE2(DBG_INFO,"S %i %i\n",data_to_send, prdma);
}
OutstreamUpdateWrPtr(data_to_send);
} // While(data)
{
unsigned uDsp = *((volatile unsigned char*)0xB0000000);
if ( gDspNum != uDsp )
{
TRACE0(DBG_INFO,"gDspNum != uDsp out of range,stop\n")
IRQ_globalDisable();
for ( ; ; );
}
}
// Process 20000 bytes of data
if (dataToProcess >= 20000)
{
if (gDspNum%2==1)
{
#if INTER_DSP_DMA_TEST
// Dma test pattern to slave DSP
dmaPattern++;
TRACE1(DBG_INFO,"master dma : %02x\n",dmaPattern);
if (gDspNum == 1) dest = 2;
else if(gDspNum == 3) dest = 8;
StartSdramTransfer(dmaTestBuffer,DMA_TEST_BUFFER_SIZE,dest);
*(volatile char *)txfr_done = 1;
CACHE_wbInvL2((void*)txfr_done,8,CACHE_WAIT);
StartSdramTransfer((void*)txfr_done,8,dest);
for ( ; ; ) // wait for DSP TO DSP int
{
while ( !( *(volatile int*)_GPIO_GPVAL_ADDR & (1 << 4) ) ); // wait interrupt
if ( (*(volatile char*)0xB000000C) & 0x08 )
{
// read interrupt source
unsigned char DspMaskInterruptSource = *(volatile unsigned char *)0xB000000E;
// clear interrupt
*(volatile unsigned char *)0xB000000F = 2; // select dsp_to_dsp interrupt clear flags
*(volatile unsigned char *)0xB000000E = DspMaskInterruptSource;
*(volatile unsigned char *)0xB000000F = 0; // return to dsp_to_dsp interrupt set flags
break;
}
}
TRACE1(DBG_INFO,"Master got ack %02x\n",dmaPattern);
#endif
}
else
{
#if INTER_DSP_DMA_TEST
dmaPattern++;
TRACE1(DBG_INFO,"Slave wait dma : %02x\n",dmaPattern);
while( *(volatile char *)txfr_done != 1 )
{
CACHE_invL2((void*)txfr_done, 8, CACHE_WAIT) ;
}
*(volatile char *)txfr_done = 0 ;
CACHE_wbInvL2((void*)txfr_done,8,CACHE_WAIT);
TRACE1(DBG_INFO,"Slave wait dma, done : %02x\n",dmaPattern);
if (gDspNum == 2) dest = 1;
else if(gDspNum == 4) dest = 4;
StartSdramTransfer(dmaTestBuffer,DMA_TEST_BUFFER_SIZE,dest);
if ( *(volatile char *)txfr_done != 0 )
{
IRQ_globalDisable();
for ( ; ; );
}
*(volatile unsigned char *)0xB000000E = dest; // send interrupt to targeted DSPs
#endif
}
// Simulate frame processing, 5ms
// reset_timer0();
// while(getdelta_timer0() < 90000*5);
dataToProcess = 0;
}
#endif
} // while(ApStateGet() == AP_STATE_RUNNING)
#if 1
TRACE1(DBG_INFO,"DMA_In_Out_Test(), exit while loop, state %d\n",ApStateGet());
//IRQ_globalDisable();
//for ( ; ; );
#endif
}
void testMpegPacketLoss(char* buffer, int size)
{
int nb = size;
UInt32 vidpid;
UInt8* pp = (UInt8*)buffer;
while(nb > 0)
{
vidpid = ((UInt32)(*(pp+1)&0x1f)<<8) + *(pp+2);
pp+=3;
// Check video continuity
if(vidpid==demux_pid && (*pp&0x10) ) // VIDEO_PID (input) 48 (output)
{
if(vcc)
{
//TRACE0(DBG_INFO,"*");
if ( (char)(*pp&0xf) != (char)((vcc+1)&0xf) )
{
TRACE3(DBG_INFO,"*Video CC error E %02x R %02x (%08x)\n", (int)((vcc+1)&0xf),(int)(*pp&0xf),(int)pp );
}
vcc = *pp&0xf;
}
else
{
vcc = *pp&0xF;
}
}
// Check audio continuity
// if(*(pp-1)==shell_base.audioStream[0].pid)
if(vidpid==shell_base.audioStream[0].pid)
{
if(acc)
{
if ( (char)(*pp&0xf) != (char)((acc+1)&0xf) )
{
TRACE3(DBG_INFO,"Audio CC error E %02x R %02x (%08x)\n",(int)((acc+1)&0xf),(int)(*pp&0xf),(int)pp);
}
acc = *pp&0xf;
}
else
{
acc = *pp&0xF;
}
}
pp +=185;
nb -= 188;
}
}
//-------------------------------------------------------------
// FUNCTION: DebugBufferUpdateWrPtr:
//
// DESCRIPTION: This function prints the debug message. Simple version
// for now.
//
// RETURN: void:
//
// NOTES: Called from dp(). TRACE or assert would cause recursion
//
//-----------------------------------------------------------------------------
void DebugBufferUpdateWrPtr(UInt32 PutData)
{
gpDebugCtrl->writePosition += PutData;
if(gpDebugCtrl->writePosition == gpDebugCtrl->size)
{
gpDebugCtrl->wrap = 1;
gpDebugCtrl->writePosition = 0;
}
#if CACHE_CE1
CACHE_flush(CACHE_L2,(void*)(gpDebugCtrl),sizeof(DebugCtrl_t)/4);
#endif
}
//-----------------------------------------------------------------------------
// FUNCTION: vntmUtilPrn:
//
// DESCRIPTION: This function prints the debug message. Simple version
// for now.
//
// RETURN: void:
//
// NOTES: Assert calls this routine. Cannot assert here!
//
//-----------------------------------------------------------------------------
void
vntmUtilPrn(
UInt32 modId, // I: Module Id
UInt32 level, // I: Debug message level
char* pFormat, // I: String 'printf' style
...
)
{
UInt32 len;
int align;
va_list argList;
UInt32 gie;
gie = IRQ_globalDisable();
//return;
/* Check configured level */
if (level > gUtilDbgMessageLevel)
{
IRQ_globalRestore(gie);
return;
}
memset(gTimeBuf,0,sizeof(gTimeBuf));
TimeStampFormat(gTimeBuf,sizeof(gTimeBuf));
snprintf(gFormatBuf, DBG_MAX_LINE_LEN, "%s %s",gTimeBuf,pFormat);
// Generate the full string based on the parameters
va_start(argList, pFormat);
len = vsnprintf(gLineBuf, DBG_MAX_LINE_LEN, gFormatBuf, argList);
va_end(argList);
/* Check length*/
if (len >= DBG_MAX_LINE_LEN)
{
gLineBuf[DBG_MAX_LINE_LEN] = '\0';
if (UtilPrn("vntmUtilPrn: WARNING format string chopped\n"))
{
printf("HELP! UtilPrn() returned error! Cannot write to debug buffer!\n");
IRQ_globalRestore(gie);
return;
}
}
// Align data on 8 bytes for DMA
align = len%8;
if (align)
{
if (gLineBuf[len-1]=='\n')
gLineBuf[len-1] = 0x20;
align = 7-align;
strcat(gLineBuf, (char*)&logStuffing[align]);
}
#if STREAMING
// Output to debug buffer
if (UtilPrn(gLineBuf))
{
TRACE0(DBG_ERR,"HELP! UtilPrn() returned error! Cannot write to debug buffer!\n");
IRQ_globalRestore(gie);
return;