Wireless Device Configuration
The listing below shows a sample wireless configuration structure for wireless devices.
Code Block |
---|
language | cpp |
---|
theme | Confluence |
---|
firstline | 1 |
---|
title | Listing - Wireless device memory configuration |
---|
linenumbers | true |
---|
|
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, /* Structure member: .RxBufIxOffset */
NET_IF_MEM_TYPE_MAIN, /* .RxBufPoolTypeTxBufPoolType */
(1) 1518u1606u, /* .RxBufLargeSizeTxBufLargeSize */
9u4u, /* .RxBufLargeNbrTxBufLargeNbr */
16u64u, /* .RxBufAlignOctetsTxBufSmallSize */
0u2u, /* .RxBufIxOffsetTxBufSmallNbr */
NET_IF_MEM_TYPE_MAIN, 16u, /* .TxBufPoolTypeTxBufAlignOctets */
*/ 1606u0u, /* .TxBufLargeSizeTxBufIxOffset */
4u0x00000000u, /* .MemAddr /* .TxBufLargeNbr */
64u, 0u, /* .TxBufSmallSizeMemSize */ */
2u,
NET_DEV_CFG_FLAG_NONE, /* .Flag /* .TxBufSmallNbr */
16u,NET_DEV_BAND_DUAL, /* .Band /* .TxBufAlignOctets */ (2)
0u25000000L, /* /* .SPI_ClkFreq .TxBufIxOffset */ (3)
0x00000000uNET_DEV_SPI_CLK_POL_INACTIVE_HIGH, /* .SPI_ClkPol /* .MemAddr */ (4)
NET_DEV_SPI_CLK_PHASE_FALLING_EDGE, /* .SPI_ClkPhase */ 0u, */ (5)
NET_DEV_SPI_XFER_UNIT_LEN_8_BITS, /* .MemSizeSPI_XferUnitLen */ (6)
NET_DEV_CFG_FLAG_NONE_SPI_XFER_SHIFT_DIR_FIRST_MSB, /* .SPI_XferShiftDir /* .Flag */ (7)
"00:50:C2:25:60:02", /*/ NET_DEV_BAND_DUAL,.HW_AddrStr /* .Band */ (8)
}; |
Panel |
---|
|
- 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.
.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
|
*/ (2)
25000000L, /* .SPI_ClkFreq */ (3)
the application requirements.
NET_DEV_BAND_2_4_GHZ NET_DEV_BAND_5_0_GHZ NET_DEV_BAND_DUAL .SPI_ClkFreq specifies the SPI controller’s clock frequency (in Hertz) configuration for writing and reading on the wireless device.
.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
|
, /* .SPI_ClkPol
.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
|
*/ (4)
FALLING, /* .SPI_ClkPhase */ (5)
.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
|
.SPI_XferUnitLen NET_DEV_SPI_XFER_UNIT_LEN_32_BITS
|
*/ (6)
SHIFTDIRFIRST_MSB, /* .SPI_XferShiftDir 64_BITS - .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
|
*/ (7)
"00:50:C2:25:60:02", /* .HW_AddrStr */ (8)
}; Panel |
---|
|
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.
.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_GHZNET_DEV_BAND_5_0_GHZNET_DEV_BAND_DUAL.SPI_ClkFreq
specifies the SPI controller’s clock frequency (in Hertz) configuration for writing and reading on the wireless device..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
.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
.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
.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
.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 |
---|
language | cpp |
---|
theme | Confluence |
---|
firstline | 1 |
---|
title | Sample loopback interface configuration |
---|
linenumbers | true |
---|
|
const NET_IF_CFG_LOOPBACK NetIF_Cfg_Loopback = {NET_DEV_SPI_XFER_SHIFT_DIR_FIRST_LSB .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 |
---|
language | cpp |
---|
theme | Confluence |
---|
firstline | 1 |
---|
title | Listing - Sample loopback interface configuration |
---|
linenumbers | true |
---|
|
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, (16)
15181594, (27)
10 5, (38)
464, (49)
05, (510)
NET_IF_MEM_TYPE_MAIN, (6)
1594 4, (711)
50, (812)
64, 0x00000000, (913)
5, 0, (1014)
NET_DEV_CFG_FLAG_NONE 4, (11)
0, (12)
0x00000000, (13)
0, (14)
NET_DEV_CFG_FLAG_NONE (15)
}; |
Panel |
---|
|
Receive (15)
}; |
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. Panel |
---|
|
- 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
- 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. - 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.
- 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.
- 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.
- Transmit buffer pool type. This configuration setting controls the memory placement of the receive data bufferstransmit 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 the two macros:
NET_IF_MEM_TYPE_MAIN
NET_IF_MEM_TYPE_DEDICATED
- Receive Large transmit buffer size. This At the time of this writing, transmit fragmentation is not supported; therefore 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 transmittable buffer for the loopback interface when the application sends from a socket that is 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 interfacethe local-host address. - Number of receive large transmit buffers. This setting field controls the number of receive large transmit 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.
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. 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.