硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4915|回复: 3
收起左侧

[以太网] ethernetif_input中的LOCK_TCPIP_CORE是否必要

[复制链接]

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2020-10-19 17:42:28 | 显示全部楼层 |阅读模式
MCU:H743VI
Lwip:2.0.2

问题
1.st早期的lwip例程中ethernetif_input里面,在low_level_input()前添加了LOCK_TCPIP_CORE(),并在netif->input()后释放,这一步是否必要?在接收udp报文时有时候会莫名其妙的ping不通,导致数据丢失,把这个锁去掉就好了。

  1. void ethernetif_input( void const *argument )
  2. {
  3.   struct pbuf *p;
  4.   struct netif *netif = (struct netif *) argument;
  5.   
  6.   for( ;; )
  7.   {
  8.     if (osSemaphoreWait( RxPktSemaphore, TIME_WAITING_FOR_INPUT)==osOK)
  9.     {
  10.       do
  11.       {
  12.         //LOCK_TCPIP_CORE();
  13.         p = low_level_input( netif );
  14.         if (p != NULL)
  15.         {
  16.           if (netif->input( p, netif) != ERR_OK )
  17.           {
  18.             pbuf_free(p);
  19.           }
  20.         }
  21.         //UNLOCK_TCPIP_CORE();
  22.       }while(p!=NULL);
  23.     }
  24.   }
  25. }
复制代码
2.另外偶尔出现83848和lwip初始化完成后板子莫名其妙直接复位,怀疑是mpu问题,一直没找到原因。而且同样的固件和板子,不一定什么时候会出现问题。
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2020-10-19 17:43:59 | 显示全部楼层
MPU配置如下
  1. static void MPU_Config( void )
  2. {
  3.   MPU_Region_InitTypeDef MPU_InitStruct;

  4.   /* Disable the MPU */
  5.   HAL_MPU_Disable();

  6.   /* Configure the MPU attributes as Device not cacheable
  7.      for ETH DMA descriptors */
  8.   MPU_InitStruct.Enable           = MPU_REGION_ENABLE;
  9.   MPU_InitStruct.BaseAddress      = 0x30040000;
  10.   MPU_InitStruct.Size             = MPU_REGION_SIZE_256B;
  11.   MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  12.   MPU_InitStruct.IsBufferable     = MPU_ACCESS_BUFFERABLE;
  13.   MPU_InitStruct.IsCacheable      = MPU_ACCESS_NOT_CACHEABLE;
  14.   MPU_InitStruct.IsShareable      = MPU_ACCESS_NOT_SHAREABLE;
  15.   MPU_InitStruct.Number           = MPU_REGION_NUMBER0;
  16.   MPU_InitStruct.TypeExtField     = MPU_TEX_LEVEL0;
  17.   MPU_InitStruct.SubRegionDisable = 0x00;
  18.   MPU_InitStruct.DisableExec      = MPU_INSTRUCTION_ACCESS_ENABLE;

  19.   HAL_MPU_ConfigRegion( &MPU_InitStruct );

  20.   /* Configure the MPU attributes as Cacheable write through
  21.      for LwIP RAM heap which contains the Tx buffers */
  22.   MPU_InitStruct.Enable           = MPU_REGION_ENABLE;
  23.   MPU_InitStruct.BaseAddress      = 0x30044000;
  24.   MPU_InitStruct.Size             = MPU_REGION_SIZE_16KB;
  25.   MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  26.   MPU_InitStruct.IsBufferable     = MPU_ACCESS_NOT_BUFFERABLE;
  27.   MPU_InitStruct.IsCacheable      = MPU_ACCESS_CACHEABLE;
  28.   MPU_InitStruct.IsShareable      = MPU_ACCESS_NOT_SHAREABLE;
  29.   MPU_InitStruct.Number           = MPU_REGION_NUMBER1;
  30.   MPU_InitStruct.TypeExtField     = MPU_TEX_LEVEL0;
  31.   MPU_InitStruct.SubRegionDisable = 0x00;
  32.   MPU_InitStruct.DisableExec      = MPU_INSTRUCTION_ACCESS_ENABLE;

  33.   HAL_MPU_ConfigRegion( &MPU_InitStruct );

  34.   /* Configure the MPU attributes as Cacheable write through
  35.      for LwIP RAM heap which contains the Tx buffers */
  36.   MPU_InitStruct.Enable           = MPU_REGION_ENABLE;
  37.   MPU_InitStruct.BaseAddress      = 0x30020000;
  38.   MPU_InitStruct.Size             = MPU_REGION_SIZE_128KB;
  39.   MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  40.   MPU_InitStruct.IsBufferable     = MPU_ACCESS_NOT_BUFFERABLE;
  41.   MPU_InitStruct.IsCacheable      = MPU_ACCESS_CACHEABLE;
  42.   MPU_InitStruct.IsShareable      = MPU_ACCESS_NOT_SHAREABLE;
  43.   MPU_InitStruct.Number           = MPU_REGION_NUMBER2;
  44.   MPU_InitStruct.TypeExtField     = MPU_TEX_LEVEL0;
  45.   MPU_InitStruct.SubRegionDisable = 0x00;
  46.   MPU_InitStruct.DisableExec      = MPU_INSTRUCTION_ACCESS_ENABLE;

  47.   HAL_MPU_ConfigRegion( &MPU_InitStruct );

  48.   /* Configure the MPU attributes as Cacheable write through
  49.      for LwIP RAM heap which contains the Tx buffers */
  50.   MPU_InitStruct.Enable           = MPU_REGION_ENABLE;
  51.   MPU_InitStruct.BaseAddress      = 0x30000000;
  52.   MPU_InitStruct.Size             = MPU_REGION_SIZE_128KB;
  53.   MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  54.   MPU_InitStruct.IsBufferable     = MPU_ACCESS_NOT_BUFFERABLE;
  55.   MPU_InitStruct.IsCacheable      = MPU_ACCESS_CACHEABLE;
  56.   MPU_InitStruct.IsShareable      = MPU_ACCESS_NOT_SHAREABLE;
  57.   MPU_InitStruct.Number           = MPU_REGION_NUMBER3;
  58.   MPU_InitStruct.TypeExtField     = MPU_TEX_LEVEL0;
  59.   MPU_InitStruct.SubRegionDisable = 0x00;
  60.   MPU_InitStruct.DisableExec      = MPU_INSTRUCTION_ACCESS_ENABLE;

  61.   HAL_MPU_ConfigRegion( &MPU_InitStruct );

  62.   /* Enable the MPU */
  63.   HAL_MPU_Enable( MPU_PRIVILEGED_DEFAULT );
  64. }
