Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In transmission, the situation is different. The TCP/IP stack knows how much data is being transmitted. In addition to RAM being limited in embedded systems, another feature is the small amount of data that needs to be transmitted. For example, in the case of sensor data to be transmitted periodically, a few hundred bytes every second can be transferred. In this case, a small buffer can be used and save RAM instead of waste a large transmit buffer. Another example is the transmission of TCP acknowledgment packets, especially when they are not carrying any data back to the transmitter. These packets are also small and do not require a large transmit buffer. RAM is also saved.

Network Buffer Architecture


µC/TCP-IP uses both small and large network buffers:

  • Network buffers
  • Small transmit buffers
  • Large transmit buffers
  • Large receive buffers

A single network buffer is allocated for each small transmit, large transmit and large receive buffer. Network buffers contain the control information for the network packet data in the network buffer data area. Currently, network buffers consume approximately 200 bytes each. The network buffers’ data areas are used to buffer the actual transmit and receive packet data. Each network buffer is connected to the data area via a pointer to the network buffer data area, and both move through the network protocol stack layers as a single entity. When the data area is no longer required, both the network buffer and the data area are freed. The figure below depicts the network buffer and data area objects.

All transmit data areas contain a small region of reserved space located at the top of the data area address space. The reserved space is used for network protocol header data and is currently fixed to 134 bytes in length. In general, not all of this space is required. However, the network protocol header region has been sized according to the maximum network protocol header usage for TCP/IP Ethernet packets.

First, µC/TCP-IP copies application-specified data from the application buffer into the application data region before writing network protocol header data to the protocol header region. After that, depending on the type of the packet being sent, each required layers will add its own protocol headers in the Protocols Headers Region of the Data Area. Starting from the highest layer to the lowest layer, all required headers are stacked on top of each other.

Network Buffer Sizes (to review)

µC/TCP-IP requires that network buffer sizes configured in net_dev_cfg.c satisfy the minimum and maximum packet frame sizes of network interfaces/devices.

Assuming an Ethernet interface (with non-jumbo or VLAN-tagged frames), the minimum frame packet size is 64 bytes (including its 4-byte CRC). If an Ethernet frame is created such that the frame length is less than 60 bytes (before its 4-byte CRC is appended), frame padding must be appended by the network driver or the Ethernet network interface layer to the application data area to meet Ethernet’s minimum packet size. For example, the ARP protocol typically creates packets of 42 bytes and therefore 18 bytes of padding must be added. The additional padding must fit within the network buffer’s data area.

Ethernet’s maximum transmit unit (MTU) size is 1500 bytes. When TCP is used as the transport protocol, TCP and IP protocol header sizes are subtracted from Ethernet’s 1500-byte MTU. A maximum of 1460 bytes of TCP application data may be sent in a full-sized Ethernet frame.

In addition, the variable size of network packet protocol headers must also be considered when configuring buffer sizes. The following computations demonstrate how to configure network buffer sizes to transmit and receive maximum sized network packets.

For transmit buffer size configuration, each layer’s maximum header sizes must be assumed/included to achieve the maximum payload for each layer. The maximum header sizes for each layer are:

Max Ethernet header : 14 bytes (this is a fixed size w/o CRC)
Max ARP header : 28 bytes (this is a fixed size for Ethernet/IPv4)
Max IP header : 60 bytes (with maximum length IP options)
Max TCP header : 60 bytes (with maximum length TCP options)
Max UDP header : 8 bytes (this is a fixed size)

Assuming both TCP and UDP are available as transport layer protocols, TCP’s maximum header size is the value used as the maximum transport layer header size since it is greater than UDP’s header size. Thus, the total maximum header size can then be computed as:

Max Hdr Size = Interface Max Header (Ethernet hdr is 14 bytes)
             + Network Max Header (IP max hdr is 60 bytes)
             + Transport Max Header (TCP max hdr is 60 bytes)
             = 14 + 60 + 60 = 134 bytes 

µC/TCP-IP configures NET_BUF_DATA_PROTOCOL_HDR_SIZE_MAX with this value in net_cfg_net.h to use as the starting data area index for transmit buffers’ application data.

The next step is to define transmit buffers’ total data area size. The issue is that we used the maximum header size for the transport and network layers. However, most of the time, the network and transport layer headers typically do not have any options:

Typical IP header :  20 bytes (without IP options)
Typical TCP header : 20 bytes (without TCP options)

These header values are used to determine the maximum payload a Data Link frame can carry. Since a TCP header is larger than UDP headers, the following compares the TCP maximum payload, also known as TCP’s Maximum Segment Size (MSS), over an Ethernet data link:

