public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] RedBoot gets() implimentation question
@ 2001-01-18 14:12 Grant Edwards
  2001-01-18 15:08 ` Gary Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2001-01-18 14:12 UTC (permalink / raw)
  To: ecos-discuss

If you don't mind, I've got a couple questions about the
implimentation of gets() in RedBoot:

========================================================================
gets(char *buf, int buflen, int timeout)
{
[...]

    while (true) {
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
        if (script && *script) {
            c = *script++;
        } else
#endif
        if ((timeout > 0) && (ptr == buf)) {
            mon_set_read_char_timeout(50);
            while (timeout > 0) {
                res = mon_read_char_with_timeout(&c);
                if (res) {
                    // Got a character
                    break;
                }
                timeout -= 50;
            }
            if (res == false) {
                return _GETS_TIMEOUT;  // Input timed out
            }
        } else {
            mon_read_char(&c);
        }
        *ptr = '\0';
        switch (c) {
[...]        
========================================================================

The test ((timeout > 0) && (ptr == buf)) means that the timeout
only applies for the first character, and once we've received
that first character we use blocking reads until we see an
end-of-line?

That means that network polling stops and TCP sockets (and
associated timers) go dead between between the time the first
character is received and the newline is received?  [I don't
think that's a problem, but it's something to keep in mind.]


I'm also curious about the inner loop:

            mon_set_read_char_timeout(50);
            while (timeout > 0) {
                res = mon_read_char_with_timeout(&c);
                if (res) {
                    // Got a character
                    break;
                }
                timeout -= 50;
            }

Would the following be equivalent?

            mon_set_read_char_timeout(timeout);
            res = mon_read_char_with_timeout(&c);

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [ECOS] RedBoot gets() implimentation question
  2001-01-18 14:12 [ECOS] RedBoot gets() implimentation question Grant Edwards
@ 2001-01-18 15:08 ` Gary Thomas
  2001-01-19  7:31   ` Grant Edwards
  0 siblings, 1 reply; 4+ messages in thread
From: Gary Thomas @ 2001-01-18 15:08 UTC (permalink / raw)
  To: Grant Edwards; +Cc: ecos-discuss

On 18-Jan-2001 Grant Edwards wrote:
> 
> If you don't mind, I've got a couple questions about the
> implimentation of gets() in RedBoot:
> 
> ========================================================================
> gets(char *buf, int buflen, int timeout)
> {
> [...]
> 
>     while (true) {
>#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
>         if (script && *script) {
>             c = *script++;
>         } else
>#endif
>         if ((timeout > 0) && (ptr == buf)) {
>             mon_set_read_char_timeout(50);
>             while (timeout > 0) {
>                 res = mon_read_char_with_timeout(&c);
>                 if (res) {
>                     // Got a character
>                     break;
>                 }
>                 timeout -= 50;
>             }
>             if (res == false) {
>                 return _GETS_TIMEOUT;  // Input timed out
>             }
>         } else {
>             mon_read_char(&c);
>         }
>         *ptr = '\0';
>         switch (c) {
> [...]        
> ========================================================================
> 
> The test ((timeout > 0) && (ptr == buf)) means that the timeout
> only applies for the first character, and once we've received
> that first character we use blocking reads until we see an
> end-of-line?
> 
> That means that network polling stops and TCP sockets (and
> associated timers) go dead between between the time the first
> character is received and the newline is received?  [I don't
> think that's a problem, but it's something to keep in mind.]
> 

Correct.  This was a design choice - avoid the overhead of polling
for potential new TCP connections (all that's really going on here)
once data starts coming in.

> 
> I'm also curious about the inner loop:
> 
>             mon_set_read_char_timeout(50);
>             while (timeout > 0) {
>                 res = mon_read_char_with_timeout(&c);
>                 if (res) {
>                     // Got a character
>                     break;
>                 }
>                 timeout -= 50;
>             }
> 
> Would the following be equivalent?
> 
>             mon_set_read_char_timeout(timeout);
>             res = mon_read_char_with_timeout(&c);
> 

Yes and no.  Yes - the overall timeout would be the same.  No since
we want to go back and check for new TCP connections as often as is
reasonable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] RedBoot gets() implimentation question
  2001-01-18 15:08 ` Gary Thomas
@ 2001-01-19  7:31   ` Grant Edwards
  2001-01-19  7:43     ` Gary Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2001-01-19  7:31 UTC (permalink / raw)
  To: Gary Thomas; +Cc: ecos-discuss

On Thu, Jan 18, 2001 at 04:08:52PM -0700, Gary Thomas wrote:

