Aurix TC387 Ethernet代码解析之六_MAC的LwIP初始化3

1、原始代码

代码位置: ...\Ethernet_TC387_Example\Libraries\Ethernet\lwip\port\src\Ifx_Lwip.c

cs 复制代码
  /** - initialise LWIP (lwip_init()) */
    lwip_init();

2、概念说明

3、代码解析

代码位置: ...\Ethernet_TC387_Example\Libraries\Ethernet\lwip\src\core\init.c

cs 复制代码
/**
 * @ingroup lwip_nosys
 * Initialize all modules.
 * Use this in NO_SYS mode. Use tcpip_init() otherwise.
 */
void
lwip_init(void)
{
#ifndef LWIP_SKIP_CONST_CHECK
  int a = 0;
  LWIP_UNUSED_ARG(a);
  LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a);
#endif
#ifndef LWIP_SKIP_PACKING_CHECK
  LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);
#endif

  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_IPV4
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
#if PPP_SUPPORT
  ppp_init();
#endif

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}

3.1、初始化之前的显示

3.1.1、原始代码

cs 复制代码
#ifndef LWIP_SKIP_CONST_CHECK
  int a = 0;
  LWIP_UNUSED_ARG(a);
  LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a);
#endif
#ifndef LWIP_SKIP_PACKING_CHECK
  LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);
#endif

显示"LWIP_CONST_CAST not implemented correctly. Check your lwIP port."

以上非重点研究对象,不展开说明

3.2、状态初始化

3.2.1、原始代码

cs 复制代码
void stats_init(void)
{
    #ifdef LWIP_DEBUG
        #if MEM_STATS
          lwip_stats.mem.name = "MEM";
        #endif /* MEM_STATS */
    #endif /* LWIP_DEBUG */
}

定义名称为"MEM"

3.3、memory初始化

3.3.1、原始代码

cs 复制代码
mem_init();

/* Zero the heap and initialize start, end and lowest-free  */
void mem_init(void)
{
  struct mem *mem;

  LWIP_ASSERT("Sanity check alignment",
              (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT - 1)) == 0);

  /* align the heap */
  ram = (u8_t *)LWIP_MEM_ALIGN(LWIP_RAM_HEAP_POINTER);
  /* initialize the start of the heap */
  mem = (struct mem *)(void *)ram;
  mem->next = MEM_SIZE_ALIGNED;
  mem->prev = 0;
  mem->used = 0;
  /* initialize the end of the heap */
  ram_end = ptr_to_mem(MEM_SIZE_ALIGNED);
  ram_end->used = 1;
  ram_end->next = MEM_SIZE_ALIGNED;
  ram_end->prev = MEM_SIZE_ALIGNED;
  MEM_SANITY();

  /* initialize the lowest-free pointer to the start of the heap */
  lfree = (struct mem *)(void *)ram;

  MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);

  if (sys_mutex_new(&mem_mutex) != ERR_OK) {
    LWIP_ASSERT("failed to create mem_mutex", 0);
  }
}

① struct mem *mem;

定义memory结构体

② LWIP_ASSERT("Sanity check alignment", (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT - 1)) == 0);

显示"Sanity check alignment"

③

相关推荐
_upupup15 小时前
GPIO输出(STM32)
stm32·单片机
Brilliantwxx17 小时前
【STM32】 DAC 数模转换器(理论 + 外设 + 四个实验案例)
笔记·stm32·单片机·嵌入式硬件
无敌贵点大王1 天前
从寄存器层面重学STM32(15)——IIC理论
stm32·单片机·嵌入式硬件
en.en..1 天前
STM32 HAL 库 | 外设双结构体机制(外设句柄结构体+外设初始化结构体)
stm32·单片机·嵌入式硬件
元器件BOM超人2 天前
ATMEGA32A-AU TQFP-44 Microchip 8位AVR MCU 选型指南
单片机·嵌入式硬件
en.en..2 天前
STM32 GPIO 复用功能寄存器 AFRL/AFRH 原理
单片机·嵌入式硬件
shimly1234562 天前
(done) 野火嵌入式 (16) STM32中断应用概览
stm32·单片机·嵌入式硬件
橘为己有4412 天前
STM32:SPI(1)
stm32·单片机·嵌入式硬件
en.en..2 天前
STM32 定时器 | 输入捕获单元与输出比较单元
单片机·嵌入式硬件
倔强的胡萝卜2 天前
基于STM32F103C8T6的计算器设计(二)
stm32·单片机·嵌入式硬件