TCP payload (max) = Interface Max (Ethernet 1514 bytes w/o CRC)
                  - Interface Header (Ethernet 14 bytes w/o CRC)
                  - Min IP Header (IP min hdr is 20 bytes) 
                  - Min TCP Header (TCP min hdr is 20 bytes)
                  = 1514 - 14 - 20 - 20 = 1460 bytes

When TCP is used in a system, it is recommended to configure the large buffer size to at least this size in order to transmit maximum size TCP MSS:

TCP Max Buf Size = Max TCP payload (1460 bytes)
                 + Max Hdr sizes (134 bytes)
                 = 1460 + 134 = 1594 bytes

If any IP or TCP options are used, it is possible that the payload must be reduced, but unfortunately, that cannot be known by the application when transmitting. It is possible that, when the packet is at the network layer and because the TCP or IP headers are larger than usual because an option is enabled, a packet is too large and needs to be fragmented to be transmitted. However, µC/TCP-IP does not yet support fragmentation; but since options are seldom used and the standard header sizes for TCP and IP are the ones supported, this is generally not a problem.

For UDP, the UDP header has no options and the size does not change – it is always 8 bytes. Thus, UDP’s maximum payload is calculated as follows:

UDP payload (max) = Interface Max (Ethernet 1514 bytes w/o CRC)
                  - Interface Header (Ethernet 14 bytes w/o CRC)
                  - Min IP Header (IP min hdr is 20 bytes)
                  - Min UDP Header (UDP hdr is 8 bytes)
                  = 1514 - 14 - 20 - 8 = 1472 bytes

So to transmit maximum-sized UDP packets, configure large buffer sizes to at least:

Max UDP Buf Size = Max UDP payload (1472 bytes)
                 + Max Hdr sizes (134 bytes)
                 = 1472 + 134 = 1606 bytes

ICMP packets which are encapsulated within IP datagrams also have variable-length header sizes from 8 to 20 bytes. However, for certain design reasons, ICMP headers are included in an IP datagram’s data area and are not included in the maximum header size calculation. (IGMP packets have a fixed header size of 8 bytes but are also included in an IP datagram’s data area.) Thus, ICMP’s maximum payload is calculated as follows:

ICMP payload (max) = Interface Max (Ethernet 1514 bytes w/o CRC)
                   - Interface Header (Ethernet 14 bytes w/o CRC)
                   - Min IP Header (IP min hdr is 20 bytes)
                   = 1514 - 14 - 20 = 1480 bytes

And to transmit maximum-sized ICMP packets, configure large buffer sizes to at least:

Max ICMP Buf Size = Max ICMP payload (1480 bytes)
                  + Max Hdr sizes (134 bytes)
                  = 1480 + 134 = 1614 bytes

Small transmit buffer sizes must also be appropriately configured to at least the minimum packet frame size for the network interface/device. This means configuring a buffer size that supports sending a minimum sized packet for each layer’s minimum header sizes. The minimum header sizes for each layer are:

Min Ethernet header : 14 bytes (this is a fixed size w/o CRC)
Min ARP header : 28 bytes (this is a fixed size for Ethernet/IPv4)
Min IP header : 20 bytes (with minimum length IP options)
Min TCP header : 20 bytes (with minimum length TCP options)
Min UDP header : 8 bytes (this is a fixed size)

For Ethernet frames, the following computation shows that both ARP packets and UDP/IP packets share the smallest minimum header sizes of 42 bytes:

ARP packet (min) = Interface Min Header (Ethernet 14 bytes w/o CRC)
                 + ARP Min Header (ARP min hdr is 28 bytes)
                 = 14 + 28 = 42 bytes

UDP packet (min) = Interface Min Header (Ethernet 14 bytes w/o CRC)
                 + IP Min Header (IP min hdr is 20 bytes)
                 + UDP Min Header (UDP min hdr is 8 bytes)
                 = 14 + 20 + 8 = 42 bytes

And since Ethernet packets must be at least 60 bytes in length (not including 4-byte CRC), small transmit buffers must be minimally configured to at least 152 bytes to receive the smallest payload for each layer:

Min Tx Pkt Size = Interface Min Size (Ethernet 60 bytes w/o CRC)
                + Max Hdr Sizes (134 bytes)
                - Min Pkt Size (42 bytes)
                = 60 + 134 - 42 = 152 bytes

The figure below shows transmit buffers with reserved space of 134 bytes/octets for the maximum protocol header sizes, application data sizes from 0 to 1472 bytes/octets, and the valid range of configured buffer data area sizes for Ethernet of 152 to 1614 bytes/octets. 

