summaryrefslogtreecommitdiffstats
path: root/uc_str912/prj_blinky_complex_startup/src/usb_regs.c
blob: 055575382a8f6a8e2a67a6ed424791f5f28e1342 (plain)
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 2006 STMicroelectronics ********************
* File Name          : usb_regs.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : Interface functions to USB cell registers
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS
* A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "USB_lib.h"

/*******************************************************************************
* Function Name  : SetCNTR
* Description    : Sets the CNTR (Control Register)
* Input          : wRegValue = register value
* Output         : None
* Return         : None
*******************************************************************************/
void SetCNTR(WORD wRegValue)
{
  _SetCNTR(wRegValue);
}

/*******************************************************************************
* Function Name  : GetCNTR
* Description    : Gets the CNTR
* Input          : None
* Output         : None
* Return         : CNTR value
*******************************************************************************/
WORD GetCNTR(void)
{
  return(_GetCNTR());
}

/*******************************************************************************
* Function Name  : SetISTR
* Description    : Sets the ISTR
* Input          : wRegValue = register value
* Output         : None
* Return         : None
*******************************************************************************/
void SetISTR(WORD wRegValue)
{
  _SetISTR(wRegValue);
}

/*******************************************************************************
* Function Name  : GetISTR
* Description    : Gets the ISTR (Interrupt Status Register)
* Input          : None
* Output         : None
* Return         : ISTR register value
*******************************************************************************/
WORD GetISTR(void)
{
  return(_GetISTR());
}

/*******************************************************************************
* Function Name  : GetFNR
* Description    : Gets the FNR (Frame Number Register)
* Input          : None
* Output         : None
* Return         : FNR regiter value
*******************************************************************************/
WORD GetFNR(void)
{
  return(_GetFNR());
}

/*******************************************************************************
* Function Name  : SetDADDR
* Description    : Sets the DADDR (Device Address Register)
* Input          : wRegValue = register value
* Output         : None
* Return         : None
*******************************************************************************/
void SetDADDR(WORD wRegValue)
{
  _SetDADDR(wRegValue);
}

/*******************************************************************************
* Function Name  : GetDADDR
* Description    : Gets the DADDR (Device Address Register)
* Input          : None
* Output         : None
* Return         : DADDR register value
*******************************************************************************/
WORD GetDADDR(void)
{
  return(_GetDADDR());
}

/*******************************************************************************
* Function Name  : SetBTABLE
* Description    : Sets the BTABLE (Buffer Table Register)
* Input          : BTABLE value
* Output         : None
* Return         : None
*******************************************************************************/
void SetBTABLE(WORD wRegValue)
{
  _SetBTABLE(wRegValue);
}

/*******************************************************************************
* Function Name  : GetBTABLE
* Description    : Gets the BTABLE (Buffer Table Register)
* Input          : None
* Output         : None
* Return         : BTABLE value
*******************************************************************************/
WORD GetBTABLE(void)
{
  return(_GetBTABLE());
}

/*******************************************************************************
* Function Name  : SetENDPOINT
* Description    : Sets the Endpoint Register
* Input          : bEpNum = endpoint Number[0:9], wRegValue= register value
* Output         : None
* Return         : None
*******************************************************************************/
void SetENDPOINT(BYTE bEpNum, WORD wRegValue)
{
  _SetENDPOINT(bEpNum,wRegValue);
}

