socket.txt 90.1 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
; generated by Component: ARM Compiler 5.06 update 6 (build 750) Tool: ArmCC [4d3637]
; commandline ArmCC [--c99 --list --split_sections --debug -c --asm --interleave -o.\flash\obj\socket.o --asm_dir=.\Flash\List\ --list_dir=.\Flash\List\ --depend=.\flash\obj\socket.d --cpu=Cortex-M4.fp --apcs=interwork -O1 --diag_suppress=9931,870 -I..\..\Libraries\CMSIS\Include -I..\..\Libraries\CMSIS\Device\ST\STM32F4xx\Include -I..\..\Libraries\STM32F4xx_StdPeriph_Driver\inc -I..\..\uCOS-III\uC-CPU -I..\..\uCOS-III\uC-LIB -I..\..\uCOS-III\uCOS-III\Ports -I..\..\uCOS-III\uCOS-III\Source -I..\..\uCOS-III\uC-CPU\ARM-Cortex-M4\RealView -I..\..\uCOS-III\uC-LIB\Ports\ARM-Cortex-M4\RealView -I..\..\uCOS-III\uCOS-III\Ports\ARM-Cortex-M4\Generic\RealView -I..\..\User -I..\..\User\bsp -I..\..\User\bsp\inc -I..\..\User\libapp -I..\..\RL-ARM\Config -I..\..\RL-ARM\Driver -I..\..\RL-ARM\RL-RTX\inc -I..\..\User\bsp\BSP -I..\..\RL-ARM\RL-CAN -I..\..\Libraries\DSP_LIB\Include -I..\..\MODBUS\modbus\rtu -I..\..\MODBUS\BARE\port -I..\..\MODBUS\modbus\include -I..\..\User\bsp\BSP -I..\..\PLC -I..\..\Avoid -I..\..\User\parameter -I..\..\User\LaserMotionCtr -I..\..\User\W5100S -I..\..\User\bsp -I..\..\User\CHASSIS -I..\..\User\CONTROLFUNCTION -I..\..\User\DATAUPDATE -I..\..\User\HARAWARE -I..\..\User\MOTORDRIVER -I..\..\User\NAVAGATION -I..\..\User\PLATFORM -I..\..\User\SENSOR -I.\RTE\_Flash -IC:\Users\YDJ\AppData\Local\Arm\Packs\ARM\CMSIS\5.5.1\CMSIS\Core\Include -IC:\Users\YDJ\AppData\Local\Arm\Packs\Keil\STM32F4xx_DFP\2.13.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include -D__UVISION_VERSION=527 -D_RTE_ -DSTM32F407xx -DUSE_STDPERIPH_DRIVER -DSTM32F40_41xxx -D__RTX -D__FPU_USED=1 --omf_browse=.\flash\obj\socket.crf ..\..\User\W5100S\socket.c]
                          THUMB

                          AREA ||i.close||, CODE, READONLY, ALIGN=2

                  close PROC
;;;157    
;;;158    int8_t close(uint8_t sn)
000000  b570              PUSH     {r4-r6,lr}
;;;159    {
000002  4604              MOV      r4,r0
;;;160      CHECK_SOCKNUM();
000004  2c04              CMP      r4,#4
000006  d902              BLS      |L1.14|
000008  f04f30ff          MOV      r0,#0xffffffff
;;;161      setSn_CR(sn,Sn_CR_CLOSE);     // 0X10--CLOSE命令
;;;162       /* wait to process the command... */
;;;163      while( getSn_CR(sn) );       // 0X00--执行完成
;;;164      /* clear all interrupt of the socket. */
;;;165      setSn_IR(sn, 0xFF);          // 写入1 清除
;;;166      //A20150401 : Release the sock_io_mode of socket n.
;;;167      sock_io_mode &= ~(1<<sn);
;;;168      //
;;;169      sock_is_sending &= ~(1<<sn);
;;;170      sock_remained_size[sn] = 0;
;;;171      sock_pack_info[sn] = 0;
;;;172      while(getSn_SR(sn) != SOCK_CLOSED);   // SOCKET状态值 是否关闭
;;;173      return SOCK_OK;
;;;174    }
00000c  bd70              POP      {r4-r6,pc}
                  |L1.14|
00000e  f2404001          MOV      r0,#0x401             ;161
000012  eb002504          ADD      r5,r0,r4,LSL #8       ;161
000016  2110              MOVS     r1,#0x10              ;161
000018  4628              MOV      r0,r5                 ;161
00001a  f7fffffe          BL       WIZCHIP_WRITE
                  |L1.30|