Note that the application data size range plus the maximum header sizes of 134 bytes do not exactly add up to the small or large transmit data area configuration total. This is due to certain protocols (e.g., ICMP) whose protocol headers are not included in the typical network protocol header region but start at index 134.

Also note that if no small transmit buffer data areas are available, a data area from the large transmit data area pool is allocated if both small and large transmit data areas are configured.

µC/TCP-IP does not require receive buffer data areas to reserve space for maximum header sizes but does require that each receive buffer data area be configured to the maximum expected packet frame size for the network interface/device. For Ethernet interfaces, receive buffers must be configured to at least 1514 bytes, assuming the interface’s Ethernet device is configured to discard and not buffer the packet’s 4-byte CRC, or 1518 bytes, if the device does buffer the CRC. Although network buffers may require additional bytes to properly align each buffer, µC/TCP-IP creates the buffers with the appropriate alignment specified in net_dev_cfg.c so no additional bytes need be added to the receive buffer size.

The following table shows how each network buffer should be configured to handle the majority of worst cases.

Type of network buffer

Size

Receive Large Buffer

1518 + Alignment

Transmit Large Buffer

1618 + Alignment

Transmit Small Buffer

156 + Alignment

 

All μC/TCP-IP device drivers require a configuration structure for each device that must be compiled into your driver. You must place all device configuration structures and declarations within a pair of files named net_dev_cfg.c and net_dev_cfg.h.

Micrium provides sample configuration code free of charge; however, most sample code will likely require modification depending on the combination of compiler, processor, evaluation board, and device hardware used.

Memory Configuration

The first step in creating a device driver configuration for µC/TCP-IP begins with the memory configuration structure. This section describes the memory configuration settings for most device drivers, and should provide you an in-depth understanding of memory configuration. You will also discover which settings to modify in order to enhance the performances of the driver.

The listing below shows a sample memory configuration structurerequires that network buffer sizes configured in net_dev_cfg.c satisfy the minimum and maximum packet frame sizes of network interfaces/devices.

Assuming an Ethernet interface (with non-jumbo or VLAN-tagged frames), the minimum frame packet size is 64 bytes (including its 4-byte CRC). If an Ethernet frame is created such that the frame length is less than 60 bytes (before its 4-byte CRC is appended), frame padding must be appended by the network driver or the Ethernet network interface layer to the application data area to meet Ethernet’s minimum packet size. For example, the ARP protocol typically creates packets of 42 bytes and therefore 18 bytes of padding must be added. The additional padding must fit within the network buffer’s data area.

Ethernet’s maximum transmit unit (MTU) size is 1500 bytes. When TCP is used as the transport protocol, TCP and IP protocol header sizes are subtracted from Ethernet’s 1500-byte MTU. A maximum of 1460 bytes of TCP application data may be sent in a full-sized Ethernet frame.

In addition, the variable size of network packet protocol headers must also be considered when configuring buffer sizes. The following computations demonstrate how to configure network buffer sizes to transmit and receive maximum sized network packets.

Typical Buffers Size

The following table shows how each network buffer should be configured to handle the majority of worst cases.

Type of network buffer

Size

Receive Large Buffer

1518 + Alignment

Transmit Large Buffer

1518 + Alignment

Transmit Small Buffer

64 + Alignment

Network Device Configuration

All μC/TCP-IP device drivers require a configuration structure for each device that must be compiled into your driver. You must place all device configuration structures and declarations within a pair of files named net_dev_cfg.c and net_dev_cfg.h.

Micriµm provides sample configuration code free of charge; however, most sample code will likely require modification depending on the combination of compiler, processor, evaluation board, and device hardware used.

Memory Configuration

The first step in creating a device driver configuration for µC/TCP-IP begins with the memory configuration structure. This section describes the memory configuration settings for most device drivers, and should provide you an in-depth understanding of memory configuration. You will also discover which settings to modify in order to enhance the performances of the driver.

The listing below shows a sample memory configuration structure.

