forked from ikalogic/ScanaStudio-scripts-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDIO.js
13575 lines (13242 loc) · 640 KB
/
SDIO.js
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
/* Protocol meta info:
<NAME> SDIO </NAME>
<DESCRIPTION>
SDIO Bus Decoder
</DESCRIPTION>
<VERSION> 1.00 </VERSION>
<AUTHOR_NAME> Corentin Maravat </AUTHOR_NAME>
<AUTHOR_URL> contact@ikalogic.com </AUTHOR_URL>
<HELP_URL> https://github.com/ikalogic/ScanaStudio-scripts-v3/wiki </HELP_URL>
<COPYRIGHT> Copyright Ikalogic SAS </COPYRIGHT>
<LICENSE> This code is distributed under the terms of the GNU General Public License GPLv3 </LICENSE>
<RELEASE_NOTES>
V1.00: Initial release.
</RELEASE_NOTES>
*/
/* Sources (les plus importantes c'est surtout les 2 premières après le problème c'est qu'elles sont relativement longue)
SD Specifications 7.10 : https://www.sdcard.org/downloads/pls/pdf/index.php?p=Part1_Physical_Layer_Simplified_Specification_Ver7.10.jpg&f=Part1_Physical_Layer_Simplified_Specification_Ver7.10.pdf&e=EN_SS1
SDIO Specifications 3.00 : https://www.sdcard.org/downloads/pls/pdf/index.php?p=PartE1_SDIO_Simplified_Specification_Ver3.00.jpg&f=PartE1_SDIO_Simplified_Specification_Ver3.00.pdf&e=EN_SSE1
Les CMD du protocole SD (elle y sont pas forcément toute car c'est pas la Version 7.1) : http://www.zeroplus.com.tw/software_download/Protocol%20Analyzer%20SD%20Introduction_Table_.pdf
Site d'un mec qui explique le protocole SDIO : https://yannik520.github.io/sdio.html
Site qui parle du protocole SD : http://wiki.seabright.co.nz/wiki/SdCardProtocol.html
Blog d'un mec qui utilse le bus SDIO, yavais des exemples de trames : https://iosoft.blog/2020/03/08/zerowi-part2/
La aussi il y avait des trames : https://esp32.com/viewtopic.php?t=6813
Encore sur le protocole SDIO : http://wiki.csie.ncku.edu.tw/embedded/SDIO
Pin des cartes SD : https://openlabpro.com/guide/interfacing-microcontrollers-with-sd-card/
Des timings sur la clk : https://e2e.ti.com/support/interface/f/138/t/532916
wiki sur le CRC en général : https://en.wikipedia.org/wiki/Cyclic_redundancy_check
Site qui donne des exemples de réponses du CRC7 et du CRC16 du protocole SD : https://bits4device.wordpress.com/2017/12/16/sd-crc7-crc16-implementation/
Le code du CRC-7 je l'ai pris ici (transfo en javascript): https://www.pololu.com/docs/0J1?section=5.f
Le code du CRC-16 je l'ai pris ici (XMODEM): https://cs.stackexchange.com/questions/119017/replacing-0x1021-polynomial-with-0x8005-in-this-crc-16-code
*/
//Decoder GUI
function on_draw_gui_decoder()
{
//Define decoder configuration GUI
ScanaStudio.gui_add_ch_selector("ch_cmd","CMD Channel","CMD");
ScanaStudio.gui_add_ch_selector("ch_clk","CLK Channel","CLK");
ScanaStudio.gui_add_ch_selector("ch_dat0","DAT0 Channel","DAT0");
if (ScanaStudio.get_device_channels_count() > 4)
{
ScanaStudio.gui_add_combo_box( "quad_DAT", "Number of data pin");
ScanaStudio.gui_add_item_to_combo_box( "DAT[0] pin only", true);
ScanaStudio.gui_add_item_to_combo_box( "4 data pins (DAT[0-3])");
ScanaStudio.gui_add_new_tab("DATA Channel",false);
ScanaStudio.gui_add_ch_selector("ch_dat1","DAT1 Channel","DAT1");
ScanaStudio.gui_add_ch_selector("ch_dat2","DAT2 Channel","DAT2");
ScanaStudio.gui_add_ch_selector("ch_dat3","DAT3 Channel","DAT3");
ScanaStudio.gui_end_tab();
}
ScanaStudio.gui_add_new_tab("SDIO Mode configuration",false);
ScanaStudio.gui_add_check_box("SDIO","SDIO Only Card ",false);
ScanaStudio.gui_add_check_box("DDR","DDR50 Mode (Data sample on every edge)",false);
ScanaStudio.gui_add_check_box("CQ","CQ Mode Enable (Physical Layer 6.00 minimum)",false);
ScanaStudio.gui_add_text_input("CMD53_block_size","Initial value of CMD53_block_size","512");
ScanaStudio.gui_add_info_label("This value of block_size will be valid for the 0 (CIA) and 1-7, I/O functions.\n"
+ "If you want to change the block_size after the beginning of the record, "
+ "use the CMD52 with the correct register adress, "
+ "however it will change it only for the function specified in the argument.");
ScanaStudio.gui_end_tab();
ScanaStudio.gui_add_new_tab("Output format",true);
ScanaStudio.gui_add_check_box("format_hex","HEX",true);
ScanaStudio.gui_add_check_box("format_ascii","ASCII",true);
ScanaStudio.gui_add_check_box("format_dec","Unsigned decimal",false);
ScanaStudio.gui_add_check_box("format_bin","Binary",false);
ScanaStudio.gui_end_tab();
ScanaStudio.gui_add_new_tab("HEX view options",false);
ScanaStudio.gui_add_combo_box( "hexview_endianness", "HEX View endianness");
ScanaStudio.gui_add_item_to_combo_box( "Big Endian (MSB at lowest address)", true);
ScanaStudio.gui_add_item_to_combo_box( "Little Endian (MSB at highest address)" );
ScanaStudio.gui_end_tab();
//Add other gui functions...
}
//Global variables
var sampling_rate;
var state_machine;
var ch_cmd;
var ch_clk;
var nbits;
var cmd_channel = [];
var data_channels = [];
var dat_clock_polarity = 1; //Rising Edge
var CMD = -1;
var last_CMD = -1;
var CMD_mode = 0;
var last_CMD_mode = 0;
var T_bit; //Transmitter bit
var R_type = "Undefined"; //Response type
var item_display = [];
var crc_pre_display = [];
var str_error = "";
var format_hex,format_bin,format_ascii,format_dec;
var hexview_endianness;
var last_trans = false;
var item_start_sample = 0;
var trs_data = [];
var sdio_value = 0;
var end_data_sample_index = 0;
var speed_mode = 0;
var BUS_WIDTH = 1;
var show_pdf_on_console = false;
var usual_data = true;
var STOP_TRANSMISSION = false;
// Variables used for CRC-7 calcul
var crc_calcul = [];
var data_transfer = false;
var SDIO_only = false;
var Card_is_Lock = false;
var SD_CARD_TYPE = 0;
var start_usual_data_sample = 0;
var sampling_rate_too_low = false;
// Variables used for CMD8/R7
var CMD8_Voltage = 0;
var CMD8_check_pattern = 0;
// Variables used for CMD52/CMD53/R5 (I/O Transfer)
var R_W = -1;
var RAW = -1;
var Write_data = -1;
var function_number = -1;
var register_adress = -1;
var Block_mode = -1;
// CMD53 Block Size
var Function_0_block_size_1 = 0;
var Function_0_block_size_2 = 0;
var Function_0_block_size = 0;
var Function_1_block_size_1 = 0;
var Function_1_block_size_2 = 0;
var Function_1_block_size = 0;
var Function_2_block_size_1 = 0;
var Function_2_block_size_2 = 0;
var Function_2_block_size = 0;
var Function_3_block_size_1 = 0;
var Function_3_block_size_2 = 0;
var Function_3_block_size = 0;
var Function_4_block_size_1 = 0;
var Function_4_block_size_2 = 0;
var Function_4_block_size = 0;
var Function_5_block_size_1 = 0;
var Function_5_block_size_2 = 0;
var Function_5_block_size = 0;
var Function_6_block_size_1 = 0;
var Function_6_block_size_2 = 0;
var Function_6_block_size = 0;
var Function_7_block_size_1 = 0;
var Function_7_block_size_2 = 0;
var Function_7_block_size = 0;
var block_size = 0;
// Variables used for data transfer
var Block_length = 512; //bytes
var Lock_unlock_Block_length = 512; //bytes
var Block_count = -1; //Number of block to read or write (CMD18/25)
var Block_counter = 0; // Number of block already read since CMD18/25
// Variables used for CMD5/R4
var CMD_VDD_value = -1;
var CMD_VDD_range = [];
var RSP_VDD_value = -1;
var RSP_VDD_range = [];
// Variables used for Packet View
var packet_string = "";
var types = "";
// Variables used for Commands Queue Function Commands
var CQ_enable = false;
var send_CQ = false;
// Variables used for demo signal
var current_state = "idle";
var current_state_value = 3;
var transfer = "operation not complete";
function reload_dec_gui_values()
{
//get GUI values
ch_cmd = ScanaStudio.gui_get_value("ch_cmd");
ch_clk = ScanaStudio.gui_get_value("ch_clk");
ch_dat0 = ScanaStudio.gui_get_value("ch_dat0");
ddr = ScanaStudio.gui_get_value("DDR");
format_hex = Number(ScanaStudio.gui_get_value("format_hex"));
format_dec = Number(ScanaStudio.gui_get_value("format_dec"));
format_ascii = Number(ScanaStudio.gui_get_value("format_ascii"));
format_bin = Number(ScanaStudio.gui_get_value("format_bin"));
hexview_endianness = Number(ScanaStudio.gui_get_value("hexview_endianness"));
block_size = Number(ScanaStudio.gui_get_value("CMD53_block_size"));
SDIO_only = ScanaStudio.gui_get_value("SDIO");
CQ_enable = ScanaStudio.gui_get_value("CQ");
if (ScanaStudio.get_device_channels_count() > 4)
{
ch_dat1 = ScanaStudio.gui_get_value("ch_dat1");
ch_dat2 = ScanaStudio.gui_get_value("ch_dat2");
ch_dat3 = ScanaStudio.gui_get_value("ch_dat3");
speed_mode = ScanaStudio.gui_get_value("quad_DAT");
}
}
//Evaluate decoder GUI
function on_eval_gui_decoder()
{
var instance_name = "SDIO [";
sdio_ch_list = [];
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_cmd"));
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_clk"));
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_dat0"));
if (ScanaStudio.get_device_channels_count() > 4)
{
if (ScanaStudio.gui_get_value("quad_DAT") == true)
{
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_dat1"));
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_dat2"));
sdio_ch_list.push(ScanaStudio.gui_get_value("ch_dat3"));
}
}
if (ScanaStudio.gui_get_value("CMD53_block_size") > 2048 || ScanaStudio.gui_get_value("CMD53_block_size") < 1)
{
return "Error, block size should be a value between 1 and 2048."
}
ch_list = []; //Global
var duplicates = false;
var i;
for (i=0; i < sdio_ch_list.length; i++)
{
if (ch_list[sdio_ch_list[i]] == sdio_ch_list[i])
{
return "Error: One or more channels are duplicates.";
}
else
{
ch_list[sdio_ch_list[i]] = sdio_ch_list[i];
}
instance_name += (sdio_ch_list[i]+1).toString();
if (i < (sdio_ch_list.length-1))
{
instance_name += ",";
}
}
instance_name += "]";
ScanaStudio.set_script_instance_name(instance_name);
return ""; //All good.
}
const CONST_t_clk_low_min = 10e-9,
CONST_t_clk_high_min = 10e-9,
CONST_t_clk_rise_min = 1e-9,
CONST_t_clk_fall_min = 1e-9,
CONST_t_clk_rise_max = 10e-9,
CONST_t_clk_fall_max = 10e-9,
CONST_t_inp_setup_min = 5e-9,
CONST_t_inp_hold_min = 5e-9,
CONST_t_output_data_delay_max = 14e-9,
CONST_t_output_id_delay_max = 50e-9;
//decoder state
const ENUM_STATE_CMD_START = 0,
ENUM_STATE_DATA_START = 1,
ENUM_STATE_CMD_INDEX = 2,
ENUM_STATE_CMD_ARGUMENT = 3,
ENUM_STATE_RSP_ARGUMENT = 4,
ENUM_STATE_DATA = 5,
ENUM_STATE_CRC7 = 6,
ENUM_STATE_CRC16 = 7,
ENUM_STATE_CMD_END = 8,
ENUM_STATE_DATA_END = 9,
ENUM_STATE_UNDEFINED = 10;
//SD Card Type
const SDSC = 0,
SDHC = 1,
SDXC = 2,
SDUC = 3;
function on_decode_signals(resume)
{
if (!resume) //If resume == false, it's the first call to this function.
{
//initialization code goes here, ex:
sampling_rate = ScanaStudio.get_capture_sample_rate();
reload_dec_gui_values();
initialize_CMD53_size_block(block_size);
if (ddr == true)
{
dat_clock_polarity = -1; //Dual Edge
}
cmd_channel.push(ch_cmd);
data_channels.push(ch_dat0);
trs_clk = ScanaStudio.trs_reset(ch_clk);
var trs_clk = ScanaStudio.trs_get_next(ch_clk);
var tmp_trs_sample_index;
tmp_trs_sample_index = trs_clk.sample_index;
while( (tmp_trs_sample_index == trs_clk.sample_index) && (ScanaStudio.trs_is_not_last(ch_clk) == true) )
{
trs_clk = ScanaStudio.trs_get_next(ch_clk);
}
trs_cmd = ScanaStudio.trs_reset(ch_cmd);
var trs_cmd = ScanaStudio.trs_get_next(ch_cmd);
tmp_trs_sample_index = trs_cmd.sample_index;
while( (tmp_trs_sample_index == trs_cmd.sample_index) && (ScanaStudio.trs_is_not_last(ch_cmd) == true) )
{
trs_cmd = ScanaStudio.trs_get_next(ch_cmd);
}
trs_dat0 = ScanaStudio.trs_reset(ch_dat0);
trs_dat0 = ScanaStudio.trs_get_next(ch_dat0);
tmp_trs_sample_index = trs_dat0.sample_index;
while( (tmp_trs_sample_index == trs_dat0.sample_index) && (ScanaStudio.trs_is_not_last(ch_dat0) == true) )
{
trs_dat0 = ScanaStudio.trs_get_next(ch_dat0);
}
trs_data.push(trs_dat0);
if (speed_mode == 1) //There is the 4 DAT channels
{
data_channels = [];
data_channels.push(ch_dat3);
data_channels.push(ch_dat2);
data_channels.push(ch_dat1);
data_channels.push(ch_dat0);
trs_dat1 = ScanaStudio.trs_reset(ch_dat1);
var trs_dat1 = ScanaStudio.trs_get_next(ch_dat1);
tmp_trs_sample_index = trs_dat1.sample_index;
while( (tmp_trs_sample_index == trs_dat1.sample_index) && (ScanaStudio.trs_is_not_last(ch_dat1) == true) )
{
trs_dat1 = ScanaStudio.trs_get_next(ch_dat1);
}
trs_dat2 = ScanaStudio.trs_reset(ch_dat2);
var trs_dat2 = ScanaStudio.trs_get_next(ch_dat2);
tmp_trs_sample_index = trs_dat2.sample_index;
while( (tmp_trs_sample_index == trs_dat2.sample_index) && (ScanaStudio.trs_is_not_last(ch_dat2) == true) )
{
trs_dat2 = ScanaStudio.trs_get_next(ch_dat2);
}
trs_dat3 = ScanaStudio.trs_reset(ch_dat3);
var trs_dat3 = ScanaStudio.trs_get_next(ch_dat3);
tmp_trs_sample_index = trs_dat3.sample_index;
while( (tmp_trs_sample_index == trs_dat3.sample_index) && (ScanaStudio.trs_is_not_last(ch_dat3) == true) )
{
trs_dat3 = ScanaStudio.trs_get_next(ch_dat3);
}
trs_data = [];
trs_data.push(trs_dat3);
trs_data.push(trs_dat2);
trs_data.push(trs_dat1);
trs_data.push(trs_dat0);
}
//init global variables
state_machine = ENUM_STATE_CMD_START;
}//end if (!resume)
else
{
//ScanaStudio.console_info_msg("Decoding resumed");
}
while (ScanaStudio.abort_is_requested() == false)
{
// ScanaStudio.console_info_msg(".");
if ((!ScanaStudio.trs_is_not_last(ch_cmd)) && (!ScanaStudio.trs_is_not_last(ch_dat0)))
{
break;
}
switch (state_machine)
{
case ENUM_STATE_CMD_START: //Looking for a starting bit
{
if (trs_cmd.value == 0) //(falling edge)
{
nbits = 2;
sdio_simple = sync_decode_v2(cmd_channel,trs_cmd.sample_index,nbits);
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_cmd();
break;
}
item_display = crc_pre_calcul(sdio_simple.unsigned_words,nbits,crc_calcul);
//Dec Item
if (item_display[0] == 1) //Start bit = 1
{
dec_item_new_v2 (ch_cmd, sdio_simple);
ScanaStudio.dec_item_add_content("Start");
ScanaStudio.dec_item_add_content("S");
ScanaStudio.dec_item_add_sample_point(sdio_simple.start_sample,"P")
ScanaStudio.dec_item_emphasize_error();
state_machine = ENUM_STATE_CMD_START;
trs_cmd.value = -1;
item_display = [];
crc_calcul = [];
ScanaStudio.dec_item_end();
//Packet View
ScanaStudio.packet_view_add_packet(true,ch_cmd,sdio_simple.start_sample,sdio_simple.end_sample,"SDIO","CH_CMD",ScanaStudio.get_channel_color(ch_cmd),ScanaStudio.get_channel_color(ch_cmd));
break;
}
//Packet View
ScanaStudio.packet_view_add_packet(true,ch_cmd,sdio_simple.start_sample,sdio_simple.end_sample,"SDIO","CH_CMD",ScanaStudio.get_channel_color(ch_cmd),ScanaStudio.get_channel_color(ch_cmd));
if (item_display[1] == 1) //Transmission bit = 1
{
dec_item_new_v2 (ch_cmd, sdio_simple);
if (R_type == "Undefined")
{
ScanaStudio.dec_item_add_content("Host to Card");
ScanaStudio.dec_item_add_content("Host");
ScanaStudio.dec_item_add_content("H");
packet_view_add_packet_v2(ch_cmd,sdio_simple,"Start","Host to Card","Wrap");
T_bit = sdio_simple.unsigned_words;
}
else
{
ScanaStudio.dec_item_add_content("Error, Transmission bit should be 0");
ScanaStudio.dec_item_add_content("Error");
ScanaStudio.dec_item_emphasize_error();
packet_view_add_packet_v2(ch_cmd,sdio_simple,"Start","Host to Card","Error");
ScanaStudio.dec_item_end();
trs_cmd.value = -1;
item_display = [];
crc_calcul = [];
state_machine = ENUM_STATE_CMD_START;
break;
T_bit = 0; //To force the decoder to decode the signal as a RSP
}
display_sample(sdio_simple);
ScanaStudio.dec_item_end();
}
else
{
dec_item_new_v2 (ch_cmd, sdio_simple);
ScanaStudio.dec_item_add_content("Card to Host");
ScanaStudio.dec_item_add_content("Card");
ScanaStudio.dec_item_add_content("C");
display_sample(sdio_simple);
ScanaStudio.dec_item_end();
packet_view_add_packet_v2(ch_cmd,sdio_simple,"Start","Card to Host","Wrap");
T_bit = sdio_simple.unsigned_words;
}
trs_cmd.value = -1;
item_display = [];
state_machine = ENUM_STATE_CMD_INDEX;
break;
}
else
{
trs_cmd = ScanaStudio.trs_get_next(ch_cmd);
break;
}
}//end ENUM_STATE_CMD_START
case ENUM_STATE_DATA_START: //Looking for a starting bit
{
if (speed_mode == 0)
{
if (trs_dat0.value == 0 ) //(falling edge)
{
nbits = 1;
sdio_simple = sync_decode_v3(data_channels,trs_dat0.sample_index,nbits);
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
item_display = crc_pre_calcul(sdio_simple.unsigned_words,nbits,crc_calcul);
//Dec Item
var item_start_stop_array = dec_item_new_v2 (ch_dat0, sdio_simple);
ScanaStudio.dec_item_add_content("Start");
ScanaStudio.dec_item_add_content("S");
ScanaStudio.dec_item_add_sample_point(sdio_simple.start_sample,"P")
if (item_display[0] == 1) //Start bit = 1
{
ScanaStudio.dec_item_emphasize_error();
state_machine = ENUM_STATE_DATA_START;
trs_dat0.value = -1;
item_display = [];
crc_calcul = [];
ScanaStudio.dec_item_end();
break;
}
ScanaStudio.dec_item_end();
trs_dat0.value = -1;
data_transfer = false;
item_display = [];
crc_calcul = [];
//Packet View
ScanaStudio.packet_view_add_packet(false,ch_dat0,item_start_stop_array[0],item_start_stop_array[1],"Start","Data",ScanaStudio.get_channel_color(ch_dat0),ScanaStudio.get_channel_color(ch_dat0));
state_machine = ENUM_STATE_DATA ;
break;
}
else
{
trs_dat0 = ScanaStudio.trs_get_next(ch_dat0);
break;
}
}
else
{
if (trs_dat0.value == 0 ) //(falling edge)
{
nbits = 1;
trs_dat0.value = -1;
sdio_simple = sync_decode_v3(data_channels,trs_dat0.sample_index,nbits);
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
for (e=0; e<data_channels.length; e++)
{
item_display = crc_pre_calcul(sdio_simple.unsigned_words[e],nbits,crc_calcul);
//Dec Item
dec_item_new_v2 (data_channels[e], sdio_simple);
ScanaStudio.dec_item_add_content("Start");
ScanaStudio.dec_item_add_content("S");
ScanaStudio.dec_item_add_sample_point(sdio_simple.start_sample,"P")
if (item_display[0] == 1) //Start bit = 1
{
ScanaStudio.dec_item_emphasize_error();
state_machine = ENUM_STATE_DATA_START;
trs_data[e].value = -1;
item_display = [];
crc_calcul = [];
ScanaStudio.dec_item_end();
break;
}
ScanaStudio.dec_item_end();
trs_data[e].value = -1;
data_transfer = false;
item_display = [];
crc_calcul = [];
}
}
else
{
trs_dat0 = ScanaStudio.trs_get_next(ch_dat0);
break;
}
//Packet View
state_machine = ENUM_STATE_DATA ;
ScanaStudio.packet_view_add_packet(false,ch_dat0,sdio_simple.start_sample,sdio_simple.start_sample,"Start","Data",ScanaStudio.get_channel_color(ch_dat0),ScanaStudio.get_channel_color(ch_dat0));
}
}//end ENUM_STATE_DATA_START
case ENUM_STATE_DATA: //Looking for the data transfer
{
switch (Number(last_CMD))
{
case 6 : //CMD 6 (SWITCH_FUNC)
{
if (last_CMD_mode == 0)
{
nbits = 512;
var nbytes_total = nbits/8;
// Maximum Current/Power Consumption
nbytes = 2;
nbytes_total = nbytes_total - nbytes;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbytes*2*4/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbytes*2*4/(data_channels.length), crc_calcul); // Create Dec Item, samples, content and packet_view
var power_consumption = sdio_value * 3.6;
ScanaStudio.dec_item_add_content("Maximum current : " + sdio_value + "mA" + " or Maximum Power Consumption : " + power_consumption + "mW");
ScanaStudio.dec_item_add_content("Maximum current : " + sdio_value + "mA");
ScanaStudio.dec_item_add_content(sdio_value + "mA");
ScanaStudio.dec_item_end();
//Packet View
packet_string = "Maximum current : " + sdio_value + "mA";
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"Max Current",packet_string,"Data");
// Support Bits of Functions in Function Group 6-1
nbytes = 2;
for (t=6; t>0; t--)
{
nbytes_total = nbytes_total - nbytes;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbytes*2*4/(data_channels.length)); // nbytes
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbytes*2*4/(data_channels.length), crc_calcul); // Create Dec Item and samples, return nbytes value
string_content = CMD6_function_supported(sdio_value)
ScanaStudio.dec_item_add_content(string_content + " of Function Group " + t + " are supported");
ScanaStudio.dec_item_add_content(string_content + " of Function Group " + t);
ScanaStudio.dec_item_add_content(string_content);
ScanaStudio.dec_item_end();
//Packet View
packet_title = "Group " + t + " supported";
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,packet_title,string_content,"Data");
}
// Function Selection of Function Group 6-1
nbytes = 0.5;
for (t=6; t>0; t--)
{
nbytes_total = nbytes_total - nbytes;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbytes*2*4/(data_channels.length)); // nbytes
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbytes*2*4/(data_channels.length), crc_calcul); // Create Dec Item and samples, return nbytes value
if (CMD6_mode == 0)
{
packet_string = "You can switch to Function " + sdio_value;
ScanaStudio.dec_item_add_content("You can switch to Function " + sdio_value + " of Group " + t);
ScanaStudio.dec_item_add_content("You can switch to Function " + sdio_value);
}
else
{
packet_string = "Switched to function " + sdio_value;
ScanaStudio.dec_item_add_content("Switched to function " + sdio_value + " of Group " + t);
ScanaStudio.dec_item_add_content("Switched to function " + sdio_value);
}
ScanaStudio.dec_item_end();
//Packet View
packet_title = "Group " + t + " selected";
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,packet_title,packet_string,"Data");
}
// Data Structure Version
nbytes = 1;
nbytes_total = nbytes_total - nbytes;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbytes*2*4/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbytes*2*4/(data_channels.length), crc_calcul); // Create Dec Item, samples, content and packet_view
if (sdio_value == 0)
{
packet_string = "Only Bits 511:376 are defined";
types = "Data";
ScanaStudio.dec_item_add_content("Only Bits 511:376 are defined, others are reserved");
ScanaStudio.dec_item_add_content("Only Bits 511:376 are defined");
}
else if (sdio_value == 1)
{
packet_string = "Bits 511:272 are defined";
types = "Data";
ScanaStudio.dec_item_add_content("Bits 511:376 are defined");
}
else
{
packet_string = "Reserved";
types = "Error";
ScanaStudio.dec_item_add_content("Data Structure : Reserved value");
}
ScanaStudio.dec_item_end();
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"Data Structure",packet_string,types);
// if sdio_value egal 1 the busy status bit are defined
if (sdio_value == 1)
{
// Reserved for Busy Status of function in group 6-1
nbytes = 2;
for (t=6; t>0; t--)
{
nbytes_total = nbytes_total - nbytes;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbytes*2*4/(data_channels.length)); // nbytes
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbytes*2*4/(data_channels.length), crc_calcul); // Create Dec Item and samples, return nbytes value
string_content = CMD6_function_supported(sdio_value);
ScanaStudio.dec_item_add_content(string_content + "of Function Group " + t + " are ready");
ScanaStudio.dec_item_add_content(string_content + " are ready");
ScanaStudio.dec_item_end();
//Packet View
packet_title = "Busy bits of Group " + t;
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,packet_title,packet_string,"Data");
}
}
nbytes = 1;
for (d=0; d<nbytes_total; d++)
{
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,8/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, 8/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Reserved bits";
types = "Misc";
ScanaStudio.dec_item_add_content("Reserved bits");
}
else
{
packet_string = "Reserved bits should be 0";
types = "Error";
ScanaStudio.dec_item_add_content("Reserved bits should be 0");
}
ScanaStudio.dec_item_end();
//Packet view
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"Reserved bit",packet_string,types);
}
trs_dat0.value = -1;
}
usual_data = false;
data_transfer = false;
break;
}
case 13 : //ACMD 13 (SD_STATUS)
{
if (last_CMD_mode == 1)
{
nbits = 512; // SD Status
nbytes_total = nbits/8;
if (speed_mode == 1)
{
for (d=0; d<nbytes_total; d++)
{
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,8/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, 8/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
ScanaStudio.dec_item_add_content("SD Status");
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SD Status","","Data");
}
}
else
{
// DAT_BUS_WIDTH
nbits = 2;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "1 DAT bus";
types = "Data";
ScanaStudio.dec_item_add_content(packet_string);
}
else if (sdio_value == 2)
{
packet_string = "4 DAT bus";
types = "Data";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = "reserved";
types = "Error";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"DAT_BUS_WIDTH",packet_string,types);
// SECURED_MODE
nbits = 1;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Not in the mode";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = "In Secured Mode";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SECURED_MODE",packet_string,"Data");
// Reserved bits
nbits = 13;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Reserved bits";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = "Reserved bits should be 0";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"Reserved bit",packet_string,"Misc");
// SD_CARD_TYPE
nbits = 16;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Regular SD RD/WR Card";
ScanaStudio.dec_item_add_content(packet_string);
}
else if (sdio_value == 1)
{
packet_string = "SD ROM Card";
ScanaStudio.dec_item_add_content(packet_string);
}
else if (sdio_value == 2)
{
packet_string = "OTP";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = "Reserved bit";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SD_CARD_TYPE",packet_string,"Data");
// SIZE_OF_PROTECTED_AREA
nbits = 32;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
ScanaStudio.dec_item_add_content("SIZE_OF_PROTECTED_AREA : " + sdio_value + " or 0b" + pad(sdio_value.toString(16),nbits/4));
ScanaStudio.dec_item_add_content("SIZE_OF_PROTECTED_AREA : " + sdio_value);
ScanaStudio.dec_item_add_content(sdio_value);
ScanaStudio.dec_item_end();
//Packet View
packet_string = sdio_value + " or 0b" + pad(sdio_value.toString(16),nbits/4);
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SIZE_OF_PROTECTED_AREA",packet_string,"Data");
// SPEED_CLASS
nbits = 8;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
string_content = CMD13_speed_class(sdio_value);
ScanaStudio.dec_item_add_content("SPEED_CLASS : " + string_content);
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SPEED_CLASS",string_content,"Data");
// PERFORMANCE_MOVE
nbits = 8;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Sequential Write";
ScanaStudio.dec_item_add_content("PERFORMANCE_MOVE : Sequential Write");
}
else if (sdio_value == 255)
{
packet_string = "Infinity";
ScanaStudio.dec_item_add_content("PERFORMANCE_MOVE : Infinity");
}
else
{
packet_string = sdio_value + "MB/sec";
ScanaStudio.dec_item_add_content("PERFORMANCE_MOVE : " + packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"SPEED_CLASS",packet_string,"Data");
// AU_SIZE
nbits = 4;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
packet_string = AU_SIZE(sdio_value);
ScanaStudio.dec_item_add_content("AU_SIZE : " + packet_string);
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"AU_SIZE",packet_string,"Data");
// Reserved bits
nbits = 4;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Reserved bits";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = "Reserved bits should be 0";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"Reserved bit",packet_string,"Misc");
// ERASE_SIZE
nbits = 16;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Erase Time-out Calculation not supported";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = sdio_value + " AU";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"ERASE_SIZE",packet_string,"Data");
// ERASE_TIMEOUT
nbits = 6;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
if (sdio_value == 0)
{
packet_string = "Erase Time-out Calculation not supported";
ScanaStudio.dec_item_add_content(packet_string);
}
else
{
packet_string = sdio_value + "s";
ScanaStudio.dec_item_add_content(packet_string);
}
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"ERASE_TIMEOUT",packet_string,"Data");
// ERASE_OFFSET
nbits = 2;
sdio_simple = sync_decode_v3(data_channels,sdio_simple.end_sample+1,nbits/(data_channels.length)); // 1 byte
if (last_trans == true) //if sync_decode overpassed the last sample
{
go_to_last_trans_data();
break;
}
sdio_value = add_sdio_wide_width_data_item(data_channels, sdio_simple, nbits/(data_channels.length), crc_calcul); // Create Dec Item, samples, return nbytes value
packet_string = sdio_value + "s";
ScanaStudio.dec_item_add_content(packet_string);
ScanaStudio.dec_item_end();
//Packet View
packet_view_add_wide_width_packet(ch_dat0,sdio_simple,"ERASE_OFFSET",packet_string,"Data");
// UHS_SPEED_GRADE
nbits = 4;