Versions Compared

Key

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

Memory is allocated to µC/TCP-IP is using µC/LIB to allocated internal data such as OS objects (semaphore, mutex), device driver's buffers and DMA descriptors, etc. µC/TCP-IP device drivers through the internal tasks stack can be also allocated using µC/LIB. Therefore µC/LIB memory module . You must enable and configure the size of the µC/LIB memory heap available to the system. The following configuration constant should be defined from within lib_cfg.h and set to match the application requirements:

#define LIB_MEM_CFG_HEAP_SIZE 58000

The heap size is specified in bytes. If the heap size is must be configured properly for µC/TCP-IP. If the heap size is not configured large enough, an error will be returned during the Network Protocol Stack initialization, or during interface addition.

...

Note: The memory module must be initialized by the application by calling Mem_Init() prior to calling prior to calling Net_Init(). We recommend initializing the memory module before calling OSStart()calling starting the RTOS, or near the top of the startup task.

Please refer to section µC/LIB Documentation libdoc for more details on the µC/LIB module and its configuration.

Heap Memory Calculation for an Interface

The µC/LIB memory heap is used for allocation of the following objects:

  1. Transmit small buffers
  2. Transmit large buffers
  3. Receive large buffers
  4. Network Buffers (Network Buffer header and pointer to data area)
  5. DMA receive descriptors
  6. DMA transmit descriptors
  7. Interface data area
  8. Device driver data area
  9. OS objects (Semaphore, mutex, stack)
  10. ICMP Echo request objects (note that object are only allocated when the ICMP Echo request is sent, not at during the Network Protocol Stack initialization)


In the following example, the use of a Network Device Driver with DMA support is assumed. DMA descriptors are included in the analysis. The size of Network Buffer Data Areas (1, 2, 3) vary based on configuration. Refer to Chapter 9, “Buffer Management”. However, for this example, the following object sizes in bytes are assumed:

  • Small transmit buffers: 15260
  • Large transmit buffers: 1594 for maximum sized TCP packets1518
  • Large receive buffers: 1518
  • Size of DMA receive descriptor: 8
  • Size of DMA transmit descriptor: 8
  • Ethernet interface data area: 7
  • Average Ethernet device driver data area: 108

...

The approximate memory heap size may be determined according to the following expressions:

Code Block
nbr buf per interface     = nbr small Tx buf + 
                            nbr large Tx buf + 
                            nbr large Rx buf 
  
nbr net buf per interface = nbr buf per interface 
  
nbr objects   =  nbr buf per interface     + 
                 nbr net buf per interface + 
                 nbr Rx descriptors        + 
                 nbr Tx descriptors        + 
                 1 Ethernet      data area + 
                 1 Device driver data area 
  
interface mem = (nbr small Tx buf       *   60) + 
                (nbr large Tx buf       * 1518) + 
                (nbr large Rx buf       * 1518) + 
                (nbr Rx descriptors     *    8) + 
                (nbr Tx descriptors     *    8) + 
                (Ethernet IF  data area *    7) + 
                (Ethernet Drv data area *  108) + 
                (nbr objects            *    3) 
  
total mem required = nbr interfaces * interface mem


Example

With the following configuration, the memory heap required is:

  • 10 small transmit buffers
  • 10 large transmit buffers
  • 10 large receive buffers
  • 6 receive descriptors
  • 20 transmit descriptors
  • Ethernet interface (interface + device driver data area required)
Code Block
languagetext
          nbr     buf per interface = 10 + 10 + 10               = 30
          nbr net buf per interface = nbr buf per interface      = 30
          nbr objects               = (30 + 30 + 6 + 20 + 1 + 1) = 88
          interface mem             = (10 *   60) + 
                                      (10 * 1518) + 
                                      (10 * 1518) + 
                                      ( 6 *    8) +
                                      (20 *    8) +
                                      ( 1 *    7) +
                                      ( 1 *  108) +
                                      (88 *    3) = 31,547 bytes
           
          total mem required > 31,547 ( + localhost memory, if enabled)


The localhost interface, when enabled, requires a similar amount of memory except that it does not require Rx and Tx descriptors, an IF data area, or a device driver data area.

The value determined by these expressions is only an estimate. In some cases, it may be possible to reduce the size of the µC/LIB memory heap by inspecting the variable Mem_PoolHeap.SegSizeRem after µC/LIB (see  libdoc) after all interfaces have been successfully initialized and any additional application allocations (if applicable) have been completed.Excess heap space, if present, may be subtracted from the lib heap size configuration macro, LIB_MEM_CFG_HEAP_SIZE, present in lib_cfg.h.