Code Block
languagecpp
themeConfluence
firstline1
titleSample memory configuration
linenumberstrue
const  NET_DEV_CFG  NetDev_Cfg_Dev1 = {
                           /* Structure member:                                           */
    NET_IF_MEM_TYPE_MAIN,  /*     .RxBufPoolType                                          */ (1)
    1518u,                 /*     .RxBufLargeSize                                         */ (2)
       9u,                 /*     .RxBufLargeNbr                                          */ (3)
      16u,                 /*     .RxBufAlignOctets                                       */ (4)
       0u,                 /*     .RxBufIxOffset                                          */ (5)

    NET_IF_MEM_TYPE_MAIN,  /*     .TxBufPoolType                                          */ (6)
    1606u,                 /*     .TxBufLargeSize                                         */ (7)
       4u,                 /*     .TxBufLargeNbr                                          */ (8)
      64u,                 /*     .TxBufSmallSize                                         */ (9)
       2u,                 /*     .TxBufSmallNbr                                          */ (10)
      16u,                 /*     .TxBufAlignOctets                                       */ (11)
       0u,                 /*     .TxBufIxOffset                                          */ (12)

    0x00000000u,           /*     .MemAddr                                                */ (13)
             0u,           /*     .MemSize                                                */ (14)

    NET_DEV_CFG_FLAG_NONE, /*     .Flag                                                   */ (15)
};



Panel
bgColor#f0f0f0
  1. .RxBufPoolType specifies the memory location for the receive data buffers. Buffers may located either in main memory or in a dedicated memory region. This setting is used by the IF layer to initialize the Rx memory pool. This field must be set to one of two macros: NET_IF_MEM_TYPE_MAIN or NET_IF_MEM_TYPE_DEDICATED. You may want to set this field when DMA with dedicated memory is used. It is possible that you might have to store descriptors within the dedicated memory if your device requires it.

  2. .RxBufLargeSize specifies the size of all receive buffers. Specifying a value is required. The buffer length is set to 1518 bytes which corresponds to the Maximum Transmission Unit (MTU) of an Ethernet network. For DMA-based Ethernet controllers, you must set the receive data buffer size to be greater or equal to the size of the largest receivable frame. If the size of the total buffer allocation is greater than the amount of available memory in the chosen memory region, a run-time error will be generated when the device is initialized.

  3. .RxBufLargeNbr specifies the number of receive buffers that will be allocated to the device. There should be at least one receive buffer allocated, and it is recommended to have at least ten receive buffers. The optimal number of receive buffers depends on your application.

  4. .RxBufAlignOctets specifies the required alignment of the receive buffers, in bytes. Some devices require that the receive buffers be aligned to a specific byte boundary. Additionally, some processor architectures do not allow multi-byte reads and writes across word boundaries and therefore may require buffer alignment. In general, it is probably a best practice to align buffers to the data bus width of the processor, which may improve performance. For example, a 32-bit processor may benefit from having buffers aligned on a four-byte boundary.

  5. .RxBufIxOffset specifies the receive buffer offset in bytes. Most devices receive packets starting at base index zero in the network buffer data areas. However, some devices may buffer additional bytes prior to the actual received Ethernet packet. This setting configures an offset to ignore these additional bytes. If a device does not buffer any additional bytes ahead of the received Ethernet packet, then an offset of 0 must be specified. However, if a device does buffer additional bytes ahead of the received Ethernet packet, then you should configure this offset with the number of additional bytes. Also, the receive buffer size must also be adjusted by the number of additional bytes.

  6. .TxBufPoolType specifies the memory placement of the transmit data buffers. Buffers may be placed either in main memory or in a dedicated memory region. This field is used by the IF layer, and it should be set to one of two macros: NET_IF_MEM_TYPE_MAIN or NET_IF_MEM_TYPE_DEDICATED. When DMA descriptors are used, they may be stored into the dedicated memory.

  7. .TxBufLargeSize specifies the size of the large transmit buffers in bytes. This field has no effect if the number of large transmit buffers is configured to zero. Setting the size of the large transmit buffers below 1594 bytes may hinder the µC/TCP-IP module’s ability to transmit full sized IP datagrams since IP transmit fragmentation is not yet supported. We recommend setting this field between 1594 and 1614 bytes in order to accommodate all of the maximum transmit packet sizes for μC/TCP-IP’s protocols.

    You can optimize the transmit buffer if you know in advance what the maximum size of the packets the user will want to transmit through the device are.

  8. .TxBufLargeNbr specifies the number of large transmit buffers allocated to the device. You may set this field to zero to make room for additional small transmit buffers, however, the size of the maximum transmittable packet will then depend on the size of the small transmit buffers.

  9. .TxBufSmallSize specifies the small transmit buffer size. For devices with a minimal amount of RAM, it is possible to allocate small transmit buffers as well as large transmit buffers. In general, we recommend a 64 byte small transmit buffer size, however, you may adjust this value according to the application requirements. This field has no effect if the number of small transmit buffers is configured to zero.

  10. .TxBufSmallNbr specifies the numbers of small transmit buffers. This field controls the number of small transmit buffers allocated to the device. You may set this field to zero to make room for additional large transmit buffers if required.

  11. .TxBufAlignOctets specifies the transmit buffer alignment in bytes. Some devices require that the transmit buffers be aligned to a specific byte boundary. Additionally, some processor architectures do not allow multi-byte reads and writes across word boundaries and therefore may require buffer alignment. In general, it's probably a best practice to align buffers to the data bus width of the processor which may improve performance. For example, a 32-bit processor may benefit from having buffers aligned on a four-byte boundary.

  12. .TxBufIxOffset specifies the transmit buffer offset in bytes. Most devices only need to transmit the actual Ethernet packets as prepared by the higher network layers. However, some devices may need to transmit additional bytes prior to the actual Ethernet packet. This setting configures an offset to prepare space for these additional bytes. If a device does not transmit any additional bytes ahead of the Ethernet packet, the default offset of zero should be configured. However, if a device does transmit additional bytes ahead of the Ethernet packet then configure this offset with the number of additional bytes. The transmit buffer size must also be adjusted to include the number of additional bytes.

  13. .MemAddr specifies the starting address of the dedicated memory region for devices with this memory type. For devices with non-dedicated memory, you can initialize this field to zero. You may use this setting to put DMA descriptors into the dedicated memory.

  14. .MemSize specifies the size of the dedicated memory region in bytes for devices with this memory type. For devices with non-dedicated memory, you can initialize this field to zero. You may use this setting to put DMA descriptors into the dedicated memory.

  15. .Flags specify the optional configuration flags. Configure (optional) device features by logically OR’ing bit-field flags:
    NET_DEV_CFG_FLAG_NONE No device configuration flags selected.
    NET_DEV_CFG_FLAG_SWAP_OCTETS Swap data bytes (i.e., swap data words’ high-order bytes with data words’ low-order bytes, and vice-versa) if required by device-to-CPU data bus wiring and/or CPU endian word order.


