⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.lst

📁 W3100是WIZnet公司专门为以太网互联和嵌入式设备推出的硬件TCP/IP协议栈芯片
💻 LST
📖 第 1 页 / 共 5 页
字号:
 438          #ifdef __IP_RAW__
              /*
              ********************************************************************************
              *               Upper layer protocol setup function in IP RAW Mode
              *
              * Description : Upper layer protocol setup function in protocol field of IP header when
              *                    developing upper layer protocol like ICMP, IGMP, EGP etc. by using IP Protocol
              * Arguments   : s          - Channel number
              *               ipprotocol - Upper layer protocol setting value of IP Protocol
              *                            (Possible to use designated IPPROTO_ in header file)
              * Returns     : None
              * Note        : API Function
              *                  This function should be called before calling socket() that is, before socket initializ
             -ation.
              ********************************************************************************
              */
              void setIPprotocol(SOCKET s, u_char ipprotocol)
              {
                      IP_PROTOCOL(s) = ipprotocol;
              }
              #endif
 458          
 459          
 460          #ifdef  __OPT__
              
              /*
              ********************************************************************************
              *               TCP timeout setup function
              *
              * Description : TCP retransmission time setup function.
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 9   

              *     Timeout Interrupt occurs if the number of retransmission exceed the limit when establishing connecti
             -on and data transmission. 
              * Arguments   : val - Pointer having the value to setup timeout
              *     Upper 2byte is for initial timeout, lower 1byte is for the number of retransmission by timeout
              * Returns     : None
              * Note        : API Function
              ********************************************************************************
              */
              void settimeout(u_char * val)
              {
                      u_char i;
              
                      for (i = 0; i < 3; i++) {
                              *(TIMEOUT_PTR + i) = val[i];
                      }
              }
              
              /*
              ********************************************************************************
              *               interrupt mask setup function
              *
              * Description : Interrupt mask setup function. Enable/Disable appropriate Interrupt.
              * Arguments   : mask - mask value to setup ('1' : interrupt enable)
              * Returns     : None
              * Note        : API Function
              ********************************************************************************
              */
              void setINTMask(u_char mask)
              {
                      INTMASK = mask;
              }
              
              /*
              ********************************************************************************
              *               TOS value setup function for TOS field of IP header
              *
              * Description : TOS value setup function for TOS field of IP header
              * Arguments   : s   - channel number
              *    tos - Valuse to setup for TOS field of IP Header
              * Returns     : None
              * Note        : API Function
              ********************************************************************************
              */
              void setTOS(SOCKET s, u_char tos)
              {
                      TOS(s) = tos;
              }
              #endif
 514          
 515          /*
 516          ********************************************************************************
 517          *               Initialization function to appropriate channel
 518          *
 519          * Description : Initialize designated channel and wait until W3100 has done.
 520          * Arguments   : s - channel number
 521          *               protocol - designate protocol for channel
 522          *                          SOCK_STREAM(0x01) -> TCP.
 523          *                          SOCK_DGRAM(0x02)  -> UDP.
 524          *                          SOCK_IPL_RAW(0x03) -> IP LAYER RAW.
 525          *                          SOCK_MACL_RAW(0x04) -> MAC LAYER RAW.
 526          *               port     - designate source port for appropriate channel
 527          *               flag     - designate option to be used in appropriate.
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 10  

 528          *                          SOCKOPT_BROADCAST(0x80) -> Send/receive broadcast message in UDP
 529          *                          SOCKOPT_NDTIMEOUT(0x40) -> Use register value which designated TIMEOUT value
 530          *                          SOCKOPT_NDACK(0x20)     -> When not using no delayed ack
 531          *                          SOCKOPT_SWS(0x10)       -> When not using silly window syndrome
 532          * Returns     : When succeeded : Channel number, failed :1
 533          * Note        : API Function
 534          ********************************************************************************
 535          */
 536          char socket(SOCKET s, u_char protocol, u_int port, u_char flag)
 537          {
 538   1              u_char k;
 539   1      
 540   1              OPT_PROTOCOL(s) = protocol | flag;                // Designate socket protocol and option
 541   1      
 542   1              if (port != 0)                                    // setup designated port number
 543   1               {
 544   2                      k = (u_char)((port & 0xff00) >> 8);
 545   2                      *(SRC_PORT_PTR(s)) = k;
 546   2                      k = (u_char)(port & 0x00ff);
 547   2                      *(SRC_PORT_PTR(s) + 1) = k;
 548   2              } 
 549   1              else                                              // Designate random port number which is managed by loc
             -al when you didn't designate source port
 550   1              {
 551   2                      Local_Port++;                                   
 552   2                      *SRC_PORT_PTR(s) = (u_char)((Local_Port & 0xff00) >> 8);
 553   2                      *(SRC_PORT_PTR(s) + 1) = (u_char)(Local_Port & 0x00ff);
 554   2              }
 555   1      
 556   1              I_STATUS[s] = 0;
 557   1              COMMAND(s) = CSOCK_INIT;                          // SOCK_INIT
 558   1              while (I_STATUS[s] == 0);                         // Waiting Interrupt to CSOCK_INIT
 559   1      
 560   1              if (!(I_STATUS[s] & SSOCK_INIT_OK)) return (-1);  // Error
 561   1              
 562   1              initseqnum(s);                                    // Use initial seq# with random number
 563   1      
 564   1              return  (s);
 565   1      }
 566          
 567          #ifdef  __TCP_CLIENT__
              /*
              ********************************************************************************
              *               Connection establishing function to designated peer.
              *
              * Description : This function establish a connection to the peer by designated channel,
              *     and wait until the connection is established successfully. (TCP client mode)
              * Arguments   : s    - channel number
              *               addr - destination IP Address
              *               port - destination Port Number
              * Returns     : when succeeded : 1, failed : -1
              * Note        : API Function
              ********************************************************************************
              */
              char connect(SOCKET s, u_char * addr, u_int port)
              {
                      if (port != 0) 
                      {                                                           // designate destination port
                              *DST_PORT_PTR(s) = (u_char)((port & 0xff00) >> 8);
                              *(DST_PORT_PTR(s) + 1) = (u_char)(port & 0x00ff);
                      }
                      else    return (-1);
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 11  

              
                      *DST_IP_PTR(s) = addr[0];                                   // designate destination IP address
                      *(DST_IP_PTR(s) + 1) = addr[1];
                      *(DST_IP_PTR(s) + 2) = addr[2];        
                      *(DST_IP_PTR(s) + 3) = addr[3];
              
                      I_STATUS[s] = 0;
              
                      COMMAND(s) = CCONNECT;                                      // CONNECT
              
                      
                      while (I_STATUS[s] == 0)                                    // Wait until connection is established succe
             -ssfully
                              if (select(s, SEL_CONTROL) == SOCK_CLOSED) return -1;   // When failed, appropriate channel will be clos
             -ed and return an error
              
                      if (!(I_STATUS[s] & SESTABLISHED)) return (-1);             // Error
              
                  return      (1);
              }
              #endif
 608          
 609          #ifdef  __TCP_SERVER__
 610          /*
 611          ********************************************************************************
 612          *               Waits for connection request from a peer (Blocking Mode)
 613          *
 614          * Description : Wait for connection request from a peer through designated channel (TCP Server mode)
 615          * Arguments   : s    - channel number
 616          *               addr - IP Address of the peer when a connection is established
 617          *               port - Port number of the peer when a connection is established 
 618          * Returns     : When succeeded : 1, failed : -1
 619          * Note        : API Function
 620          ********************************************************************************
 621          */
 622          /*
 623          char listen(SOCKET s, u_char * addr, u_int * port)
 624          {
 625                  u_int i;
 626          
 627                  I_STATUS[s] = 0;
 628          
 629                  COMMAND(s) = CLISTEN;                                       // LISTEN
 630          
 631                  while (I_STATUS[s] == 0)                                    // Wait until connection is established
 632                      if (select(s, SEL_CONTROL) == SOCK_CLOSED) return -1;   // When failed to connect, the designated cha
             -nnel will be closed and return an error.
 633          
 634                  if (I_STATUS[s] & SESTABLISHED)                             // Receive IP address and port number of the 
             -peer connected
 635                  { 
 636                          i = *DST_PORT_PTR(s);
 637                          *port = (u_int)((i & 0xff00) >> 8);
 638                          i = *(DST_PORT_PTR(s) + 1);
 639                          i = (u_int)(i & 0x00ff);
 640                          *port += (i << 8);
 641          
 642                          addr[0] = *DST_IP_PTR(s);
 643                          addr[1] = *(DST_IP_PTR(s) + 1);
 644                          addr[2] = *(DST_IP_PTR(s) + 2);
 645                          addr[3] = *(DST_IP_PTR(s) + 3);
 646                  } 
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 12  

 647                  else    return (-1);                                        // Error
 648          
 649                  return (1);
 650          }
 651          */
 652          
 653          /*
 654          ********************************************************************************
 655          *              Waits for connection request from a peer (Non-blocking Mode)
 656          *
 657          * Description : Wait for connection request from a peer through designated channel (TCP Server mode)
 658          * Arguments   : s - channel number
 659          * Returns     : None
 660          * Note        : API Function
 661          ********************************************************************************
 662          */
 663          void NBlisten(SOCKET s)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -