stm32 lwip demo中的Delay函数是否错了?

[复制链接]
 楼主| test 发表于 2010-1-23 18:11 | 显示全部楼层 |阅读模式
wIP TCP/IP stack demonstration for STM32F107xx connectivity line microcontrollers 演示程序中, 在main.c 文件里,有一段用systick 延时的函数
void Delay(uint32_t nCount)
{
  /* Capture the current local time */
  timingdelay = LocalTime + nCount;  

  /* wait until the desired delay finish */  
  while(timingdelay > LocalTime)
  {     
  }
}


LocalTime处于 0xfff0时,  需要延时 nCount = 0x100 时长,
在这个函数中,不是没有经过延时就return了吗?
是否这里错误了?
sunmonth 发表于 2010-1-23 18:38 | 显示全部楼层
timingdelay是32位整数,还是64位?
huatong 发表于 2010-1-23 18:54 | 显示全部楼层
本帖最后由 huatong 于 2010-1-23 19:08 编辑

??
 楼主| test 发表于 2010-1-23 22:43 | 显示全部楼层
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;
xsgy123 发表于 2010-1-24 14:06 | 显示全部楼层
很显然是32位的
dfsa 发表于 2010-1-24 21:34 | 显示全部楼层
跟位数有关系吗
IJK 发表于 2010-1-25 09:35 | 显示全部楼层
LocalTime 是32位的,最多只是偶尔出现LZ担心的问题。另外,还要看代码是怎么使用LocalTime 的,如果常对它清0,就不会出问题。
香水城 发表于 2010-1-25 09:47 | 显示全部楼层
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;
test 发表于 2010-1-23 22:43


如果按照4楼的说法,LocalTime的每一步表示10ms,如果不清零,则需要497天之后LocalTime才会溢出,出现楼主担心的情况。
lut1lut 发表于 2010-1-25 11:19 | 显示全部楼层
是有逻辑问题。

不过demo始终是demo。如果LZ觉得不适合自己的应用,改改好了。
TuBie 发表于 2010-1-26 18:08 | 显示全部楼层
感觉这个函数正确啊,先满足循环条件,随着LocalTime值的增加,某个时刻不满足循环条件,就退出了,达到了延时的效果。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

27

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部