Ethernet Device Configuration

152010771 shows a sample Ethernet configuration structure for Ethernet devices.

Code Block
languagecpp
themeConfluence
firstline1
titleListing - Ethernet Device Configuration
linenumberstrue
const  NET_DEV_CFG_ETHER  NetDev_Cfg_Dev1_0 = {
                           /* Structure member:                                           */
    NET_IF_MEM_TYPE_MAIN,  /*     .RxBufPoolType                                          */ (1)
    1518u,                 /*     .RxBufLargeSize                                         */
      10u,                 /*     .RxBufLargeNbr                                          */
       4u,                 /*     .RxBufAlignOctets                                       */
       0u,                 /*     .RxBufIxOffset                                          */

    NET_IF_MEM_TYPE_MAIN,  /*     .TxBufPoolType                                          */
    1606u,                 /*     .TxBufLargeSize                                         */
       4u,                 /*     .TxBufLargeNbr                                          */
      64u,                 /*     .TxBufSmallSize                                         */
       4u,                 /*     .TxBufSmallNbr                                          */
       4u,                 /*     .TxBufAlignOctets                                       */
       0u,                 /*     .TxBufIxOffset                                          */

    0x00000000u,           /*     .MemAddr                                                */
             0u,           /*     .MemSize                                                */

    NET_DEV_CFG_FLAG_NONE, /*     .Flag                                                   */

             6u,           /*     .RxDescNbr                                               */ (2)
             6u,           /*     .TxDescNbr                                               */ (3)
    0x40028000u,           /*     .BaseAddr                                                */ (4)
             0u,           /*     .DataBusSizeNbrBits                                      */ (5)
   "00:50:C2:25:61:00",    /*     .HW_AddrStr                                              */ (6)
};


Panel
bgColor#f0f0f0
  1. Memory configuration of the Ethernet Device. See “Memory Configuration” for further information about how to configure the memory of your Ethernet interface.
     
  2. .RxDescNbr specifies the number of receive descriptors. For DMA-based devices, this value is used by the device driver during initialization in order to allocate a fixed-size pool of receive descriptors to be used by the device. The number of descriptors must be less than the number of configured receive buffers. We recommend setting this value to something within 40% and 70% of the number of receive buffers. Non-DMA based devices may configure this value to zero. You must use this setting with DMA based devices and at least two descriptors must be set.
     
  3. .TxDescNbr specifies the number of transmit descriptors. For DMA based devices, this value is used by the device driver during initialization to allocate a fixed size pool of transmit descriptors to be used by the device. For best performance, it’s recommended to set the number of transmit descriptors equal to the number of small, plus the number of large transmit buffers configured for the device. Non-DMA based devices may configure this value to zero. You must use this setting with DMA based devices and set at least two descriptors.
     
  4. .BaseAddr specifies the base address of the device’s hardware/registers.
     
  5. .DataBusSizeNbrBits specifies the size of device's data bus (in bits), if available.
     
  6. .HW_AddrStr specifies the desired device hardware address; may be NULL address or string if the device hardware address is configured or set at run-time. Depending on the driver, if this value is kept NULL or invalid, most of the device driver will automatically try to load and use the hardware address located in the memory of the device.