> > That means that network polling stops and TCP sockets (and
> > associated timers) go dead between between the time the first
> > character is received and the newline is received?  [I don't
> > think that's a problem, but it's something to keep in mind.]
> 
> Correct.  This was a design choice - avoid the overhead of polling
> for potential new TCP connections (all that's really going on here)
> once data starts coming in.

You must be able to type a lot faster than me.  ;)

> > I'm also curious about the inner loop:
> > 
> >             mon_set_read_char_timeout(50);
> >             while (timeout > 0) {
> >                 res = mon_read_char_with_timeout(&c);
> >                 if (res) {
> >                     // Got a character
> >                     break;
> >                 }
> >                 timeout -= 50;
> >             }
> > 
> > Would the following be equivalent?
> > 
> >             mon_set_read_char_timeout(timeout);
> >             res = mon_read_char_with_timeout(&c);
> 
> Yes and no.  Yes - the overall timeout would be the same.  No since
> we want to go back and check for new TCP connections as often as is
> reasonable.

I can't figure out where the check for TCP connections is done.
Is mon_read_char_with_timeout() supposed to call __tcp_poll()
in some way that I've broken?  My tests with ping seem to
verify that on my board TCP polling is done once every 250ms
(the value of timeout) while waiting for the first character of
a command line.

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] RedBoot gets() implimentation question
  2001-01-19  7:31   ` Grant Edwards
@ 2001-01-19  7:43     ` Gary Thomas
  0 siblings, 0 replies; 4+ messages in thread
From: Gary Thomas @ 2001-01-19  7:43 UTC (permalink / raw)
  To: Grant Edwards; +Cc: ecos-discuss

On 19-Jan-2001 Grant Edwards wrote:
> On Thu, Jan 18, 2001 at 04:08:52PM -0700, Gary Thomas wrote:
> 
>> > That means that network polling stops and TCP sockets (and
>> > associated timers) go dead between between the time the first
>> > character is received and the newline is received?  [I don't
>> > think that's a problem, but it's something to keep in mind.]
>> 
>> Correct.  This was a design choice - avoid the overhead of polling
>> for potential new TCP connections (all that's really going on here)
>> once data starts coming in.
> 
> You must be able to type a lot faster than me.  ;)
> 
>> > I'm also curious about the inner loop:
>> > 
>> >             mon_set_read_char_timeout(50);
>> >             while (timeout > 0) {
>> >                 res = mon_read_char_with_timeout(&c);
>> >                 if (res) {
>> >                     // Got a character
>> >                     break;
>> >                 }
>> >                 timeout -= 50;
>> >             }
>> > 
>> > Would the following be equivalent?
>> > 
>> >             mon_set_read_char_timeout(timeout);
>> >             res = mon_read_char_with_timeout(&c);
>> 
>> Yes and no.  Yes - the overall timeout would be the same.  No since
>> we want to go back and check for new TCP connections as often as is
>> reasonable.
> 
> I can't figure out where the check for TCP connections is done.
> Is mon_read_char_with_timeout() supposed to call __tcp_poll()
> in some way that I've broken?  My tests with ping seem to
> verify that on my board TCP polling is done once every 250ms
> (the value of timeout) while waiting for the first character of
> a command line.

No, it actually only happens in "main.c" while RedBoot is waiting for
the command line itself.

    while (true) {
        if (prompt) {
            printf("RedBoot> ");
            prompt = false;
        }
        res = gets(line, sizeof(line), 250);
        if (res == _GETS_TIMEOUT) {
            // No input arrived
#ifdef CYGPKG_REDBOOT_NETWORKING
            if (have_net) {
                // Check for incoming TCP debug connection
                net_io_test();
            }
#endif
        } else {
            if (res == _GETS_GDB) {
                // Special case of '$' - need to start GDB protocol
                CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
#ifdef HAL_ARCH_PROGRAM_NEW_STACK
                HAL_ARCH_PROGRAM_NEW_STACK(breakpoint);
#else
                breakpoint();  // Get GDB stubs started, with a proper environment, etc.
#endif
            } else {
                if (strlen(line) > 0) {
                    if ((cmd = parse(line, &argc, &argv[0])) != (struct cmd *)0) {
                        (cmd->fun)(argc, argv);
                    } else {
                        printf("** Error: Illegal command: \"%s\"\n", argv[0]);
                    }
                }
                prompt = true;
            }
        }
    }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-01-19  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-18 14:12 [ECOS] RedBoot gets() implimentation question Grant Edwards
2001-01-18 15:08 ` Gary Thomas
2001-01-19  7:31   ` Grant Edwards
2001-01-19  7:43     ` Gary Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).