forked from CodeKill3r/BCD2000HIDplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcd2000hid+.8051.asm
3713 lines (3288 loc) · 101 KB
/
bcd2000hid+.8051.asm
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 : tusb_8051_raw.bin
; Format : Binary file
; Base Address: 0000h Range: 0000h - 0C16h Loaded length: 0C16h
; Processor : 8032 [RAM=256 ROM=0 EPROM=0 EEPROM=0]
; Target assembler: 8051 Cross-Assembler by MetaLink Corporation
; Byte sex : Big endian
; ===========================================================================
; Segment type: Pure code
;.segment code
CSEG
; =============== S U B R O U T I N E =======================================
; RESET
; Attributes: thunk
; public RESET
org RESET
ljmp RESET_0
; End of function RESET
; =============== S U B R O U T I N E =======================================
; public IE0
org EXTI0
ljmp IE0_0
; End of function IE0
; =============== S U B R O U T I N E =======================================
usbPrepResp: ; CODE XREF: usbreqgetstat+1Cp
; usbreqgetstat+32p ...
setb C
mov A, R5 ; desc_len_L
subb A, wLenRamL
mov A, R4 ; desc_len_H
subb A, wLenRamH
jnc desctoolong ; desc len >= req len
mov usbRespLenH, R4
mov usbRespLenL, R5
sjmp code_1B
; ---------------------------------------------------------------------------
desctoolong: ; CODE XREF: usbPrepResp+7j
mov usbRespLenH, wLenRamH ; if descriptor too long, only reply the requested length
mov usbRespLenL, wLenRamL
; public code_1B
code_1B: ; CODE XREF: usbPrepResp+Dj
mov usbRespCfg, R3
mov usbRespH, R2
mov usbRespL, R1
ret
; End of function usbPrepResp
; =============== S U B R O U T I N E =======================================
nullsub_1: ; CODE XREF: RESET_0-32Ap
ret
; End of function nullsub_1
; =============== S U B R O U T I N E =======================================
; Serial port interrupt
; Attributes: thunk
; public RI_TI
RI_TI:
ljmp RI_TI_0 ; Serial IO handler
; End of function RI_TI ;
; Serial_in -> MIDI-OUT
; MIDI-IN -> Serial_out
; =============== S U B R O U T I N E =======================================
serBtoUsbMidOut: ; CODE XREF: RESET_0-306p
;new code to build MIDI messages to USB sandard
;there are only 3 types of messages supported:
; -note on
; -note off
; -control change
; all are 3 bytes converted to 4 UsB message bytes
; only accept if there are at least 3 bytes in the serial buffer
;
; need to purge incomplete data***
; need to handle running status (same message type) ---> note off = note on /w velocity=0
;
;
; MIDI IN embedded bJackID (CN) = 1
jb GlobStat.3, presRxBuff ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
ljmp noRxBuff
presRxBuff:
mov RAM_13, #1 ; ext RAM
mov RAM_14, #0F8h ; 'ř' ; usbMidiOutBufH
mov RAM_15, #50h ; 'P' ; usbMidiOutBufL
mov R3, RAM_13
mov R2, RAM_14
mov R1, RAM_15
; if size rx buff size < 3 then return (no complete message)
lcall getRxBuf_size
mov RAM_12, R7 ;midi buff size
;find midi msg head byte (90 80 or B0)
mov R6, #0 ;usb msg byte count
midiOutCpLoop: ; CODE XREF: serBtoUsbMidOut+92j
mov A, RAM_12
jnz midibyteloop
ljmp endmidiOutCpLoop
midibyteloop:
lcall getMidiOutBuf ; read a MIDI_OUT_BUF byte to R7
; 0xFF if empty
;process data
mov A, R7
jb ACC.7, midictrl ;jump if midi status byte present (need 3 bytes)
;otherwise it is a rolling status (only need 2 bytes)
mov A, RAM_12
clr C
subb A, #2
jc endmidiOutRlLoop ;not enough data in buffer
mov A, RAM_1C
mov R7, RAM_1C
sjmp midimsg ;this will decrement the size properly
midictrl: ;midi control/status byte found
mov A, RAM_12
clr C
subb A, #3
jc endmidiOutCpLoop ;not enough data in buffer
dec RAM_12
lcall readMidiOutBuf ; already know this, but this will step the pointers properly
cjne R7, #80h, notNoteOff
;note off --- may not be present -- used instead note on /w velocity=0
sjmp midimsg
notNoteOff:
cjne R7, #90h, notNoteOn
;note on
sjmp midimsg
notNoteOn:
cjne R7, #0B0h, notCC
;control change
sjmp midimsg
notCC:
mov A, RAM_12
jz endmidiOutCpLoop
sjmp midibyteloop
;if (R6) && (RAM_11+R6 < RAM_12) -- removed -- wait for enough bytes instead
;remaining bytes
;else
;remove byte and loop
midimsg:
clr C
mov A, RAM_12
subb A, #2
jc endmidiOutCpLoop ; msg too small, wait for more bytes
mov RAM_12, A
;usb header byte
mov A, R7
mov RAM_1C, A
;add A, #2
swap A
lcall writeAToBuff ; R2 ptrH
; R1 ptrL
; R3 mode select:
; 0x00 - write RAM (R1)
; 0x01 - write ext RAM (R2:R1)
; 0xFE - write ext RAM (R1)
; other - no write
;midi byte0
inc R1
mov A, R7
lcall writeAToBuff
;midi byte1
lcall readMidiOutBuf
inc R1
mov A, R7
lcall writeAToBuff
;midi byte2
;jog fix --- if msg is "B0 12 40" or "B0 13 40" then replace 40h with 3Fh
mov A, RAM_1C
cjne A, #0B0h, nojog
cjne R7, #13h, nodeckb
dec R7
nodeckb:
cjne R7, #12h, nojog
lcall readMidiOutBuf
inc R1
mov A, R7
cjne A, #40h, notjogrev
dec A
notjogrev:
lcall writeAToBuff
sjmp usbmsglen
nojog:
lcall readMidiOutBuf
inc R1
mov A, R7
lcall writeAToBuff
usbmsglen:
;usb message length
mov A, R6
add A, #4
mov R6, A
ljmp midiOutCpLoop
endmidiOutRlLoop:
add A, #2
jnz leftinbuff
clr GlobStat.3 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp leftinbuff
endmidiOutCpLoop:
add A, #3
jnz leftinbuff
clr GlobStat.3 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
leftinbuff:
mov A, R6
jz noRxBuff
mov DPTR, #IEPDCNTX1 ; In endpoint 1 - X buffer data count byte
mov A, R6; '<' ; data counter = 0x3C
; no NACK
movx @DPTR, A
noRxBuff:
ret;
; =============== S U B R O U T I N E =======================================
usb_in_ep0: ; CODE XREF: code_507p
mov A, RAM_4B
code_F9:
jz code_107
clr A
mov RAM_4B, A
code_FE:
mov A, RAM_47
xrl A, #3
jz code_107
code_104:
ljmp code_1B1
; ---------------------------------------------------------------------------
code_107: ; CODE XREF: usb_in_ep0:code_F9j
; usb_in_ep0+Bj
mov A, RAM_47
xrl A, #1
jnz code_110
ljmp code_1B1
; ---------------------------------------------------------------------------
code_110: ; CODE XREF: usb_in_ep0+14j
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
jnb ACC.3, code_11A ; Accumulator
ljmp code_1B1
; ---------------------------------------------------------------------------
code_11A: ; CODE XREF: usb_in_ep0+1Dj
mov A, RAM_4E
xrl A, #1
jnz code_14A
mov A, RAM_47
xrl A, #3
jnz code_146
lcall usbTxResp_iep0 ; Input Endpoint 0 response copy to USB Buffer
; in chunks of 8 bytes
;
; return status in R7
; 1 = Tx ended
; 0 = Tx pending
mov A, R7
xrl A, #1
jnz code_192
mov RAM_47, #7
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; in endp 0 Stall
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
anl A, #0F7h ; '÷' ; out endp 0 Not Stall
movx @DPTR, A
mov DPTR, #OEPDCNTX0 ; Out endpoint 0 - X buffer data count byte
clr A ; out endp 0 buff clear
movx @DPTR, A
sjmp code_192
; ---------------------------------------------------------------------------
code_146: ; CODE XREF: usb_in_ep0+2Dj
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp code_192
; ---------------------------------------------------------------------------
code_14A: ; CODE XREF: usb_in_ep0+27j
mov A, RAM_4E
xrl A, #2
jnz code_190
mov A, RAM_47
cjne A, #6, code_16B
mov RAM_47, #1
clr A
mov RAM_4E, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; in endp 0 Stall
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; out endp 0 Stall
movx @DPTR, A
sjmp code_192
; ---------------------------------------------------------------------------
code_16B: ; CODE XREF: usb_in_ep0+5Bj
mov A, RAM_47
cjne A, #8, code_18C
mov DPTR, #USBFADR ; USB function address register
mov A, wValRamL
movx @DPTR, A
mov RAM_47, #1
clr A
mov RAM_4E, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; in endp 0 Stall
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; out endp 0 Stall
movx @DPTR, A
sjmp code_192
; ---------------------------------------------------------------------------
code_18C: ; CODE XREF: usb_in_ep0+76j
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp code_192
; ---------------------------------------------------------------------------
code_190: ; CODE XREF: usb_in_ep0+57j
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
code_192: ; CODE XREF: usb_in_ep0+35j
; usb_in_ep0+4Dj ...
jnb GlobStat.2, code_1B1 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
mov RAM_47, #1
clr A
mov RAM_4E, A
clr GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
mov DPTR, #IEPDCNTX0 ; In endpoint 0 - X buffer data count byte
mov A, #80h ; '€'
movx @DPTR, A ; NACK -- X buff empty
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; in endp 0 Stall
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8 ; out endp 0 Stall
movx @DPTR, A
code_1B1: ; CODE XREF: usb_in_ep0:code_104j
; usb_in_ep0+16j ...
ret
; End of function usb_in_ep0
; =============== S U B R O U T I N E =======================================
usbMidiInToSerB: ; CODE XREF: RESET_0-310p
mov DPTR, #OEPDCNTX1 ; Out endpoint 1 - X buffer data count byte
movx A, @DPTR
mov RAM_11, A
mov A, RAM_11
jb ACC.7, oep1_nack ; jump if NACK set
ljmp subret
; ---------------------------------------------------------------------------
oep1_nack: ; CODE XREF: usbMidiInToSerB+8j
anl RAM_11, #7Fh ; '' ; X buff count
mov A, RAM_11
cjne A, #04h, clrBuff ;accept only 4 byte messages
mov DPTR, #usbBufMidiIn ; @(OEPBBAX1) -- message type:
movx A, @DPTR ;USB header byte
anl A, #0Fh
cjne A, #0Ch, txNormal ;if not program change, just dump to serial buffer
inc DPL
movx A, @DPTR ;midi status/command byte (midi byte0)
mov R7, A
lcall writeMidiInBuf
inc DPL
movx A, @DPTR ;midi byte1
setb C
subb A, #0
jc code_21C
setb C ; mic enabled
sjmp code_21D
; ---------------------------------------------------------------------------
code_21C: ; CODE XREF: usbMidiInToSerB+65j
clr C ; mic disabled
code_21D: ; CODE XREF: usbMidiInToSerB+68j
mov P1.1, C ; set mic mode
addc A, #0
sjmp txRest
txNormal:
inc DPL
movx A, @DPTR
mov R7, A
lcall writeMidiInBuf
inc DPL
movx A, @DPTR
txRest:
mov R7, A
lcall writeMidiInBuf
inc DPL
movx A, @DPTR
mov R7, A
lcall writeMidiInBuf
clrBuff: ; CODE XREF: usbMidiInToSerB+1Ej
; usbMidiInToSerB+35j ...
mov DPTR, #OEPDCNTX1 ; Out endpoint 1 - X buffer data count byte
clr A
movx @DPTR, A
subret: ; CODE XREF: usbMidiInToSerB+Bj
ret
; End of function usbMidiInToSerB
; =============== S U B R O U T I N E =======================================
usb_setup_st: ; CODE XREF: code_510p
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
anl A, #0F7h ; '÷' ; not stall
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
anl A, #0F7h ; '÷' ; not stall
movx @DPTR, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #20h ; ' ' ; set toggle (?)
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
orl A, #20h ; ' ' ; set toggle (?)
movx @DPTR, A
mov DPTR, #OEPDCNTX0 ; Out endpoint 0 - X buffer data count byte
clr A ; X buff empty
movx @DPTR, A
mov DPTR, #IEPDCNTX0 ; In endpoint 0 - X buffer data count byte
mov A, #80h ; '€' ; NACK -- X buff empty
movx @DPTR, A
clr GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
clr A
mov RAM_4C, A
mov DPTR, #bmRequestType ; identifies the characteristics of the request
movx A, @DPTR
mov bmReqRam, A
inc DPTR ; bRequest
movx A, @DPTR
mov bReqRam, A
inc DPTR ; wValue
movx A, @DPTR
mov wValRamL, A
inc DPTR ; wValue
movx A, @DPTR
mov wValRamH, A
inc DPTR ; wIndex
movx A, @DPTR
mov wIdxRamL, A
inc DPTR ; wIndex
movx A, @DPTR
mov wIdxRamH, A
inc DPTR ; wLength
movx A, @DPTR
mov wLenRamL, A
inc DPTR ; wLength
movx A, @DPTR
mov wLenRamH, A
mov A, RAM_47
xrl A, #7
jz code_2B1
mov A, RAM_47
cjne A, #3, code_2B4
code_2B1: ; CODE XREF: usb_setup_st+52j
mov RAM_46, #1
code_2B4: ; CODE XREF: usb_setup_st+56j
mov A, RAM_47
xrl A, #6
jz code_2BF
mov A, RAM_47
cjne A, #4, code_2C2
code_2BF: ; CODE XREF: usb_setup_st+60j
mov RAM_4B, #1
code_2C2: ; CODE XREF: usb_setup_st+64j
mov A, bmReqRam
jnb ACC.7, code_2D9 ; Accumulator
mov RAM_47, #5
mov RAM_4E, #1
lcall usbrequest
mov A, RAM_47
cjne A, #3, code_2F8
lcall usbTxResp_iep0 ; Input Endpoint 0 response copy to USB Buffer
; in chunks of 8 bytes
;
; return status in R7
; 1 = Tx ended
; 0 = Tx pending
ret
; ---------------------------------------------------------------------------
code_2D9: ; CODE XREF: usb_setup_st+6Cj
mov A, wLenRamL
orl A, wLenRamH
jnz code_2E9
mov RAM_47, #4
mov RAM_4E, #2
lcall usbrequest
ret
; ---------------------------------------------------------------------------
code_2E9: ; CODE XREF: usb_setup_st+85j
mov RAM_47, #2
mov RAM_4E, #2
mov usbRespLenH, wLenRamH
mov usbRespLenL, wLenRamL
clr A
mov RAM_4C, A
code_2F8: ; CODE XREF: usb_setup_st+7Aj
ret
; End of function usb_setup_st
; =============== S U B R O U T I N E =======================================
usb_out_ep0: ; CODE XREF: code_502p
mov A, RAM_46
jz code_309
clr A
mov RAM_46, A
mov A, RAM_47
xrl A, #2
jz code_309
ljmp usboe0_ret
; ---------------------------------------------------------------------------
code_309: ; CODE XREF: usb_out_ep0+2j
; usb_out_ep0+Bj
mov A, RAM_47
xrl A, #1
jnz code_312
ljmp usboe0_ret
; ---------------------------------------------------------------------------
code_312: ; CODE XREF: usb_out_ep0+14j
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
mov R7, A
jb ACC.3, usboe0_ret ; Accumulator
mov A, RAM_4E
xrl A, #1
jnz code_345
mov A, RAM_47
xrl A, #7
jz code_32B
mov A, RAM_47
cjne A, #3, code_341
code_32B: ; CODE XREF: usb_out_ep0+2Bj
mov RAM_47, #1
clr A
mov RAM_4E, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
mov A, R7
orl A, #8
movx @DPTR, A
sjmp code_36B
; ---------------------------------------------------------------------------
code_341: ; CODE XREF: usb_out_ep0+2Fj
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp code_36B
; ---------------------------------------------------------------------------
code_345: ; CODE XREF: usb_out_ep0+25j
mov A, RAM_4E
xrl A, #2
jnz code_369
mov A, RAM_47
cjne A, #2, code_365
lcall code_949
mov A, R7
jnz code_35A
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp code_36B
; ---------------------------------------------------------------------------
code_35A: ; CODE XREF: usb_out_ep0+5Bj
cjne R7, #1, code_36B
mov RAM_47, #4
lcall usbrequest
sjmp code_36B
; ---------------------------------------------------------------------------
code_365: ; CODE XREF: usb_out_ep0+54j
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
sjmp code_36B
; ---------------------------------------------------------------------------
code_369: ; CODE XREF: usb_out_ep0+50j
setb GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
code_36B: ; CODE XREF: usb_out_ep0+46j
; usb_out_ep0+4Aj ...
jnb GlobStat.2, usboe0_ret ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
clr GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
mov RAM_47, #1
clr A
mov RAM_4E, A
mov DPTR, #IEPDCNTX0 ; In endpoint 0 - X buffer data count byte
mov A, #80h ; '€'
movx @DPTR, A
mov DPTR, #OEPDCNTX0 ; Out endpoint 0 - X buffer data count byte
clr A
movx @DPTR, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
movx A, @DPTR
orl A, #8
movx @DPTR, A
usboe0_ret: ; CODE XREF: usb_out_ep0+Dj
; usb_out_ep0+16j ...
ret
; End of function usb_out_ep0
; =============== S U B R O U T I N E =======================================
setCodecDma: ; CODE XREF: usbreqsetcnf+3p
mov DPTR, #CPTCTL ; CODEC port interface control and status register
mov A, #1 ; CODEC reset
movx @DPTR, A
mov DPTR, #OEPCNF2 ; Out endpoint 2 - configuration byte
mov A, #0C7h ; 'Ç' ; endp2 enable -- isocho -- 8bytes/sample
movx @DPTR, A
inc DPTR ; OEPBBAX2
mov A, #20h ; ' ' ; X buffer @ 0x100
movx @DPTR, A
inc DPTR ; OEPBSIZ2
mov A, #30h ; '0' ; buff size=48*8 =384 bytes (0x180)
movx @DPTR, A
inc DPTR ; OEPDCNTX2
clr A ; no NACK -- X buff empty
movx @DPTR, A
mov DPTR, #OEPBBAY2 ; Out endpoint 2 - Y buffer base address byte
mov A, #50h ; 'P' ; Y buffer @ 0x280
movx @DPTR, A
mov DPTR, #OEPDCNTY2 ; Out endpoint 2 - Y buffer data count byte
clr A
movx @DPTR, A ; no NACK -- Y buff empty
mov DPTR, #IEPCNF3 ; In endpoint 3 - configuration byte
mov A, #0C7h ; 'Ç' ; endp2 enable -- isocho -- 8bytes/sample
movx @DPTR, A
inc DPTR ; IEPBBAX3
mov A, #80h ; '€' ; X buffer @ 0x400
movx @DPTR, A
inc DPTR ; IEPBSIZ3
mov A, #30h ; '0' ; buff size=48*8 =384 bytes (0x180)
movx @DPTR, A
inc DPTR ; IEPDCNTX3
mov A, #80h ; '€' ; NACK -- X buff empty
movx @DPTR, A
mov DPTR, #IEPBBAY3 ; In endpoint 3 - Y buffer base address byte
mov A, #0B0h ; '°' ; Y buffer & 0x580
movx @DPTR, A
mov DPTR, #IEPDCNTY3 ; In endpoint 3 - Y buffer data count byte
mov A, #80h ; '€' ; NACK -- Y buff empty
movx @DPTR, A
mov DPTR, #GLOBCTL ; Global control register
movx A, @DPTR
anl A, #0FEh ; 'ţ' ; disable CODEC port
movx @DPTR, A
mov DPTR, #CPTCNF1 ; CODEC port interface configuration register 1
mov A, #0Dh ; 2 time slot/frame -- i2s mode - 2 ser out & 2 in (mode5)
movx @DPTR, A
mov DPTR, #CPTCNF2 ; CODEC port interface configuration register 2
mov A, #0CDh ; 'Í' ; 32 CSCLK cycles for time slot 0 -- 16bits/time slot
; 32 CSCLK cycles per time slot
movx @DPTR, A
mov DPTR, #CPTCNF3 ; CODEC port interface configuration register 3
mov A, #0BCh ; 'Ľ' ; 1 CSCLK cyc delay from CSYNC -- no padding if audio frame invalid
; CSCLK on negative edge -- CSYNC active high
; CSYNC length=time slot0 -- byte order flip by DMA
; CSCLK & CSYNC == output (from tusb)
movx @DPTR, A
mov DPTR, #CPTCNF4 ; CODEC port interface configuration register 4
mov A, #3 ; CLK source from divM -- CSCLK div = div by 4
movx @DPTR, A
mov DPTR, #DMATSH0 ; DMA channel 0 time slot assignment register (high byte)
mov A, #40h ; '@' ; 2 bytes per slot
movx @DPTR, A
inc DPTR ; DMATSL0
mov A, #33h ; '3' ; time slots 5-4 & 1-0 are supported
movx @DPTR, A
mov DPTR, #DMACTL0 ; DMA channel 0 control register
mov A, #82h ; '‚' ; DMA enabled -- no wrap -- USB in -- endp 2
movx @DPTR, A
mov DPTR, #DMATSH1 ; DMA channel 1 time slot assignment register (high byte)
mov A, #40h ; '@' ; 2 bytes per slot
movx @DPTR, A
inc DPTR ; DMATSL1
mov A, #33h ; '3'
movx @DPTR, A ; time slots 5-4 & 1-0 are supported
mov DPTR, #DMACTL1 ; DMA channel 1 control register
mov A, #8Bh ; '‹' ; DMA enabled -- no wrap -- USB out -- endp 3
movx @DPTR, A
mov DPTR, #DMACTL2 ; DMA channel 2 control register
clr A ; clear DMA2 & 3
movx @DPTR, A
inc DPTR
movx @DPTR, A
inc DPTR
movx @DPTR, A
inc DPTR
movx @DPTR, A
inc DPTR
movx @DPTR, A
inc DPTR
movx @DPTR, A
mov DPTR, #GLOBCTL ; Global control register
movx A, @DPTR
orl A, #1 ; enable CODEC port
movx @DPTR, A
ret
; End of function setCodecDma
; =============== S U B R O U T I N E =======================================
usb_init: ; CODE XREF: RESET_0-333p
mov DPTR, #ACGFRQ2 ; Adaptive clock generator frequency register (byte 2)
mov A, #6Ah ; 'j'
movx @DPTR, A
inc DPTR ; ACGFRQ1
mov A, #4Bh ; 'K'
movx @DPTR, A
inc DPTR ; ACGFRQ0 -- N=26.5734 --> MCLKO= (25/N)*(192/8)=22.5792MHz
;(CS4220 @ 44100 Hz)
mov A, #20h ; ' '
movx @DPTR, A
mov DPTR, #ACGDCTL ; Adaptive clock generator divider control register
mov A, #10h ; MCLKO /2 --- MCLKI /1 (no div)
movx @DPTR, A
mov DPTR, #ACGCTL ; Adaptive clock generator control register
mov A, #44h ; 'D' ; MCLKO enable -- MCLK_cpt=MCLKO -- MCLK_inp=MCLKI -- divider_en
movx @DPTR, A
mov DPTR, #IEPCNF0 ; In endpoint 0 - configuration byte
mov A, #84h ; '„' ; endp enable -- not isocho -- interrupt enable
movx @DPTR, A
inc DPTR ; IEPBBAX0
mov A, #1 ; X buff addr= 0x08
movx @DPTR, A
inc DPTR ; IEPBSIZ0
movx @DPTR, A ; X & Y buff size=8 bytes
inc DPTR ; IEPDCNTX0
mov A, #80h ; '€' ; NACK -- X buff empty
movx @DPTR, A
mov DPTR, #OEPCNF0 ; Out endpoint 0 - configuration byte
mov A, #84h ; '„' ; endp enable -- not isocho -- interrupt enable
movx @DPTR, A
inc DPTR ; OEPBBAX0
clr A ; X buff addr= 0x00
movx @DPTR, A
inc DPTR ; OEPBSIZ0
inc A ; X & Y buff size=8 bytes
movx @DPTR, A
inc DPTR ; OEPDCNTX0
clr A ; no NACK -- X buff empty
movx @DPTR, A
mov DPTR, #IEPCNF1 ; In endpoint 1 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF2 ; In endpoint 0 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF3 ; In endpoint 3 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF4 ; In endpoint 4 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF5 ; In endpoint 5 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF6 ; In endpoint 6 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #IEPCNF7 ; In endpoint 7 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF1 ; Out endpoint 1 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF2 ; Out endpoint 2 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF3 ; Out endpoint 3 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF4 ; Out endpoint 4 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF5 ; Out endpoint 5 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF6 ; Out endpoint 6 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #OEPCNF7 ; Out endpoint 7 - configuration byte
movx @DPTR, A ; endp disabled
mov DPTR, #USBFADR ; USB function address register
movx @DPTR, A ; USB func addr reset to 0x00
mov DPTR, #USBIMSK ; USB interrupt mask register
mov A, #0F5h ; 'ő' ; eanble USB interrupts except pseudo start-of-frame
movx @DPTR, A
mov RAM_47, #1
clr A
mov RAM_4E, A
clr GlobStat.2 ; 3: rx buff
; 4: tx buff empty
; 6: enable response counter
mov RAM_4B, A
mov RAM_46, A
clr IE.7
clr TCON.0 ; Timer 0/1 Control Register
setb IE.0
setb IE.7
mov DPTR, #USBCTL ; USB control register
mov A, #0D0h ; 'Đ' ; USB connect -- function enable -- function reset enable
movx @DPTR, A
ret
; End of function usb_init
; =============== S U B R O U T I N E =======================================
IE0_0: ; CODE XREF: IE0j
push ACC ; Accumulator
push B ; B Register
push DPH ; Data Pointer, High Byte
push DPL ; Data Pointer, Low Byte
push PSW ; Program Status Word Register
mov PSW, #0 ; Program Status Word Register
push RAM_0
push RAM_1
push RAM_2
push RAM_3
push RAM_4
push RAM_5
push RAM_6
push RAM_7
clr IE.7
mov DPTR, #VECINT ; interrupt vector register
movx A, @DPTR ; save interrupt type to A
mov R7, A ; copy A to R7
lcall find_inth_addr ; starting from DPTR find int_type
; End of function IE0_0 ;
; if ((DPTR*) or ((DPTR+1)*))
; if ((DPTR+2)* == int_type)
; jmp ( (DPTR*)<<8 || ((DPTR+1)*) )
; else
; DPTR+=3
; else
; DPTR+=2
; jmp ( (DPTR*)<<8 || ((DPTR+1)*) )
;
; interrupt table items
; 0xHH -- handler address high
; 0xLL -- handler address low
; 0xtt -- intterrupt type
;
; if there is a 0x0000 address word in the table
; then jump to the next address word
; ---------------------------------------------------------------------------
int_vect_table: dw code_502
db 0 ; USB out endpoint 0
dw code_50C
db 1 ; USB out endpoint 1
dw code_507
db 8 ; USB in endpoint 0
dw code_510
db 12h ; USB setup stage transaction
dw code_52C
db 13h ; USB pseudo start-of-frame
dw code_52C
db 14h ; USB start-of-frame
dw code_527
db 15h ; USB function resume
dw code_522
db 16h ; USB function suspended
dw usb_rst
db 17h ; USB function reset
db 0 ; end_of table
db 0
dw cleanup_n_reti ; default handler
; =============== S U B R O U T I N E =======================================
code_502: ; DATA XREF: code:int_vect_tableo
lcall usb_out_ep0
sjmp cleanup_n_reti
; End of function code_502
; =============== S U B R O U T I N E =======================================
code_507: ; DATA XREF: code:000004E9o
lcall usb_in_ep0
sjmp cleanup_n_reti
; End of function code_507
; =============== S U B R O U T I N E =======================================