Ethernet PHY Configuration

152010771 shows a typical Ethernet PHY configuration structure.



Panel
bgColor#f0f0f0
titleListing - Ethernet PHY Configuration

NET_PHY_CFG_ETHER NetPhy_Cfg_FEC_0= {
    NET_PHY_ADDR_AUTO,                   (1)
    NET_PHY_BUS_MODE_MII,                (2)
    NET_PHY_TYPE_EXT                     (3)
    NET_PHY_SPD_AUTO,                    (4)
    NET_PHY_DUPLEX_AUTO,                 (5)
};


Panel
bgColor#f0f0f0
  1. PHY Address. This field represents the address of the PHY on the (R)MII bus. The value configured depends on the PHY and the state of the PHY pins during power-up. Developers may need to consult the schematics for their board to determine the configured PHY address.
    Alternatively, the PHY address may be detected automatically by specifying NET_PHY_ADDR_AUTO; however, this will increase the initialization latency of µC/TCP-IP and possibly the rest of the application depending on where the application places the call to NetIF_Start().
     
  2. PHY bus mode. This value should be set to one of the following values depending on the hardware capabilities and schematics of the development board. The network device BSP should configure
    the Phy-level hardware based on this configuration value.

    NET_PHY_BUS_MODE_MII
    NET_PHY_BUS_MODE_RMII
    NET_PHY_BUS_MODE_SMII

  3. PHY bus type. This field represents the type of electrical attachment of the PHY to the Ethernet controller. In some cases, the PHY may be internal to the network controller, while in other cases, it may be attached via an external MII or RMII bus. It is desirable to specify which attachment method is in use so that a device driver can initialize additional hardware resources if an external PHY is attached to a device that also has an internal PHY. Available settings for this field are:

    NET_PHY_TYPE_INT

    NET_PHY_TYPE_EXT

  4. Initial PHY link speed. This configuration setting will force the PHY to link to the specified link speed. Optionally, auto-negotiation may be enabled. This field must be set to one of the following values:

    NET_PHY_SPD_AUTO
    NET_PHY_SPD_10
    NET_PHY_SPD_100
    NET_PHY_SPD_1000
  5. Initial PHY link duplex. This configuration setting will force the PHY to link using the specified duplex. This setting must be set to one of the following values:

    NET_PHY_DUPLEX_AUTO
    NET_PHY_DUPLEX_HALF
    NET_PHY_DUPLEX_FULL



Wireless Device Configuration

The listing below shows a sample wireless configuration structure for wireless devices.


Code Block
languagecpp
themeConfluence
firstline1
titleListing - Wireless device memory configuration
linenumberstrue
const  NET_DEV_CFG_WIFI  NetDev_Cfg_WiFi_0 = {
                                           /* Structure member:                           */
    NET_IF_MEM_TYPE_MAIN,                  /*     .RxBufPoolType                          */ (1)
    1518u,                                 /*     .RxBufLargeSize                         */
       9u,                                 /*     .RxBufLargeNbr                          */
      16u,                                 /*     .RxBufAlignOctets                       */
       0u,                                 /*     .RxBufIxOffset                          */

    NET_IF_MEM_TYPE_MAIN,                  /*     .TxBufPoolType                          */
    1606u,                                 /*     .TxBufLargeSize                         */
       4u,                                 /*     .TxBufLargeNbr                          */
      64u,                                 /*     .TxBufSmallSize                         */
       2u,                                 /*     .TxBufSmallNbr                          */
      16u,                                 /*     .TxBufAlignOctets                       */
       0u,                                 /*     .TxBufIxOffset                          */

    0x00000000u,                           /*     .MemAddr                                */
             0u,                           /*     .MemSize                                */

    NET_DEV_CFG_FLAG_NONE,                 /*     .Flag                                   */

    NET_DEV_BAND_DUAL,                     /*     .Band                                    */ (2)

      25000000L,                           /*     .SPI_ClkFreq                             */ (3)
    NET_DEV_SPI_CLK_POL_INACTIVE_HIGH,     /*     .SPI_ClkPol                              */ (4)
    NET_DEV_SPI_CLK_PHASE_FALLING_EDGE,    /*     .SPI_ClkPhase                            */ (5)
    NET_DEV_SPI_XFER_UNIT_LEN_8_BITS,      /*     .SPI_XferUnitLen                         */ (6)
    NET_DEV_SPI_XFER_SHIFT_DIR_FIRST_MSB,  /*     .SPI_XferShiftDir                        */ (7)

   "00:50:C2:25:60:02",                    /*     .HW_AddrStr                              */ (8)
};