/*******************************************************************************
* Function Name  : GetENDPOINT
* Description    : Gets the Endpoint Register value
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : Endpoint register value
*******************************************************************************/
WORD GetENDPOINT(BYTE bEpNum)
{
  return(_GetENDPOINT(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPtype
* Description    : Sets the Endpoint Type
* Input          : - bEpNum = endpoint number[0:9]
*                  - wType  = endpint type:  EP_BULK,EP_CONTROL,EP_ISOCHRONOUS
*                  EP_INTERRUPT
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPType(BYTE bEpNum, WORD wType)
{
  _SetEPType(bEpNum, wType);
}

/*******************************************************************************
* Function Name  : GetEPtype
* Description    : Gets the Endpoint type
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : Endpoint type: EP_BULK,EP_CONTROL,EP_ISOCHRONOUS
*                  EP_INTERRUPT
*******************************************************************************/
WORD GetEPType(BYTE bEpNum)
{
  return(_GetEPType(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPTxStatus
* Description    : Sets the endpoint Tx status
* Input          : - bEpNum = endpoint number[0:9]
*                  - wState = Tx status: EP_TX_DIS,EP_TX_STALL,EP_TX_NAK,EP_TX_VALID
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPTxStatus(BYTE bEpNum, WORD wState)
{
  _SetEPTxStatus(bEpNum,wState);
}

/*******************************************************************************
* Function Name  : SetEPRxStatus
* Description    : Sets the endpoint Rx status
* Input          : - bEpNum = endpoint number[0:9]
*                  - wState = Rx status: EP_RX_DIS,EP_RX_STALL,EP_RX_NAK,EP_RX_VALID
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPRxStatus(BYTE bEpNum, WORD wState)
{
  _SetEPRxStatus(bEpNum,wState);
}

/*******************************************************************************
* Function Name  : GetEPTxStatus
* Description    : Gets the endpoint Tx Status
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : Enpointx Tx Status: EP_TX_DIS,EP_TX_STALL,EP_TX_NAK,EP_TX_VALID
*******************************************************************************/
WORD GetEPTxStatus(BYTE bEpNum)
{
  return(_GetEPTxStatus(bEpNum));
}

/*******************************************************************************
* Function Name  : GetEPRxStatus
* Description    : Gets the endpoint Rx Status
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : Enpointx Rx Status: EP_RX_DIS,EP_RX_STALL,EP_RX_NAK,EP_RX_VALID
*******************************************************************************/
WORD GetEPRxStatus(BYTE bEpNum)
{
  return(_GetEPRxStatus(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPTxValid
* Description    : Sets the Endpoint Tx Status as valid
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPTxValid(BYTE bEpNum)
{
  _SetEPTxStatus(bEpNum, EP_TX_VALID);
}

/*******************************************************************************
* Function Name  : SetEPRxStatus
* Description    : Sets the Endpoint Rx Status as valid
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPRxValid(BYTE bEpNum)
{
  _SetEPRxStatus(bEpNum, EP_RX_VALID);
}

/*******************************************************************************
* Function Name  : SetEP_KIND
* Description    : Sets the Endpoint EP_KIND bit
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void SetEP_KIND(BYTE bEpNum)
{
  _SetEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : ClearEP_KIND
* Description    : Clears the Endpoint EP_KIND bit
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearEP_KIND(BYTE bEpNum)
{
  _ClearEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : Clear_Status_Out
* Description    : Clears the Status_Out bit (= EP_KIND bit)
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void Clear_Status_Out(BYTE bEpNum)
{
   _ClearEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : Set_Status_Out
* Description    : Sets the Status_Out bit (=EP_KIND bit)
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void Set_Status_Out(BYTE bEpNum)
{
  _SetEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : SetEPDoubleBuff
* Description    : Sets the DBL_BUF bit (=EP_KIND bit)
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDoubleBuff(BYTE bEpNum)
{
   _SetEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : ClearEPDoubleBuff
* Description    : Clears the DBL_BUF bit (=EP_KIND bit)
* Input          : bEpNum = endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearEPDoubleBuff(BYTE bEpNum)
{
   _ClearEP_KIND(bEpNum);
}

/*******************************************************************************
* Function Name  : GetTxStallStatus
* Description    : checks if endpoint Tx status== STALL
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : TRUE or FALSE
*******************************************************************************/
BOOL GetTxStallStatus(BYTE bEpNum)
{
  return(_GetTxStallStatus(bEpNum));
}

/*******************************************************************************
* Function Name  : GetRxStallStatus
* Description    : checks if endpoint Rx status ==STALL
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : TRUE or FALSE
*******************************************************************************/
BOOL GetRxStallStatus(BYTE bEpNum)
{
  return(_GetRxStallStatus(bEpNum));
}

/*******************************************************************************
* Function Name  : ClearEP_CTR_RX
* Description    : Clears the CTR_RX flag in endpoint
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearEP_CTR_RX(BYTE bEpNum)
{
  _ClearEP_CTR_RX(bEpNum);
}

/*******************************************************************************
* Function Name  : ClearEP_CTR_Tx
* Description    : Clears the CTR_Tx flag
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearEP_CTR_TX(BYTE bEpNum)
{
  _ClearEP_CTR_TX(bEpNum);
}

/*******************************************************************************
* Function Name  : ToggleDTOG_RX
* Description    : Toggles the DTOG_RX bit
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ToggleDTOG_RX(BYTE bEpNum)
{
 _ToggleDTOG_RX(bEpNum);
}

/*******************************************************************************
* Function Name  : ToggleDTOG_TX
* Description    : Toggles the DTOG_Tx bit
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ToggleDTOG_TX(BYTE bEpNum)
{
  _ToggleDTOG_TX(bEpNum);
}

/*******************************************************************************
* Function Name  : ClearDTOG_RX
* Description    : Clears the DTOG_RX bit
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearDTOG_RX(BYTE bEpNum)
{
  _ClearDTOG_RX(bEpNum);
}

/*******************************************************************************
* Function Name  : ClearDTOG_TX
* Description    : Clears the DTOG_TX bit
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void ClearDTOG_TX(BYTE bEpNum)
{
  _ClearDTOG_TX(bEpNum);
}

/*******************************************************************************
* Function Name  : SetEPAddress
* Description    : Sets the Endpoint Address
* Input          : -bEpNum: endpoint number[0:9]
*                  -bAddr : Address value
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPAddress(BYTE bEpNum,BYTE bAddr)
{
  _SetEPAddress(bEpNum,bAddr);
}

/*******************************************************************************
* Function Name  : GetEPAddress
* Description    : Gets the Endpoint Address
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Endpoint address value
*******************************************************************************/
BYTE GetEPAddress(BYTE bEpNum)
{
  return(_GetEPAddress(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPTxAddr
* Description    : Sets the Endpoint Tx buffer Addr offset in the PMA
* Input          : - bEpNum: endpoint number[0:9]
*                  - wAddr : Tx buffer address offset value in the PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPTxAddr(BYTE bEpNum, WORD wAddr)
{
	_SetEPTxAddr(bEpNum,wAddr);
}

/*******************************************************************************
* Function Name  : SetEPRxAddr
* Description    : Sets the Endpoint Rx buffer Addr in the Packet Memory Area PMA
* Input          : - bEpNum: endpoint number[0:9]
*                  - wAddr : Rx buffer address offset value in the PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPRxAddr(BYTE bEpNum, WORD wAddr)
{
   _SetEPRxAddr(bEpNum,wAddr);
}

/*******************************************************************************
* Function Name  : GetEPTxAddr
* Description    : Gets the Endpoint Tx buffer address offset in PMA
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Endpoint Tx buffer Address offset in PMA
*******************************************************************************/
WORD GetEPTxAddr(BYTE bEpNum)
{
  return (_GetEPTxAddr(bEpNum));
}

/*******************************************************************************
* Function Name  : GetEPRxAddr
* Description    : Gets the Endpoint Rx buffer address offset in the PMA
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Endpoint Rx buffer Address offset in PMA
*******************************************************************************/
WORD GetEPRxAddr(BYTE bEpNum)
{
 return(_GetEPRxAddr(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPTxCount
* Description    : Sets the Endpoint Tx buffer size
* Input          : - bEpNum: endpoint number[0:9]
*                  - wCount: size (in bytes) of the Tx buffer in the PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPTxCount(BYTE bEpNum, WORD wCount)
{
  _SetEPTxCount(bEpNum,wCount);
}

/*******************************************************************************
* Function Name  : SetEPRxCount
* Description    : Sets the Endpoint Rx buffer size
* Input          : - bEpNum: endpoint number[0:9]
*                  - wCount : size (in bytes) of the Rx buffer in the PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPRxCount(BYTE bEpNum, WORD wCount)
{
   _SetEPRxCount(bEpNum,wCount);
}
/*******************************************************************************
* Function Name  : GetEPTxCount
* Description    : Gets the Endpoint count value
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Endpoint TxCount value
*******************************************************************************/

WORD GetEPTxCount(BYTE bEpNum)
{
	  return(_GetEPTxCount(bEpNum));
}

/*******************************************************************************
* Function Name  : GetEPRxCount
* Description    : Gets the Endpoint Count register value
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Endpoint Rx Count value
*******************************************************************************/
WORD GetEPRxCount(BYTE bEpNum)
{
   return(_GetEPRxCount(bEpNum));
}

/*******************************************************************************
* Function Name  : SetEPDblBuffAddr
* Description    : Set double buffer buffer0, buffer1 addresses in the PMA
* Input          : - bEpNum: endpoint number[0:9]
*                  - wBuf0Addr : buffer0 Address offset in PMA
*                  - wBuf1Addr : buffer1 Address offset in PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuffAddr(BYTE bEpNum, WORD wBuf0Addr, WORD wBuf1Addr)
{
  _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
}

/*******************************************************************************
* Function Name  : SetEPDBlBuf0Addr
* Description    : Set buffer0 address in PMA
* Input          : -bEpNum: endpoint number[0:9]
*                  -wBuf0Addr: buffer0 Address offset in PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuf0Addr(BYTE bEpNum,WORD wBuf0Addr)
{
  _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
}
/*******************************************************************************
* Function Name  : SetEPDBlBuf1Addr
* Description    : Set buffer1 address in PMA
* Input          : -bEpNum: endpoint number[0:9]
*                  -wBuf1Addr: buffer1 Address offset in PMA
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuf1Addr(BYTE bEpNum,WORD wBuf1Addr)
{
  _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
}

/*******************************************************************************
* Function Name  : GetEPDblBuf0Addr
* Description    : Gets buffer0 address
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Buffer 0 Address offset in PMA
*******************************************************************************/
WORD GetEPDblBuf0Addr(BYTE bEpNum)
{
  return(_GetEPDblBuf0Addr(bEpNum));
}

/*******************************************************************************
* Function Name  : GetEPDblbuf1Addr
* Description    : Gets buffer1 address
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : Buffer 1 Address offset in PMA
*******************************************************************************/
WORD GetEPDblBuf1Addr(BYTE bEpNum)
{
  return(_GetEPDblBuf1Addr(bEpNum));
}
/*******************************************************************************
* Function Name  : SetEPDblBuf1Count
* Description    : Set buffer1 size
* Input          : - bEpNum: endpoint number[0:9]
*                  - bDir: buffer direction :  EP_DBUF_OUT or EP_DBUF_IN
*                  - wCount: bytes count value
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuf1Count(BYTE bEpNum, BYTE bDir,WORD wCount)
{
 if(bDir == EP_DBUF_IN)					
 /* IN double buffered endpoint */						
 {
   *_pEPBufCount(bEpNum)&= 0x000FFFF;
   *_pEPBufCount(bEpNum)|=(wCount<<16);
 }
 else if(bDir == EP_DBUF_OUT)				
 /* OUT double buffered endpoint */						
  _SetEPRxCount(bEpNum, wCount);
}


/*******************************************************************************
* Function Name  : SetEPDblBuf0Count
* Description    : Set buffer0 size
* Input          : - bEpNum: endpoint number[0:9]
*                  - bDir: buffer direction :  EP_DBUF_OUT or EP_DBUF_IN
*                  - wCount: bytes count value
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuf0Count(BYTE bEpNum, BYTE bDir,WORD wCount)
{
DWORD BLsize=0;
DWORD Blocks;
if(bDir == EP_DBUF_IN)   					
/* IN double bufferd endpoint */						
SetEPTxCount(bEpNum,wCount);
else if(bDir == EP_DBUF_OUT) {				
/* OUT double bufferd endpoint */			

   if (wCount < 64) Blocks = wCount>>1;
   else
   {
   BLsize = 0x8000;
   Blocks = wCount>>6;
   }
	 *_pEPBufCount(bEpNum) &=~0x8000;
	 *_pEPBufCount(bEpNum) |=BLsize;
	 *_pEPBufCount(bEpNum)  &=~0x7C00;
	 *_pEPBufCount(bEpNum) |=Blocks<<10;
	 *_pEPBufCount(bEpNum) &=0xFFFFFC00;
 }
}

/*******************************************************************************
* Function Name  : SetEPDblBuffCount
* Description    : Set buffer0 or 1 size
* Input          : - bEpNum: endpoint number[0:9]
                   - bDir: buffer direction :  EP_DBUF_OUT, EP_DBUF_IN
                   - wCount: bytes count value
* Output         : None
* Return         : None
*******************************************************************************/
void SetEPDblBuffCount(BYTE bEpNum, BYTE bDir, WORD wCount)
{
	SetEPDblBuf0Count(bEpNum, bDir,wCount);
	SetEPDblBuf1Count(bEpNum, bDir,wCount);
}

/*******************************************************************************
* Function Name  : GetEPDblBuf0Count
* Description    : Get buffer0 bytes count
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : buffer0 bytes count
*******************************************************************************/
WORD GetEPDblBuf0Count(BYTE bEpNum)
{
	return(_GetEPDblBuf0Count(bEpNum));
}

/*******************************************************************************
* Function Name  : GetEPDBuf1Count
* Description    : Get buffer1 bytes count
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : buffer1 bytes count
*******************************************************************************/
WORD GetEPDblBuf1Count(BYTE bEpNum)
{
	return(_GetEPDblBuf1Count(bEpNum));
}

/*******************************************************************************
* Function Name  : Free User buffer
* Description    : Toggles the SW_Buf bit
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void FreeUserBuffer(BYTE bEpNum, BYTE bDir)
{
   if(bDir== EP_DBUF_OUT)
   { /* OUT double buffered endpoint */
    _ToggleDTOG_TX(bEpNum);
   }
   else if(bDir == EP_DBUF_IN)
   { /* IN double buffered endpoint */
    _ToggleDTOG_RX(bEpNum);
   }
}

/*******************************************************************************
* Function Name  : ToWord
* Description    : Puts 2 bytes into a single word
* Input          : -bh : MSB byte
                   -bl : LSB byte
* Output         : None
* Return         : Word
*******************************************************************************/
WORD ToWord(BYTE bh, BYTE bl)
{
	WORD wRet;
	wRet = (WORD)bl | ((WORD)bh << 8);
	return(wRet);
}

/*******************************************************************************
* Function Name  : ByteSwap
* Description    : Swaps two bytes in a word
* Input          : wSwW: word
* Output         : None
* Return         : Word swapped
*******************************************************************************/
WORD ByteSwap(WORD wSwW)
{
	BYTE bTemp;
	WORD wRet;
	bTemp = (BYTE)(wSwW & 0xff);
	wRet =  (wSwW >> 8) | ((WORD)bTemp << 8);
	return(wRet);
}


/* DMA Functions */

/*******************************************************************************
* Function Name  : SetDMAburstTxSize
* Description    : Configure the Burst Size for a Tx Endpoint
* Input          : DestBsize: Destination Burst Size
* Output         : None
* Return         : None
*******************************************************************************/
void SetDMABurstTxSize(BYTE DestBsize)
{
  *DMABSIZE &=~0xEF;
  *DMABSIZE = (DestBsize<<4);
}

/*******************************************************************************
* Function Name  : SetDMABurstRxSize
* Description    : Configure the Burst Size for a Rx Endpoint
* Input          : SrcBsize: Source Burst
* Output         : None
* Return         : None
*******************************************************************************/
void SetDMABurstRxSize(BYTE SrcBsize)
{
	*DMABSIZE &=~0x7;
	*DMABSIZE = SrcBsize;
}

/*******************************************************************************
* Function Name  : DMAUnlinkedModeTxConfig
* Description    : Configure a Tx Endpoint to trigger TX Unlinked DMA request
* Note           : Up to three endpoints could be configured to trigger DMA
                   request, an index[0:2] must be associated to an endpoint
* Input          : -bEpNum: endpoint number[0:9]
*                  -index: 0,1 or 2
* Output         : None
* Return         : None
*******************************************************************************/
void DMAUnlinkedModeTxConfig(BYTE bEpNum ,BYTE index)
{
  *DMACR2 &=~(0x0F<<(4*index));
  *DMACR2 |=bEpNum<<(4*index);
}

/*******************************************************************************
* Function Name  : DMAUnlinkedModeTxEnable
* Description    : Enable a Tx endpoint to trigger Tx DMA request
* Input          : -index :0,1 or 2 = index associated to endpoint in function
*                   "DMAUnlinkedModeTxConfig"
* Output         : None
* Return         : None
*******************************************************************************/
void DMAUnlinkedModeTxEnable(BYTE index)
{
	*DMACR3 &=~0x01;  /*DMA Tx linked mode disabled*/
	*DMACR2 &=~0x3000;
	*DMACR2 |=(index+1)<<12;
}
	
/*******************************************************************************
* Function Name  : DMAUnlinkedModeTxDisable
* Description    : Enable a Tx endpoint to trigger Tx DMA request
* Input          : index :0,1 or 2 = index associated to endpoint in function
*                   "DMAUnlinkedModeTxConfig"
* Output         : None
* Return         : None
*******************************************************************************/	
void DMAUnlinkedModeTxDisable(BYTE index)
{
	*DMACR2 &=~0x3000;
}

/*******************************************************************************
* Function Name  : DMAUnlinkedModeRxEnable
* Description    : Enable a Rx Endpoint to trigger Rx DMA
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void DMAUnlinkedModeRxEnable(BYTE bEpNum)
{
	*DMACR3 &=~0x80;   /*DMA Rx linked mode disabled*/
	*DMACR1 |=(0x1<<bEpNum);
}

/*******************************************************************************
* Function Name  : DMAUnlinkedModeRxDisable
* Description    : Disable a Rx Endpoint to trigger Rx DMA
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void DMAUnlinkedModeRxDisable(BYTE bEpNum)
{
	*DMACR1 &=~(0x1<<bEpNum);
}

/*******************************************************************************
* Function Name  : DMALinkedModeRxConfig
* Description    : Configure a Rx endpoint to trigger DMA linked request
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeRxConfig(BYTE bEpNum)
{
	*DMACR3 &=~0x1E00;
	*DMACR3 |=bEpNum<<9;
}

/*******************************************************************************
* Function Name  : DMALinkedModeTxConfig
* Description    : Configure a Tx endpoint to trigger DMA linked request
* Input          : bEpNum: endpoint number[0:9]
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeTxConfig(BYTE bEpNum)
{
	*DMACR3 &=~0x1E;
	*DMACR3 |=bEpNum<<1;
}

/*******************************************************************************
* Function Name  : DMALinkedModeRxEnable
* Description    : Enable the DMA Linked Rx mode
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeRxEnable(void)
{
	*DMACR3 |=0x100;
	*DMACR3 |=0x2000;
}

/*******************************************************************************
* Function Name  : DMALinkedModeTxEnable
* Description    : Enable the DMA Linked Tx mode
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeTxEnable(void)
{
	*DMACR3 |=0x1;
	*DMACR3 |=0x20;
}
/*******************************************************************************
* Function Name  : DMALinkedModeRxDisable
* Description    : Disable the DMA Linked Rx mode
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeRxDisable(void)
{
	*DMACR3 &=~0x100;
	*DMACR3 &=~0x2000;
}

/*******************************************************************************
* Function Name  : DMALinkedModeTxDisable
* Description    : Disable the DMA Linked Tx mode
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DMALinkedModeTxDisable(void)
{
	*DMACR3 &=~0x1;
	*DMACR3 &=~0x20;
}
/*******************************************************************************
* Function Name  : USB_DMASynchEnable
* Description    : Enable the Synchronization Logic
* Input          : TRUE or FALSE
* Output         : None
* Return         : None
*******************************************************************************/
void DMASynchEnable(void)
{
	*DMACR3 |=0x40;
}

/*******************************************************************************
* Function Name  : USB_DMASynchDisable
* Description    : Disable the Synchronization Logic
* Input          : TRUE or FALSE
* Output         : None
* Return         : None
*******************************************************************************/
void DMASynchDisable(void)
{
	*DMACR3 &=~0x40;
}

/*******************************************************************************
* Function Name  : SetDMALLITxLength
* Description    : Set the DMA LLI Tx length
* Input          : length
* Output         : None
* Return         : None
*******************************************************************************/
void SetDMALLITxLength(BYTE length)
{
	*DMALLI &=~0xFF;
	*DMALLI |= length;
}

/*******************************************************************************
* Function Name  : SetDMALLIRxLength
* Description    : Set the DMA LLI Rx length
* Input          : length
* Output         : None
* Return         : None
*******************************************************************************/
void SetDMALLIRxLength(BYTE length )
{
		*DMALLI &=~0xFF00;
	  *DMALLI |= length<<8;
}

/*******************************************************************************
* Function Name  : SetDMALLIRxPacketNum
* Description    : Set the LLI_RX_NPACKETS field in register USB_DMABSIZE register
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SetDMALLIRxPacketNum(BYTE PacketNum)
{
	*DMABSIZE &=0xFF;
	*DMABSIZE |=(PacketNum<<8);
}

/*******************************************************************************
* Function Name  : GetDMALLIPacketNum
* Description    : gets the LLI_RX_NPACKETS field value
* Input          : None
* Output         : None
* Return         : LLI_RX_NPACKETS field value
*******************************************************************************/
BYTE GetDMALLIRxPacketNum(void)
{
	return((BYTE)(*DMABSIZE & 0xFF00)>>8);
}
OpenPOWER on IntegriCloud