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

📄 socket.lst

📁 W3100是WIZnet公司专门为以太网互联和嵌入式设备推出的硬件TCP/IP协议栈芯片
💻 LST
📖 第 1 页 / 共 5 页
字号:
 218          ********************************************************************************
 219          *               W3100A initialization function
 220          *
 221          * Description :
 222          *   Function for S/W resetting of the W3100A.
 223          *   Sets the initial SEQ# to be used for TCP communication.
 224          * Arguments   : None
 225          * Returns     : None
 226          * Note        : API Function
 227          ********************************************************************************
 228          */
 229          void initW3100A(void)
 230          {
 231   1      #ifdef DEBUG
              //      printf("initW3100A()\r\n");
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 5   

                  PutStringLn("initW3100A()");
              #endif 
 235   1          Local_Port = 1000;          // This default value will be set if you didn't designate it when you crea
             -te a socket
 236   1                                      // If you don't designate port number and create a socket continuously,
 237   1                                      // the port number will be assigned with incremented by one to Local_Port
 238   1          SEQ_NUM.lVal = 0x12233445;  // Sets the initial SEQ# to be used for TCP communication. (It should be r
             -amdom value)
 239   1          COMMAND(0) = CSW_RESET;     // Software RESET
 240   1      }
 241          
 242          /*
 243          ********************************************************************************
 244          *               W3100A initialization function
 245          *
 246          * Description : 
 247          *   Sets the Tx, Rx memory size by each channel, source MAC, source IP, gateway, and subnet mask
 248          *   to be used by the W3100A to the designated values.
 249          *   May be called when reflecting modified network information or Tx, Rx memory size on the W3100A
 250          *   Include Ping Request for ARP update (In case that a device embedding W3100A is directly connected to R
             -outer)
 251          * Arguments   : sbufsize - Tx memory size (00 - 1KByte, 01- 2KBtye, 10 - 4KByte, 11 - 8KByte)
 252          *                          bit 1-0 : Tx memory size of channel #0 
 253          *                          bit 3-2 : Tx memory size of channel #1 
 254          *                          bit 5-4 : Tx memory size of channel #2
 255          *                          bit 7-6 : Tx memory size of channel #3 
 256          *               rbufsize - Rx memory size (00 - 1KByte, 01- 2KBtye, 10 - 4KByte, 11 - 8KByte)
 257          *                          bit 1-0 : Rx memory size of channel #0 
 258          *                          bit 3-2 : Rx memory size of channel #1 
 259          *                          bit 5-4 : Rx memory size of channel #2
 260          *                          bit 7-6 : Rx memory size of channel #3 
 261          * Returns     : None
 262          * Note        : API Function
 263          *               Maximum memory size for Tx, Rx in W3100A is 8KBytes,
 264          *               In the range of 8KBytes, the memory size could be allocated dynamically by each channel 
 265          *               Be attentive to sum of memory size shouldn't exceed 8Kbytes
 266          *               and to data transmission and receiption from non-allocated channel may cause some problems
             -.
 267          *               If 8KBytes memory already is assigned to centain channel, other 3 channels couldn't be use
             -d, for there's no available memory.
 268          *               If two 4KBytes memory are assigned to two each channels, other 2 channels couldn't be used
             -, for there's no available memory.
 269          *               (Example of memory assignment)
 270          *                sbufsize => 00000011, rbufsize => 00000011 : Assign 8KBytes for Tx and Rx to channel #0, 
             -Cannot use channel #1,#2,#3
 271          *                sbufsize => 00001010, rbufsize => 00001010 : Assign 4KBytes for Tx and Rx to each channel
             - #0,#1 respectively. Cannot use channel #2,#3
 272          *                sbufsize => 01010101, rbufsize => 01010101 : Assign 2KBytes for Tx and Rx to each all cha
             -nnels respectively.
 273          *                sbufsize => 00010110, rbufsize => 01010101 : Assign 4KBytes for Tx, 2KBytes for Rx to cha
             -nnel #0
 274          *                                                             2KBytes for Tx, 2KBytes for Rx to channel #1
 275          *                                                             2KBytes for Tx, 2KBytes for Rx to channel #2
 276          *                                                             2KBytes is available exclusively for Rx in c
             -hannel #3. There's no memory for Tx.
 277          ********************************************************************************
 278          */
 279          void sysinit(u_char sbufsize, u_char rbufsize)
 280          {
 281   1              char i;
 282   1              int ssum,rsum;
 283   1      
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 6   

 284   1              ssum = 0;
 285   1              rsum = 0;
 286   1              
 287   1              TX_DMEM_SIZE = sbufsize;                 // Set Tx memory size for each channel
 288   1              RX_DMEM_SIZE = rbufsize;                 // Set Rx memory size for each channel
 289   1              
 290   1              SBUFBASEADDRESS[0] = SEND_DATA_BUF;      // Set Base Address of Tx memory for channel #0
 291   1              RBUFBASEADDRESS[0] = RECV_DATA_BUF;      // Set Base Address of Rx memory for channel #0
 292   1      
 293   1      #ifdef DEBUG
                              PutStringLn("Channel : SEND MEM SIZE : RECV MEM SIZE");
              #endif
 296   1      
 297   1              for(i = 0 ; i < MAX_SOCK_NUM; i++)               // Set maximum memory size for Tx and Rx, mask, base add
             -ress of memory by each channel
 298   1              {
 299   2                      SSIZE[i] = 0;
 300   2                      RSIZE[i] = 0;
 301   2                      if(ssum < 8192)
 302   2                      {
 303   3                              switch((sbufsize >> i*2) & 0x03) // Set maximum Tx memory size
 304   3                              {
 305   4                              case 0:
 306   4                                      SSIZE[i] = 1024;
 307   4                                      SMASK[i] = 0x000003FF;
 308   4                                      break;
 309   4                              case 1:
 310   4                                      SSIZE[i] = 2048;
 311   4                                      SMASK[i] = 0x000007FF;
 312   4                                      break;
 313   4                              case 2:
 314   4                                      SSIZE[i] = 4096;
 315   4                                      SMASK[i] = 0x00000FFF;
 316   4                                      break;
 317   4                              case 3:
 318   4                                      SSIZE[i] = 8192;
 319   4                                      SMASK[i] = 0x00001FFF;
 320   4                                      break;
 321   4                              }
 322   3                      }
 323   2                      if( rsum < 8192)
 324   2                      {
 325   3                              switch((rbufsize>> i*2) & 0x03)  // Set maximum Rx memory size
 326   3                              {
 327   4                              case 0:
 328   4                                      RSIZE[i] = 1024;
 329   4                                      RMASK[i] = 0x000003FF;
 330   4                                      break;
 331   4                              case 1:
 332   4                                      RSIZE[i] = 2048;
 333   4                                      RMASK[i] = 0x000007FF;
 334   4                                      break;
 335   4                              case 2:
 336   4                                      RSIZE[i] = 4096;
 337   4                                      RMASK[i] = 0x00000FFF;
 338   4                                      break;
 339   4                              case 3:
 340   4                                      RSIZE[i] = 8192;
 341   4                                      RMASK[i] = 0x00001FFF;
 342   4                                      break;
 343   4                              }
 344   3                      }
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 7   

 345   2                      ssum += SSIZE[i];
 346   2                      rsum += RSIZE[i];
 347   2      
 348   2                      if(i != 0)                               // Set base address of Tx and Rx memory for channel #1,#2,#3
 349   2                      {
 350   3                              SBUFBASEADDRESS[i] = SBUFBASEADDRESS[i-1] + SSIZE[i-1];
 351   3                              RBUFBASEADDRESS[i] = RBUFBASEADDRESS[i-1] + RSIZE[i-1];
 352   3                      }
 353   2      #ifdef DEBUG
                              PutHTOA(i); PutString("      :    0x");PutITOA(SSIZE[i]); PutString("     :    0x");PutITOA(RSIZE[i]);Pu
             -tStringLn("");
              #endif
 356   2              }
 357   1              I_STATUS[0] = 0;
 358   1              COMMAND(0) = CSYS_INIT;
 359   1              while(!(I_STATUS[0] & SSYS_INIT_OK));
 360   1      }
 361          
 362          /*
 363          ********************************************************************************
 364          *               Subnet mask setup function
 365          *
 366          * Description : Subnet mask setup function
 367          * Arguments   : addr - pointer having the value for setting up the Subnet Mask
 368          * Returns     : None
 369          * Note        : API Function
 370          ********************************************************************************
 371          */
 372          void setsubmask(u_char * addr)
 373          {
 374   1              u_char i;
 375   1      
 376   1              for (i = 0; i < 4; i++) {
 377   2                      *(SUBNET_MASK_PTR + i) = addr[i];
 378   2              }
 379   1      }
 380          
 381          /*
 382          ********************************************************************************
 383          *               gateway IP setup function
 384          *
 385          * Description : gateway IP setup function
 386          * Arguments   : addr - pointer having the value for setting up the gateway IP
 387          * Returns     : None
 388          * Note        : API Function
 389          ********************************************************************************
 390          */
 391          void setgateway(u_char * addr)
 392          {
 393   1              u_char i;
 394   1      
 395   1              for (i = 0; i < 4; i++) {
 396   2                      *(GATEWAY_PTR + i) = addr[i];
 397   2              }
 398   1      }
 399          
 400          /*
 401          ********************************************************************************
 402          *               W3100A IP Address setup function
 403          *
 404          * Description : W3100A IP Address setup function
 405          * Arguments   : addr - pointer having the value for setting up the source IP Address
C51 COMPILER V8.02   SOCKET                                                                10/17/2006 16:52:42 PAGE 8   

 406          * Returns     : None
 407          * Note        : API Function
 408          ********************************************************************************
 409          */
 410          void setIP(u_char * addr)
 411          {
 412   1              u_char i;
 413   1      
 414   1              for (i = 0; i < 4; i++) {
 415   2                      *(SRC_IP_PTR + i) = addr[i];
 416   2              }
 417   1      }
 418          
 419          /*
 420          ********************************************************************************
 421          *               MAC Address setup function
 422          *
 423          * Description : MAC Address setup function
 424          * Arguments   : addr - pointer having the value for setting up the MAC Address
 425          * Returns     : None
 426          * Note        : API Function
 427          ********************************************************************************
 428          */
 429          void setMACAddr(u_char * addr)
 430          {
 431   1              u_char i;
 432   1      
 433   1              for (i = 0; i < 6; i++) {
 434   2                      *(SRC_HA_PTR + i) = addr[i];
 435   2              }
 436   1      }
 437          

⌨️ 快捷键说明

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