Panel
bgColor#f0f0f0
  1. Memory configuration of the wireless device. See µC/TCP-IP Network Interface Configuration for further information about how to configure the memory of your wireless interface.
     
  2. .Band specifies the desired wireless band enabled and used by the wireless device. This value should be set to one of the following values depending on the
    hardware capabilities and the application requirements.

    NET_DEV_BAND_2_4_GHZ
    NET_DEV_BAND_5_0_GHZ
    NET_DEV_BAND_DUAL
  3. .SPI_ClkFreq specifies the SPI controller’s clock frequency (in Hertz) configuration for writing and reading on the wireless device.

  4. .SPI_ClkPol specifies the SPI controller’s clock polarity configuration for writing and reading on the wireless device. The network device BSP should configure the SPI
    controller’s clock polarity based on this configuration value.
        NET_DEV_SPI_CLK_POL_INACTIVE_LOW 
    NET_DEV_SPI_CLK_POL_INACTIVE_HIGH

  5. .SPI_ClkPhase specifies the SPI controller’s clock phase configuration for writing and reading on the wireless device. The network device BSP should configure the SPI controller’s clock phase based on this configuration value.
     

         NET_DEV_SPI_CLK_PHASE_FALLING_EDGE
    NET_DEV_SPI_CLK_PHASE_RAISING_EDGE
     
  6. .SPI_XferUnitLen specifies the SPI controller’s transfer unit length configuration for writing and reading on the wireless device. The network device BSP should configure the SPI
    controller’s transfer unit length based on this configuration value.
         NET_DEV_SPI_XFER_UNIT_LEN_8_BITS
    NET_DEV_SPI_XFER_UNIT_LEN_16_BITS
    NET_DEV_SPI_XFER_UNIT_LEN_32_BITS
    NET_DEV_SPI_XFER_UNIT_LEN_64_BITS
     
  7. .SPI_XferShiftDir specifies the SPI controller’s shift direction configuration for writing and reading on the wireless device. The network device BSP should configure the SPI controller’s transfer unit length based on this configuration value.

         NET_DEV_SPI_XFER_SHIFT_DIR_FIRST_MSB
    NET_DEV_SPI_XFER_SHIFT_DIR_FIRST_LSB
     
  8. .HW_AddrStr specifies the desired device hardware address; may be NULL address or string if the device hardware address is configured or set at run-time. Depending on the driver, if this value is kept NULL or invalid, most device
    drivers will automatically try to load and use the hardware address located in the memory of the device.


Loopback Configuration

Configuring the loopback interface requires only a memory configuration, as described in µC/TCP-IP Network Interface Configuration.

Listing 5-9 shows a sample configuration structure for the loopback interface.

Code Block
languagecpp
themeConfluence
firstline1
titleListing - Sample loopback interface configuration
linenumberstrue
const  NET_IF_CFG_LOOPBACK  NetIF_Cfg_Loopback = {

    NET_IF_MEM_TYPE_MAIN,                             (1)
    1518,                                             (2)
      10,                                             (3)
       4,                                             (4)
       0,                                             (5)

    NET_IF_MEM_TYPE_MAIN,                             (6)
    1594,                                             (7)
       5,                                             (8)
      64,                                             (9)
       5,                                            (10)
       4,                                            (11)
       0,                                            (12)

    0x00000000,                                      (13)
             0,                                      (14)

    NET_DEV_CFG_FLAG_NONE                            (15)
};


