From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew F. Davis Date: Fri, 26 Aug 2016 08:40:00 -0500 Subject: [U-Boot] [PATCH] common/xyzModem.c: Fix delay timeout calculation In-Reply-To: <67dce890-d80a-f0c1-59af-1e333441f15d@denx.de> References: <20160825184333.2296-1-afd@ti.com> <67dce890-d80a-f0c1-59af-1e333441f15d@denx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 08/26/2016 12:18 AM, Stefan Roese wrote: > On 25.08.2016 20:43, Andrew F. Davis wrote: >> When waiting for input in CYGACC_COMM_IF_GETC_TIMEOUT we delay 2 >> seconds by incrementing and checking a counter variable every 20 >> uSeconds. The overhead in the loop calling tstc() millions of times >> causes the timeout to be closer to 20 seconds. Delay longer per iteration >> to reduce overhead and bring the timeout back closer to the correct time. >> >> Signed-off-by: Andrew F. Davis >> --- >> common/xyzModem.c | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/common/xyzModem.c b/common/xyzModem.c >> index 5656aac..c3f2afc 100644 >> --- a/common/xyzModem.c >> +++ b/common/xyzModem.c >> @@ -71,11 +71,10 @@ typedef int cyg_int32; >> static int >> CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c) >> { >> -#define DELAY 20 >> unsigned long counter = 0; >> - while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT * 1000 / DELAY)) >> + while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT)) >> { >> - udelay (DELAY); >> + mdelay (1); Thinking about this more, all we have to change is to remove the "* 1000" and switch to mdelay. That's a smaller change and results in an even more correct timeout time. CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c) { #define DELAY 20 unsigned long counter = 0; - while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT * 1000 / DELAY)) + while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT / DELAY)) { - udelay (DELAY); + mdelay (DELAY); counter++; } >> counter++; >> } >> if (tstc ()) > > Reviewed-by: Stefan Roese > > Thanks, > Stefan