-
Notifications
You must be signed in to change notification settings - Fork 46
/
Main.c
3533 lines (3038 loc) · 144 KB
/
Main.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
/********************* (C) COPYRIGHT 2010 e-Design Co.,Ltd. ********************
File Name : Main.c
Version : DS203_APP Ver 2.5x Author : bure
*******************************************************************************/
#include "Interrupt.h"
#include "Function.h"
#include "Calibrat.h"
#include "Process.h"
#include "Draw.h"
#include "BIOS.h"
#include "Menu.h"
#include "File.h"
#include <string.h>
/*******************************************************************************
Version changes
APP V2.30: since this version no longer to compatible PCB_V2.6 the following version of the motherboard
Since this version is no longer compatible SYS_V1.31 the following version
Sleep timing was revised to 600 seconds (Main.c)
Modify, and add a new SYS library functions (BIOS.s)
Modify the boot information display program (Main.c)
APP V2.31: an increase of boot identify FPGA load configuration completion discriminant (Main.c)
Increase the Licence rights management functionality Demo program example (Ident.c, Main.c),,
Modified analog channel correction function entry and exit operations (calibrat.c)
Increase the the 144MHz alternately sampling mode function (Process.c)
APP V2.32 from the version from the IAR 4.42 and version 5.0 can be used in parallel
Source did not change, the increase of the folder IAR_V5_Prpject
APP V2.33 modified scan <1uS, display the refresh BUG (Process.c,)
Modified in the calibration state, the operation message BUG (Calibrat.c)
APP V2.34 changed by channel separate calibration (Calibrat.c & Main.c,)
Modify the calibration mode of operation (option Calibrat.c)
APP V2.35 modified in the calibration process BUG (Calibrat.c),
Modified, <5uS scan, the suspension can not BUG (Process.c)
To optimize the display data handler (Process.c)
Increase of the analog channel automatic zero balance function (Main.c, Process.c, Calibrat.c)
APP V2.36 part of the calibration operation into automatic mode (Calibrat.c, Process.c, Function.c)
Modify the boot loader to the operating parameters (Main.c)
APP V2.37 to further improve and optimize the display data handler (Process.c)
Modify the 32-bit signed and unsigned integer conversion process rounded BUG (Function.c,)
Increase the pulse width duty cycle of the time and frequency measurement function (Process.c, Menu.c)
APP V2.40 increase write U disk to create the file function (Main.c, and Flies.c dosfs.c)
Modify the save file number is displayed when BUG (Menu.c)
APP V2.41 increase the file format for the BUF's read / write sample buffer data files (Main.c, Flies.c, Menu.c)
Increased the file format for the CSV export sample buffer data files (Main.c Flies.c, Menu.c)
APP V2.42 for space-saving file system to SYS_V1.40 module (ASM.s, Flies.c, dosfs.c)
Changed use "SerialNo.WPT" file is stored parameter table (Flies.c)
Note: the APP V2.42 or later must be used in conjunction with the SYS V1.40 or later
APP V2.43 modify the adjustment of the analog channels stalls BUG (Main.c),
APP V2.44 modified to save the parameters in the calibration operation BUG (Calibrat.c),
Increase the power load parameters, the success of Tips (Main.c)
APP V2.45 modified to read and write BUF file recovery Display the corresponding menu BUG (Files.c)
Delete the read test information when the BUF file feedback (Main.c)
APP V2.50 rewrite based on the new FAT12 file system, file read and write procedures (Files.c, ASM.s)
Changes to TH, TL measurements the display BUG (Menu.c,)
Optimized with dimensionless values ??show the correlation function (Menu.c Function.c, Calibrat.c)
Modify the pulse width trigger the BUG (Process.c)
APP V2.51 modify Vmin and Vmax, Vpp measured BUG (Process.c)
*******************************************************************************/
#define APP_VERSION "GCCv1.7W6.5 APP(2.51+SmTech1.8+PMOS69 fixes)"
#define APP_REVISION "Revision(W6.5) by Wildcat "
#define LINE2 "!PRESS > !#! !?! !]! < O > < O > !"
#define LINE3 "! < ADJ > !< MENU > "
#define LINE5 "!SHORT> !HOLD! AUTO METERS SELECT SET TRG !BUFFER "
#define LINE6 " !reset TRIG sav/ld ITEM CHANNEL!(spec/env)"
#define LINE7 " !(config) !(XYper)/ (Change) "
#define LINE4 " (Raw-Nor)/ !(Spc)! "
#define LINE8 " (Spc Func) (Func) "
#define LINE9 " !CH on! "
#define LINE10 " LONG!> V/DIV !MAN STAND! T-BASE MTR PGE !MENU/MTR "
#define LINE11 " !short TRIG BY !short (w/mtrs! on)! "
#define LINE12 " !cut !cut !WAV CAL STDBY TIM!"
#define LINE13 " !(w/mtrs !off) "
#define LINE14 " !METERS! "
#define LINE15 " HOLD!> CHART !CAL! SAVE CURSOR TRIGGER !HOLD "
#define LINE16 " (adj)!config RSTRCT HOLDOFF MIN/MAX! "
typedef struct {char*ChartLine;}DisplayLine;
DisplayLine DisplayChart[15]= {{(char*)LINE2},{(char*)LINE3},{(char*)LINE5},{(char*)LINE6},{(char*)LINE7},{(char*)LINE4},{(char*)LINE8},
{(char*)LINE9},{(char*)LINE10},{(char*)LINE11},{(char*)LINE12},{(char*)LINE13},{(char*)LINE14},
{(char*)LINE15},{(char*)LINE16}};
//uc8 PROJECT_STR[20] = "Demo PROG. Ver 1.00";
u8 OldCurrent;
u8 OldDet;
u8 FlagFrameMode;
u8 OldFrame;
u8 FlagMeter;
u8 TrgAuto;
u16 OldPosX;
u16 OldPosY;
s16 PreviousTrigSelect[4];
u8 LastSelected=0;
u8 XposFlag=0;
u8 C_Dmeter[8]={4,8,9,10,11,4,10,11};
u8 UpdateMeter=4;
u8 Timeout=1;
extern u8 _vectors[];
u8 ShortBuffXpos;
u32 Tmp;
u8 SelectiveUpdate=0;
u8 UpdateFlag=0;
u8 BTwinkState=0;
u8 SaveCurrent[2]={0,0};
u8 ChStatus[4]={0,0,0,0};
u8 ABTrigStatus=0;
u8 ChOnStatus[2]={1,1};
u8 RefreshDisplay=0;
u8 OSStatus=0;
const char NoneStr[13]="None ";
//const char ErrorCode[5][6]={" OK "," FULL"," NONE"," ERR"," CNCL"};
const char DisableSTR[37]="SCOPE DISABLED- PRESS ANY KEY TO RUN";
u8 OldMeter;
u8 TrgAutoOld;
u16 OldTrack1X;
u16 OldTrack2X;
s16 _Vt1Old;
s16 _Vt2Old;
u16 XposRef; //Xpos compensated for interpolated ranges to show equivalent screen position
u8 UpdateCount=0;
u8 ShowFFT=0;
extern u8 UpdateWindow;
u8 ClearDir=0;
void UpdateBigMeters(void);
void EnableTitleMeters(u8 Service);
void UpdateMeterPage(void);
u8 ConfigFile(u8 service);
//void FileMessage(u8 i);
//u16 GetXpos(u16 XposRef);
u16 GetHoldoffIndPos(void);
void EnableChannel(u8 track);
void UpdateTriggerMem(void);
void SelUpdate(u8 detail);
void TriggFlagUpdate(void);
void MessageHandler(u8 number);
void CurDetailUpdate(void);
void ChannelStatus(u8 service);
void MeterUpdate(u8 start,u8 limit);
void TrigMemory(u8 i);
void PWMdutyControl(u8 Dir);
void PWMscaleReset(u8 Dir);
void BurstAdjust(u8 Dir);
void InitChart(void);
void ProcessEditName(void);
void ResetEditList(void);
u8 LeftToggleSpecialFunctions(void);
u8 CursorSpeedLogic(u8 enable);
void UpdateFrameMode(void);
NVIC_InitTypeDef NVIC_InitStructure;
typedef struct {char*Message;}SelectMessage;
u8 MessageNumber;
#define SAVESET " "
#define WAVCAL_ON " WAVE CALIBRATION - ON " //1
#define WAVCAL_OFF " WAVE CALIBRATION - OFF " //2
#define STDBYTIM_ON " STANDBY TIMER - ON " //3
#define STDBYTIM_OFF " STANDBY TIMER - OFF " //4
#define CURMETERS_ON "CURSOR SELECT METERS - ON " //5
#define CURMETERS_OFF "CURSOR SELECT METERS - OFF" //6
#define TRGHLD_ON " TRIGGER HOLDOFF - ON " //7
#define TRGHLD_OFF " TRIGGER HOLDOFF - OFF " //8
#define SHOWEDGE_ON " MIN/MAX HOLD ON " //9
#define SHOWEDGE_OFF " MIN/MAX HOLD OFF " //10
#define WAIT_RESET " WAITING FOR RESET... " //11
#define NOR_DISPLAY " NORMAL WAVEFORM DISPLAY " //12
#define RAW_DATA " RAW DATA DISPLAY " //13
#define CUR_DIS_ON " CURSOR DISPLAY ON " //14
#define CUR_DIS_OFF " CURSOR DISPLAY OFF " //15
//#define SHOWEDGE_ON " EDGE FILTER OFF " //9
//#define SHOWEDGE_OFF " EDGE FILTER ON " //10
SelectMessage Show[16]= {{(char*)SAVESET},{(char*)WAVCAL_ON},{(char*)WAVCAL_OFF},{(char*)STDBYTIM_ON},{(char*)STDBYTIM_OFF},{
(char*)CURMETERS_ON},{(char*)CURMETERS_OFF},{(char*)TRGHLD_ON},{(char*)TRGHLD_OFF},{
(char*)SHOWEDGE_ON},{(char*)SHOWEDGE_OFF},{(char*)WAIT_RESET},{(char*)NOR_DISPLAY},{(char*)RAW_DATA},{
(char*)CUR_DIS_ON},{(char*)CUR_DIS_OFF}};
uc16 TrigReset[22]= {300, 150, 100, 75, 35, 15, 10, 10, 5, 3, //for auto trig mode, set time to reset after loosing data
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2};
uc16 NoteTimer[3]= {250, 125, 50}; //*20ms
/*******************************************************************************
main : Main routine.
*******************************************************************************/
int main(void)
{
u16 Tmp;
s32 i;
u16 Second = 0;//,Offset, Result,Count_FPS = 0
u8 j=0;
s16 TmpVT;
s16 Vt1Old=0;
s16 Vt2Old=0;
u16 loopcount=0;
char DelFileName[13];
const char AutoStr[4][6]={"!Man!","!1/4!","!1/2!","!3/4!"};
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (u32)&_vectors);
__USB_Init();
if(__Get(FPGA_OK)== 0){
__Display_Str(152, 30, YEL, PRN, "FPGA error");
while (1){};
}
__Display_Str(32, 50, WHT, PRN, APP_VERSION);
__Display_Str(96, 130, WHT, PRN, APP_REVISION);
Y_Attr = (Y_attr*)__Get(VERTICAL);
X_Attr = (X_attr*)__Get(HORIZONTAL);
G_Attr = (G_attr*)__Get(GLOBAL);
T_Attr = (T_attr*)__Get(TRIGGER);
if(memcmp((u8*)__Get(13),"2.81",4)>=0)HardwareVersion=1; else HardwareVersion=0; //HDWVER
InitiateCalData();
LoadBaseBuffers();
Load_Attr(); // assignment Y_Attr
FineAdjust=2;
i = Load_Param(0);
if(i == 0) // read the default boot parameters
__Display_Str(88, 30, GRN, PRN, "Loaded configuration file");
else
__Display_Str(80, 30, YEL, PRN, "Configuration file not found");
if(FineAdjust>4)FineAdjust=2;
Beep_mS = 500;
Key_Buffer=0;
Delayms(2000);
App_init(1);
SetIRQ2Priority();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel=TIM4_IRQChannel; //TIM4 IRQ setup for noise generator
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//----------------- TIM2_IRQ Used for sweep and burst generator ----------------
TIM2->PSC =72-1;
TIM2->ARR =1000-1; // 1mS
TIM2->DIER =0x0001; // enable TIM2_IRQ
TIM2->CR1 = 0x0085; // enable timer
TIM_2IRQControl();
Config_init();
OldMode=_Mode;
DisableCursorTimer=1;
Update=2; //=2 initiates delayed trig loop to prevent locking up with no trigger and empty buffer
Title[FILE][0].Value=LOAD; //preset file menu to load config files
Title[FILE][1].Value=0; //config file number (0=boot file)
Title[FILE][2].Value=CFG;
GPIOC->BSRR = 0x00000010; //Set port C bit 4, sets C_D (ClR)
if((u16)__Get(0)==0x5731)FPGAver=1; //get FPGA version
__Set(32+5, 1); //load data
__Set(32+5, 1); //register
if((u16)__Get(0)==0x0101)FPGAsubVer=1; //get FPGA update version
GPIOC->BRR = 0x00000010; //Reset port C bit 4
if(FPGAver>0)StartOffset=14; else StartOffset=16; //for oversampling buffer function
//-------------------------------------------------------------------------- ************** LOOP MAIN *****************
while (1){
//-------------------------------------------------------------------------- Gestione Entra e Uscita da Modalità X Y
if(_Kind!=PWM)PWAdjustMode=0;
if((ChartLogic())&&(ChartMode))OsChartFlag=1;else OsChartFlag=0;
if (_Mode!=OldMode)
{
if (_Mode ==X_Y ){ // entra in XY_S
BackGround_Reset(1);
if (OldMode<6){ //4
OldTrack1X=Title[TRACK1][POSI].Value;
OldTrack2X=Title[TRACK2][POSI].Value;
}
OffsetX=135;
OffsetY=100;
ChannelStatus(0); //save status
EnableChannel(TRACK1);
EnableChannel(TRACK2);
OldMeter=FlagMeter;
if (FlagMeter==0) {EnableMeter();UpdateMeterPage();}
_Vt1Old=_Vt1;
_Vt2Old=_Vt2;
Vt1Old=0;
Vt2Old=0;
TrgAutoOld=TrgAuto;
TrgAuto=2;
OldFrame=FrameMode;
FlagFrameMode=0;
}
if ((_Mode<6) &&(OldMode>5)){ // esce da XY_S o XY_A
ChannelStatus(1); //restore status
Title[TRACK1][POSI].Value = OldTrack1X;
Title[TRACK2][POSI].Value = OldTrack2X;
BackGround_Reset(1);
if (OldMeter==0) DisableMeter();
_Vt1=_Vt1Old;
_Vt2=_Vt2Old;
TrgAuto=TrgAutoOld;
if(OldFrame)FlagFrameMode=1;
Update_View_Area(); // in case file menu display was showing
}
}
if(Title[TRIGG][SOURCE].Value !=4) OldMode=_Mode;
if (_Mode==X_Y)Title[TRACK1][POSI].Value=100;
if (_Mode==X_Y)Title[TRACK2][POSI].Value=100;
if (_4_source>11)ShowFFT=1;
else{
ShowFFT=0;
DownConvert=0;
if(DownConvertMode){DownConvertMode=0; DownConvertRestore();}
}
OsBufferLogicFlag=OSBufferLogic();
//-------------------------------------------------------------------------- ********* LIFE *************
if (((__Get(USB_POWER)>0)||(Timeout==0))&&(PD_Cnt>0)) PD_Cnt = 600; //don't time out into standby on external power or if timeout is disabled and not already in standby
if(PD_Cnt == 0){
__Set(BACKLIGHT, 0); // turn off the backlight
__Set(STANDBY, EN); // enter low power states
} else {
if((Update)&&((_Mode!=SCAN)||(ChartLogic()))){
if((!ChartLogic())||(FrameMode==0))
_X_posi.Value=GetXpos(XposRef); //align interpolated time bases with the others
}
if (SelectiveUpdate&1){ // restore screen after removing chart
if (_Mode==X_Y){
ClearScreenArea(0,400,214,215); //clear top line
}
ClearScreenArea(0,11,12,214); //clear left mark area
DisableCursorTimer=2;
}
Synchro(); // simultaneous display of waveform data of each track
if ((TrgAuto>0)&&(_Mode!=SCAN)&&(_Mode!=AUTO)&&(_Mode!=SGL)){
if(__Get(FIFO_START)== 0){ //check to see if not triggered w/auto trig on
loopcount++;
if (loopcount>TrigReset[_T_base]){ //after proper wait time, re-initialize trig
if(Title[TRIGG][SOURCE].Value==4){ //in A&B mode, reset only non triggered ch
if((Sweep)&&(_Tr_kind==8)&&(_Kind<5)){
if(TrigSourceEnable==0)_Vt2=_2_posi+10;
if(TrigSourceEnable==1)_Vt1=_1_posi+10;
}else{
if(TrigSourceEnable==0)_Vt2=_2_posi; //alternate channel function call at end of synchro has shifted over to
if(TrigSourceEnable==1)_Vt1=_1_posi; //other ch if one ch is not triggered so need to reset alternate ch
}
Update_Trig(0);
}else{
if((Sweep)&&(_Tr_kind==8)&&(_Kind<5)){
_Vt1=_1_posi+10; //keep trig level away from zero for time based gen sweep/burst synch
_Vt2=_2_posi+10;
}else{
_Vt1=_1_posi; // set trig at signal zero point in hope to get device to trigger
_Vt2=_2_posi;
}
Update_Trig(1);
}
UpdateMarkLogic();
loopcount=0;
}
}else{ //if triggered
if(Title[TRIGG][SOURCE].Value==4){ //in A&B mode
if(TrigSourceEnable==0)ABTrigStatus|=1; //ch A is triggered
if(TrigSourceEnable==1)ABTrigStatus|=2; //ch B is triggered
if(ABTrigStatus==3) {loopcount=0;ABTrigStatus=0;} //if both ch are triggered, reset count and trigger status
}else loopcount=0;
} //if get fifo start else...
}else loopcount=0; //if trgauto>...
if(ToggleName){
if(ConfNameTimer==0){
UpdateMarkLogic();
ToggleName=0;
}
}
if((FlagMeter==0)&&(Update)){
Title[T_VERNIE][2].Flag &= 0xFD;
_D_V_Source.Flag &= 0xFD;
_Delta_V.Flag &= 0xFD; //shut update delta display flags with meter off
_Delta_T.Flag &= 0xFD;
}
//============================================REGULAR METER TIMING====================================================
if(Second != Sec_Cnt) {
Second = Sec_Cnt;
Result_FPS = Count_FPS;
Count_FPS = 0;
if((__Get(V_BATTERY)>(PrevBatLevel+40))||(__Get(V_BATTERY)<(PrevBatLevel-40))){ //update with greater than 40Mv change (WAS +/-20Mv)
BatLevelCompensation();
PrevBatLevel=__Get(V_BATTERY);
SetOffset(0,_A_Range,_1_posi); //provides update for Ka3
SetOffset(1,_B_Range,_2_posi);
}
Update_Battery();
if (FlagMeter==1){ // refresh the measured values ??per second
if(EnableMeterCalc){
DETflag=1;
Display_Value(FRQ);
DETflag=0;
}else LastFreqReadout=0;
EnablePaS=1;
for(i=0; i<9; ++i) Display_Value(i);
if(((__Get(FIFO_START)!=0)||((_Mode!=NORH)&&(_Mode!=NORHLD)))||((DownConvertInitiate==1)&&(FFTt1Mode))){ //hold reset to show meter values when in normal mode not triggered
if((_T_base > 10)||((_T_base>8)&&(FastMode==1)))ResetSum();else SumResetFlag=1; //in slow mode wait until frame is completed before resetting
WaitForTrigFlag=0;
}else WaitForTrigFlag=1; //allows reset to occur prior to meter loads on triggering after holding values
}
if(((FlagMeter==0)&&(EnableMeterCalc==0))&&
((DownConvertMode==0)||(DownConvertInitiate==1)))ResetSum(); //DownConvert initiates here
}
if((ChartLogic())&&(CursorDisplaySelect<4))CalculateTvernier(1); //Xpos/Tvernier display moving update
//============================================================================================================================
if (((Cnt_20mS%16)>7)&&((Cnt_20mS%16)<16)&&(UpdateFlag==1))UpdateFlag=0;
//===========================================LARGE METER TIMING===========================================================
if (((Cnt_20mS%16)>=0)&&((Cnt_20mS%16)<8)&&(UpdateFlag==0)){ //update meters %16= 3 times/sec %24= 2 times/sec %12= 4 times/sec
UpdateFlag=1; //note that big meter highlight blink rate is tied to update speed
if(UpdateCount==2){
EnablePaS=1; //enables TH, TL and duty% to update 1/sec
UpdateCount=0;
}else{
EnablePaS=0;
UpdateCount++;
}
//if((_State.Value)&&(CursorDisplayTimer>20))CursorDisplayTimer=75; //allow hold to freeze cursor value display
//if((ChartLogic())&&(CursorDisplaySelect<4))CalculateTvernier(1); //Xpos/Tvernier display moving update 3/sec
GenTrigColor(); //also monitor generator trig mode 3/sec
if(_Kind == PWM)LimitTransfer=((D_Tab[_Frqn].PSC+1)*D_Tab[_Frqn].ARR)/2; //bailout calculations for sweep wave ending functions
else LimitTransfer=A_Tab[_Frqn]*(TIM7->PSC+1)*125;
UpdateBigMeters();
if((FlagMeter!=1)&&(EnableMeterCalc)){ //allow to get frequency for detector mode display with meters off
DETflag=1;
Display_Value(FRQ);
DETflag=0;
}
if (((FlagMeter==2)||((FlagMeter!=1)&&(EnableMeterCalc)))||((DownConvertMode)&&((DownConvertInitiate!=1)||(FFTt1Mode)))){
if(((__Get(FIFO_START)!=0)||((_Mode!=NORH)&&(_Mode!=NORHLD)))||((DownConvertMode)&&(FFTt1Mode))){
if((_T_base > 10)||((_T_base>8)&&(FastMode==1))){
if((DownConvertMode)&&(DownConvertInitiate==0))Display_Value(0);
ResetSum();
}else{
SumResetFlag=1; //in slow mode wait until frame is completed before resetting
if((__Get(FIFO_START)==0)&&(DownConvertMode) //allows FFT1 mode to work without a triggered signal
&&(DownConvertInitiate==0)&&(FFTt1Mode))Display_Value(0);
}
WaitForTrigFlag=0;
}else WaitForTrigFlag=1;
}
if ((FlagMeter==2)&&(UpdateMeter==4)){
FlagMeter=1; //display value on small meter
Display_Value(0);
FlagMeter=2; //return
}
}
//============================================================================================================================
if (FlagMeter>0){
Display_Meter();
}
Display_Title();
//1-Twink, INV, OR PRN
if((Current != FILE)&&(NotificationTimer>4))Print_Str(95,0,0x0405,PRN,Show[MessageNumber].Message); //show message
if((Current != FILE)&&(NotificationTimer>0)&&(NotificationTimer<5)) {Update_View_Area(); NotificationTimer=0;} //end after delay
if(Update){ // handle button to refresh item
if((DisableCursorTimer)&&(Update==2))DisableCursorTimer++;
UpdateCursorMeter();
if ((SelectiveUpdate&1)&&(FlagMeter>0))EnableMeter();
for(i=0;i<4;i++){
if (TrgAuto==i) Print_Str(365, 216, ((SCRN<<8)+Title[TRIGG][SOURCE].Value), i,(char*)AutoStr[i]);
}
if ((SelectiveUpdate & 0x02)==0)Update_Range(); //these 4 are exclusions, bit set prevents update
if ((SelectiveUpdate & 0x04)==0)Update_Base();
if ((SelectiveUpdate & 0x08)==0)Update_Output();
if ((SelectiveUpdate & 0x10)==0){if(Title[TRIGG][SOURCE].Value==4) Update_Trig(0); else Update_Trig(1);}
UpdateMarkLogic();
BackLight(0);
if (SelectiveUpdate & 0x20){
ClearHoldFlag|=1; //transfer clear hold calls as selectiveupdate gets reset
if(_T_base<11)SlowModeSkip=2; //slowmodeskip allows x frames to finish to properly update buffer
}
if (SelectiveUpdate & 0x40){
ClearHoldFlag|=2;
if(_T_base<11)SlowModeSkip=2;
}
Tmp=InvertA;
TmpVT=InvertB;
InvertA=0;InvertB=0;
if((!UartLogic())&&(!i2cLogic())&&(!SpiLogic())&&(_Mode!=X_Y)){
if((Title[0][SOURCE].Value==2)||(Title[0][SOURCE].Value==4))InvertA=1;
if((Title[1][SOURCE].Value==2)||(Title[1][SOURCE].Value==4))InvertB=1;
}
if((Tmp!=InvertA)||(TmpVT!=InvertB)){if(Title[TRIGG][SOURCE].Value==4) Update_Trig(0); else Update_Trig(1);}
if (Current<4)Title[Current][3].Flag|= UPDAT;
if((Current == TRIGG) && (_Det==3)){
if ((FrameMode==0)||((Options&1)==0)||(_Mode==AUTO)||(OsBufferLogicFlag)||(_Mode==X_Y)||(_Mode==SGL)||(_Mode==SCAN)||(_T_base>9)) _Det=0;
Title[Current][_Det].Flag |= UPDAT;
}
if((Current != FILE)&&(NotificationTimer<43)) Update_View_Area(); //after 3/4 second, allow notification overwrite if button pushed
if (FlagMeter>0) {
_D_V_Source.Flag |= UPDAT; // Updat delta V
_Delta_V.Flag |= UPDAT;
_Delta_T.Flag |= UPDAT; // Updat delta T
}else{
if ((Current == V_VERNIE)&&(_Det == 2)) _Det=0;
if ((Current == T_VERNIE)&&(_Det == 2)) _Det=0;
}
if (FrameMode==2) SaveShortBuffXpos=XposRef; //save trig cursor in config file
if(Update)Update--; // Update finish
SelectiveUpdate=0;
UpdateScale=1;
OsBufferLogicFlag=OSBufferLogic();
if ((Current==FILE)&&(_Det==DIR)){
if(Title[9][2].Value==7){
Ext[0]='B';Ext[1]='I';Ext[2]='N';Ext[3]=0;
}else{
for(i=0;i<3;i++)Ext[i]=F_EXT[Title[9][2].Value][i+1];
}
if(ClearDir){
PrintDir(0,0,3); //clear file list when changing in SPEC or MAP modes
ClearDir=0;
}
ReadDir((char*)Ext);
if(Label[Title[9][3].Value][0]==0){if(Title[9][3].Value>0)Title[9][3].Value--;} //if presently selected last file non existant
if(Label[0][0]==0)for(i=0;i<13;i++)Label[0][i]=NoneStr[i]; //no files found
if(DirRange>0){if(Label[14][0]==0)for(i=0;i<13;i++)Label[14][i]=NoneStr[i];} //no more files found
PrintDir(0,0,2);
}
if((BufferRestore)&&(Title[RUNNING][STATE].Value==0)){UpdateFileMenu();BufferRestore=0;}
}
if((FlagMeter==0)&&(ClearMeterAreaFlag)){Clear_Meter_Area();Update=1;} ClearMeterAreaFlag=0;
if(_T_base > 10){
if(UpdateBackground==3)UpdateBackground=0;
if(UpdateBackground==1)UpdateBackground=3;
}
}//else, if power down
if((_State.Value == HOLD)&&((__Get(FIFO_FULL)!= 0)||(__Get(FIFO_START)== 0))){
_State.Value = 2;
_State.Flag |= UPDAT;
}
if((ChartLogic())&&(FrameMode==0)){
if(JumpCnt<=380)ScrollFlag=2;
}
//-------------------------------------------------------------------------- TRIGGER AUTOMATICO
if((TrgAuto>0)&&((_Mode!=SCAN)||(AutoSetFlag))){
if((Current == TRIGG) && (_Det==2)){
if (((_Mode==NORH)||(_Mode==NORHLD)||(_Mode==NORC))&&(_T_base < 10)&&(Options&1)&&(!OsBufferLogicFlag)) _Det=3; else _Det=0;
Title[Current][_Det].Flag |= UPDAT;
}
if ((Title[TRIGG][SOURCE].Value == TRACK1)||((Title[TRIGG][SOURCE].Value==4)&&(TrigSourceEnable==0))){
TmpVT=(((((aT_Min+Ka1[_A_Range])-_1_posi)*Ka2[_A_Range])/1024)+((aT_Max-aT_Min)*(TrgAuto*2)/8))+_1_posi;
if ((TmpVT>Vt1Old +5) || (TmpVT<Vt1Old -5) || (AutoTrigIni) ||(AutoSetFlag) ){
_Vt1=TmpVT;
if(Title[TRIGG][SOURCE].Value==4) Update_Trig(0); else Update_Trig(1);
UpdateMarkLogic();
Vt1Old=_Vt1;
AutoTrigIni=0;
}
}
if ((Title[TRIGG][SOURCE].Value == TRACK2)||((Title[TRIGG][SOURCE].Value==4)&&(TrigSourceEnable==1))){
TmpVT=(((((bT_Min+Kb1[_B_Range])-_2_posi)*Kb2[_B_Range])/1024)+((bT_Max-bT_Min)*(TrgAuto*2)/8))+_2_posi;
if ((TmpVT>Vt2Old +5) || (TmpVT<Vt2Old -5) || (AutoTrigIni) ||(AutoSetFlag) ){
_Vt2=TmpVT;
if(Title[TRIGG][SOURCE].Value==4) Update_Trig(0); else Update_Trig(1);
UpdateMarkLogic();
Vt2Old=_Vt2;
AutoTrigIni=0;
}
}
}
//-------------------------------------------------------------------------- FRAME MODE
UpdateFrameMode();
if(Update==1)SelectiveUpdate|=0x08; //anything setting update up to this point has nothing to do with gen output
if(RefreshDisplay){ //update display when changing buffer size while not triggered un uart mode
_State.Value=1; //shift to hold mode so data is not transfered
Process(); //update screen so x pos can be changed
_State.Value=0; //return to run mode
RefreshDisplay=0;
}
//-------------------------------------------------------------------------- GESTIONE TASTI MENU
if(Key_Buffer) {
if(PD_Cnt == 0) {
App_init(1); // exit the power saving state
Key_Buffer=0; // don't execute any functions when just getting device out of standby with any key press
Update_View_Area(); // in case file menu display was showing
DisableCursorTimer=3;
if(ChartLogic())InitChart();
}
PD_Cnt = 600; // 600 seconds
//--------------------------------------------------------------------------------------------------------------
for (i=0;i<4;i++){ //clear memorized trigger settings of ch if ch is turned off
if (Title[i][SOURCE].Value == HIDE)TrigMemory(i);
}
//---------------------------------------------------------------------------------------------------------------------
if(Key_Buffer == KEY1){
DisableCursorTimer=1;
Delay_Cnt = 1500;
if(AutoSetFlag>1){ //bail out of autoset
AutoSetFlag=0;
AutoSetTimer=0;
reset_parameter();
if (_Mode!=SCAN) {
if(FlagFrameMode==0)XposRef=GetXposRef(OldPosi);
if(FlagFrameMode==1)XposRef=ShortBuffXpos;
_X_posi.Value=GetXpos(XposRef);
}
CurDefTime=OldCurDefTime;
if(MeterStatus){
FlagMeter=MeterStatus;
EnableMeter();
}
Update_Range();
Update_Base();
App_init(0);
goto bypasslongpress;
}
if(AutoSetTimer)AutoSetFlag=1;
AutoSetTimer=25; //x20mS double click timer
while (Delay_Cnt > 1000)
{
if((__Get(KEY_STATUS)& KEY1_STATUS)!=0){
_State.Flag |= UPDAT; // set the corresponding update flag
if((_State.Value==0)&&(AutoSetFlag==0)){ //0=run 1=hold also has 2
ClearMeters(); //clears meters if untriggered in NORH
_State.Value=1;
}else{
DigChLockout=0;
_State.Value=0;
if(ChartLogic())InitChart();else{
SelectiveUpdate |=0x60;
if(_Mode!=NORH)ClearTrackBuff(1);else ClearLeadingEdge=1; //REMOVING NORH CONDITION WOULD CLEAR WAVE ALONG WITH METERS...
if(( (_Mode == SGL)||(_Mode==NORH)||(Options&4)||((FrameMode>0)&&(_T_base<3))||((FrameMode==0)&&(_T_base<6))) && (_Mode!=NORHLD) ){ //in run mode if frame >1 1/2 sec
if(!(ChartLogic())){__Set(FIFO_CLR, W_PTR);cleardatabuf(2);}
if(Options&4) {ClearHold(3);ClearMinMax(3);}
if(OsBufferLogicFlag)InitiateOSBuffers();
if(_T_base<11)JumpCnt=0;
EnablePaS=1;
ResetSum();
}
}
if((_T_base<3)&&(_Mode!=SCAN)&&(_Mode!=NORHLD)){
MessageNumber=11; //wait for reset
if(OSBufferLogic()){
NotificationTimer=(NoteTimer[_T_base]*(150-_X_posi.Value))/150;
}else{
NotificationTimer=NoteTimer[_T_base];
}
}
if(_Mode==NORHLD){cleardatabuf(2);ClearFFTbuffer();}
//InitXY=1; //resets XY persistence if enabled. Using button 5 center press instead
//allows to see waveform prior to re-enabling by pressing button again
if(DownConvertMode)DownConvertShiftEnable=2;
}
goto bypasslongpress;
} //if get key status
} //while
Beeper(125); BackLight(1);
while ((Delay_Cnt >0)&&(Delay_Cnt <=1000)){ // long press
if(Delay_Cnt<875)BackLight(0);
if((__Get(KEY_STATUS)& KEY1_STATUS)!=0){
_Curr[_Det].Flag |= UPDAT;
if(((ListLogic())||(_Mode==X_Y))&&(EditListActive(1))){
PrintDir(0,0,3); //clear file list when leaving
if(_Mode==X_Y)InitXY=1;
}
switch (Current){
case TRACK1:
if (_Det==RANGE){
if(_1_source==0){
AlignTbaseSweep(4);
_1_source=ChOnStatus[0];
LastSelected=1;
} else {
AlignTbaseSweep(5);
ChOnStatus[0]=_1_source;
_1_source=0;
}
}else{
if(Title[TRACK4][SOURCE].Value<10)EnableChannel(TRACK1); //if FFT on, do not turn channel trace on
}
break;
case TRACK2:
if (_Det==RANGE){
if(_2_source==0){
AlignTbaseSweep(4);
_2_source=ChOnStatus[1];
LastSelected=2;
} else {
AlignTbaseSweep(5);
ChOnStatus[1]=_2_source;
_2_source=0;
}
}else{
if(_4_source<10)EnableChannel(TRACK2);
}
break;
default:
if ((Title[TRACK1][SOURCE].Value != HIDE)&&(Title[TRACK2][SOURCE].Value == HIDE)){ //Cha A on B off
Current = TRACK1;
LastSelected=1;
}else if ((Title[TRACK1][SOURCE].Value == HIDE)&&(Title[TRACK2][SOURCE].Value != HIDE)){ //Cha B on A off
Current = TRACK2;
LastSelected=2;
}else if(_4_source<10){ //if FFT off //both on or off
switch (LastSelected){
case 0:
case 1:
Current = TRACK1;
EnableChannel(TRACK1);
break;
case 2:
Current = TRACK2;
EnableChannel(TRACK2);
} //switch
}else{ //FFT on, both tracks on or both off
if(_4_source<14)Current=TRACK2;else Current=TRACK1; //go to ch v/div but do not turn on
}
} //switch
_Det = RANGE;
Title[TRACK1][SOURCE].Flag |= UPDAT;
Title[TRACK2][SOURCE].Flag |= UPDAT;
CurDetailUpdate();
goto bypasslongpress;
} // if get key status
} //while delay count 0 to 1000
Beeper(60);
if(Delay_Cnt == 0){
j=0;
for(i=204;i>49;i-=11){
Print_Str(0,i,0x040C,PRN,DisplayChart[j++].ChartLine);
}
Delayms(300);
Key_Buffer=0;
while (1) {
if (Key_Buffer>0){
SelectiveUpdate=1;
BackGround_Reset(1);
Update_View_Area();
break;
}
}
}
} //if key buffer
//--------------------------------------------------------------------------------------------------------------
if(Key_Buffer== KEY2){ // ===--- TASTO 2 PREMUTO ---===
Delay_Cnt = 3000; // Carica il temporizzatore del tasto permuto
while (Delay_Cnt > 2500){ // Se il tempo non è arrivato a 0
if((__Get(KEY_STATUS)& KEY2_STATUS)!=0){ // CAMBIO MODO TRIGGER
DisableCursorTimer=1;
if ((Title[TRIGG][SOURCE].Value != TRACK3)&&(Title[TRIGG][SOURCE].Value != TRACK4)){
_Curr[_Det].Flag |= UPDAT;
if (TrgAuto==0){
TrgAuto=2;
Vt1Old=0;
Vt2Old=0;
}else {
TrgAuto++; // AUTO TRIGGER
}
if((Sweep)&&(_Tr_kind==8)&&(TrgAuto==2)&&(_Kind<5))TrgAuto++; //auto trig= 1/2 does not work well with kind=GEN
if (TrgAuto>3) {TrgAuto=1;} // short press
Title[Current][_Det].Flag |= UPDAT;
if ((Current == TRIGG) && (_Det==2)){ Title[Current][_Det].Flag |= UPDAT;_Det=0;}
}
goto bypasslongpress;
}//if get key
}//while
Beeper(125); BackLight(1);
while ((Delay_Cnt >0)&&(Delay_Cnt <=2500)){ // long press
if(Delay_Cnt<2375)BackLight(0);
if((__Get(KEY_STATUS)& KEY2_STATUS)!=0){
if ((Title[TRIGG][SOURCE].Value != TRACK3)&&(Title[TRIGG][SOURCE].Value != TRACK4)){
_Curr[_Det].Flag |= UPDAT;
if (TrgAuto>0) TrgAuto=0;
Current = TRIGG;
_Det=2;
Title[Current][_Det].Flag |= UPDAT;
}
goto bypasslongpress;
}// if get key status
} // while delay count
Beeper(60);
if(Delay_Cnt == 0){
DisableCursorTimer=1;
if(Current<2){
CalibrateMode=1;
Calibrat(Current);
CalibrateMode=0;
goto BypassExclusions;
}else{
if((Current==T_BASE)&&(_Det==1)&&(OSBufferLogic())
&&(FPGAsubVer)&&(FPGAosFlag)){ //Tbase RANGE sub menu
if(OS_RateSelect)OS_RateSelect=0;else OS_RateSelect=1;
goto bypassOSselect;
}
if(Current!=9){ //not in file menu
if(OffsetSelect)OffsetSelect=0;else OffsetSelect=1;
goto bypassOSselect;
}
} //if current <2 else
} // if delay cnt
}
//--------------------------------------------------------------------------------------------------------------
if(Key_Buffer== KEY3){ // ===--- TASTO 3 PREMUTO --====
DisableCursorTimer=1;
if((Current!=FILE)||(_Curr[2].Value!=CFG)){
Delay_Cnt = 1500; // Carica il temporizzatore del tasto permuto
while (Delay_Cnt > 1000){ //WAS >0 Se il tempo non è arrivato a 0
if((__Get(KEY_STATUS)& KEY3_STATUS)!=0){
if(DownConvertMode==0){
if (FlagMeter==2) //if in big meters, shut off
{
if (_Mode != X_Y){
if((ListLogic())&&(EditListActive(1)))PrintDir(0,0,3);
DisableMeter();
if((_4_source==SPEC_A)||(_4_source==SPEC_B)||(_Mode==NORHLD))Clear_Meter_Area();
}else{ //toggle the 2 meters in xy mode, instead of shutting meters off
FlagMeter=1;
EnableMeter();
}
goto bypasslongpress;
}
else
{
if (FlagMeter==1){ //if in small meters go to big meters
if(Current > METER_3)Current=METER_3;
if(UpdateMeter==4){
if(Current==METER_1)Current=METER_2;
}else{
if(Current==METER_0)Current=METER_1;
if((Current < METER_0)&&(Current>T_VERNIE))Current=T_VERNIE; //if not in meter item select mode
}
FlagMeter=2;
}
if( (FlagMeter==0)&&(ListLogic())&&(EditListActive(1)) )PrintDir(0,0,3);
EnableMeter(); //if meters off, go to small meters
goto bypasslongpress;
}
}else goto bypasslongpress;
} //if get key status
} //while delay count
Beeper(125); BackLight(1);
while ((Delay_Cnt >0)&&(Delay_Cnt <=1000)){ // long press
if(Delay_Cnt<875)BackLight(0);
if((__Get(KEY_STATUS)& KEY3_STATUS)!=0){
if(Title[OUTPUT][0].Value!=6){ //if generator is not turned off
Print_Str(15, 90, 0x0405, PRN, (char*)DisableSTR);
Delayms(900);
Key_Buffer=0;
__Set(BACKLIGHT, 4); // set backlight dim
while(1){if(Key_Buffer>0)break;}
InitXY=1;
Key_Buffer=0;
BackLight(0);
PD_Cnt = 600;
goto BypassUpdate;
}else{
Print_Str(119, 90, 0x0405, PRN, "LONG PRESS-STANDBY");
Delayms(900);
PD_Cnt = 0;
__Set(BACKLIGHT, 0); // turn off the backlight
__Set(STANDBY, EN); // enter low power states
goto bypasslongpress;
}
} //IF GET KEY STATUS
} // WHILE DELAY COUNT...
Beeper(60);
if(Delay_Cnt == 0){ //extra long press
for(i=0;i<3;i++)_Curr[i].Flag |= UPDAT;
SaveCurrent[0]=Current; //save current menu item position
SaveCurrent[1]=_Det;
Current=FILE;
Title[FILE][0].Value=0; //save file
Title[FILE][2].Value=4; //conf file
_Curr[1].Value=ConfigFileNumber;
if(ListOverride){
_Det=3;
ProcessEditName();
}else _Det=1;
for(i=0;i<3;i++)Title[FILE][i].Flag|=UPDAT;
}
}else{ //Current = file
if(_Curr[2].Value==CFG){
if(_Curr[0].Value == SAVE){
if(_Det==3){
Edited=1;
ProcessFileName();
for(i=0;i<8;i++)LastAccessedConfig[i]=SelectedFileName[i];
ProcessEditName(); //loads processed name into edit function
ListOverride=1;
}else ListOverride=0;
i=ConfigFile(SAVE);
Edited=0;
FileMessage(i);