复制代码
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115653
QQ
发表于 2020-10-20 01:15:07 | 显示全部楼层
我用的是CMSIS-Driver里的:

  1. static void
  2. ethernetif_input(struct netif *netif)
  3. {
  4.   struct ethernetif *eth = netif->state;
  5.   struct pbuf *p;

  6.   /* move received packet into a new pbuf */
  7.   sys_sem_wait (&eth->sem);
  8.   p = low_level_input(netif);
  9.   sys_sem_signal (&eth->sem);
  10.   /* if no packet could be read, silently ignore this */
  11.   if (p != NULL) {
  12.     /* pass all packets to ethernet_input, which decides what packets it supports */
  13.     if (netif->input(p, netif) != ERR_OK) {
  14.       LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
  15.       pbuf_free(p);
  16.       p = NULL;
  17.     }
  18.     return;
  19.   }
  20.   eth->rx_event = false;
  21. }
复制代码



LwIP网络教程开始更新,使用MDK的RTE环境开发,配套RTX5和FreeRTOS两个版本,更新至第7章(2020-05-03)
http://www.armbbs.cn/forum.php?m ... 5874&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2020-10-20 09:23:04 | 显示全部楼层
eric2013 发表于 2020-10-20 01:15
我用的是CMSIS-Driver里的:

这种相当于对netif加锁吧
这个锁在别的地方还有调用吗?
是不是在netif_add的时候创建的信号量?

如果没有这个线程锁,tftp的时候总会出现数据错误。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-10 06:41 , Processed in 0.220252 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表