Panel
bgColor#f0f0f0
  1. Receive buffer pool type. This configuration setting controls the memory placement of the receive data buffers. Buffers may either be placed in main memory or in a dedicated, possibly higher speed, memory region (see point #13, below). This field should be set to one of the two macros:

    NET_IF_MEM_TYPE_MAIN
    NET_IF_MEM_TYPE_DEDICATED
  2. Receive buffer size. This field sets the size of the largest receivable packet, and can be set to match the application’s requirements.

    Note: If packets are sent from a socket bound to a non local-host address, to the local host address (127.0.0.1), then the receive buffer size must be configured to match the maximum transmit buffer size, or maximum expected data size, that could be generated from a socket bound to any other interface.
     
  3. Number of receive buffers. This setting controls the number of receive buffers that will be allocated to the loopback interface. This value must be set greater than or equal to one buffer if loopback is receiving only UDP. If TCP data is expected to be transferred across the loopback interface, then there must be a minimum of four receive buffers.
     
  4. Receive buffer alignment. This setting controls the alignment of the receive buffers in bytes. Some processor architectures do not allow multi-byte reads and writes across word boundaries and therefore may require buffer alignment. In general, it is probably best practice to align buffers to the data bus width of the processor which may improve performance. For example, a 32-bit processor may benefit from having buffers aligned on a 4-byte boundary.

  5. Receive buffer offset. The loopback interface receives packets starting at base index 0 in the network buffer data areas. This setting configures an offset from the base index of 0 to receive loopback packets. The default offset of 0 should be configured. However, if loopback receive packets are configured with an offset, the receive buffer size must also be adjusted by the additional number of offset bytes.

  6. Transmit buffer pool type. This configuration setting controls the memory placement of the transmit data buffers for the loopback interface. Buffers may either be placed in main memory or in a dedicated, possibly higher speed, memory region (see point #13, below). This field should be set to one of two macros:
    NET_IF_MEM_TYPE_MAIN
    NET_IF_MEM_TYPE_DEDICATED
  7. Large transmit buffer size. At the time of this writing, transmit fragmentation is not supported; therefore this field sets the size of the largest transmittable buffer for the loopback interface when the application sends from a socket that is bound to the local-host address.
     
  8. Number of large transmit buffers. This field controls the number of large transmit buffers allocated to the loopback interface. The developer may set this field to zero to make room for additional large transmit buffers, however, the number of large plus the number of small transmit buffers must be greater than or equal to one for UDP traffic and three for TCP traffic.
     
  9. Small transmit buffer size. For devices with a minimal amount of RAM, it is possible to allocate small transmit buffers as well as large transmit buffers. In general, we recommend 64 byte small transmit buffers, however, the developer may adjust this value according to the application requirements. This field has no effect if the number of small transmit buffers is configured to zero.
     
  10. Number of small transmit buffers. This field controls the number of small transmit buffers allocated to the device. The developer may set this field to zero to make room for additional large transmit buffers, however, the number of large plus the number of small transmit buffers must be greater than or equal to one for UDP traffic and three for TCP traffic.
     
  11. Transmit buffer alignment. This setting controls the alignment of the receive buffers in bytes. Some processor architectures do not allow multi-byte reads and writes across word boundaries and therefore may require buffer alignment. In general, it is probably best practice to align buffers to the data bus width of the processor which may improve performance. For example, a 32-bit processor may benefit from having buffers aligned on a 4-byte boundary.
     
  12. Transmit buffer offset. This setting configures an offset from the base transmit index to prepare loopback packets. The default offset of 0 should be configured. However, if loopback transmit packets are configured with an offset, the transmit buffer size must also be adjusted by the additional number of offset bytes.
     
  13. Memory address. By default, this field is configured to 0x00000000. A value of 0 tells µC/TCP-IP to allocate buffers for the loopback interface from the µC/LIB Memory Manager default heap. If a faster, more specialized memory is available, the loopback interface buffers may be allocated into an alternate region if desired.
     
  14. Memory size. By default, this field is configured to 0. A value of 0 tells µC/TCP-IP to allocate as much memory as required from the µC/LIB Memory Manager default heap. If an alternate memory region is specified in the ‘Memory Address’ field above, then the maximum size of the specified memory segment must be specified.

  15. Optional configuration flags. Configure (optional) loopback features by logically OR’ing bit-field flags:
    NET_DEV_CFG_FLAG_NONE No loopback configuration flags selected



Adding a Loopback Interface

Basically, to enable and add the loopback interface you only have to enable the loopback interface within the network configuration See Network Interfaces Configuration.

Network Queues Configuration

The device configuration will directly impact the Network Task Queues Configuration.

The µC/TCP-IP stack includes two queues. The first one is the Rx queue and is used to store the Rx buffer that have been filled and are ready to be process. The second queue is the Tx deallocation and is used to store the Tx buffers that are ready to be deallocate.

The size of the Rx queue should reflects the total number of DMA receive descriptors configured for all the interfaces. If the devices are not DMA-based, it should reflects the maximum number of packets that can be acknowledged and signaled during a single receive interrupt even for all interfaces.

The size of the Tx queue should be defined as the total number of small and large transmit buffers declared for all interfaces.

Please refer to section Task Queue Configuration for more details.