00001e  4628              MOV      r0,r5                 ;163
000020  f7fffffe          BL       WIZCHIP_READ
000024  2800              CMP      r0,#0                 ;163
000026  d1fa              BNE      |L1.30|
000028  f2404002          MOV      r0,#0x402             ;165
00002c  eb002004          ADD      r0,r0,r4,LSL #8       ;165
000030  21ff              MOVS     r1,#0xff              ;165
000032  f7fffffe          BL       WIZCHIP_WRITE
000036  490d              LDR      r1,|L1.108|
000038  2001              MOVS     r0,#1                 ;167
00003a  40a0              LSLS     r0,r0,r4              ;167
00003c  884a              LDRH     r2,[r1,#2]            ;167  ; sock_io_mode
00003e  4382              BICS     r2,r2,r0              ;167
000040  804a              STRH     r2,[r1,#2]            ;167
000042  888a              LDRH     r2,[r1,#4]            ;169  ; sock_is_sending
000044  4382              BICS     r2,r2,r0              ;169
000046  808a              STRH     r2,[r1,#4]            ;169
000048  2000              MOVS     r0,#0                 ;170
00004a  310a              ADDS     r1,r1,#0xa            ;170
00004c  f8210014          STRH     r0,[r1,r4,LSL #1]     ;170
000050  1f09              SUBS     r1,r1,#4              ;171
000052  5508              STRB     r0,[r1,r4]            ;171
000054  f2404003          MOV      r0,#0x403             ;172
000058  eb002404          ADD      r4,r0,r4,LSL #8       ;172
                  |L1.92|
00005c  4620              MOV      r0,r4                 ;172
00005e  f7fffffe          BL       WIZCHIP_READ
000062  2800              CMP      r0,#0                 ;172
000064  d1fa              BNE      |L1.92|
000066  2001              MOVS     r0,#1                 ;173
000068  bd70              POP      {r4-r6,pc}
;;;175    
                          ENDP

00006a  0000              DCW      0x0000
                  |L1.108|
                          DCD      ||.data||

                          AREA ||i.connect||, CODE, READONLY, ALIGN=2

                  connect PROC
;;;191    
;;;192    int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
000000  e92d41f0          PUSH     {r4-r8,lr}
;;;193    {  
000004  4604              MOV      r4,r0
000006  460e              MOV      r6,r1
000008  4617              MOV      r7,r2
;;;194       uint32_t taddr;
;;;195       CHECK_SOCKNUM();
00000a  2c04              CMP      r4,#4
00000c  d903              BLS      |L2.22|
00000e  f04f30ff          MOV      r0,#0xffffffff
                  |L2.18|
;;;196       CHECK_SOCKMODE(Sn_MR_TCP);
;;;197       CHECK_SOCKINIT();
;;;198       //M20140501 : For avoiding fatal error on memory align mismatched
;;;199        
;;;200       taddr = ((uint32_t)addr[0] & 0x000000FF);
;;;201       taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
;;;202       taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
;;;203       taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
;;;204       if( taddr == 0xFFFFFFFF || taddr == 0) return SOCKERR_IPINVALID;
;;;205         
;;;206      if(port == 0) return SOCKERR_PORTZERO;
;;;207      setSn_DIPR(sn,addr);
;;;208      setSn_DPORT(sn,port);
;;;209      setSn_CR(sn,Sn_CR_CONNECT);
;;;210       while(getSn_CR(sn));
;;;211       if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
;;;212       while(getSn_SR(sn) != SOCK_ESTABLISHED)
;;;213       {
;;;214        if (getSn_IR(sn) & Sn_IR_TIMEOUT)
;;;215        {
;;;216          setSn_IR(sn, Sn_IR_TIMEOUT);
;;;217                return SOCKERR_TIMEOUT;
;;;218        }
;;;219    
;;;220        if (getSn_SR(sn) == SOCK_CLOSED)
;;;221        {
;;;222          return SOCKERR_SOCKCLOSED;
;;;223        }
;;;224      }
;;;225       
;;;226       return SOCK_OK;
;;;227    }
000012  e8bd81f0          POP      {r4-r8,pc}
                  |L2.22|
000016  f44f6080          MOV      r0,#0x400             ;196
00001a  eb002004          ADD      r0,r0,r4,LSL #8       ;196
00001e  f7fffffe          BL       WIZCHIP_READ
000022  f000000f          AND      r0,r0,#0xf            ;196
000026  2801              CMP      r0,#1                 ;196
000028  d002              BEQ      |L2.48|
00002a  f06f0004          MVN      r0,#4                 ;196
00002e  e7f0              B        |L2.18|
                  |L2.48|
000030  f2404003          MOV      r0,#0x403             ;197
000034  eb002504          ADD      r5,r0,r4,LSL #8       ;197
000038  4628              MOV      r0,r5                 ;197
00003a  f7fffffe          BL       WIZCHIP_READ
00003e  2813              CMP      r0,#0x13              ;197
000040  d002              BEQ      |L2.72|
000042  f06f0002          MVN      r0,#2                 ;197
000046  e7e4              B        |L2.18|
                  |L2.72|
000048  7830              LDRB     r0,[r6,#0]            ;200
00004a  7871              LDRB     r1,[r6,#1]            ;201
00004c  eb012000          ADD      r0,r1,r0,LSL #8       ;201
000050  78b1              LDRB     r1,[r6,#2]            ;202
000052  eb012000          ADD      r0,r1,r0,LSL #8       ;202
000056  78f1              LDRB     r1,[r6,#3]            ;203
000058  eb012000          ADD      r0,r1,r0,LSL #8       ;203
00005c  1c41              ADDS     r1,r0,#1              ;204
00005e  d02c              BEQ      |L2.186|
000060  b358              CBZ      r0,|L2.186|
000062  b36f              CBZ      r7,|L2.192|
000064  f240400c          MOV      r0,#0x40c             ;207
000068  eb002004          ADD      r0,r0,r4,LSL #8       ;207
00006c  2204              MOVS     r2,#4                 ;207
00006e  4631              MOV      r1,r6                 ;207
000070  f7fffffe          BL       WIZCHIP_WRITE_BUF
000074  f44f6082          MOV      r0,#0x410             ;208
000078  0a39              LSRS     r1,r7,#8              ;208
00007a  eb002004          ADD      r0,r0,r4,LSL #8       ;208
00007e  f7fffffe          BL       WIZCHIP_WRITE
000082  f2404011          MOV      r0,#0x411             ;208
000086  b2f9              UXTB     r1,r7                 ;208
000088  eb002004          ADD      r0,r0,r4,LSL #8       ;208
00008c  f7fffffe          BL       WIZCHIP_WRITE
000090  f2404001          MOV      r0,#0x401             ;209
000094  eb002604          ADD      r6,r0,r4,LSL #8       ;209
000098  2104              MOVS     r1,#4                 ;209
00009a  4630              MOV      r0,r6                 ;209
00009c  f7fffffe          BL       WIZCHIP_WRITE
                  |L2.160|
0000a0  4630              MOV      r0,r6                 ;210
0000a2  f7fffffe          BL       WIZCHIP_READ
0000a6  2800              CMP      r0,#0                 ;210
0000a8  d1fa              BNE      |L2.160|
0000aa  4916              LDR      r1,|L2.260|
0000ac  2001              MOVS     r0,#1                 ;211
0000ae  40a0              LSLS     r0,r0,r4              ;211
0000b0  8849              LDRH     r1,[r1,#2]            ;211  ; sock_io_mode
0000b2  4208              TST      r0,r1                 ;211
0000b4  d007              BEQ      |L2.198|
0000b6  2000              MOVS     r0,#0                 ;211
0000b8  e7ab              B        |L2.18|
                  |L2.186|
0000ba  f06f000b          MVN      r0,#0xb               ;204
0000be  e7a8              B        |L2.18|
                  |L2.192|
0000c0  f06f000a          MVN      r0,#0xa               ;206
0000c4  e7a5              B        |L2.18|
                  |L2.198|
0000c6  f2404002          MOV      r0,#0x402             ;214
0000ca  eb002404          ADD      r4,r0,r4,LSL #8       ;214
0000ce  e00f              B        |L2.240|
                  |L2.208|
0000d0  4620              MOV      r0,r4                 ;214
0000d2  f7fffffe          BL       WIZCHIP_READ
0000d6  0700              LSLS     r0,r0,#28             ;214
0000d8  d506              BPL      |L2.232|
0000da  4620              MOV      r0,r4                 ;216
0000dc  2108              MOVS     r1,#8                 ;216
0000de  f7fffffe          BL       WIZCHIP_WRITE
0000e2  f06f000c          MVN      r0,#0xc               ;217
0000e6  e794              B        |L2.18|
                  |L2.232|
0000e8  4628              MOV      r0,r5                 ;220
0000ea  f7fffffe          BL       WIZCHIP_READ
0000ee  b130              CBZ      r0,|L2.254|
                  |L2.240|
0000f0  4628              MOV      r0,r5                 ;212
0000f2  f7fffffe          BL       WIZCHIP_READ
0000f6  2817              CMP      r0,#0x17              ;212
0000f8  d1ea              BNE      |L2.208|
0000fa  2001              MOVS     r0,#1                 ;226
0000fc  e789              B        |L2.18|
                  |L2.254|
0000fe  f06f0003          MVN      r0,#3                 ;222
000102  e786              B        |L2.18|
;;;228    
                          ENDP

                  |L2.260|
                          DCD      ||.data||

                          AREA ||i.ctlsocket||, CODE, READONLY, ALIGN=2

                  ctlsocket PROC
;;;549    
;;;550    int8_t  ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg)
000000  e92d47f0          PUSH     {r4-r10,lr}
;;;551    {
000004  4614              MOV      r4,r2
;;;552       uint8_t tmp = 0;
;;;553       CHECK_SOCKNUM();
000006  2804              CMP      r0,#4
000008  d903              BLS      |L3.18|
00000a  f04f30ff          MOV      r0,#0xffffffff
                  |L3.14|
;;;554       switch(cstype)
;;;555       {
;;;556          case CS_SET_IOMODE:
;;;557             tmp = *((uint8_t*)arg);
;;;558             if(tmp == SOCK_IO_NONBLOCK)  sock_io_mode |= (1<<sn);
;;;559             else if(tmp == SOCK_IO_BLOCK) sock_io_mode &= ~(1<<sn);
;;;560             else return SOCKERR_ARG;
;;;561             break;
;;;562          case CS_GET_IOMODE:   
;;;563             //M20140501 : implict type casting -> explict type casting   
;;;564             *((uint8_t*)arg) = (uint8_t)((sock_io_mode >> sn) & 0x0001);
;;;565             break;
;;;566          case CS_GET_MAXTXBUF:
;;;567             *((uint16_t*)arg) = getSn_TxMAX(sn);
;;;568             break;
;;;569          case CS_GET_MAXRXBUF:    
;;;570             *((uint16_t*)arg) = getSn_RxMAX(sn);
;;;571             break;
;;;572          case CS_CLR_INTERRUPT:
;;;573             if( (*(uint8_t*)arg) > SIK_ALL) return SOCKERR_ARG;
;;;574             setSn_IR(sn,*(uint8_t*)arg);
;;;575             break;
;;;576          case CS_GET_INTERRUPT:
;;;577             *((uint8_t*)arg) = getSn_IR(sn);
;;;578             break;
;;;579          default:
;;;580             return SOCKERR_ARG;
;;;581       }
;;;582       return SOCK_OK;
;;;583    }
00000e  e8bd87f0          POP      {r4-r10,pc}
                  |L3.18|
000012  f8df90a0          LDR      r9,|L3.180|
000016  f2404202          MOV      r2,#0x402             ;574
00001a  2503              MOVS     r5,#3                 ;551
00001c  0046              LSLS     r6,r0,#1              ;567
00001e  eb022300          ADD      r3,r2,r0,LSL #8       ;574
000022  2701              MOVS     r7,#1                 ;551
000024  40b5              LSLS     r5,r5,r6              ;567
000026  f8b92002          LDRH     r2,[r9,#2]            ;558
00002a  f06f0c09          MVN      r12,#9                ;560
00002e  f64f78ff          MOV      r8,#0xffff            ;567
000032  2906              CMP      r1,#6                 ;554
000034  d23c              BCS      |L3.176|
000036  e8dff001          TBB      [pc,r1]               ;554
00003a  0313              DCB      0x03,0x13
00003c  18222c35          DCB      0x18,0x22,0x2c,0x35
000040  7823              LDRB     r3,[r4,#0]            ;557
000042  2101              MOVS     r1,#1                 ;551
000044  4081              LSLS     r1,r1,r0              ;558
000046  2b01              CMP      r3,#1                 ;558
000048  d002              BEQ      |L3.80|
00004a  b12b              CBZ      r3,|L3.88|
00004c  4660              MOV      r0,r12                ;560
00004e  e7de              B        |L3.14|
                  |L3.80|
000050  4311              ORRS     r1,r1,r2              ;558
000052  f8a91002          STRH     r1,[r9,#2]            ;558
000056  e029              B        |L3.172|
                  |L3.88|
000058  438a              BICS     r2,r2,r1              ;559
00005a  f8a92002          STRH     r2,[r9,#2]            ;559
00005e  e025              B        |L3.172|
000060  40c2              LSRS     r2,r2,r0              ;564
000062  f0020001          AND      r0,r2,#1              ;564
000066  7020              STRB     r0,[r4,#0]            ;564
000068  e020              B        |L3.172|
00006a  201b              MOVS     r0,#0x1b              ;567
00006c  f7fffffe          BL       WIZCHIP_READ
000070  4028              ANDS     r0,r0,r5              ;567
000072  40f0              LSRS     r0,r0,r6              ;567
000074  4087              LSLS     r7,r7,r0              ;567
000076  ea082087          AND      r0,r8,r7,LSL #10      ;567
00007a  8020              STRH     r0,[r4,#0]            ;567
00007c  e016              B        |L3.172|
00007e  201a              MOVS     r0,#0x1a              ;570
000080  f7fffffe          BL       WIZCHIP_READ
000084  4028              ANDS     r0,r0,r5              ;570
000086  40f0              LSRS     r0,r0,r6              ;570
000088  4087              LSLS     r7,r7,r0              ;570
00008a  ea082087          AND      r0,r8,r7,LSL #10      ;570
00008e  8020              STRH     r0,[r4,#0]            ;570
000090  e00c              B        |L3.172|
000092  7821              LDRB     r1,[r4,#0]            ;573
000094  291f              CMP      r1,#0x1f              ;573
000096  d901              BLS      |L3.156|
000098  4660              MOV      r0,r12                ;573
00009a  e7b8              B        |L3.14|
                  |L3.156|
00009c  4618              MOV      r0,r3                 ;574
00009e  f7fffffe          BL       WIZCHIP_WRITE
0000a2  e003              B        |L3.172|
0000a4  4618              MOV      r0,r3                 ;577
0000a6  f7fffffe          BL       WIZCHIP_READ
0000aa  7020              STRB     r0,[r4,#0]            ;577
                  |L3.172|
0000ac  2001              MOVS     r0,#1                 ;582
0000ae  e7ae              B        |L3.14|
                  |L3.176|
0000b0  4660              MOV      r0,r12                ;580
0000b2  e7ac              B        |L3.14|
;;;584    
                          ENDP

                  |L3.180|
                          DCD      ||.data||

                          AREA ||i.disconnect||, CODE, READONLY, ALIGN=2

                  disconnect PROC
;;;228    
;;;229    int8_t disconnect(uint8_t sn)
000000  b570              PUSH     {r4-r6,lr}
;;;230    {
000002  4604              MOV      r4,r0
;;;231       CHECK_SOCKNUM();
000004  2c04              CMP      r4,#4
000006  d902              BLS      |L4.14|
000008  f04f30ff          MOV      r0,#0xffffffff
;;;232       CHECK_SOCKMODE(Sn_MR_TCP);
;;;233      setSn_CR(sn,Sn_CR_DISCON);
;;;234      /* wait to process the command... */
;;;235      while(getSn_CR(sn));
;;;236      sock_is_sending &= ~(1<<sn);
;;;237       if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
;;;238      while(getSn_SR(sn) != SOCK_CLOSED)
;;;239      {
;;;240         if(getSn_IR(sn) & Sn_IR_TIMEOUT)
;;;241         {
;;;242            close(sn);
;;;243            return SOCKERR_TIMEOUT;
;;;244         }
;;;245      }
;;;246      return SOCK_OK;
;;;247    }
00000c  bd70              POP      {r4-r6,pc}
                  |L4.14|
00000e  f44f6080          MOV      r0,#0x400             ;232
000012  eb002004          ADD      r0,r0,r4,LSL #8       ;232
000016  f7fffffe          BL       WIZCHIP_READ
00001a  f000000f          AND      r0,r0,#0xf            ;232
00001e  2801              CMP      r0,#1                 ;232
000020  d002              BEQ      |L4.40|
000022  f06f0004          MVN      r0,#4                 ;232
000026  bd70              POP      {r4-r6,pc}
                  |L4.40|
000028  f2404001          MOV      r0,#0x401             ;233
00002c  eb002504          ADD      r5,r0,r4,LSL #8       ;233
000030  2108              MOVS     r1,#8                 ;233
000032  4628              MOV      r0,r5                 ;233
000034  f7fffffe          BL       WIZCHIP_WRITE
                  |L4.56|
000038  4628              MOV      r0,r5                 ;235
00003a  f7fffffe          BL       WIZCHIP_READ
00003e  2800              CMP      r0,#0                 ;235
000040  d1fa              BNE      |L4.56|
000042  4912              LDR      r1,|L4.140|
000044  2001              MOVS     r0,#1                 ;236
000046  40a0              LSLS     r0,r0,r4              ;236
000048  888a              LDRH     r2,[r1,#4]            ;236  ; sock_is_sending
00004a  4382              BICS     r2,r2,r0              ;236
00004c  808a              STRH     r2,[r1,#4]            ;236
00004e  8849              LDRH     r1,[r1,#2]            ;237  ; sock_io_mode
000050  4208              TST      r0,r1                 ;237
000052  d001              BEQ      |L4.88|
000054  2000              MOVS     r0,#0                 ;237
000056  bd70              POP      {r4-r6,pc}
                  |L4.88|
000058  f2404002          MOV      r0,#0x402             ;240
00005c  eb002504          ADD      r5,r0,r4,LSL #8       ;240
000060  1c40              ADDS     r0,r0,#1              ;238
000062  eb002604          ADD      r6,r0,r4,LSL #8       ;238
000066  e00a              B        |L4.126|
                  |L4.104|
000068  4628              MOV      r0,r5                 ;240
00006a  f7fffffe          BL       WIZCHIP_READ
00006e  0700              LSLS     r0,r0,#28             ;240
000070  d505              BPL      |L4.126|
000072  4620              MOV      r0,r4                 ;242
000074  f7fffffe          BL       close
000078  f06f000c          MVN      r0,#0xc               ;243
00007c  bd70              POP      {r4-r6,pc}
                  |L4.126|
00007e  4630              MOV      r0,r6                 ;238
000080  f7fffffe          BL       WIZCHIP_READ
000084  2800              CMP      r0,#0                 ;238
000086  d1ef              BNE      |L4.104|
000088  2001              MOVS     r0,#1                 ;246
00008a  bd70              POP      {r4-r6,pc}
;;;248    
                          ENDP

                  |L4.140|
                          DCD      ||.data||

                          AREA ||i.getsockopt||, CODE, READONLY, ALIGN=2

                  getsockopt PROC
;;;611    
;;;612    int8_t  getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
000000  b570              PUSH     {r4-r6,lr}
;;;613    {
000002  4604              MOV      r4,r0
000004  4615              MOV      r5,r2
;;;614       CHECK_SOCKNUM();
000006  2c04              CMP      r4,#4
000008  d902              BLS      |L5.16|
00000a  f04f30ff          MOV      r0,#0xffffffff
;;;615       switch(sotype)
;;;616       {
;;;617          case SO_FLAG:
;;;618             *(uint8_t*)arg = getSn_MR(sn) & 0xF0;
;;;619             break;
;;;620          case SO_TTL:
;;;621             *(uint8_t*) arg = getSn_TTL(sn);
;;;622             break;
;;;623          case SO_TOS:
;;;624             *(uint8_t*) arg = getSn_TOS(sn);
;;;625             break;
;;;626          case SO_MSS:   
;;;627             *(uint8_t*) arg = getSn_MSSR(sn);
;;;628             break;
;;;629          case SO_DESTIP:
;;;630             getSn_DIPR(sn, (uint8_t*)arg);
;;;631             break;
;;;632          case SO_DESTPORT:  
;;;633             *(uint16_t*) arg = getSn_DPORT(sn);
;;;634             break;
;;;635        
;;;636          case SO_SENDBUF:
;;;637             *(uint16_t*) arg = getSn_TX_FSR(sn);
;;;638             break;
;;;639          case SO_RECVBUF:
;;;640             *(uint16_t*) arg = getSn_RX_RSR(sn);
;;;641             break;
;;;642          case SO_STATUS:
;;;643             *(uint8_t*) arg = getSn_SR(sn);
;;;644             break;
;;;645          case SO_REMAINSIZE:
;;;646             if(getSn_MR(sn) == Sn_MR_TCP)
;;;647                *(uint16_t*)arg = getSn_RX_RSR(sn);
;;;648             else
;;;649                *(uint16_t*)arg = sock_remained_size[sn];
;;;650             break;
;;;651          case SO_PACKINFO:
;;;652             CHECK_SOCKMODE(Sn_MR_TCP);
;;;653             *(uint8_t*)arg = sock_pack_info[sn];
;;;654             break;
;;;655          default:
;;;656             return SOCKERR_SOCKOPT;
;;;657       }
;;;658       return SOCK_OK;
;;;659    }
00000e  bd70              POP      {r4-r6,pc}
                  |L5.16|
000010  f44f6080          MOV      r0,#0x400             ;618
000014  eb002004          ADD      r0,r0,r4,LSL #8       ;618
000018  290b              CMP      r1,#0xb               ;615
00001a  d278              BCS      |L5.270|
00001c  e8dff001          TBB      [pc,r1]               ;615
000020  060c141c          DCB      0x06,0x0c,0x14,0x1c
000024  2d36474c          DCB      0x2d,0x36,0x47,0x4c
000028  51596700          DCB      0x51,0x59,0x67,0x00
00002c  f7fffffe          BL       WIZCHIP_READ
000030  f00000f0          AND      r0,r0,#0xf0           ;618
000034  7028              STRB     r0,[r5,#0]            ;618
000036  e068              B        |L5.266|
000038  f2404016          MOV      r0,#0x416             ;621
00003c  eb002004          ADD      r0,r0,r4,LSL #8       ;621
000040  f7fffffe          BL       WIZCHIP_READ
000044  7028              STRB     r0,[r5,#0]            ;621
000046  e060              B        |L5.266|
000048  f2404015          MOV      r0,#0x415             ;624
00004c  eb002004          ADD      r0,r0,r4,LSL #8       ;624
000050  f7fffffe          BL       WIZCHIP_READ
000054  7028              STRB     r0,[r5,#0]            ;624
000056  e058              B        |L5.266|
000058  f2404013          MOV      r0,#0x413             ;627
00005c  eb002004          ADD      r0,r0,r4,LSL #8       ;627
000060  f7fffffe          BL       WIZCHIP_READ
000064  4606              MOV      r6,r0                 ;627
000066  f2404012          MOV      r0,#0x412             ;627
00006a  eb002004          ADD      r0,r0,r4,LSL #8       ;627
00006e  f7fffffe          BL       WIZCHIP_READ
000072  eb062000          ADD      r0,r6,r0,LSL #8       ;627
000076  7028              STRB     r0,[r5,#0]            ;627
000078  e047              B        |L5.266|
00007a  f240400c          MOV      r0,#0x40c             ;630
00007e  eb002004          ADD      r0,r0,r4,LSL #8       ;630
000082  2204              MOVS     r2,#4                 ;630
000084  4629              MOV      r1,r5                 ;630
000086  f7fffffe          BL       WIZCHIP_READ_BUF
00008a  e03e              B        |L5.266|
00008c  f2404011          MOV      r0,#0x411             ;633
000090  eb002004          ADD      r0,r0,r4,LSL #8       ;633
000094  f7fffffe          BL       WIZCHIP_READ
000098  4606              MOV      r6,r0                 ;633
00009a  f44f6082          MOV      r0,#0x410             ;633
00009e  eb002004          ADD      r0,r0,r4,LSL #8       ;633
0000a2  f7fffffe          BL       WIZCHIP_READ
0000a6  eb062000          ADD      r0,r6,r0,LSL #8       ;633
0000aa  8028              STRH     r0,[r5,#0]            ;633
0000ac  e02d              B        |L5.266|
0000ae  4620              MOV      r0,r4                 ;637
0000b0  f7fffffe          BL       getSn_TX_FSR
0000b4  8028              STRH     r0,[r5,#0]            ;637
0000b6  e028              B        |L5.266|
0000b8  4620              MOV      r0,r4                 ;640
0000ba  f7fffffe          BL       getSn_RX_RSR
0000be  8028              STRH     r0,[r5,#0]            ;640
0000c0  e023              B        |L5.266|
0000c2  f2404003          MOV      r0,#0x403             ;643
0000c6  eb002004          ADD      r0,r0,r4,LSL #8       ;643
0000ca  f7fffffe          BL       WIZCHIP_READ
0000ce  7028              STRB     r0,[r5,#0]            ;643
0000d0  e01b              B        |L5.266|
0000d2  f7fffffe          BL       WIZCHIP_READ
0000d6  2801              CMP      r0,#1                 ;646
0000d8  d004              BEQ      |L5.228|
0000da  480e              LDR      r0,|L5.276|
0000dc  f8300014          LDRH     r0,[r0,r4,LSL #1]     ;649
0000e0  8028              STRH     r0,[r5,#0]            ;649
0000e2  e012              B        |L5.266|
                  |L5.228|
0000e4  4620              MOV      r0,r4                 ;647
0000e6  f7fffffe          BL       getSn_RX_RSR
0000ea  8028              STRH     r0,[r5,#0]            ;647
0000ec  e00d              B        |L5.266|
0000ee  f7fffffe          BL       WIZCHIP_READ
0000f2  f000000f          AND      r0,r0,#0xf            ;652
0000f6  2801              CMP      r0,#1                 ;652
0000f8  d003              BEQ      |L5.258|
0000fa  f06f0004          MVN      r0,#4                 ;652
                  |L5.254|
0000fe  bd70              POP      {r4-r6,pc}
000100  e005              B        |L5.270|
                  |L5.258|
000102  4804              LDR      r0,|L5.276|
000104  1f00              SUBS     r0,r0,#4              ;653
000106  5d00              LDRB     r0,[r0,r4]            ;653
000108  7028              STRB     r0,[r5,#0]            ;653
                  |L5.266|
00010a  2001              MOVS     r0,#1                 ;658
00010c  e7f7              B        |L5.254|
                  |L5.270|
00010e  f06f0001          MVN      r0,#1                 ;656
000112  e7f4              B        |L5.254|
                          ENDP

                  |L5.276|
                          DCD      ||.data||+0xa

                          AREA ||i.listen||, CODE, READONLY, ALIGN=1

                  listen PROC
;;;175    
;;;176    int8_t listen(uint8_t sn)
000000  b570              PUSH     {r4-r6,lr}
;;;177    {
000002  4604              MOV      r4,r0
;;;178      CHECK_SOCKNUM();
000004  2c04              CMP      r4,#4
000006  d902              BLS      |L6.14|
000008  f04f30ff          MOV      r0,#0xffffffff
;;;179       CHECK_SOCKMODE(Sn_MR_TCP);
;;;180      CHECK_SOCKINIT();
;;;181      setSn_CR(sn,Sn_CR_LISTEN);
;;;182      while(getSn_CR(sn));
;;;183       while(getSn_SR(sn) != SOCK_LISTEN)
;;;184       {
;;;185             close(sn);
;;;186             return SOCKERR_SOCKCLOSED;
;;;187       }
;;;188       return SOCK_OK;
;;;189    }
00000c  bd70              POP      {r4-r6,pc}
                  |L6.14|
00000e  f44f6080          MOV      r0,#0x400             ;179
000012  eb002004          ADD      r0,r0,r4,LSL #8       ;179
000016  f7fffffe          BL       WIZCHIP_READ
00001a  f000000f          AND      r0,r0,#0xf            ;179
00001e  2801              CMP      r0,#1                 ;179
000020  d002              BEQ      |L6.40|
000022  f06f0004          MVN      r0,#4                 ;179
000026  bd70              POP      {r4-r6,pc}
                  |L6.40|
000028  f2404003          MOV      r0,#0x403             ;180
00002c  eb002004          ADD      r0,r0,r4,LSL #8       ;180
000030  4606              MOV      r6,r0                 ;180
000032  f7fffffe          BL       WIZCHIP_READ
000036  2813              CMP      r0,#0x13              ;180
000038  d002              BEQ      |L6.64|
00003a  f06f0002          MVN      r0,#2                 ;180
00003e  bd70              POP      {r4-r6,pc}
                  |L6.64|
000040  f2404001          MOV      r0,#0x401             ;181
000044  eb002504          ADD      r5,r0,r4,LSL #8       ;181
000048  2102              MOVS     r1,#2                 ;181
00004a  4628              MOV      r0,r5                 ;181
00004c  f7fffffe          BL       WIZCHIP_WRITE
                  |L6.80|
000050  4628              MOV      r0,r5                 ;182
000052  f7fffffe          BL       WIZCHIP_READ
000056  2800              CMP      r0,#0                 ;182
000058  d1fa              BNE      |L6.80|
00005a  4630              MOV      r0,r6                 ;183
00005c  f7fffffe          BL       WIZCHIP_READ
000060  2814              CMP      r0,#0x14              ;183
000062  d005              BEQ      |L6.112|
000064  4620              MOV      r0,r4                 ;185
000066  f7fffffe          BL       close
00006a  f06f0003          MVN      r0,#3                 ;186
00006e  bd70              POP      {r4-r6,pc}
                  |L6.112|
000070  2001              MOVS     r0,#1                 ;188
000072  bd70              POP      {r4-r6,pc}
;;;190    
                          ENDP


                          AREA ||i.recv||, CODE, READONLY, ALIGN=2

                  recv PROC
;;;301    
;;;302    int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
000000  e92d4ff7          PUSH     {r0-r2,r4-r11,lr}
;;;303    {
000004  4605              MOV      r5,r0
000006  4616              MOV      r6,r2
;;;304       uint8_t  tmp = 0;
;;;305       uint16_t recvsize = 0;
;;;306    
;;;307       CHECK_SOCKNUM();
000008  2d04              CMP      r5,#4
00000a  d903              BLS      |L7.20|
00000c  f04f30ff          MOV      r0,#0xffffffff
                  |L7.16|
;;;308       CHECK_SOCKMODE(Sn_MR_TCP);
;;;309       CHECK_SOCKDATA();
;;;310       
;;;311       recvsize = getSn_RxMAX(sn);   // 得到接收缓存大小 1024 2048 4096 8192
;;;312       if(recvsize < len) len = recvsize;   // 发送的数据不能超过RXMAX
;;;313          
;;;314       while(1)
;;;315       {
;;;316         recvsize = getSn_RX_RSR(sn);  // 读取接收数据大小
;;;317         tmp = getSn_SR(sn);
;;;318         if (tmp != SOCK_ESTABLISHED)
;;;319         {
;;;320            if(tmp == SOCK_CLOSE_WAIT)
;;;321            {
;;;322               if(recvsize != 0) break;
;;;323               else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn))  //Sn_TX_FSR--发送缓存空闲大小
;;;324               {
;;;325                  close(sn);
;;;326                  return SOCKERR_SOCKSTATUS;
;;;327               }
;;;328            }
;;;329            else
;;;330            {
;;;331               close(sn);
;;;332               return SOCKERR_SOCKSTATUS;
;;;333            }
;;;334         }
;;;335         if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY;
;;;336         if(recvsize != 0) break;
;;;337       };
;;;338      
;;;339       if(recvsize < len) len = recvsize;   
;;;340       wiz_recv_data(sn, buf, len);
;;;341       setSn_CR(sn,Sn_CR_RECV);       // 更新接收读指针寄存器
;;;342       while(getSn_CR(sn));     
;;;343       //M20150409 : Explicit Type Casting
;;;344       return (int32_t)len;
;;;345    }
000010  e8bd8ffe          POP      {r1-r11,pc}
                  |L7.20|
000014  f44f6080          MOV      r0,#0x400             ;308
000018  eb002005          ADD      r0,r0,r5,LSL #8       ;308
00001c  f7fffffe          BL       WIZCHIP_READ
000020  f000000f          AND      r0,r0,#0xf            ;308
000024  2801              CMP      r0,#1                 ;308
000026  d002              BEQ      |L7.46|
000028  f06f0004          MVN      r0,#4                 ;308
00002c  e7f0              B        |L7.16|
                  |L7.46|
00002e  b1d6              CBZ      r6,|L7.102|
000030  201a              MOVS     r0,#0x1a              ;311
000032  f7fffffe          BL       WIZCHIP_READ
000036  006f              LSLS     r7,r5,#1              ;311
000038  f04f0903          MOV      r9,#3                 ;311
00003c  fa09f907          LSL      r9,r9,r7              ;311
000040  ea000009          AND      r0,r0,r9              ;311
000044  40f8              LSRS     r0,r0,r7              ;311
000046  f04f0801          MOV      r8,#1                 ;311
00004a  fa08f000          LSL      r0,r8,r0              ;311
00004e  f64f71ff          MOV      r1,#0xffff            ;311
000052  ea012080          AND      r0,r1,r0,LSL #10      ;311
000056  42b0              CMP      r0,r6                 ;312
000058  d200              BCS      |L7.92|
00005a  4606              MOV      r6,r0                 ;312
                  |L7.92|
00005c  f2404003          MOV      r0,#0x403             ;317
000060  eb002a05          ADD      r10,r0,r5,LSL #8      ;317
000064  e042              B        |L7.236|
                  |L7.102|
000066  f06f000d          MVN      r0,#0xd               ;309
00006a  e7d1              B        |L7.16|
                  |L7.108|
00006c  281c              CMP      r0,#0x1c              ;320
00006e  d005              BEQ      |L7.124|
000070  4628              MOV      r0,r5                 ;331
000072  f7fffffe          BL       close
000076  f06f0006          MVN      r0,#6                 ;332
00007a  e7c9              B        |L7.16|
                  |L7.124|
00007c  b9ec              CBNZ     r4,|L7.186|
00007e  4628              MOV      r0,r5                 ;323
000080  f7fffffe          BL       getSn_TX_FSR
000084  4683              MOV      r11,r0                ;323
000086  201b              MOVS     r0,#0x1b              ;323
000088  f7fffffe          BL       WIZCHIP_READ
00008c  ea000009          AND      r0,r0,r9              ;323
000090  40f8              LSRS     r0,r0,r7              ;323
000092  fa08f000          LSL      r0,r8,r0              ;323
000096  b280              UXTH     r0,r0                 ;323
000098  ebbb2f80          CMP      r11,r0,LSL #10        ;323
00009c  d105              BNE      |L7.170|
00009e  4628              MOV      r0,r5                 ;325
0000a0  f7fffffe          BL       close
0000a4  f06f0006          MVN      r0,#6                 ;326
0000a8  e7b2              B        |L7.16|
                  |L7.170|
0000aa  4915              LDR      r1,|L7.256|
0000ac  fa08f005          LSL      r0,r8,r5              ;335
0000b0  8849              LDRH     r1,[r1,#2]            ;335  ; sock_io_mode
0000b2  4208              TST      r0,r1                 ;335
0000b4  d000              BEQ      |L7.184|
0000b6  b1bc              CBZ      r4,|L7.232|
                  |L7.184|
0000b8  b1c4              CBZ      r4,|L7.236|
                  |L7.186|
0000ba  42b4              CMP      r4,r6                 ;339
0000bc  d200              BCS      |L7.192|
0000be  4626              MOV      r6,r4                 ;339
                  |L7.192|
0000c0  4632              MOV      r2,r6                 ;340
0000c2  4628              MOV      r0,r5                 ;340
0000c4  9901              LDR      r1,[sp,#4]            ;340
0000c6  f7fffffe          BL       wiz_recv_data
0000ca  f2404001          MOV      r0,#0x401             ;341
0000ce  eb002405          ADD      r4,r0,r5,LSL #8       ;341
0000d2  2140              MOVS     r1,#0x40              ;341
0000d4  4620              MOV      r0,r4                 ;341
0000d6  f7fffffe          BL       WIZCHIP_WRITE
                  |L7.218|
0000da  4620              MOV      r0,r4                 ;342
0000dc  f7fffffe          BL       WIZCHIP_READ
0000e0  2800              CMP      r0,#0                 ;342
0000e2  d1fa              BNE      |L7.218|
0000e4  4630              MOV      r0,r6                 ;344
0000e6  e793              B        |L7.16|
                  |L7.232|
0000e8  2000              MOVS     r0,#0                 ;335
0000ea  e791              B        |L7.16|
                  |L7.236|
0000ec  4628              MOV      r0,r5                 ;316
0000ee  f7fffffe          BL       getSn_RX_RSR
0000f2  4604              MOV      r4,r0                 ;316
0000f4  4650              MOV      r0,r10                ;317
0000f6  f7fffffe          BL       WIZCHIP_READ
0000fa  2817              CMP      r0,#0x17              ;318
0000fc  d0d5              BEQ      |L7.170|
0000fe  e7b5              B        |L7.108|
;;;346    int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
                          ENDP

                  |L7.256|
                          DCD      ||.data||

                          AREA ||i.recvfrom||, CODE, READONLY, ALIGN=2

                  recvfrom PROC
;;;423    
;;;424    int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port)
000000  e92d4fff          PUSH     {r0-r11,lr}
;;;425    {
000004  b083              SUB      sp,sp,#0xc
000006  4604              MOV      r4,r0
000008  4690              MOV      r8,r2
00000a  461f              MOV      r7,r3
;;;426    
;;;427      uint8_t  mr;   
;;;428      uint8_t  head[8];
;;;429      uint16_t pack_len=0;
00000c  2500              MOVS     r5,#0
;;;430    
;;;431       CHECK_SOCKNUM();
00000e  2c04              CMP      r4,#4
000010  d903              BLS      |L8.26|
000012  1e68              SUBS     r0,r5,#1
                  |L8.20|
;;;432        
;;;433       switch((mr=getSn_MR(sn)) & 0x0F)
;;;434       {
;;;435          case Sn_MR_UDP:
;;;436          case Sn_MR_MACRAW:
;;;437             break;
;;;438          case Sn_MR_IPRAW:
;;;439          case Sn_MR_PPPoE:
;;;440             break;
;;;441          default:
;;;442             return SOCKERR_SOCKMODE;
;;;443       }
;;;444       CHECK_SOCKDATA();
;;;445       if(sock_remained_size[sn] == 0)
;;;446       {
;;;447          while(1)
;;;448          {
;;;449             pack_len = getSn_RX_RSR(sn);
;;;450             if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
;;;451             if( (sock_io_mode & (1<<sn)) && (pack_len == 0) ) return SOCK_BUSY;
;;;452             if(pack_len != 0) break;
;;;453          };
;;;454       }
;;;455    //D20150601 : Move it to bottom
;;;456    // sock_pack_info[sn] = PACK_COMPLETED;
;;;457      switch (mr & 0x07)
;;;458      {
;;;459         case Sn_MR_UDP :
;;;460            if(sock_remained_size[sn] == 0)
;;;461            {
;;;462             wiz_recv_data(sn, head, 8);
;;;463             setSn_CR(sn,Sn_CR_RECV);
;;;464             while(getSn_CR(sn));
;;;465            // read peer's IP address, port number & packet length
;;;466    
;;;467      
;;;468            addr[0] = head[0];
;;;469            addr[1] = head[1];
;;;470            addr[2] = head[2];
;;;471            addr[3] = head[3];
;;;472            *port = head[4];
;;;473            *port = (*port << 8) + head[5];
;;;474            sock_remained_size[sn] = head[6];
;;;475            sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[7];
;;;476         
;;;477             sock_pack_info[sn] = PACK_FIRST;
;;;478            }
;;;479          if(len < sock_remained_size[sn]) pack_len = len;
;;;480          else pack_len = sock_remained_size[sn];
;;;481          //A20150601 : For W5300
;;;482          len = pack_len;
;;;483          // Need to packet length check (default 1472)    
;;;484           wiz_recv_data(sn, buf, pack_len); // data copy.
;;;485          break;
;;;486         case Sn_MR_MACRAW :
;;;487            if(sock_remained_size[sn] == 0)
;;;488            {
;;;489             wiz_recv_data(sn, head, 2);
;;;490             setSn_CR(sn,Sn_CR_RECV);
;;;491             while(getSn_CR(sn));
;;;492             // read peer's IP address, port number & packet length
;;;493              sock_remained_size[sn] = head[0];
;;;494             sock_remained_size[sn] = (sock_remained_size[sn] <<8) + head[1];
;;;495             if(sock_remained_size[sn] > 1514) 
;;;496             {
;;;497                close(sn);
;;;498                return SOCKFATAL_PACKLEN;
;;;499             }
;;;500             sock_pack_info[sn] = PACK_FIRST;
;;;501            }
;;;502          if(len < sock_remained_size[sn]) pack_len = len;
;;;503          else pack_len = sock_remained_size[sn];
;;;504          wiz_recv_data(sn,buf,pack_len);
;;;505           break;
;;;506       
;;;507        case Sn_MR_IPRAW:
;;;508           if(sock_remained_size[sn] == 0)
;;;509           {
;;;510             wiz_recv_data(sn, head, 6);
;;;511             setSn_CR(sn,Sn_CR_RECV);
;;;512             while(getSn_CR(sn));
;;;513             addr[0] = head[0];
;;;514             addr[1] = head[1];
;;;515             addr[2] = head[2];
;;;516             addr[3] = head[3];
;;;517             sock_remained_size[sn] = head[4];
;;;518             //M20150401 : For Typing Error
;;;519             sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[5];
;;;520             sock_pack_info[sn] = PACK_FIRST;
;;;521             }
;;;522          //
;;;523          // Need to packet length check
;;;524          //
;;;525          if(len < sock_remained_size[sn]) pack_len = len;
;;;526          else pack_len = sock_remained_size[sn];
;;;527           wiz_recv_data(sn, buf, pack_len); // data copy.
;;;528          break;
;;;529    
;;;530          default:
;;;531             wiz_recv_ignore(sn, pack_len); // data copy.
;;;532             sock_remained_size[sn] = pack_len;
;;;533             break;
;;;534       }
;;;535      setSn_CR(sn,Sn_CR_RECV);
;;;536      /* wait to process the command... */
;;;537      while(getSn_CR(sn)) ;
;;;538      sock_remained_size[sn] -= pack_len;
;;;539      //M20150601 : 
;;;540      if(sock_remained_size[sn] != 0)
;;;541      {
;;;542         sock_pack_info[sn] |= PACK_REMAINED;      
;;;543      }
;;;544      else sock_pack_info[sn] = PACK_COMPLETED;
;;;545       //M20150409 : Explicit Type Casting
;;;546       return (int32_t)pack_len;
;;;547    }
000014  b007              ADD      sp,sp,#0x1c
000016  e8bd8ff0          POP      {r4-r11,pc}
                  |L8.26|
00001a  f44f6080          MOV      r0,#0x400             ;433
00001e  eb002004          ADD      r0,r0,r4,LSL #8       ;433
000022  f7fffffe          BL       WIZCHIP_READ
000026  4606              MOV      r6,r0                 ;433
000028  f000000f          AND      r0,r0,#0xf            ;433
00002c  2802              CMP      r0,#2                 ;433
00002e  d008              BEQ      |L8.66|
000030  2803              CMP      r0,#3                 ;433
000032  d006              BEQ      |L8.66|
000034  2804              CMP      r0,#4                 ;433
000036  d004              BEQ      |L8.66|
000038  2805              CMP      r0,#5                 ;433
00003a  d002              BEQ      |L8.66|
00003c  f06f0004          MVN      r0,#4                 ;442
000040  e7e8              B        |L8.20|
                  |L8.66|
000042  f1b80f00          CMP      r8,#0                 ;444
000046  d005              BEQ      |L8.84|
000048  f8df9200          LDR      r9,|L8.588|
00004c  f8390014          LDRH     r0,[r9,r4,LSL #1]     ;445
000050  b118              CBZ      r0,|L8.90|
000052  e016              B        |L8.130|
                  |L8.84|
000054  f06f000d          MVN      r0,#0xd               ;444
000058  e7dc              B        |L8.20|
                  |L8.90|
00005a  f04f0a01          MOV      r10,#1                ;451
00005e  f2404003          MOV      r0,#0x403             ;450
000062  fa0afa04          LSL      r10,r10,r4            ;451
000066  eb002b04          ADD      r11,r0,r4,LSL #8      ;450
00006a  e03e              B        |L8.234|
                  |L8.108|
00006c  f06f0003          MVN      r0,#3                 ;450
000070  e7d0              B        |L8.20|
                  |L8.114|
000072  4876              LDR      r0,|L8.588|
000074  380a              SUBS     r0,r0,#0xa            ;451
000076  8840              LDRH     r0,[r0,#2]            ;451  ; sock_io_mode
000078  ea1a0f00          TST      r10,r0                ;451
00007c  d000              BEQ      |L8.128|
00007e  b385              CBZ      r5,|L8.226|
                  |L8.128|
000080  b385              CBZ      r5,|L8.228|
                  |L8.130|
000082  f0060007          AND      r0,r6,#7              ;457
000086  f8dfa1c4          LDR      r10,|L8.588|
00008a  f2404101          MOV      r1,#0x401             ;463
00008e  f04f0b80          MOV      r11,#0x80             ;477
000092  f1aa0a04          SUB      r10,r10,#4            ;477
000096  eb012604          ADD      r6,r1,r4,LSL #8       ;463
00009a  2802              CMP      r0,#2                 ;457
00009c  d02f              BEQ      |L8.254|
00009e  2803              CMP      r0,#3                 ;457
0000a0  d07d              BEQ      |L8.414|
0000a2  2804              CMP      r0,#4                 ;457
0000a4  d067              BEQ      |L8.374|
0000a6  4629              MOV      r1,r5                 ;531
0000a8  4620              MOV      r0,r4                 ;531
0000aa  f7fffffe          BL       wiz_recv_ignore
0000ae  f8295014          STRH     r5,[r9,r4,LSL #1]     ;532
                  |L8.178|
0000b2  4630              MOV      r0,r6                 ;535
0000b4  2140              MOVS     r1,#0x40              ;535
0000b6  f7fffffe          BL       WIZCHIP_WRITE
                  |L8.186|
0000ba  4630              MOV      r0,r6                 ;537
0000bc  f7fffffe          BL       WIZCHIP_READ
0000c0  2800              CMP      r0,#0                 ;537
0000c2  d1fa              BNE      |L8.186|
0000c4  f8390014          LDRH     r0,[r9,r4,LSL #1]     ;538
0000c8  1b40              SUBS     r0,r0,r5              ;538
0000ca  b280              UXTH     r0,r0                 ;538
0000cc  f8290014          STRH     r0,[r9,r4,LSL #1]     ;538
0000d0  2800              CMP      r0,#0                 ;540
0000d2  d065              BEQ      |L8.416|
0000d4  f81a0004          LDRB     r0,[r10,r4]           ;542
0000d8  f0400001          ORR      r0,r0,#1              ;542
0000dc  f80a0004          STRB     r0,[r10,r4]           ;542
0000e0  e0b2              B        |L8.584|
                  |L8.226|
0000e2  e000              B        |L8.230|
                  |L8.228|
0000e4  e001              B        |L8.234|
                  |L8.230|
0000e6  2000              MOVS     r0,#0                 ;451
0000e8  e794              B        |L8.20|
                  |L8.234|
0000ea  4620              MOV      r0,r4                 ;449
0000ec  f7fffffe          BL       getSn_RX_RSR
0000f0  4605              MOV      r5,r0                 ;449
0000f2  4658              MOV      r0,r11                ;450
0000f4  f7fffffe          BL       WIZCHIP_READ
0000f8  2800              CMP      r0,#0                 ;447
0000fa  d1ba              BNE      |L8.114|
0000fc  e7b6              B        |L8.108|
                  |L8.254|
0000fe  f8390014          LDRH     r0,[r9,r4,LSL #1]     ;460
000102  bb68              CBNZ     r0,|L8.352|
000104  2208              MOVS     r2,#8                 ;462
000106  a901              ADD      r1,sp,#4              ;462
000108  4620              MOV      r0,r4                 ;462
00010a  f7fffffe          BL       wiz_recv_data
00010e  4630              MOV      r0,r6                 ;463
000110  2140              MOVS     r1,#0x40              ;463
000112  f7fffffe          BL       WIZCHIP_WRITE
                  |L8.278|
000116  4630              MOV      r0,r6                 ;464
000118  f7fffffe          BL       WIZCHIP_READ
00011c  2800              CMP      r0,#0                 ;464
00011e  d1fa              BNE      |L8.278|
000120  f89d0004          LDRB     r0,[sp,#4]            ;468
000124  7038              STRB     r0,[r7,#0]            ;468
000126  f89d0005          LDRB     r0,[sp,#5]            ;469
00012a  7078              STRB     r0,[r7,#1]            ;469
00012c  f89d0006          LDRB     r0,[sp,#6]            ;470
000130  70b8              STRB     r0,[r7,#2]            ;470
000132  f89d0007          LDRB     r0,[sp,#7]            ;471
000136  70f8              STRB     r0,[r7,#3]            ;471
000138  9910              LDR      r1,[sp,#0x40]         ;472
00013a  f89d0008          LDRB     r0,[sp,#8]            ;472
00013e  8008              STRH     r0,[r1,#0]            ;472
000140  f89d1009          LDRB     r1,[sp,#9]            ;473
000144  eb012000          ADD      r0,r1,r0,LSL #8       ;473
000148  9910              LDR      r1,[sp,#0x40]         ;473
00014a  8008              STRH     r0,[r1,#0]            ;473
00014c  f89d000a          LDRB     r0,[sp,#0xa]          ;474
000150  f89d100b          LDRB     r1,[sp,#0xb]          ;475
000154  eb012000          ADD      r0,r1,r0,LSL #8       ;475
000158  f8290014          STRH     r0,[r9,r4,LSL #1]     ;475
00015c  f80ab004          STRB     r11,[r10,r4]          ;477
                  |L8.352|
000160  f8395014          LDRH     r5,[r9,r4,LSL #1]     ;479
000164  4545              CMP      r5,r8                 ;479
000166  d900              BLS      |L8.362|
000168  4645              MOV      r5,r8                 ;479
                  |L8.362|
00016a  462a              MOV      r2,r5                 ;484
00016c  4620              MOV      r0,r4                 ;484
00016e  9904              LDR      r1,[sp,#0x10]         ;484
000170  f7fffffe          BL       wiz_recv_data
000174  e79d              B        |L8.178|
                  |L8.374|
000176  f8390014          LDRH     r0,[r9,r4,LSL #1]     ;487
00017a  bb28              CBNZ     r0,|L8.456|
00017c  2202              MOVS     r2,#2                 ;489
00017e  a901              ADD      r1,sp,#4              ;489
000180  4620              MOV      r0,r4                 ;489
000182  f7fffffe          BL       wiz_recv_data
000186  4630              MOV      r0,r6                 ;490
000188  2140              MOVS     r1,#0x40              ;490
00018a  f7fffffe          BL       WIZCHIP_WRITE
                  |L8.398|
00018e  4630              MOV      r0,r6                 ;491
000190  f7fffffe          BL       WIZCHIP_READ
000194  2800              CMP      r0,#0                 ;491
000196  d1fa              BNE      |L8.398|
000198  f89d0004          LDRB     r0,[sp,#4]            ;493
00019c  e001              B        |L8.418|
                  |L8.414|
00019e  e01e              B        |L8.478|
                  |L8.416|
0001a0  e04f              B        |L8.578|
                  |L8.418|
0001a2  f89d1005          LDRB     r1,[sp,#5]            ;494
0001a6  eb012000          ADD      r0,r1,r0,LSL #8       ;494
0001aa  b280              UXTH     r0,r0                 ;494
0001ac  f8290014          STRH     r0,[r9,r4,LSL #1]     ;494
0001b0  f24051ea          MOV      r1,#0x5ea             ;495
0001b4  4288              CMP      r0,r1                 ;495
0001b6  d905              BLS      |L8.452|
0001b8  4620              MOV      r0,r4                 ;497
0001ba  f7fffffe          BL       close
0001be  f46f707a          MVN      r0,#0x3e8             ;498
0001c2  e727              B        |L8.20|
                  |L8.452|
0001c4  f80ab004          STRB     r11,[r10,r4]          ;500
                  |L8.456|
0001c8  f8395014          LDRH     r5,[r9,r4,LSL #1]     ;502
0001cc  4545              CMP      r5,r8                 ;502
0001ce  d900              BLS      |L8.466|
0001d0  4645              MOV      r5,r8                 ;502
                  |L8.466|
0001d2  462a              MOV      r2,r5                 ;504
0001d4  4620              MOV      r0,r4                 ;504
0001d6  9904              LDR      r1,[sp,#0x10]         ;504
0001d8  f7fffffe          BL       wiz_recv_data
0001dc  e769              B        |L8.178|
                  |L8.478|
0001de  f8390014          LDRH     r0,[r9,r4,LSL #1]     ;508
0001e2  bb18              CBNZ     r0,|L8.556|
0001e4  2206              MOVS     r2,#6                 ;510
0001e6  a901              ADD      r1,sp,#4              ;510
0001e8  4620              MOV      r0,r4                 ;510
0001ea  f7fffffe          BL       wiz_recv_data
0001ee  4630              MOV      r0,r6                 ;511
0001f0  2140              MOVS     r1,#0x40              ;511
0001f2  f7fffffe          BL       WIZCHIP_WRITE
                  |L8.502|
0001f6  4630              MOV      r0,r6                 ;512
0001f8  f7fffffe          BL       WIZCHIP_READ
0001fc  2800              CMP      r0,#0                 ;512
0001fe  d1fa              BNE      |L8.502|
000200  f89d0004          LDRB     r0,[sp,#4]            ;513
000204  7038              STRB     r0,[r7,#0]            ;513
000206  f89d0005          LDRB     r0,[sp,#5]            ;514
00020a  7078              STRB     r0,[r7,#1]            ;514
00020c  f89d0006          LDRB     r0,[sp,#6]            ;515
000210  70b8              STRB     r0,[r7,#2]            ;515
000212  f89d0007          LDRB     r0,[sp,#7]            ;516
000216  70f8              STRB     r0,[r7,#3]            ;516
000218  f89d0008          LDRB     r0,[sp,#8]            ;517
00021c  f89d1009          LDRB     r1,[sp,#9]            ;519
000220  eb012000          ADD      r0,r1,r0,LSL #8       ;519
000224  f8290014          STRH     r0,[r9,r4,LSL #1]     ;519
000228  f80ab004          STRB     r11,[r10,r4]          ;520
                  |L8.556|
00022c  f8395014          LDRH     r5,[r9,r4,LSL #1]     ;525
000230  4545              CMP      r5,r8                 ;525
000232  d900              BLS      |L8.566|
000234  4645              MOV      r5,r8                 ;525
                  |L8.566|
000236  462a              MOV      r2,r5                 ;527
000238  4620              MOV      r0,r4                 ;527
00023a  9904              LDR      r1,[sp,#0x10]         ;527
00023c  f7fffffe          BL       wiz_recv_data
000240  e737              B        |L8.178|
                  |L8.578|
000242  2000              MOVS     r0,#0                 ;544
000244  f80a0004          STRB     r0,[r10,r4]           ;544
                  |L8.584|
000248  4628              MOV      r0,r5                 ;546
00024a  e6e3              B        |L8.20|
;;;548    
                          ENDP

                  |L8.588|
                          DCD      ||.data||+0xa

                          AREA ||i.send||, CODE, READONLY, ALIGN=2

                  send PROC
;;;248    
;;;249    int32_t send(uint8_t sn, uint8_t * buf, uint16_t len)
000000  e92d4ff7          PUSH     {r0-r2,r4-r11,lr}
;;;250    {
000004  4605              MOV      r5,r0
000006  4614              MOV      r4,r2
;;;251       uint8_t tmp=0;
;;;252       uint16_t freesize=0;
;;;253       
;;;254       CHECK_SOCKNUM();
000008  2d04              CMP      r5,#4
00000a  d903              BLS      |L9.20|
00000c  f04f30ff          MOV      r0,#0xffffffff
                  |L9.16|
;;;255       CHECK_SOCKMODE(Sn_MR_TCP);
;;;256       CHECK_SOCKDATA();
;;;257       tmp = getSn_SR(sn);
;;;258       if(tmp != SOCK_ESTABLISHED && tmp != SOCK_CLOSE_WAIT)
;;;259         return SOCKERR_SOCKSTATUS;
;;;260       if( sock_is_sending & (1<<sn) )
;;;261       {
;;;262          tmp = getSn_IR(sn);
;;;263          if(tmp & Sn_IR_SENDOK)
;;;264          {
;;;265             setSn_IR(sn, Sn_IR_SENDOK);   // SENDOK--发送完成  清除标志
;;;266                   
;;;267             sock_is_sending &= ~(1<<sn);   // 清除标志       
;;;268          }
;;;269          else if(tmp & Sn_IR_TIMEOUT)      // 超时
;;;270          {
;;;271             close(sn);
;;;272             return SOCKERR_TIMEOUT;
;;;273          }
;;;274          else return SOCK_BUSY;    // 忙
;;;275       }
;;;276       freesize = getSn_TxMAX(sn);  // 获取 发送缓存大小
;;;277       if (len > freesize) len = freesize; // check size not to exceed MAX size.
;;;278       while(1)
;;;279       {
;;;280          freesize = getSn_TX_FSR(sn);   // 获取发送缓存空闲大小
;;;281          tmp = getSn_SR(sn);
;;;282          if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT))
;;;283          {
;;;284             close(sn);
;;;285             return SOCKERR_SOCKSTATUS;
;;;286          }
;;;287          if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
;;;288          if(len <= freesize) break;
;;;289       }
;;;290       wiz_send_data(sn, buf, len);
;;;291       
;;;292       setSn_CR(sn,Sn_CR_SEND);
;;;293       /* wait to process the command... */
;;;294       while(getSn_CR(sn));
;;;295    
;;;296       sock_is_sending |= (1 << sn);
;;;297       //M20150409 : Explicit Type Casting
;;;298       return (int32_t)len;
;;;299    }
000010  e8bd8ffe          POP      {r1-r11,pc}
                  |L9.20|
000014  f44f6080          MOV      r0,#0x400             ;255
000018  eb002005          ADD      r0,r0,r5,LSL #8       ;255
00001c  f7fffffe          BL       WIZCHIP_READ
000020  f000000f          AND      r0,r0,#0xf            ;255
000024  2801              CMP      r0,#1                 ;255
000026  d002              BEQ      |L9.46|
000028  f06f0004          MVN      r0,#4                 ;255
00002c  e7f0              B        |L9.16|
                  |L9.46|
00002e  b174              CBZ      r4,|L9.78|
000030  f2404003          MOV      r0,#0x403             ;257
000034  eb002a05          ADD      r10,r0,r5,LSL #8      ;257
000038  4650              MOV      r0,r10                ;257
00003a  f7fffffe          BL       WIZCHIP_READ
00003e  f06f0906          MVN      r9,#6                 ;259
000042  2817              CMP      r0,#0x17              ;258
000044  d006              BEQ      |L9.84|
000046  281c              CMP      r0,#0x1c              ;258
000048  d004              BEQ      |L9.84|
00004a  4648              MOV      r0,r9                 ;259
00004c  e7e0              B        |L9.16|
                  |L9.78|
00004e  f06f000d          MVN      r0,#0xd               ;256
000052  e7dd              B        |L9.16|
                  |L9.84|
000054  f8df80d8          LDR      r8,|L9.304|
000058  f04f0b01          MOV      r11,#1                ;260
00005c  fa0bf605          LSL      r6,r11,r5             ;260
000060  f8b80004          LDRH     r0,[r8,#4]            ;260  ; sock_is_sending
000064  4206              TST      r6,r0                 ;260
000066  d011              BEQ      |L9.140|
000068  f2404002          MOV      r0,#0x402             ;262
00006c  eb002705          ADD      r7,r0,r5,LSL #8       ;262
000070  4638              MOV      r0,r7                 ;262
000072  f7fffffe          BL       WIZCHIP_READ
000076  06c1              LSLS     r1,r0,#27             ;263
000078  d51b              BPL      |L9.178|
00007a  4638              MOV      r0,r7                 ;265
00007c  2110              MOVS     r1,#0x10              ;265
00007e  f7fffffe          BL       WIZCHIP_WRITE
000082  f8b80004          LDRH     r0,[r8,#4]            ;267  ; sock_is_sending
000086  43b0              BICS     r0,r0,r6              ;267
000088  f8a80004          STRH     r0,[r8,#4]            ;267
                  |L9.140|
00008c  201b              MOVS     r0,#0x1b              ;276
00008e  f7fffffe          BL       WIZCHIP_READ
000092  4601              MOV      r1,r0                 ;276
000094  0068              LSLS     r0,r5,#1              ;276
000096  2203              MOVS     r2,#3                 ;276
000098  4082              LSLS     r2,r2,r0              ;276
00009a  4011              ANDS     r1,r1,r2              ;276
00009c  40c1              LSRS     r1,r1,r0              ;276
00009e  fa0bfb01          LSL      r11,r11,r1            ;276
0000a2  f64f70ff          MOV      r0,#0xffff            ;276
0000a6  ea00208b          AND      r0,r0,r11,LSL #10     ;276
0000aa  4284              CMP      r4,r0                 ;277
0000ac  d935              BLS      |L9.282|
0000ae  4604              MOV      r4,r0                 ;277
0000b0  e033              B        |L9.282|
                  |L9.178|
0000b2  0700              LSLS     r0,r0,#28             ;269
0000b4  d505              BPL      |L9.194|
0000b6  4628              MOV      r0,r5                 ;271
0000b8  f7fffffe          BL       close
0000bc  f06f000c          MVN      r0,#0xc               ;272
0000c0  e7a6              B        |L9.16|
                  |L9.194|
0000c2  2000              MOVS     r0,#0                 ;274
0000c4  e7a4              B        |L9.16|
                  |L9.198|
0000c6  281c              CMP      r0,#0x1c              ;282
0000c8  d004              BEQ      |L9.212|
0000ca  4628              MOV      r0,r5                 ;284
0000cc  f7fffffe          BL       close
0000d0  4648              MOV      r0,r9                 ;285
0000d2  e79d              B        |L9.16|
                  |L9.212|
0000d4  f8b80002          LDRH     r0,[r8,#2]            ;287  ; sock_io_mode
0000d8  4206              TST      r6,r0                 ;287
0000da  d003              BEQ      |L9.228|
0000dc  42bc              CMP      r4,r7                 ;287
0000de  d901              BLS      |L9.228|
0000e0  2000              MOVS     r0,#0                 ;287
0000e2  e795              B        |L9.16|
                  |L9.228|
0000e4  42bc              CMP      r4,r7                 ;288
0000e6  d818              BHI      |L9.282|
0000e8  4622              MOV      r2,r4                 ;290
0000ea  4628              MOV      r0,r5                 ;290
0000ec  9901              LDR      r1,[sp,#4]            ;290
0000ee  f7fffffe          BL       wiz_send_data
0000f2  f2404001          MOV      r0,#0x401             ;292
0000f6  eb002505          ADD      r5,r0,r5,LSL #8       ;292
0000fa  2120              MOVS     r1,#0x20              ;292
0000fc  4628              MOV      r0,r5                 ;292
0000fe  f7fffffe          BL       WIZCHIP_WRITE
                  |L9.258|
000102  4628              MOV      r0,r5                 ;294
000104  f7fffffe          BL       WIZCHIP_READ
000108  2800              CMP      r0,#0                 ;294
00010a  d1fa              BNE      |L9.258|
00010c  f8b80004          LDRH     r0,[r8,#4]            ;296  ; sock_is_sending
000110  4306              ORRS     r6,r6,r0              ;296
000112  f8a86004          STRH     r6,[r8,#4]            ;296
000116  4620              MOV      r0,r4                 ;298
000118  e77a              B        |L9.16|
                  |L9.282|
00011a  4628              MOV      r0,r5                 ;280
00011c  f7fffffe          BL       getSn_TX_FSR
000120  4607              MOV      r7,r0                 ;280
000122  4650              MOV      r0,r10                ;281
000124  f7fffffe          BL       WIZCHIP_READ
000128  2817              CMP      r0,#0x17              ;282
00012a  d0d3              BEQ      |L9.212|
00012c  e7cb              B        |L9.198|
;;;300    
                          ENDP

00012e  0000              DCW      0x0000
                  |L9.304|
                          DCD      ||.data||

                          AREA ||i.sendto||, CODE, READONLY, ALIGN=2

                  sendto PROC
;;;345    }
;;;346    int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
000000  e92d4ff8          PUSH     {r3-r11,lr}
;;;347    {
000004  4604              MOV      r4,r0
000006  9f0a              LDR      r7,[sp,#0x28]
000008  4688              MOV      r8,r1
00000a  4615              MOV      r5,r2
00000c  461e              MOV      r6,r3
;;;348       uint8_t tmp = 0;
;;;349       uint16_t freesize = 0;
;;;350       uint32_t taddr;
;;;351    
;;;352       CHECK_SOCKNUM();
00000e  2c04              CMP      r4,#4
000010  d903              BLS      |L10.26|
000012  f04f30ff          MOV      r0,#0xffffffff
                  |L10.22|
;;;353       switch(getSn_MR(sn) & 0x0F)
;;;354       {
;;;355          case Sn_MR_UDP:
;;;356          case Sn_MR_MACRAW:
;;;357        case Sn_MR_IPRAW:
;;;358             break;
;;;359          default:
;;;360             return SOCKERR_SOCKMODE;
;;;361       }
;;;362       CHECK_SOCKDATA();
;;;363       //M20140501 : For avoiding fatal error on memory align mismatched
;;;364       taddr = ((uint32_t)addr[0]) & 0x000000FF;
;;;365       taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
;;;366       taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
;;;367       taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
;;;368    
;;;369       if(taddr == 0)         return SOCKERR_IPINVALID;
;;;370       if(port == 0)          return SOCKERR_PORTZERO;
;;;371       tmp = getSn_SR(sn);
;;;372       if(tmp != SOCK_MACRAW && tmp != SOCK_UDP && tmp != SOCK_IPRAW) return SOCKERR_SOCKSTATUS;
;;;373          
;;;374       setSn_DIPR(sn,addr);
;;;375       setSn_DPORT(sn,port);      
;;;376       freesize = getSn_TxMAX(sn);
;;;377       if (len > freesize) len = freesize; // check size not to exceed MAX size.
;;;378       while(1)
;;;379       {
;;;380          freesize = getSn_TX_FSR(sn);
;;;381          if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
;;;382          if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
;;;383          if(len <= freesize) break;
;;;384       };
;;;385       wiz_send_data(sn, buf, len);
;;;386    
;;;387       getSIPR((uint8_t*)&taddr);
;;;388       if(taddr == 0)
;;;389       {
;;;390          getSUBR((uint8_t*)&taddr);
;;;391          setSUBR((uint8_t*)"\x00\x00\x00\x00");
;;;392       }
;;;393       else taddr = 0;
;;;394       
;;;395      setSn_CR(sn,Sn_CR_SEND);
;;;396      /* wait to process the command... */
;;;397      while(getSn_CR(sn));
;;;398       while(1)
;;;399       {
;;;400          tmp = getSn_IR(sn);
;;;401          if(tmp & Sn_IR_SENDOK)
;;;402          {
;;;403             setSn_IR(sn, Sn_IR_SENDOK);
;;;404             break;
;;;405          }
;;;406          //M:20131104    
;;;407          else if(tmp & Sn_IR_TIMEOUT)
;;;408          {
;;;409             setSn_IR(sn, Sn_IR_TIMEOUT);
;;;410             //M20150409 : Fixed the lost of sign bits by type casting.
;;;411             if(taddr) setSUBR((uint8_t*)&taddr);
;;;412            
;;;413             return SOCKERR_TIMEOUT;
;;;414          }
;;;415     
;;;416       }
;;;417          if(taddr) setSUBR((uint8_t*)&taddr); 
;;;418       //M20150409 : Explicit Type Casting
;;;419       return (int32_t)len;
;;;420    }
000016  e8bd8ff8          POP      {r3-r11,pc}
                  |L10.26|
00001a  f44f6080          MOV      r0,#0x400             ;353
00001e  eb002004          ADD      r0,r0,r4,LSL #8       ;353
000022  f7fffffe          BL       WIZCHIP_READ
000026  f000000f          AND      r0,r0,#0xf            ;353
00002a  2802              CMP      r0,#2                 ;353
00002c  d006              BEQ      |L10.60|
00002e  2803              CMP      r0,#3                 ;353
000030  d004              BEQ      |L10.60|
000032  2804              CMP      r0,#4                 ;353
000034  d002              BEQ      |L10.60|
000036  f06f0004          MVN      r0,#4                 ;360
00003a  e7ec              B        |L10.22|
                  |L10.60|
00003c  b1fd              CBZ      r5,|L10.126|
00003e  7830              LDRB     r0,[r6,#0]            ;364
000040  9000              STR      r0,[sp,#0]            ;364
000042  7871              LDRB     r1,[r6,#1]            ;365
000044  eb012000          ADD      r0,r1,r0,LSL #8       ;365
000048  9000              STR      r0,[sp,#0]            ;365
00004a  78b1              LDRB     r1,[r6,#2]            ;366
00004c  eb012000          ADD      r0,r1,r0,LSL #8       ;366
000050  9000              STR      r0,[sp,#0]            ;366
000052  78f1              LDRB     r1,[r6,#3]            ;367
000054  eb012000          ADD      r0,r1,r0,LSL #8       ;367
000058  9000              STR      r0,[sp,#0]            ;367
00005a  b198              CBZ      r0,|L10.132|
00005c  b1af              CBZ      r7,|L10.138|
00005e  f2404003          MOV      r0,#0x403             ;371
000062  eb002904          ADD      r9,r0,r4,LSL #8       ;371
000066  4648              MOV      r0,r9                 ;371
000068  f7fffffe          BL       WIZCHIP_READ
00006c  2842              CMP      r0,#0x42              ;372
00006e  d00f              BEQ      |L10.144|
000070  2822              CMP      r0,#0x22              ;372
000072  d00d              BEQ      |L10.144|
000074  2832              CMP      r0,#0x32              ;372
000076  d00b              BEQ      |L10.144|
000078  f06f0006          MVN      r0,#6                 ;372
00007c  e7cb              B        |L10.22|
                  |L10.126|
00007e  f06f000d          MVN      r0,#0xd               ;362
000082  e7c8              B        |L10.22|
                  |L10.132|
000084  f06f000b          MVN      r0,#0xb               ;369
000088  e7c5              B        |L10.22|
                  |L10.138|
00008a  f06f000a          MVN      r0,#0xa               ;370
00008e  e7c2              B        |L10.22|
                  |L10.144|
000090  f240400c          MOV      r0,#0x40c             ;374
000094  eb002004          ADD      r0,r0,r4,LSL #8       ;374
000098  2204              MOVS     r2,#4                 ;374
00009a  4631              MOV      r1,r6                 ;374
00009c  f7fffffe          BL       WIZCHIP_WRITE_BUF
0000a0  f44f6082          MOV      r0,#0x410             ;375
0000a4  0a39              LSRS     r1,r7,#8              ;375
0000a6  eb002004          ADD      r0,r0,r4,LSL #8       ;375
0000aa  f7fffffe          BL       WIZCHIP_WRITE
0000ae  f2404011          MOV      r0,#0x411             ;375
0000b2  b2f9              UXTB     r1,r7                 ;375
0000b4  eb002004          ADD      r0,r0,r4,LSL #8       ;375
0000b8  f7fffffe          BL       WIZCHIP_WRITE
0000bc  201b              MOVS     r0,#0x1b              ;376
0000be  f7fffffe          BL       WIZCHIP_READ
0000c2  4601              MOV      r1,r0                 ;376
0000c4  0060              LSLS     r0,r4,#1              ;376
0000c6  2203              MOVS     r2,#3                 ;376
0000c8  4082              LSLS     r2,r2,r0              ;376
0000ca  4011              ANDS     r1,r1,r2              ;376
0000cc  40c1              LSRS     r1,r1,r0              ;376
0000ce  2201              MOVS     r2,#1                 ;376
0000d0  fa02f701          LSL      r7,r2,r1              ;376
0000d4  f64f70ff          MOV      r0,#0xffff            ;376
0000d8  ea002087          AND      r0,r0,r7,LSL #10      ;376
0000dc  4285              CMP      r5,r0                 ;377
0000de  d900              BLS      |L10.226|
0000e0  4605              MOV      r5,r0                 ;377
                  |L10.226|
0000e2  fa02f704          LSL      r7,r2,r4              ;382
0000e6  f8dfa0d0          LDR      r10,|L10.440|
0000ea  e02c              B        |L10.326|
                  |L10.236|
0000ec  f06f0003          MVN      r0,#3                 ;381
0000f0  e791              B        |L10.22|
                  |L10.242|
0000f2  f8ba0002          LDRH     r0,[r10,#2]           ;382  ; sock_io_mode
0000f6  4207              TST      r7,r0                 ;382
0000f8  d003              BEQ      |L10.258|
0000fa  42b5              CMP      r5,r6                 ;382
0000fc  d901              BLS      |L10.258|
0000fe  2000              MOVS     r0,#0                 ;382
000100  e789              B        |L10.22|
                  |L10.258|
000102  42b5              CMP      r5,r6                 ;383
000104  d81f              BHI      |L10.326|
000106  462a              MOV      r2,r5                 ;385
000108  4641              MOV      r1,r8                 ;385
00010a  4620              MOV      r0,r4                 ;385
00010c  f7fffffe          BL       wiz_send_data
000110  2204              MOVS     r2,#4                 ;387
000112  4669              MOV      r1,sp                 ;387
000114  200f              MOVS     r0,#0xf               ;387
000116  f7fffffe          BL       WIZCHIP_READ_BUF
00011a  9800              LDR      r0,[sp,#0]            ;383
00011c  b1e8              CBZ      r0,|L10.346|
00011e  2000              MOVS     r0,#0                 ;393
000120  9000              STR      r0,[sp,#0]            ;393
                  |L10.290|
000122  f2404001          MOV      r0,#0x401             ;395
000126  eb002604          ADD      r6,r0,r4,LSL #8       ;395
00012a  2120              MOVS     r1,#0x20              ;395
00012c  4630              MOV      r0,r6                 ;395
00012e  f7fffffe          BL       WIZCHIP_WRITE
                  |L10.306|
000132  4630              MOV      r0,r6                 ;397
000134  f7fffffe          BL       WIZCHIP_READ
000138  2800              CMP      r0,#0                 ;397
00013a  d1fa              BNE      |L10.306|
00013c  f2404002          MOV      r0,#0x402             ;403
000140  eb002404          ADD      r4,r0,r4,LSL #8       ;403
000144  e031              B        |L10.426|
                  |L10.326|
000146  4620              MOV      r0,r4                 ;380
000148  f7fffffe          BL       getSn_TX_FSR
00014c  4606              MOV      r6,r0                 ;380
00014e  4648              MOV      r0,r9                 ;381
000150  f7fffffe          BL       WIZCHIP_READ
000154  2800              CMP      r0,#0                 ;378
000156  d1cc              BNE      |L10.242|
000158  e7c8              B        |L10.236|
                  |L10.346|
00015a  2204              MOVS     r2,#4                 ;390
00015c  4669              MOV      r1,sp                 ;390
00015e  2005              MOVS     r0,#5                 ;390
000160  f7fffffe          BL       WIZCHIP_READ_BUF
000164  2204              MOVS     r2,#4                 ;391
000166  a115              ADR      r1,|L10.444|
000168  2005              MOVS     r0,#5                 ;391
00016a  f7fffffe          BL       WIZCHIP_WRITE_BUF
00016e  e7d8              B        |L10.290|
                  |L10.368|
000170  4620              MOV      r0,r4                 ;403
000172  2110              MOVS     r1,#0x10              ;403
000174  f7fffffe          BL       WIZCHIP_WRITE
000178  9800              LDR      r0,[sp,#0]            ;417
00017a  b120              CBZ      r0,|L10.390|
00017c  2204              MOVS     r2,#4                 ;417
00017e  4669              MOV      r1,sp                 ;417
000180  2005              MOVS     r0,#5                 ;417
000182  f7fffffe          BL       WIZCHIP_WRITE_BUF
                  |L10.390|
000186  4628              MOV      r0,r5                 ;419
000188  e745              B        |L10.22|
                  |L10.394|
00018a  0700              LSLS     r0,r0,#28             ;407
00018c  d50d              BPL      |L10.426|
00018e  4620              MOV      r0,r4                 ;409
000190  2108              MOVS     r1,#8                 ;409
000192  f7fffffe          BL       WIZCHIP_WRITE
000196  9800              LDR      r0,[sp,#0]            ;411
000198  b120              CBZ      r0,|L10.420|
00019a  2204              MOVS     r2,#4                 ;411
00019c  4669              MOV      r1,sp                 ;411
00019e  2005              MOVS     r0,#5                 ;411
0001a0  f7fffffe          BL       WIZCHIP_WRITE_BUF
                  |L10.420|
0001a4  f06f000c          MVN      r0,#0xc               ;413
0001a8  e735              B        |L10.22|
                  |L10.426|
0001aa  4620              MOV      r0,r4                 ;400
0001ac  f7fffffe          BL       WIZCHIP_READ
0001b0  06c1              LSLS     r1,r0,#27             ;401
0001b2  d5ea              BPL      |L10.394|
0001b4  e7dc              B        |L10.368|
;;;421    
                          ENDP

0001b6  0000              DCW      0x0000
                  |L10.440|
                          DCD      ||.data||
                  |L10.444|
0001bc  00                DCB      0
0001bd  00                DCB      0
0001be  00                DCB      0
0001bf  00                DCB      0
0001c0  00                DCB      0
0001c1  00                DCB      0
0001c2  00                DCB      0
0001c3  00                DCB      0

                          AREA ||i.setsockopt||, CODE, READONLY, ALIGN=1

                  setsockopt PROC
;;;584    
;;;585    int8_t  setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
000000  b570              PUSH     {r4-r6,lr}
;;;586    {
000002  4604              MOV      r4,r0
000004  4615              MOV      r5,r2
;;;587     // M20131220 : Remove warning
;;;588       CHECK_SOCKNUM();
000006  2c04              CMP      r4,#4
000008  d902              BLS      |L11.16|
00000a  f04f30ff          MOV      r0,#0xffffffff
;;;589       switch(sotype)
;;;590       {
;;;591          case SO_TTL:
;;;592             setSn_TTL(sn,*(uint8_t*)arg);
;;;593             break;
;;;594          case SO_TOS:
;;;595             setSn_TOS(sn,*(uint8_t*)arg);
;;;596             break;
;;;597          case SO_MSS:
;;;598             setSn_MSSR(sn,*(uint16_t*)arg);
;;;599             break;
;;;600          case SO_DESTIP:
;;;601             setSn_DIPR(sn, (uint8_t*)arg);
;;;602             break;
;;;603          case SO_DESTPORT:
;;;604             setSn_DPORT(sn, *(uint16_t*)arg);
;;;605             break;  
;;;606          default:
;;;607             return SOCKERR_ARG;
;;;608       }   
;;;609       return SOCK_OK;
;;;610    }
00000e  bd70              POP      {r4-r6,pc}
                  |L11.16|
000010  2906              CMP      r1,#6                 ;589
000012  d23e              BCS      |L11.146|
000014  e8dff001          TBB      [pc,r1]               ;589
000018  3d030b13          DCB      0x3d,0x03,0x0b,0x13
00001c  232c              DCB      0x23,0x2c
00001e  f2404016          MOV      r0,#0x416             ;592
000022  7829              LDRB     r1,[r5,#0]            ;592
000024  eb002004          ADD      r0,r0,r4,LSL #8       ;592
000028  f7fffffe          BL       WIZCHIP_WRITE
00002c  e02f              B        |L11.142|
00002e  f2404015          MOV      r0,#0x415             ;595
000032  7829              LDRB     r1,[r5,#0]            ;595
000034  eb002004          ADD      r0,r0,r4,LSL #8       ;595
000038  f7fffffe          BL       WIZCHIP_WRITE
00003c  e027              B        |L11.142|
00003e  8828              LDRH     r0,[r5,#0]            ;598
000040  0a01              LSRS     r1,r0,#8              ;598
000042  f2404012          MOV      r0,#0x412             ;598
000046  eb002004          ADD      r0,r0,r4,LSL #8       ;598
00004a  f7fffffe          BL       WIZCHIP_WRITE
00004e  f2404013          MOV      r0,#0x413             ;598
000052  7829              LDRB     r1,[r5,#0]            ;598
000054  eb002004          ADD      r0,r0,r4,LSL #8       ;598
000058  f7fffffe          BL       WIZCHIP_WRITE
00005c  e017              B        |L11.142|
00005e  f240400c          MOV      r0,#0x40c             ;601
000062  eb002004          ADD      r0,r0,r4,LSL #8       ;601
000066  2204              MOVS     r2,#4                 ;601
000068  4629              MOV      r1,r5                 ;601
00006a  f7fffffe          BL       WIZCHIP_WRITE_BUF
00006e  e00e              B        |L11.142|
000070  8828              LDRH     r0,[r5,#0]            ;604
000072  0a01              LSRS     r1,r0,#8              ;604
000074  f44f6082          MOV      r0,#0x410             ;604
000078  eb002004          ADD      r0,r0,r4,LSL #8       ;604
00007c  f7fffffe          BL       WIZCHIP_WRITE
000080  f2404011          MOV      r0,#0x411             ;604
000084  7829              LDRB     r1,[r5,#0]            ;604
000086  eb002004          ADD      r0,r0,r4,LSL #8       ;604
00008a  f7fffffe          BL       WIZCHIP_WRITE
                  |L11.142|
00008e  2001              MOVS     r0,#1                 ;609
000090  bd70              POP      {r4-r6,pc}
                  |L11.146|
000092  f06f0009          MVN      r0,#9                 ;607
000096  bd70              POP      {r4-r6,pc}
;;;611    
                          ENDP


                          AREA ||i.socket||, CODE, READONLY, ALIGN=2

                  socket PROC
;;;94     
;;;95     int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
000000  b5f8              PUSH     {r3-r7,lr}
;;;96     {
000002  4604              MOV      r4,r0
000004  460f              MOV      r7,r1
000006  4616              MOV      r6,r2
000008  461d              MOV      r5,r3
;;;97       CHECK_SOCKNUM();
00000a  2c04              CMP      r4,#4
00000c  d902              BLS      |L12.20|
00000e  f04f30ff          MOV      r0,#0xffffffff
                  |L12.18|
;;;98       switch(protocol)
;;;99       {
;;;100          case Sn_MR_TCP :
;;;101             {
;;;102                //M20150601 : Fixed the warning - taddr will never be NULL    
;;;103                uint32_t taddr;
;;;104                getSIPR((uint8_t*)&taddr);
;;;105                if(taddr == 0) return SOCKERR_SOCKINIT;
;;;106             }
;;;107          case Sn_MR_UDP :
;;;108          case Sn_MR_MACRAW :
;;;109             break;
;;;110          case Sn_MR_IPRAW :
;;;111          case Sn_MR_PPPoE :
;;;112             break;
;;;113          default :
;;;114             return SOCKERR_SOCKMODE;
;;;115      }
;;;116      //M20150601 : For SF_TCP_ALIGN & W5300
;;;117      if((flag & 0x04) != 0) return SOCKERR_SOCKFLAG;     
;;;118      if(flag != 0)
;;;119      {
;;;120         switch(protocol)
;;;121         {
;;;122            case Sn_MR_TCP:
;;;123             //M20150601 :  For SF_TCP_ALIGN & W5300        
;;;124                if((flag & (SF_TCP_NODELAY|SF_IO_NONBLOCK))==0) return SOCKERR_SOCKFLAG;    
;;;125               break;
;;;126            case Sn_MR_UDP:
;;;127               if(flag & SF_IGMP_VER2)
;;;128               {
;;;129                  if((flag & SF_MULTI_ENABLE)==0) return SOCKERR_SOCKFLAG;
;;;130               }        
;;;131               break;
;;;132            default:
;;;133               break;
;;;134         }
;;;135       }
;;;136      close(sn);
;;;137      setSn_MR(sn, (protocol | (flag & 0xF0)));     // PROTOCOL--0X01 FLAG--0X20  设置Sn_MR BIT5=1 BIT0=1
;;;138      if(!port)
;;;139      {
;;;140         port = sock_any_port++;
;;;141         if(sock_any_port == 0xFFF0) sock_any_port = SOCK_ANY_PORT_NUM;
;;;142      }
;;;143       setSn_PORT(sn,port);          // 将端口写入寄存器  此处绑定了端口sn与port 2020-2-5
;;;144       setSn_CR(sn,Sn_CR_OPEN);      // 开启 SOCKET
;;;145       while(getSn_CR(sn));
;;;146       //A20150401 : For release the previous sock_io_mode
;;;147       sock_io_mode &= ~(1 <<sn);
;;;148       sock_io_mode |= ((flag & SF_IO_NONBLOCK) << sn);   
;;;149       sock_is_sending &= ~(1<<sn);
;;;150       sock_remained_size[sn] = 0;
;;;151       //M20150601 : repalce 0 with PACK_COMPLETED
;;;152       sock_pack_info[sn] = PACK_COMPLETED;
;;;153       
;;;154       while(getSn_SR(sn) == SOCK_CLOSED);
;;;155       return (int8_t)sn;
;;;156    }     
000012  bdf8              POP      {r3-r7,pc}
                  |L12.20|
000014  2f06              CMP      r7,#6                 ;98
000016  d218              BCS      |L12.74|
000018  e8dff007          TBB      [pc,r7]               ;98
00001c  17030a0a          DCB      0x17,0x03,0x0a,0x0a
000020  0a0a              DCB      0x0a,0x0a
000022  2204              MOVS     r2,#4                 ;104
000024  4669              MOV      r1,sp                 ;104
000026  200f              MOVS     r0,#0xf               ;104
000028  f7fffffe          BL       WIZCHIP_READ_BUF
00002c  9800              LDR      r0,[sp,#0]            ;105
00002e  b148              CBZ      r0,|L12.68|
000030  0769              LSLS     r1,r5,#29             ;117
000032  f06f0005          MVN      r0,#5                 ;117
000036  d4ec              BMI      |L12.18|
000038  b195              CBZ      r5,|L12.96|
00003a  2f01              CMP      r7,#1                 ;120
00003c  d008              BEQ      |L12.80|
00003e  2f02              CMP      r7,#2                 ;120
000040  d10e              BNE      |L12.96|
000042  e009              B        |L12.88|
                  |L12.68|
000044  f06f0002          MVN      r0,#2                 ;105
000048  bdf8              POP      {r3-r7,pc}
                  |L12.74|
00004a  f06f0004          MVN      r0,#4                 ;114
                  |L12.78|
00004e  bdf8              POP      {r3-r7,pc}
                  |L12.80|
000050  f0150f21          TST      r5,#0x21              ;124
000054  d0fb              BEQ      |L12.78|
000056  e003              B        |L12.96|
                  |L12.88|
000058  06a9              LSLS     r1,r5,#26             ;127
00005a  d501              BPL      |L12.96|
00005c  0629              LSLS     r1,r5,#24             ;129
00005e  d5f6              BPL      |L12.78|
                  |L12.96|
000060  4620              MOV      r0,r4                 ;136
000062  f7fffffe          BL       close
000066  f00501f0          AND      r1,r5,#0xf0           ;137
00006a  f44f6080          MOV      r0,#0x400             ;137
00006e  4339              ORRS     r1,r1,r7              ;137
000070  eb002004          ADD      r0,r0,r4,LSL #8       ;137
000074  f7fffffe          BL       WIZCHIP_WRITE
000078  4f22              LDR      r7,|L12.260|
00007a  b956              CBNZ     r6,|L12.146|
00007c  883e              LDRH     r6,[r7,#0]            ;140  ; sock_any_port
00007e  1c70              ADDS     r0,r6,#1              ;140
000080  b280              UXTH     r0,r0                 ;140
000082  8038              STRH     r0,[r7,#0]            ;140
000084  f5a0417f          SUB      r1,r0,#0xff00         ;141
000088  39f0              SUBS     r1,r1,#0xf0           ;141
00008a  d102              BNE      |L12.146|
00008c  f44f4040          MOV      r0,#0xc000            ;141
000090  8038              STRH     r0,[r7,#0]            ;141
                  |L12.146|
000092  f2404004          MOV      r0,#0x404             ;143
000096  0a31              LSRS     r1,r6,#8              ;143
000098  eb002004          ADD      r0,r0,r4,LSL #8       ;143
00009c  f7fffffe          BL       WIZCHIP_WRITE
0000a0  f2404005          MOV      r0,#0x405             ;143
0000a4  b2f1              UXTB     r1,r6                 ;143
0000a6  eb002004          ADD      r0,r0,r4,LSL #8       ;143
0000aa  f7fffffe          BL       WIZCHIP_WRITE
0000ae  f2404001          MOV      r0,#0x401             ;144
0000b2  eb002604          ADD      r6,r0,r4,LSL #8       ;144
0000b6  2101              MOVS     r1,#1                 ;144
0000b8  4630              MOV      r0,r6                 ;144
0000ba  f7fffffe          BL       WIZCHIP_WRITE
                  |L12.190|
0000be  4630              MOV      r0,r6                 ;145
0000c0  f7fffffe          BL       WIZCHIP_READ
0000c4  2800              CMP      r0,#0                 ;145
0000c6  d1fa              BNE      |L12.190|
0000c8  2001              MOVS     r0,#1                 ;147
0000ca  8879              LDRH     r1,[r7,#2]            ;147  ; sock_io_mode
0000cc  40a0              LSLS     r0,r0,r4              ;147
0000ce  4381              BICS     r1,r1,r0              ;147
0000d0  f0050201          AND      r2,r5,#1              ;148
0000d4  40a2              LSLS     r2,r2,r4              ;148
0000d6  430a              ORRS     r2,r2,r1              ;148
0000d8  807a              STRH     r2,[r7,#2]            ;148
0000da  88b9              LDRH     r1,[r7,#4]            ;149  ; sock_is_sending
0000dc  4381              BICS     r1,r1,r0              ;149
0000de  80b9              STRH     r1,[r7,#4]            ;149
0000e0  4908              LDR      r1,|L12.260|
0000e2  2000              MOVS     r0,#0                 ;150
0000e4  310a              ADDS     r1,r1,#0xa            ;150
0000e6  f8210014          STRH     r0,[r1,r4,LSL #1]     ;150
0000ea  1f09              SUBS     r1,r1,#4              ;152
0000ec  5508              STRB     r0,[r1,r4]            ;152
0000ee  f2404003          MOV      r0,#0x403             ;154
0000f2  eb002504          ADD      r5,r0,r4,LSL #8       ;154
                  |L12.246|
0000f6  4628              MOV      r0,r5                 ;154
0000f8  f7fffffe          BL       WIZCHIP_READ
0000fc  2800              CMP      r0,#0                 ;154
0000fe  d0fa              BEQ      |L12.246|
000100  b260              SXTB     r0,r4                 ;155
000102  bdf8              POP      {r3-r7,pc}
;;;157    
                          ENDP

                  |L12.260|
                          DCD      ||.data||

                          AREA ||.data||, DATA, ALIGN=1

                  sock_any_port
000000  c000              DCW      0xc000
                  sock_io_mode
000002  0000              DCW      0x0000
                  sock_is_sending
000004  0000              DCW      0x0000
                  sock_pack_info
000006  0000              DCB      0x00,0x00
000008  0000              DCB      0x00,0x00
                  sock_remained_size
00000a  0000              DCW      0x0000
00000c  0000              DCW      0x0000
00000e  0000              DCB      0x00,0x00
000010  0000              DCB      0x00,0x00