uart_vfifo.c
63.7 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* uart_vfifo.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This Module defines the functions for virtual FIFO
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "drv_features.h"
#include "sync_data.h"
//#include "kal_release.h"
//#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
//#include "stack_buff_pool.h"
//#include "app_buff_alloc.h"
#include "drv_comm.h"
#include "reg_base.h"
#include "uart_hw.h"
//#include "bmd.h"
//#include "intrCtrl.h"
//#include "drvpdn.h"
//#include "stack_ltlcom.h" /*msg_send_ext_queue.....definitions*/
#include "stack_config.h" /*MOD_UART1_HISR,MOD_UART2_HISR*/
#include "uart_sw.h"
#include "uart_internal.h"
#include "dma_hw.h"
//#include "dma_sw.h"
#include "uart_hw.h"
#include "gpt_sw.h"
//#include "init.h"
#include "drv_trc.h"
#ifdef __ROMSA_SUPPORT__
#ifndef __ROMSA_EXPORT_UART_H__
#include "romsa_export_uart.h"
#endif
#include "gpt_hw.h"
#endif
//#include "kal_non_specific_general_types.h"
//#include "kal_common_defs.h"
#include "l1_interface.h"
#include "us_timer.h"
#include "kal_general_types.h"
#include "kal_public_defs.h"
#include "kal_public_api.h"
#include "btif_sw.h"
#include "dcl.h"
#include "kal_internal_api.h"
#ifdef __DMA_UART_VIRTUAL_FIFO__
#if !defined(DRV_UART_OFF)
/*variable*/
extern const kal_uint32 UART_BaseAddr[MAX_UART_PORT_NUM];
extern UARTStruct UARTPort[MAX_UART_PORT_NUM];
extern const UART_rings_struct *UART_rings;
extern kal_uint8 uart_escape_state;
extern kal_bool send_Rxilm[MAX_UART_PORT_NUM];
extern kal_bool send_Txilm[MAX_UART_PORT_NUM];
/*function*/
extern void UART_sendilm(UART_PORT port, msg_type msgid);
extern void UART_Calback(void *parameter);
extern UartDriver_strcut* pUart_CMD_FUNC[];
kal_uint32 GET_RX_DMA_WRPTR( UART_PORT port);
kal_uint32 GET_RX_DMA_RDPTR( UART_PORT port);
#if defined(DRV_UART_VFIFO_V3)
void DMA_PUSH32(kal_uint8 channel, kal_uint32 data )
{
kal_uint16 LeftRingRoom, VFIFOSize ;
kal_uint8 i = 0;
kal_uint32* pBuffer = NULL;
kal_uint16 WritePointer = 0;
kal_uint8* pdata = (kal_uint8*)&data;
//ch = channel;
WritePointer = DRV_Reg(DMA_VFF_WPT(channel));
VFIFOSize = DRV_Reg(DMA_VFF_SIZE(channel));
LeftRingRoom = VFIFOSize-WritePointer;
pBuffer = (kal_uint32*)(WritePointer + DRV_Reg32(DMA_SRC(channel)));
if(LeftRingRoom > 5)
{
*pBuffer = data;
Data_Sync_Barrier();
DRV_WriteReg(DMA_VFF_WPT(channel),(WritePointer+4));
}
else
{
for(i =0; i < 4; i++)
{
DMA_PUSH(channel, *pdata);
}
}
}
void DMA_PUSH_Multi_VFIFO(UART_PORT port,kal_uint8 *pData, kal_uint32 size, kal_uint32 multi)
{
kal_uint8 ch;
kal_uint32 LeftRoom, VFIFO_Size, Write_Pointer ;
ch = UARTPort[port].Tx_DMA_Ch;
VFIFO_Size = DRV_Reg(DMA_VFF_SIZE(ch));
Write_Pointer = DRV_Reg(DMA_VFF_WPT(ch));
if(0 == size)
return;
LeftRoom = VFIFO_Size - Write_Pointer;
if(LeftRoom == 0)
return;
if(LeftRoom > size)
{
//memcpy((volatile kal_uint8 *)(DRV_Reg(DMA_VFF_WPT(ch))+DRV_Reg32(DMA_SRC(ch))), (kal_uint8 *)pData, size);
//for build warning
memcpy((kal_uint8 *)(DRV_Reg(DMA_VFF_WPT(ch))+DRV_Reg32(DMA_SRC(ch))), (kal_uint8 *)pData, size);
Data_Sync_Barrier();
DRV_WriteReg32(DMA_VFF_WPT(ch), DRV_Reg32(DMA_VFF_WPT(ch))+size);
}
if(LeftRoom < size)
{
memcpy((kal_uint8 *)(DRV_Reg(DMA_VFF_WPT(ch))+DRV_Reg32(DMA_SRC(ch))), (kal_uint8 *)pData, LeftRoom);
Data_Sync_Barrier();
DRV_WriteReg32(DMA_VFF_WPT(ch), (~DRV_Reg32(DMA_VFF_WPT(ch)))&0x10000);
memcpy((kal_uint8 *)(DRV_Reg(DMA_VFF_WPT(ch))+DRV_Reg32(DMA_SRC(ch))), (kal_uint8 *)(pData +LeftRoom), (size-LeftRoom));
Data_Sync_Barrier();
DRV_WriteReg32(DMA_VFF_WPT(ch), DRV_Reg32(DMA_VFF_WPT(ch))+(size-LeftRoom));
}
if(LeftRoom == size)
{
memcpy((kal_uint8 *)(DRV_Reg(DMA_VFF_WPT(ch))+DRV_Reg32(DMA_SRC(ch))), (kal_uint8 *)pData, LeftRoom);
Data_Sync_Barrier();
DRV_WriteReg32(DMA_VFF_WPT(ch), (~DRV_Reg32(DMA_VFF_WPT(ch)))&0x10000);
}
}
#endif
#if defined(DRV_UART_VFIFO_V2)
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
#else
kal_timerid uart_isr_flush_timer_id;
UART_PORT uart_isr_port;
kal_hisrid uart_isr_hisr_id = KAL_NILHISR_ID;
#endif //defined(DRV_UART_VFIFO_V2_USE_GPT)
#define UART_DMA_FLUSH_WAIT_LOOP 500000
void DMA_PUSH_Multi_VFIFO(UART_PORT port,kal_uint8 *pData, kal_uint32 size, kal_uint32 multi)
{
kal_uint32 *p32tmp;
kal_uint32 i;
kal_uint32 header, tail;
kal_uint32 _times;
// kal_uint16 LSR;
kal_uint8 *pTemp;
kal_uint8 ch;
ch = UARTPort[port].Tx_DMA_Ch;
multi = multi<=4?4:8;
header = size>=multi?multi-((int)pData%multi):size; // align 8
header = header==multi?0:header;
tail = size>=multi?(size-header)%multi:0;
_times = (size-header-tail)/multi;
for (i=0;i<header;i++)
{
//DMA_PUSH(ch,*(pData+i));
while(DRV_UART_Reg(DMA_W_INT_BUF_SIZE(ch))>=64);
*(volatile kal_uint8*)DMA_VPORT(ch) = (kal_uint8)*(pData+i);
}
for(i=0;i<_times;i++)
{
p32tmp = (kal_uint32 *)(pData+header);
// if(multi == 4)
DMA_PUSH32(ch, *(p32tmp+i) );
// else
// DMA_PUSH64(*(p32tmp+2*i), *(p32tmp+2*i+1), ch);
}
for (i=0;i<tail;i++)
{
pTemp = pData+header+multi*_times;
DMA_PUSH(ch,*(pTemp+i));
}
}
void uart_dma_flush(void *timer_param)
{
kal_uint8 i;
kal_uint8 ch;
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
kal_uint32 *pTimerHandle=(kal_uint32 *)timer_param;
SGPT_CTRL_START_T start;
#else
kal_timerid *pTimerid=(kal_timerid *)timer_param;
#endif
kal_uint32 flush_tick;
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
for (i=0;i<MAX_UART_PORT_NUM;i++)
{
if (UARTPort[i].uart_flush_timer_handle==*pTimerHandle)
{
break;
}
else if(UARTPort[i].uart_isr_flush_timer_handle==*pTimerHandle)
{
break;
}
}
#else
for (i=0;i<MAX_UART_PORT_NUM;i++)
{
if (UARTPort[i].uart_flush_timer_id==*pTimerid)
{
break;
}
}
if (i==MAX_UART_PORT_NUM && *pTimerid==uart_isr_flush_timer_id)
{
i=uart_isr_port;
}
#endif
ASSERT(i < MAX_UART_PORT_NUM);
ch=UARTPort[i].Tx_DMA_Ch;
if (DRV_UART_Reg(DMA_W_INT_BUF_SIZE(ch))!=0)
{
if (DRV_UART_Reg(DMA_FLUSH(ch))==0)
{
DMA_Flush(ch);
}
else
{
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
flush_tick=DRV_UART_Reg(DMA_VFF_VALID_SIZE(ch))*10/UARTPort[i].DCB.baud/100;
// GPTI_StopItem(*pTimerHandle);
DclSGPT_Control(*pTimerHandle,SGPT_CMD_STOP,0);
/*
GPTI_StartItem(*pTimerHandle,
flush_tick,
uart_dma_flush,
(void*)pTimerHandle);
*/
start.u2Tick=flush_tick;
start.pfCallback=uart_dma_flush;
start.vPara=(void*)pTimerHandle;
DclSGPT_Control(*pTimerHandle,SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start);
#else
flush_tick=DRV_UART_Reg(DMA_VFF_VALID_SIZE(ch))*10*650/3/UARTPort[i].DCB.baud;
kal_set_timer(*pTimerid, (kal_timer_func_ptr)uart_dma_flush, (void*)pTimerid, flush_tick, 0);
#endif
}
}
}
void uart_isr_dma_flush(void)
{
kal_uint32 uart_flush_timer_tick;
if (kal_get_time_remaining(uart_isr_flush_timer_id)==0)
{
uart_flush_timer_tick=DRV_UART_Reg(DMA_VFF_VALID_SIZE(UARTPort[uart_isr_port].Tx_DMA_Ch))*10*650/3/UARTPort[uart_isr_port].DCB.baud;
kal_cancel_timer(uart_isr_flush_timer_id);
kal_set_timer(uart_isr_flush_timer_id, (kal_timer_func_ptr)uart_dma_flush, (void*)&uart_isr_flush_timer_id, uart_flush_timer_tick,0);
}
}
void VFIFO_DMA_Flush(UART_PORT port,kal_bool is_ISR)
{
kal_uint32 uart_flush_timer_tick;
kal_uint8 ch;
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
DCL_HANDLE *pTimerHandle;
SGPT_CTRL_START_T start;
#else
kal_timerid *pTimerid;
#endif
ch=UARTPort[port].Tx_DMA_Ch;
if (DRV_UART_Reg(DMA_W_INT_BUF_SIZE(ch))!=0)
{
if(DRV_UART_Reg(DMA_FLUSH(ch))==0)
{
DMA_Flush(ch);
}
else
{
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
if (is_ISR==KAL_FALSE)
pTimerHandle=&UARTPort[port].uart_flush_timer_handle;
else
pTimerHandle=&UARTPort[port].uart_isr_flush_timer_handle;
uart_flush_timer_tick=DRV_UART_Reg(DMA_VFF_VALID_SIZE(ch))*10/UARTPort[port].DCB.baud/100;
// GPTI_StopItem(*pTimerHandle);
DclSGPT_Control(*pTimerHandle,SGPT_CMD_STOP,0);
/*
GPTI_StartItem(*pTimerHandle,
uart_flush_timer_tick,
uart_dma_flush,
(void*)pTimerHandle);*/
start.u2Tick=uart_flush_timer_tick;
start.pfCallback=uart_dma_flush;
start.vPara=(void*)pTimerHandle;
DclSGPT_Control(*pTimerHandle,SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start);
#else
if (is_ISR==KAL_FALSE)
{
pTimerid=&UARTPort[port].uart_flush_timer_id;
if (kal_get_time_remaining(*pTimerid)==0)
{
uart_flush_timer_tick=DRV_UART_Reg(DMA_VFF_VALID_SIZE(ch))*10*650/3/UARTPort[port].DCB.baud;
kal_cancel_timer(*pTimerid);
kal_set_timer(*pTimerid, (kal_timer_func_ptr)uart_dma_flush, (void*)pTimerid, uart_flush_timer_tick,0);
}
}
else
{
uart_isr_port=port;
kal_activate_hisr(uart_isr_hisr_id);
}
#endif //defined(DRV_UART_VFIFO_V2_USEGPT)
}
}
}
#endif /* defined(DRV_UART_VFIFO_V2) */
/*UART API*/
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_GetTxISRRoomLeft_VFIFO(UART_PORT port)
{
kal_uint16 real_count;
real_count=DMA_GetVFIFO_Roomleft(UARTPort[port].Tx_DMA_Ch);
/*temp solution: to cover L1 trace bug*/
if(real_count<=16)
real_count=0;
else
real_count-=16;
return real_count;
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_GetTxRoomLeft_VFIFO(UART_PORT port)
{
kal_uint16 real_count;
kal_uint32 savedMask;
savedMask = SaveAndSetIRQMask();
real_count=DMA_GetVFIFO_Roomleft(UARTPort[port].Tx_DMA_Ch);
RestoreIRQMask(savedMask);
return real_count;
}
kal_uint16 U_GetBytesAvail_VFIFO(UART_PORT port)
{
kal_uint16 real_count;
real_count=DMA_GetVFIFO_Avail(UARTPort[port].Rx_DMA_Ch);
return real_count;
}
// toy recommend: do not handle any tx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint8 U_GetUARTByte_VFIFO(UART_PORT port)
{
kal_uint8 data;
kal_uint8 ch;
kal_uint16 real_count=0;
ch = UARTPort[port].Rx_DMA_Ch;
while(1)
{
real_count=DMA_GetVFIFO_Avail(ch);
if (real_count!=0)
{
data = DMA_POP(ch);
//Shengkai
if (uart_support_autoescape()==KAL_FALSE || (stack_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_TST_READER) )
{
if(UARTPort[port].DCB.flowControl==fc_sw)
{
if(uart_escape_state==0)
{
if(data==0x77)
uart_escape_state=0x77;
else
return data;
}
else if (uart_escape_state==0x77)
{
uart_escape_state=0x0;
switch(data)
{
case 0x01:
return UARTPort[port].DCB.xonChar;
// break;
case 0x02:
return UARTPort[port].DCB.xoffChar;
// break;
case 0x03:
return 0x77;
// break;
default:
break;
}
}
}
else
return data;
}
else
{
return data;
}
}
}
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
void U_PutUARTByte_VFIFO(UART_PORT port, kal_uint8 data)
{
kal_uint8 ch;
#if defined(DRV_UART_VFIFO_V2)
kal_uint32 start_ticks=0;
#endif /* defined(DRV_UART_VFIFO_V2) */
ch = UARTPort[port].Tx_DMA_Ch;
while(1)
{
if (!IS_VFIFO_FULL(ch)) // fifo not full
{
DMA_PUSH(ch,data);
break;
}
}
#if defined(DRV_UART_VFIFO_V2)
while (DRV_UART_Reg(DMA_FLUSH(ch))!=0)
{
start_ticks++;//busy loop to wait DMA send out all data.
if(start_ticks > UART_DMA_FLUSH_WAIT_LOOP)
break;
}
DMA_Flush(ch);
#elif defined(DRV_UART_VFIFO_V3)
DMA_Flush(ch);
DMA_Flush(ch);
#else
#endif /* defined(DRV_UART_VFIFO_V2) */
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
void PutUARTData_VFIFO(UART_PORT port, kal_uint8 escape_char, kal_uint8 data)
{
if(port >= MAX_UART_PORT_NUM)
return;
if( (stack_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_TST_READER)||
(uart_support_autoescape()==KAL_FALSE))
{
if (data == UARTPort[port].DCB.xonChar)
{
pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
pUart_CMD_FUNC[port]->PutUARTByte(port, 0x01);
}
else if (data == UARTPort[port].DCB.xoffChar)
{
pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
pUart_CMD_FUNC[port]->PutUARTByte(port, 0x02);
}
else if (data == escape_char)
{
pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
pUart_CMD_FUNC[port]->PutUARTByte(port, 0x03);
}
else
{
pUart_CMD_FUNC[port]->PutUARTByte(port, data);
}
}
else
{
pUart_CMD_FUNC[port]->PutUARTByte(port, data);
}
}
// toy recommend: do not handle any tx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_GetBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid)
{
kal_uint16 real_count,index;
kal_uint8 ch;
kal_uint16 data_count=0;
#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif //#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
ch = UARTPort[port].Rx_DMA_Ch;
EXT_ASSERT( (UARTPort[port].ownerid == ownerid), (kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
if (status != NULL)
*status = 0;
// get available bytes in rx ring buffer
real_count = DMA_GetVFIFO_Avail(ch);
#if defined(DRV_UART_MEMORY_TRACE)
if(MOD_BT == ownerid)
{
wp = GET_RX_DMA_WRPTR(port);
nextChar = DRV_UART_Reg8(wp);
rp = GET_RX_DMA_RDPTR(port);
UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), Length);
UART_DBG(real_count, wp, nextChar, rp);
}
#endif //#if defined(DRV_UART_MEMORY_TRACE)
#if defined(DRV_UART_COMPENSATE_AT)
if( (UARTPort[port].CompensateAT == Compensate_AT) || (UARTPort[port].CompensateAT == Compensate_at))
{
data_count += 2;
*(Buffaddr) = (UARTPort[port].CompensateAT == Compensate_AT) ? 0x41 : 0x61; // A or a
*(Buffaddr+1) = (UARTPort[port].CompensateAT == Compensate_AT) ? 0x54 : 0x74; // T or t
UARTPort[port].CompensateAT = Compensate_None;
}
else if(UARTPort[port].CompensateAT == Compensate_Wait) // it should never happen.
{ // if autobaud fail, restart autobaud detection again.
// UART_SetBaudRate(port, UART_BAUD_AUTO, UARTPort[port].ownerid);
// U_SetBaudRate(port, UART_BAUD_AUTO, UARTPort[port].ownerid);
pUart_CMD_FUNC[port]->SetBaudRate(port, UART_BAUD_AUTO, UARTPort[port].ownerid);
send_Rxilm[port] = KAL_TRUE;
EnableRxIntr(UART_BaseAddr[port]);
return 0;
}
#endif
if (status != NULL)
{
if (UARTPort[port].EscFound)
{
*status |= UART_STAT_EscDet;
UARTPort[port].EscFound = KAL_FALSE;
}
if (UARTPort[port].breakDet)
{
*status |= UART_STAT_Break;
UARTPort[port].breakDet = KAL_FALSE;
}
}
do
{
real_count = DMA_GetVFIFO_Avail(ch);
if( (stack_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_TST_READER)||
(uart_support_autoescape()==KAL_FALSE&& UARTPort[port].DCB.flowControl==fc_sw ))
{
for (index = 0; (index < real_count)&& (data_count<Length) ; index++)
{
*(Buffaddr+data_count) = DMA_POP(ch);
/*The following are for software flow control*/
if(uart_escape_state==0)
{
if(*(Buffaddr+data_count)==0x77)
{
uart_escape_state=0x77;
}
else
{
data_count++;
}
}
else if (uart_escape_state==0x77)
{
switch(*(Buffaddr+data_count))
{
case 0x01:
*(Buffaddr+data_count)=UARTPort[port].DCB.xonChar;
data_count++;
break;
case 0x02:
*(Buffaddr+data_count)=UARTPort[port].DCB.xoffChar;
data_count++;
break;
case 0x03:
*(Buffaddr+data_count)=0x77;
data_count++;
break;
default:
break;
}
uart_escape_state=0x0;
}
}
}
else/*HW flow control*/
{
for (index = 0; (index < real_count)&& (data_count<Length) ; index++)
{
*(Buffaddr+data_count) = DMA_POP(ch);
data_count++;
}
}
/*satisfy uart owner request, so break*/
if (data_count == Length) break;
/* disable interrupt*/
DMA_DisableINT(ch);
//race condition, 3M baudrate only need 12us to trigger timeout interrupt
//it may cause interrupt between get avail and set flag.
DisableRxIntr(UART_BaseAddr[port]);
real_count = DMA_GetVFIFO_Avail(ch);
/*there is no data in ringbuffer, so break*/
if (real_count==0)
{
send_Rxilm[port] = KAL_TRUE;
EnableRxIntr(UART_BaseAddr[port]);
#if defined(DRV_UART_MEMORY_TRACE)
if(MOD_BT == ownerid)
{
wp = GET_RX_DMA_WRPTR(port);
nextChar = DRV_UART_Reg8(wp);
rp = GET_RX_DMA_RDPTR(port);
UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), Length);
UART_DBG(real_count, wp, nextChar, rp);
}
#endif //#if defined(DRV_UART_MEMORY_TRACE)
DMA_EnableINT(ch);
/* enable interrupt*/
break;
}
EnableRxIntr(UART_BaseAddr[port]);
DMA_EnableINT(ch);
/* enable interrupt*/
}while(KAL_TRUE);
DMA_EnableINT(ch);
return data_count;
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_PutBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid)
{
kal_uint8 ch;
kal_uint8 data;
#ifndef DRV_DEBUG
kal_uint16 real_count,index;
kal_uint32 savedMask;
ch = UARTPort[port].Tx_DMA_Ch;
EXT_ASSERT( (UARTPort[port].ownerid == ownerid), (kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
if((UARTPort[port].EnableTX == KAL_FALSE) || (UARTPort[port].power_on == KAL_FALSE))
{
return Length;
}
#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
if (UARTPort[port].sleep_on_tx == uart_sleep_on_tx_forbid)
{
UART_PDN_Disable(port);
}
#endif//#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
real_count = DMA_GetVFIFO_Roomleft(ch);
UART_DBG(__LINE__,0,0,real_count);
/*#ifdef VFIFO_DBG
{
kal_char s[50];
sprintf(s,"uart_putbytes,len %d,left %d",Length,real_count);
kal_print(s);
}
#endif*/
if(UARTPort[port].ownerid != MOD_TST_READER)// if catcher log via UART,Tx will be too many data
drv_trace2(TRACE_GROUP_4,UART_TX_VFIFO_U_PutBytes_VFIFO,Length,real_count);
if (real_count >= Length)
{
real_count = Length;
}
else
{
send_Txilm[port] = KAL_TRUE;
DMA_EnableINT(ch);
}
if(ownerid==MOD_TST_READER)
{
for (index = 0; index < real_count; index++)
{
data = *(Buffaddr+index);
savedMask = SaveAndSetIRQMask();
if(!IS_VFIFO_FULL(ch))
{
DMA_PUSH(ch,data);
}
else
{
real_count=index;
send_Txilm[port] = KAL_TRUE;
DMA_EnableINT(ch);
RestoreIRQMask(savedMask);
break;
}
RestoreIRQMask(savedMask);
}
}
else/*not TST */
{
#if defined(DRV_UART_VFIFO_V2)
DMA_PUSH_Multi_VFIFO(port,Buffaddr,real_count,4);
VFIFO_DMA_Flush(port,KAL_FALSE);
#elif defined(DRV_UART_VFIFO_V3)
DMA_PUSH_Multi_VFIFO(port,Buffaddr,real_count,4);
DMA_Flush(ch);
DMA_Flush(ch);
#else
for (index = 0; index < real_count; index++)
{
DMA_PUSH(ch,*(Buffaddr+index));
}
#endif /* defined(DRV_UART_VFIFO_V2) */
}
/*invoke THRE interrupt*/
//EnableTxIntr(UART_BaseAddr[port]);
return real_count;
#else /*DRV_DEBUG*/
return Length;
#endif /*DRV_DEBUG*/
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_PutISRBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid)
{
kal_uint8 ch;
#ifndef DRV_DEBUG
kal_uint16 real_count;
#if (!defined(DRV_UART_VFIFO_V2)) && (!defined(DRV_UART_VFIFO_V3))
kal_uint16 index;
#endif
if(port >= MAX_UART_PORT_NUM)
EXT_ASSERT (0,(kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
ch = UARTPort[port].Tx_DMA_Ch;
EXT_ASSERT( (UARTPort[port].ownerid == ownerid), (kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
if((UARTPort[port].EnableTX == KAL_FALSE) || (UARTPort[port].power_on == KAL_FALSE))
{
return Length;
}
#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
if (UARTPort[port].sleep_on_tx == uart_sleep_on_tx_forbid)
{
UART_PDN_Disable(port);
}
#endif//#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
real_count = DMA_GetVFIFO_Roomleft(ch);
/*#ifdef VFIFO_DBG
{
kal_char s[50];
sprintf(s,"uart_putbytes,len %d,left %d",Length,real_count);
kal_print(s);
}
#else //#ifndef DRV_DEBUG
if(port >= MAX_UART_PORT_NUM)
return 0;
ch = UARTPort[port].Tx_DMA_Ch;
#endif //#ifndef DRV_DEBUG
*/
if(UARTPort[port].ownerid != MOD_TST_READER)// if catcher log via UART,Tx will be too many data
drv_trace2(TRACE_GROUP_4,UART_TX_VFIFO_U_PutISRBytes_VFIFO,Length,real_count);
if (real_count >= Length)
{
real_count = Length;
}
else
{
send_Txilm[port] = KAL_TRUE;
DMA_EnableINT(ch);
}
#if defined(DRV_UART_VFIFO_V2)
DMA_PUSH_Multi_VFIFO(port,Buffaddr,real_count,4);
VFIFO_DMA_Flush(port,KAL_TRUE);
#elif defined(DRV_UART_VFIFO_V3)
DMA_PUSH_Multi_VFIFO(port,Buffaddr,real_count,4);
DMA_Flush(ch);
DMA_Flush(ch);
#else
for (index = 0; index < real_count; index++)
{
DMA_PUSH(ch,*(Buffaddr+index));
}
#endif /* defined(DRV_UART_VFIFO_V2) */
/*invoke THRE interrupt*/
//EnableTxIntr(UART_BaseAddr[port]);
return real_count;
#else /*DRV_DEBUG*/
return Length;
#endif /*DRV_DEBUG*/
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_SendData_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid)
{
#ifndef DRV_DEBUG
kal_uint16 real_count,index;
kal_uint8 data;
kal_uint8 ch;
kal_uint32 savedMask;
ch = UARTPort[port].Tx_DMA_Ch;
EXT_ASSERT( (UARTPort[port].ownerid == ownerid), (kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
if((UARTPort[port].EnableTX == KAL_FALSE) || (UARTPort[port].power_on == KAL_FALSE))
{
return Length;
}
if( (stack_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_TST_READER)||
(uart_support_autoescape()==KAL_FALSE) )
{
if(mode == 0)
real_count = U_PutBytes_VFIFO(port, Buffaddr, Length, ownerid);
// real_count = UART_PutBytes(port, Buffaddr, Length, ownerid);
else
{
#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
if (UARTPort[port].sleep_on_tx == uart_sleep_on_tx_forbid)
{
UART_PDN_Disable(port);
}
#endif//#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
real_count = DMA_GetVFIFO_Roomleft(ch);
/* #ifdef VFIFO_DBG
{
char s[50];
sprintf(s,"uart_SendData,len %d,left %d",Length,real_count);
kal_print(s);
}
#endif*/
if(UARTPort[port].ownerid != MOD_TST_READER)// if catcher log via UART,Tx will be too many data
drv_trace2(TRACE_GROUP_4,UART_TX_VFIFO_U_SendData_VFIFO,Length,real_count);
if (real_count > Length)
{
real_count = Length;
}
else
{
send_Txilm[port] = KAL_TRUE;
DMA_EnableINT(ch);
}
for (index = 0; index < real_count; index++)
{
data = *(Buffaddr+index);
if (data == UARTPort[port].DCB.xonChar)
{
savedMask = SaveAndSetIRQMask();
if(DMA_GetVFIFO_Roomleft(ch)>=2)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x01);
}
else
{
RestoreIRQMask(savedMask);
break;
}
RestoreIRQMask(savedMask);
}
else if (data == UARTPort[port].DCB.xoffChar)
{
savedMask = SaveAndSetIRQMask();
if(DMA_GetVFIFO_Roomleft(ch)>=2)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x02);
}
else
{
RestoreIRQMask(savedMask);
break;
}
RestoreIRQMask(savedMask);
}
else if (data == escape_char)
{
savedMask = SaveAndSetIRQMask();
if(DMA_GetVFIFO_Roomleft(ch)>=2)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x03);
}
else
{
RestoreIRQMask(savedMask);
break;
}
RestoreIRQMask(savedMask);
}
else
{
savedMask = SaveAndSetIRQMask();
if(DMA_GetVFIFO_Roomleft(ch)>=1)
{
DMA_PUSH(ch,data);
}
else
{
RestoreIRQMask(savedMask);
break;
}
RestoreIRQMask(savedMask);
}
}
real_count = index;
}
}
else
{
//real_count = UART_PutBytes(port, Buffaddr, Length, ownerid);
real_count = U_PutBytes_VFIFO(port, Buffaddr, Length, ownerid);
}
#if defined(DRV_UART_VFIFO_V2)
VFIFO_DMA_Flush(port,KAL_FALSE);
#elif defined(DRV_UART_VFIFO_V3)
DMA_Flush(ch);
DMA_Flush(ch);
#endif //defined(DRV_UART_VFIFO_V2)
/*invoke THRE interrupt*/
//EnableTxIntr(UART_BaseAddr[port]);
return real_count;
#else//#ifndef DRV_DEBUG
return Length;
#endif//#ifndef DRV_DEBUG
}
// toy recommend: do not handle any rx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
kal_uint16 U_SendISRData_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid)
{
#ifndef DRV_DEBUG
kal_uint16 real_count,index;
kal_uint8 data;
kal_uint8 ch;
ch = UARTPort[port].Tx_DMA_Ch;
EXT_ASSERT( (UARTPort[port].ownerid == ownerid), (kal_uint32) ownerid, (kal_uint32)port, (kal_uint32)UARTPort[port].ownerid);
if((UARTPort[port].EnableTX == KAL_FALSE) || (UARTPort[port].power_on == KAL_FALSE))
{
return Length;
}
if( (stack_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_TST_READER)||
(uart_support_autoescape()==KAL_FALSE) )
{
if(mode == 0)
real_count = U_PutISRBytes_VFIFO(port, Buffaddr, Length, ownerid);
// real_count = UART_PutISRBytes(port, Buffaddr, Length, ownerid);
else
{
#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
if (UARTPort[port].sleep_on_tx == uart_sleep_on_tx_forbid)
{
UART_PDN_Disable(port);
}
#endif//#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
real_count = DMA_GetVFIFO_Roomleft(ch);
/* #ifdef VFIFO_DBG
{
char s[50];
sprintf(s,"uart_SendData,len %d,left %d",Length,real_count);
kal_print(s);
}
#endif*/
if(UARTPort[port].ownerid != MOD_TST_READER)// if catcher log via UART,Tx will be too many data
drv_trace2(TRACE_GROUP_4,UART_TX_VFIFO_U_SendISRData_VFIFO,Length,real_count);
if (real_count > Length)
{
real_count = Length;
}
else
{
send_Txilm[port] = KAL_TRUE;
DMA_EnableINT(ch);
}
for (index = 0; index < real_count; index++)
{
data = *(Buffaddr+index);
if (data == UARTPort[port].DCB.xonChar)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x01);
}
else if (data == UARTPort[port].DCB.xoffChar)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x02);
}
else if (data == escape_char)
{
DMA_PUSH(ch,escape_char);
DMA_PUSH(ch,0x03);
}
else
{
DMA_PUSH(ch,data);
}
}
}
}
else
{
// real_count = UART_PutISRBytes(port, Buffaddr, Length, ownerid);
real_count = U_PutISRBytes_VFIFO(port, Buffaddr, Length, ownerid);
}
#if defined(DRV_UART_VFIFO_V2)
VFIFO_DMA_Flush(port,KAL_TRUE);
#elif defined(DRV_UART_VFIFO_V3)
DMA_Flush(ch);
DMA_Flush(ch);
#endif //defined(DRV_UART_VFIFO_V2)
/*invoke THRE interrupt*/
//EnableTxIntr(UART_BaseAddr[port]);
return real_count;
#else //#ifndef DRV_DEBUG
return Length;
#endif//#ifndef DRV_DEBUG
}
//because two reason: ----to add GET_RX_DMA_WRPTR() and GET_RX_DMA_RDPTR() the two function!
// 1:because VFIFO_V1'sWrite point is absolute address,VFIFO_V2 & VFIFO_V3 is relative address
// 2:when VFIFO_V2 & VFIFO_V3,the 16 bit is RX_VFF_WPT_WRA,this bit will be set to 1,when write point wrap.
kal_uint32 GET_RX_DMA_WRPTR(UART_PORT port)
{
kal_uint32 wp;
wp = DMA_WRPTR(UARTPort[port].Rx_DMA_Ch);
#if defined(DRV_UART_VFIFO_V2) || defined(DRV_UART_VFIFO_V3)
//,because VFIFO_V1'sWrite point is absolute address,VFIFO_V2 & VFIFO_V3 is relative address
wp = DRV_UART_Reg(wp);//because the 16 bit is RX_VFF_WPT_WRA,this bit will be set to 1,when write point wrap.
wp+=(kal_uint32) UART_rings->ring[UARTPort[port].port_no].rx_adrs;
#else
wp = DRV_UART_Reg32(wp);
#endif
return wp;
}
kal_uint32 GET_RX_DMA_RDPTR( UART_PORT port)
{
kal_uint32 rp;
rp = DMA_RDPTR(UARTPort[port].Rx_DMA_Ch);
#if defined(DRV_UART_VFIFO_V2) || defined(DRV_UART_VFIFO_V3)
//because VFIFO_V1'sWrite point is absolute address,VFIFO_V2 & VFIFO_V3 is relative address
rp = DRV_UART_Reg(rp);//because the 16 bit is RX_VFF_WPT_WRA,this bit will be set to 1,when write point wrap.
rp+=(kal_uint32) UART_rings->ring[UARTPort[port].port_no].rx_adrs;
#else
rp = DRV_UART_Reg32(rp);
#endif
return rp;
}
/************************ISR level**************************************************/
kal_uint32 last_w;
kal_uint32 last_r;
// toy recommend: do not handle any tx data in UART_RecTimeOutHandler(), otherwise single vfifo will fail
void UART_RecTimeOutHandler(UART_PORT port)
{
UARTStruct *UARTData=&UARTPort[port];
kal_uint32 UART_BASE;
kal_uint16 avail;
kal_uint8 ch;
SGPT_CTRL_START_T start;
volatile kal_uint8 tmp;
//kal_bool btmp; //avoid Warning 534: Ignoring return value of function 'GPTI_StartItem"
#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#else
if(UARTData->port_no >= MAX_UART_PORT_NUM)
return;
UART_BASE = UART_BaseAddr[UARTData->port_no];
#endif //#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
#ifdef VFIFO_DBG
gUART_RecTimeOutHandler++;
#endif
#ifdef DCM_ENABLE
if(UARTData->AutobaudDetection)
{
UART_SetRateFix(UARTData->port_no); // if under autobaud detection, set ratefix back and set correct baudrate.
}
#endif
// clear the timeout interrupt
tmp = DRV_UART_Reg(UART_RXDMA(UART_BASE));
//check if no incomming data ----for future don't remove it.
//if(!(DRV_UART_Reg(UART_RXDMA(UART_BASE))&UART_RXDMA_TIMEOUT))
//return;
// inform the upper layer to check virtual fifo remains data
ch = UARTData->Rx_DMA_Ch;
avail = DMA_GetVFIFO_Avail(ch);
#if defined(DRV_UART_MEMORY_TRACE)
if(UARTData->port_no == uart_port3)
{
wp = GET_RX_DMA_WRPTR(port);
nextChar = DRV_UART_Reg8(wp);
rp = GET_RX_DMA_RDPTR(port);
UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), avail);
UART_DBG(__LINE__, wp, nextChar, rp);
}
#endif //#if defined(DRV_UART_MEMORY_TRACE)
drv_trace2(TRACE_GROUP_3,UART_RX_VFIFO_TIMEOUT_INT,port,avail);
if(avail == 0)
return;
/*TY adds these to expand flexibility 2004/10/15*/
UARTPort[UARTData->port_no].rx_cb(UARTData->port_no);
DMA_DisableINT(ch);
if (UARTData->ESCDet.GuardTime != 0)
{
//toy mark this, already initial UARTData at function beginning.
//UARTStruct *UARTData=(UARTStruct *)parameter;
switch(UARTData->Rec_state)
{
case UART_Get3EscChar:
UARTData->Rec_state = UART_RecNormal;
UARTData->EscCount = 0;
break;
case UART_RecNormal:
UARTData->Rec_state = UART_RecNormal;
UARTData->EscCount = 0;
break;
case UART_StartCheckESC:
if(avail>3)
{
UARTData->Rec_state = UART_RecNormal;
UARTData->EscCount = 0;
}
else
{
kal_uint16 i;
kal_uint8 data;
last_w=GET_RX_DMA_WRPTR(port);
for(i=1;i<(avail+1);i++)
{
last_w--;
if( (last_w) <(kal_uint32) UART_rings->ring[UARTData->port_no].rx_adrs )
last_w=(kal_uint32)UART_rings->ring[UARTData->port_no].rx_adrs+
UART_rings->ring[UARTData->port_no].rx_len-1;
data=DRV_UART_Reg8((last_w));
if(data==UARTData->ESCDet.EscChar)
{
UARTData->EscCount++;
if(UARTData->EscCount == 3)
{
UARTData->Rec_state = UART_Get3EscChar;
}
else if(UARTData->EscCount > 3)
{
UARTData->Rec_state = UART_RecNormal;
UARTData->EscCount = 0;
}
}
else
{
UARTData->Rec_state = UART_RecNormal;
UARTData->EscCount = 0;
}
}
}
break;
default:
break;
}
/*
GPTI_StartItem(UARTData->handle,
(UARTData->ESCDet.GuardTime/10),
UART_Calback,
&UARTPort[UARTData->port_no]); */
start.u2Tick=UARTData->ESCDet.GuardTime/10;
start.pfCallback=UART_Calback;
start.vPara=&UARTPort[UARTData->port_no];
DclSGPT_Control(UARTData->handle,SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start);
}
#if defined(DRV_UART_MEMORY_TRACE)
if(UARTData->port_no == uart_port3)
{
avail = DMA_GetVFIFO_Avail(ch);
wp = GET_RX_DMA_WRPTR(port);
nextChar = DRV_UART_Reg8(wp);
rp = GET_RX_DMA_RDPTR(port);
UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), avail);
UART_DBG(__LINE__, wp, nextChar, rp);
}
#endif //#if defined(DRV_UART_MEMORY_TRACE)
}
// called by DMA ISR while tx fifo is under the threshold
// toy recommend: do not handle any rx data in UART_TrxHandler_VFIFO(), otherwise single vfifo will fail
void UART_TrxHandler_VFIFO(UART_PORT port)
{
UARTStruct *UARTData=&UARTPort[port];
kal_int16 room;
kal_uint8 ch;
if(UARTData->port_no >= MAX_UART_PORT_NUM)
return;
#ifdef VFIFO_DBG
gUART_TrxHandler_VFIFO++;
#endif
ch = UARTData->Tx_DMA_Ch;
room = DMA_GetVFIFO_Roomleft(ch);
if(room == 0)
return;
/* inform the upper layer to send data to vfifo*/
/*TY adds these to expand flexibility 2004/10/15*/
UARTPort[UARTData->port_no].tx_cb(UARTData->port_no);
DMA_DisableINT(ch);
}
// called by DMA ISR while rx vfifo is over the threshold
// toy recommend: do not handle any tx data in UART_RecHandler_VFIFO(), otherwise single vfifo will fail
void UART_RecHandler_VFIFO(UART_PORT port)
{
UARTStruct *UARTData=&UARTPort[port];
kal_uint16 avail;
kal_uint8 ch;
#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif //#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
if(UARTData->port_no >= MAX_UART_PORT_NUM)
return;
#ifdef VFIFO_DBG
gUART_RecHandler_VFIFO++;
#endif
#ifdef DCM_ENABLE
if(UARTData->AutobaudDetection)
{
UART_SetRateFix(UARTData->port_no); // if under autobaud detection, set ratefix back and set correct baudrate.
}
#endif
ch = UARTData->Rx_DMA_Ch;
avail = DMA_GetVFIFO_Avail(ch);
drv_trace2(TRACE_GROUP_3,UART_RX_VFIFO_INT,port,avail);
if(avail == 0)
return;
// inform the upper layer to get data from vfifo
/*TY adds these to expand flexibility 2004/10/15*/
#if defined(DRV_UART_MEMORY_TRACE)
if(UARTData->port_no == uart_port3)
{
wp = GET_RX_DMA_WRPTR(port);
nextChar = DRV_UART_Reg8(wp);
rp = GET_RX_DMA_RDPTR(port);
UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), avail);
UART_DBG(__LINE__, wp, nextChar, rp);
}
#endif //#if defined(DRV_UART_MEMORY_TRACE)
UARTPort[UARTData->port_no].rx_cb(UARTData->port_no);
DMA_DisableINT(ch);
}
// toy recommend: do not handle any rx data in UART_THRE_hdr_VFIFO(), otherwise single vfifo will fail
void UART_THRE_hdr_VFIFO(UART_PORT port)
{
kal_uint16 avail;
kal_uint32 UART_BASE;
if(port >= MAX_UART_PORT_NUM)
return;
UART_BASE = UART_BaseAddr[port];
/*check if there is data in ring buffer*/
avail=DMA_GetVFIFO_Avail(UARTPort[port].Tx_DMA_Ch);
if(avail==0)
{
#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
UART_PDN_Enable(port);
#endif//#if !defined(DRV_MISC_TDMA_PDN0) // For MT6516 MD side do not have pdn
DisableTxIntr(UART_BASE);
}
}
#if !defined(__MEUT__) && !defined(__MEIT__)
void U_configure_DMA_VFIFO(void)
{
#if defined(DRV_UART_VFIFO_V2)
kal_uint8 i;
#endif
#if defined(__DMA_UART_VFIFO_SINGLE_TUNNEL__)
const kal_uint8 VFIFO_BASE = 11;
kal_uint8 i;
kal_uint8 occupyMap = 0; // uart1 rx --> bit 0; uart3 tx --> bit 5...etc
kal_uint8 nonVFIFO1 = UART_rings->not_support_VFIFO_TUNNEL1;
kal_uint8 nonVFIFO2 = UART_rings->not_support_VFIFO_TUNNEL2;
kal_uint8 tunnel;
kal_uint8 port;
for(i=0;i<MAX_UART_TUNNEL_NUM;i++)//initial UART_SINGLE_VFIFO_support[]
UART_SINGLE_VFIFO_support[i] = KAL_TRUE;
UART_SINGLE_VFIFO_support[nonVFIFO1] = KAL_FALSE;
UART_SINGLE_VFIFO_support[nonVFIFO2] = KAL_FALSE;
for(i=0; i<MAX_UART_PORT_NUM; i++) // assign rx vfifo channel first, for rx has its specific channels.
{
tunnel = uart1_rx_tunnel + i*2; // tunnel = uart1_rx_tunnel, uart2_rx_tunnel, uart3_rx_tunnel
port = uart_port1 + i; // port = uart1_port, uart2_port, uart3_port
if( tunnel != nonVFIFO1 && tunnel != nonVFIFO2) // rx tunnel support VFIFO, fill it the specific channel.
{
UARTPort[port].Rx_DMA_Ch = VFIFO_BASE + i;
occupyMap = occupyMap | (1 << i); // record which channel already occupy
}
}
for(i=0; i<MAX_UART_PORT_NUM; i++) // assign tx vfifo channel according occupy map.
{
tunnel = uart1_tx_tunnel + i*2; // tunnel = uart1_tx_tunnel, uart2_tx_tunnel, uart3_tx_tunnel
port = uart_port1 + i; // port = uart1_port, uart2_port, uart3_port
if(UART_SINGLE_VFIFO_support[tunnel])
{
if(0 == (occupyMap & 0x1)){
UARTPort[port].Tx_DMA_Ch = VFIFO_BASE ;
occupyMap |= 0x1;
}else if(0 == (occupyMap & 0x2)){
UARTPort[port].Tx_DMA_Ch = VFIFO_BASE + 1;
occupyMap |= 0x2;
}else if(0 == (occupyMap & 0x4)){
UARTPort[port].Tx_DMA_Ch = VFIFO_BASE + 2;
occupyMap |= 0x4;
}else if(0 == (occupyMap & 0x8)){
UARTPort[port].Tx_DMA_Ch = VFIFO_BASE + 3;
occupyMap |= 0x8;
}else{
ASSERT(0); //use more than 4 channels
}
}// end of if(UART_SINGLE_VFIFO_support[tunnel])
}// end of for(i=0; i<3; i++) // assign tx vfifo channel according occupy map.
#else //#if defined(__DMA_UART_VFIFO_SINGLE_TUNNEL__)
#if defined(DRV_UART_DMA_VFIFO_CONFIG2)
if(UART_rings->not_support_VFIFO==uart_port1)
{
UARTPort[uart_port2].Rx_DMA_Ch=12;
UARTPort[uart_port2].Tx_DMA_Ch=11;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=13;
UARTPort[uart_port3].Tx_DMA_Ch=14;
#endif
UART_VFIFO_support[uart_port1]=KAL_FALSE;
}
else if(UART_rings->not_support_VFIFO==uart_port2)
{
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=12;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=13;
UARTPort[uart_port3].Tx_DMA_Ch=14;
#endif
UART_VFIFO_support[uart_port2]=KAL_FALSE;
}
else if(UART_rings->not_support_VFIFO==uart_port3)
{
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=13;
UARTPort[uart_port2].Rx_DMA_Ch=12;
UARTPort[uart_port2].Tx_DMA_Ch=14;
#ifdef __UART3_SUPPORT__
UART_VFIFO_support[uart_port3]=KAL_FALSE;
#endif
}
else
{
UART_VFIFO_support[uart_port2]=KAL_FALSE;
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=12;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=13;
UARTPort[uart_port3].Tx_DMA_Ch=14;
#endif
}
#elif defined(DRV_UART_DMA_VFIFO_CONFIG3) //MT6253T
UARTPort[uart_port1].Rx_DMA_Ch=12;
UARTPort[uart_port1].Tx_DMA_Ch=15;
UARTPort[uart_port2].Rx_DMA_Ch=13;
UARTPort[uart_port2].Tx_DMA_Ch=16;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=14;
UARTPort[uart_port3].Tx_DMA_Ch=17;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG4) //MT6268
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=14;
UARTPort[uart_port2].Rx_DMA_Ch=12;
UARTPort[uart_port2].Tx_DMA_Ch=15;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=13;
UARTPort[uart_port3].Tx_DMA_Ch=16;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG5) //MT6236
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=15;
UARTPort[uart_port2].Rx_DMA_Ch=12;
UARTPort[uart_port2].Tx_DMA_Ch=16;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=13;
UARTPort[uart_port3].Tx_DMA_Ch=17;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG6) //MT6276
UARTPort[uart_port1].Rx_DMA_Ch=13;
UARTPort[uart_port1].Tx_DMA_Ch=12;
UARTPort[uart_port2].Rx_DMA_Ch=15;
UARTPort[uart_port2].Tx_DMA_Ch=14;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=17;
UARTPort[uart_port3].Tx_DMA_Ch=16;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG9)
UARTPort[uart_port1].Rx_DMA_Ch=16;
UARTPort[uart_port1].Tx_DMA_Ch=15;
UARTPort[uart_port2].Rx_DMA_Ch=18;
UARTPort[uart_port2].Tx_DMA_Ch=17;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=20;
UARTPort[uart_port3].Tx_DMA_Ch=19;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG12)
UARTPort[uart_port1].Rx_DMA_Ch=8;
UARTPort[uart_port1].Tx_DMA_Ch=11;
UARTPort[uart_port2].Rx_DMA_Ch=9;
UARTPort[uart_port2].Tx_DMA_Ch=12;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=10;
UARTPort[uart_port3].Tx_DMA_Ch=13;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG13)
UARTPort[uart_port1].Rx_DMA_Ch=11;
UARTPort[uart_port1].Tx_DMA_Ch=10;
UARTPort[uart_port2].Rx_DMA_Ch=13;
UARTPort[uart_port2].Tx_DMA_Ch=12;
#elif defined(DRV_UART_DMA_VFIFO_CONFIG7) //MT6251
UARTPort[uart_port1].Rx_DMA_Ch=13;
UARTPort[uart_port1].Tx_DMA_Ch=15;
UARTPort[uart_port2].Rx_DMA_Ch=14;
UARTPort[uart_port2].Tx_DMA_Ch=16;
#elif defined(DRV_UART_DMA_VFIFO_CONFIG10) //MT6575
UARTPort[uart_port1].Rx_DMA_Ch=4;
UARTPort[uart_port1].Tx_DMA_Ch=3;
UARTPort[uart_port2].Rx_DMA_Ch=6;
UARTPort[uart_port2].Tx_DMA_Ch=5;
#elif defined(DRV_UART_DMA_VFIFO_CONFIG8) //MT6253EL
UARTPort[uart_port1].Rx_DMA_Ch=10;
UARTPort[uart_port1].Tx_DMA_Ch=13;
UARTPort[uart_port2].Rx_DMA_Ch=11;
UARTPort[uart_port2].Tx_DMA_Ch=14;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Rx_DMA_Ch=12;
UARTPort[uart_port3].Tx_DMA_Ch=15;
#endif
#elif defined(DRV_UART_DMA_VFIFO_CONFIG14) //MT6261
UARTPort[uart_port1].Tx_DMA_Ch=9;
UARTPort[uart_port1].Rx_DMA_Ch=10;
UARTPort[uart_port2].Tx_DMA_Ch=11;
UARTPort[uart_port2].Rx_DMA_Ch=12;
#ifdef __UART3_SUPPORT__
UARTPort[uart_port3].Tx_DMA_Ch=13;
UARTPort[uart_port3].Rx_DMA_Ch=14;
#endif
#endif //#if defined(DRV_UART_DMA_VFIFO_CONFIG2)
#endif //#if defined(__DMA_UART_VFIFO_SINGLE_TUNNEL__)
#if defined(DRV_UART_VFIFO_V2)
#if defined(DRV_UART_VFIFO_V2_USE_GPT)
for (i=0;i<MAX_UART_PORT_NUM;i++)
{
//GPTI_GetHandle(&UARTPort[i].uart_flush_timer_handle);
//GPTI_GetHandle(&UARTPort[i].uart_isr_flush_timer_handle);
UARTPort[i].uart_flush_timer_handle = DclSGPT_Open(DCL_GPT_CB, 0);
UARTPort[i].uart_isr_flush_timer_handle = DclSGPT_Open(DCL_GPT_CB, 0);
}
#else
for (i=0;i<MAX_UART_PORT_NUM;i++)
{
UARTPort[i].uart_flush_timer_id=kal_create_timer("UART_Flush_Timer");
}
uart_isr_flush_timer_id=kal_create_timer("UART_Flush_Timer");
uart_isr_hisr_id = kal_create_hisr("UART_ISR_FLUSH_HISR", 1, 512, uart_isr_dma_flush, NULL);
#endif //defined(DRV_UART_VFIFO_V2_USEGPT)
#endif /* defined(DRV_UART_VFIFO_V2) */
}
#endif //#if !defined(__MEUT__) && !defined(__MEIT__)
#if defined(__MEUT__) || defined(__MEIT__)
#if defined(__UART3_SUPPORT__)
#define UART_VFIFO_3_PORTS
#endif //defined(__UART3_SUPPORT__)
#if defined(UART_VFIFO_3_PORTS)
#define UART_VFIFO_PORT_CNT 3
#define UART_VFIFO_CH_CNT (UART_VFIFO_PORT_CNT*2)
#if defined(DRV_UART_DMA_VFIFO_CONFIG6)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {13, 15, 17, 16, 14, 12};
#endif
#if defined(DRV_UART_DMA_VFIFO_CONFIG3)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {12, 13, 14, 15, 16, 17};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG8) //MT6253EL
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {10, 11, 12, 13, 14, 15};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG9)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {16, 18, 20,19,17,15};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG12)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {8,9,10,13,12,11};//{9, 11, 13, 12, 10, 8};
#endif
kal_bool vfifo_used[UART_VFIFO_CH_CNT] = {KAL_FALSE, KAL_FALSE, KAL_FALSE, KAL_FALSE, KAL_FALSE, KAL_FALSE};
#else //defined(UART_VFIFO_3_PORTS)
#define UART_VFIFO_PORT_CNT 2
#define UART_VFIFO_CH_CNT (UART_VFIFO_PORT_CNT*2)
kal_bool vfifo_used[UART_VFIFO_CH_CNT] = {KAL_FALSE, KAL_FALSE, KAL_FALSE, KAL_FALSE};
#if defined(DRV_UART_DMA_VFIFO_CONFIG2)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {11, 12, 13, 14};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG3)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {12, 13, 15, 16};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG5)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {11, 12, 15, 16};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG6)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {13, 15, 14, 12};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG7)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {13, 14, 15, 16};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG8) //MT6253EL
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {10, 11, 13, 14};
#elif defined(DRV_UART_DMA_VFIFO_CONFIG10)
static const kal_uint8 vfifo_ch_num[UART_VFIFO_CH_CNT] = {3, 4, 5, 6};
#endif
//kal_bool vfifo_used[UART_VFIFO_CH_CNT] = {KAL_FALSE, KAL_FALSE, KAL_FALSE, KAL_FALSE};
#endif//defined(UART_VFIFO_3_PORTS)
static kal_uint8 uart_vfifo_used_cnt = 0;
kal_bool UART_UseVFIFO(UART_PORT port, kal_bool use_vfifo)
{
ASSERT(port < MAX_UART_PORT_NUM);
if (port >= MAX_UART_PORT_NUM)
return KAL_FALSE;
if (UARTPort[port].initialized &&
(UARTPort[port].ownerid != (module_type)((kal_uint16)MOD_UART1_HISR + (kal_uint8)port)))
return KAL_FALSE;
if (KAL_TRUE == use_vfifo)
{
if (KAL_FALSE == UART_VFIFO_support[port])
{
kal_int16 index;
if (uart_vfifo_used_cnt < UART_VFIFO_PORT_CNT)
{
ASSERT(vfifo_used[port] == KAL_FALSE);
UARTPort[port].Rx_DMA_Ch=vfifo_ch_num[port];
vfifo_used[port] = KAL_TRUE;
//DMA_Start(UARTPort[port].Rx_DMA_Ch);
//liming for VFIFO test
index = UART_VFIFO_CH_CNT-1-port;
UARTPort[port].Tx_DMA_Ch = vfifo_ch_num[index];
vfifo_used[index] = KAL_TRUE;
DMA_Vfifo_SetAdrs((kal_uint32)UART_rings->ring[port].rx_adrs, UART_rings->ring[port].rx_len, (DMA_VFIFO_UART)UARTPort[port].Rx_DMA_Ch, KAL_FALSE);
DMA_Vfifo_SetAdrs((kal_uint32)UART_rings->ring[port].tx_adrs, UART_rings->ring[port].tx_len, (DMA_VFIFO_UART)UARTPort[port].Tx_DMA_Ch, KAL_TRUE);
UART_VFIFO_support[port]=KAL_TRUE;
DMA_Vfifo_SetChan(port);//liming remove!!! should enable DMA interrupt when U_Putbytes_VFIFO().Becase enable interrupt now,there will be issue a interrupt right away. UDVT test load maybe fail!!!
uart_vfifo_used_cnt++;
//DMA_Start(UARTPort[port].Tx_DMA_Ch);
}
else
{
return KAL_FALSE;
}
}
}
else
{
if (KAL_TRUE == UART_VFIFO_support[port])
{
kal_int16 index;
//DMA_Stop(UARTPort[port].Rx_DMA_Ch);
//DMA_Stop(UARTPort[port].Tx_DMA_Ch);
UARTPort[port].Rx_DMA_Ch=0xff;
vfifo_used[port] = KAL_FALSE;
//liming for VFIFO test
index = UART_VFIFO_CH_CNT-1-port;
vfifo_used[index] = KAL_FALSE;
UARTPort[port].Tx_DMA_Ch=0xff;
UART_VFIFO_support[port]=KAL_FALSE;
ASSERT(uart_vfifo_used_cnt > 0);
uart_vfifo_used_cnt--;
}
}
return KAL_TRUE;
}
#else
kal_bool UART_UseVFIFO(UART_PORT port, kal_bool use_vfifo)
{
return KAL_TRUE;
}
#endif //defined(__MEUT__) || defined(__MEIT__)
#else //#if !defined(DRV_UART_OFF)
void PutUARTData_VFIFO(UART_PORT port, kal_uint8 escape_char, kal_uint8 data){}
void U_configure_DMA_VFIFO(void){}
kal_uint16 U_GetBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid){}
kal_uint16 U_GetBytesAvail_VFIFO(UART_PORT port){}
kal_uint16 U_GetTxISRRoomLeft_VFIFO(UART_PORT port){}
kal_uint16 U_GetTxRoomLeft_VFIFO(UART_PORT port){}
kal_uint8 U_GetUARTByte_VFIFO(UART_PORT port){}
kal_uint16 U_PutBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid){}
kal_uint16 U_PutISRBytes_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid){}
void U_PutUARTByte_VFIFO(UART_PORT port, kal_uint8 data){}
kal_uint16 U_SendData_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid){}
kal_uint16 U_SendISRData_VFIFO(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid){}
void UART_RecHandler_VFIFO(UART_PORT port){}
void UART_RecTimeOutHandler(UART_PORT port){}
void UART_THRE_hdr_VFIFO(UART_PORT port){}
void UART_TrxHandler_VFIFO(UART_PORT port){}
kal_bool UART_UseVFIFO(UART_PORT port, kal_bool use_vfifo){}
#endif //#if !defined(DRV_UART_OFF)
#if 1
extern kal_bool U_Open(UART_PORT port, module_type owner);
extern void U_Close(UART_PORT port, module_type ownerid);
extern void U_Purge(UART_PORT port, UART_buffer dir, module_type ownerid);
//extern void U_SetOwner (UART_PORT port, kal_uint8 owner);
extern void U_SetOwner (UART_PORT port, module_type owner);
extern void U_SetFlowCtrl(UART_PORT port, kal_bool XON, module_type ownerid);
extern void U_CtrlDCD(UART_PORT port, IO_level SDCD, module_type ownerid);
extern void U_ConfigEscape (UART_PORT port, kal_uint8 EscChar, kal_uint16 ESCGuardtime, module_type ownerid);
extern void U_SetDCBConfig(UART_PORT port, UARTDCBStruct *UART_Config, module_type ownerid);
extern void U_CtrlBreak(UART_PORT port, IO_level SBREAK, module_type ownerid);
extern void U_ClrRxBuffer(UART_PORT port, module_type ownerid);
extern void U_ClrTxBuffer(UART_PORT port, module_type ownerid);
extern void U_SetBaudRate(UART_PORT port, UART_baudrate baudrate, module_type ownerid);
extern module_type U_GetOwnerID(UART_PORT port);
extern void U_SetAutoBaud_Div(UART_PORT port, module_type ownerid);
extern void U_Register_TX_cb(UART_PORT port, module_type owner, UART_TX_FUNC func);
extern void U_Register_RX_cb(UART_PORT port, module_type owner, UART_RX_FUNC func);
extern void U_PutUARTBytes(UART_PORT port, kal_uint8 *data,kal_uint16 len);
extern void U_ReadDCBConfig (UART_PORT port, UARTDCBStruct *DCB);
extern void U_CtrlRI (UART_PORT port, IO_level SRI, module_type ownerid); /*NULL for DCE*/
extern void U_CtrlDTR (UART_PORT port, IO_level SDTR, module_type ownerid);
extern void U_ReadHWStatus(UART_PORT port, IO_level *SDSR, IO_level *SCTS);
// uart dispatch funtion table
extern kal_uint16 U_GetBytesAvail(UART_PORT port);
extern kal_uint16 U_GetBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid);
extern kal_uint8 U_GetUARTByte(UART_PORT port);
extern kal_uint16 U_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid );
extern kal_uint16 U_GetTxRoomLeft(UART_PORT port);
extern kal_uint16 U_SendISRData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode, kal_uint8 escape_char, module_type ownerid);
extern kal_uint16 U_SendData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid);
extern kal_uint16 U_PutISRBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid);
//extern void U_PutUARTByte(UART_PORT port, kal_uint8 data);
extern kal_uint16 U_GetTxISRRoomLeft(UART_PORT port);
UartDriver_strcut UartDriver_VFIFO=
{
U_Open,
U_Close,
U_GetBytes_VFIFO,
U_PutBytes_VFIFO,
U_GetBytesAvail_VFIFO,
U_GetTxRoomLeft_VFIFO,
U_PutISRBytes_VFIFO,
U_GetTxISRRoomLeft_VFIFO,
U_Purge,
U_SetOwner,
U_SetFlowCtrl,
U_ConfigEscape,
U_SetDCBConfig,
U_CtrlDCD,
U_CtrlBreak,
U_ClrRxBuffer,
U_ClrTxBuffer,
U_SetBaudRate,
U_SendISRData_VFIFO,
U_SendData_VFIFO,
U_GetOwnerID,
U_SetAutoBaud_Div,
/*TY adds these to expand flexibility 2004/10/15*/
U_Register_TX_cb,
U_Register_RX_cb,
/*TY adds these to let virtual COM port can retrive exception log 2005/3/8*/
U_GetUARTByte_VFIFO,
U_PutUARTByte_VFIFO,
U_PutUARTBytes,
/*for virtual com port to return DCB configuration*/
U_ReadDCBConfig,
U_CtrlRI,
U_CtrlDTR,
U_ReadHWStatus
};
UartDriver_strcut UartDriver_VFIFO_TX=
{
U_Open,
U_Close,
U_GetBytes,
U_PutBytes_VFIFO,
U_GetBytesAvail,
U_GetTxRoomLeft_VFIFO,
U_PutISRBytes_VFIFO,
U_GetTxISRRoomLeft_VFIFO,
U_Purge,
U_SetOwner,
U_SetFlowCtrl,
U_ConfigEscape,
U_SetDCBConfig,
U_CtrlDCD,
U_CtrlBreak,
U_ClrRxBuffer,
U_ClrTxBuffer,
U_SetBaudRate,
U_SendISRData_VFIFO,
U_SendData_VFIFO,
U_GetOwnerID,
U_SetAutoBaud_Div,
/*TY adds these to expand flexibility 2004/10/15*/
U_Register_TX_cb,
U_Register_RX_cb,
/*TY adds these to let virtual COM port can retrive exception log 2005/3/8*/
U_GetUARTByte,
U_PutUARTByte_VFIFO,
U_PutUARTBytes,
/*for virtual com port to return DCB configuration*/
U_ReadDCBConfig,
U_CtrlRI,
U_CtrlDTR,
U_ReadHWStatus
};
UartDriver_strcut UartDriver_VFIFO_RX=
{
U_Open,
U_Close,
U_GetBytes_VFIFO,
U_PutBytes,
U_GetBytesAvail_VFIFO,
U_GetTxRoomLeft,
U_PutISRBytes,
U_GetTxISRRoomLeft,
U_Purge,
U_SetOwner,
U_SetFlowCtrl,
U_ConfigEscape,
U_SetDCBConfig,
U_CtrlDCD,
U_CtrlBreak,
U_ClrRxBuffer,
U_ClrTxBuffer,
U_SetBaudRate,
U_SendISRData,
U_SendData,
U_GetOwnerID,
U_SetAutoBaud_Div,
/*TY adds these to expand flexibility 2004/10/15*/
U_Register_TX_cb,
U_Register_RX_cb,
/*TY adds these to let virtual COM port can retrive exception log 2005/3/8*/
U_GetUARTByte_VFIFO,
U_PutUARTByte,
U_PutUARTBytes,
/*for virtual com port to return DCB configuration*/
U_ReadDCBConfig,
U_CtrlRI,
U_CtrlDTR,
U_ReadHWStatus
};
#endif
#endif //__DMA_UART_VIRTUAL_FIFO__