public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] how to set overtime to serial port block read/write?
@ 2009-09-26  7:58 wb ning
  2009-09-27 21:55 ` Jonathan Larmour
  0 siblings, 1 reply; 6+ messages in thread
From: wb ning @ 2009-09-26  7:58 UTC (permalink / raw)
  To: ecos-discuss

Hi, everyone:
    I think it's a common question, but i can't find the answer. I
think block read/write of serial port need a overtime, if time exceeds
that, i can made my program don't
wait any longer, if i can't set overtime, maybe i send a command and
wait for response, but when some error occurs and the reponse is lost,
my thread will wait forever.

Do anyone have find how to send overtime to block read/write? Please help me.

Thanks.
wenbo

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] how to set overtime to serial port block read/write?
  2009-09-26  7:58 [ECOS] how to set overtime to serial port block read/write? wb ning
@ 2009-09-27 21:55 ` Jonathan Larmour
  2009-09-28  6:42   ` wb ning
  2009-10-07  2:44   ` wb ning
  0 siblings, 2 replies; 6+ messages in thread
From: Jonathan Larmour @ 2009-09-27 21:55 UTC (permalink / raw)
  To: wb ning; +Cc: ecos-discuss

wb ning wrote:
> Hi, everyone:
>     I think it's a common question, but i can't find the answer. I
> think block read/write of serial port need a overtime, if time exceeds
> that, i can made my program don't
> wait any longer, if i can't set overtime, maybe i send a command and
> wait for response, but when some error occurs and the reponse is lost,
> my thread will wait forever.
> 
> Do anyone have find how to send overtime to block read/write? Please help me.

By overtime, I assume you mean a timeout. You can use a kernel alarm and 
from the alarm callback (after the timeout) use the 
CYG_IO_GET_CONFIG_SERIAL_ABORT config key with cyg_io_get_config(). Look 
at the eCos documentation for how to use kernel alarms, and 
cyg_io_get_config().

Alternatively don't forget that with the file I/O package, you can use 
select() with serial drivers (e.g. if opened as filename "/dev/ser0").

Jifl
-- 
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] how to set overtime to serial port block read/write?
  2009-09-27 21:55 ` Jonathan Larmour
@ 2009-09-28  6:42   ` wb ning
  2009-10-07  2:44   ` wb ning
  1 sibling, 0 replies; 6+ messages in thread
From: wb ning @ 2009-09-28  6:42 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

Thanks. that really helps.

2009/9/28 Jonathan Larmour <jifl@jifvik.org>:
> wb ning wrote:
>>
>> Hi, everyone:
>>    I think it's a common question, but i can't find the answer. I
>> think block read/write of serial port need a overtime, if time exceeds
>> that, i can made my program don't
>> wait any longer, if i can't set overtime, maybe i send a command and
>> wait for response, but when some error occurs and the reponse is lost,
>> my thread will wait forever.
>>
>> Do anyone have find how to send overtime to block read/write? Please help
>> me.
>
> By overtime, I assume you mean a timeout. You can use a kernel alarm and
> from the alarm callback (after the timeout) use the
> CYG_IO_GET_CONFIG_SERIAL_ABORT config key with cyg_io_get_config(). Look at
> the eCos documentation for how to use kernel alarms, and
> cyg_io_get_config().
>
> Alternatively don't forget that with the file I/O package, you can use
> select() with serial drivers (e.g. if opened as filename "/dev/ser0").
>
> Jifl
> --
> --["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] how to set overtime to serial port block read/write?
  2009-09-27 21:55 ` Jonathan Larmour
  2009-09-28  6:42   ` wb ning
@ 2009-10-07  2:44   ` wb ning
  2009-10-07  3:17     ` Jonathan Larmour
  1 sibling, 1 reply; 6+ messages in thread
From: wb ning @ 2009-10-07  2:44 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

I use cyg_io_get_config(io_handle, CYG_IO_GET_CONFIG_SERIAL_ABORT, 0,
&len) as you said. The return code of this function is 0, but seems my
cyg_io_read() seems still block there. I cannot find where the mistake
is, i used the test file at $ECOS_REPOSITORY/io/serial/v3_0/tests/.
And my code is like this:

//ser0 is initialize here. i omit these codes. i tested it alone, and it's ok.
// these following code are the same as the test example from ecos,
except that i add some hint message to help me debug.
static void
do_abort(void *handle)
{
    printf("%s","now it is timeout.");  // my code can run to here and
print the hint message.
    cyg_io_handle_t io_handle = (cyg_io_handle_t)handle;
    cyg_uint32 len = 1;  // Need something here ( i don't know here i
need what, it's the ecos comment,  do i need something here?)
    Cyg_ErrNo no = cyg_io_get_config(io_handle,
CYG_IO_GET_CONFIG_SERIAL_ABORT, 0, &len);
    printf("Arrive here,no=%d",no); // my code can run to here also,
and the "no" equals 0.
    aborted = 1;
}

#include "timeout.inl"
// Read with timeout (__t = timeout in ticks, int* __r = result)
#define Tcyg_io_read_timeout(__h, __d, __l, __t, __r)           \
    CYG_MACRO_START                                             \
    int __res;                                                  \
    printf("%s"," Begin to do time."); \     //my code can run to here
    r_stamp = timeout((__t), do_abort, (__h));                  \
    printf("%s","Time is not up now, this message will be print before
messages in do_abort function "); \
    __res = cyg_io_read((__h), (__d), (__l));                   \
    printf("If i arrive here, this means the cyg_io_read() sentence
before is cancelled successfully,and the return code is :%d",__res); \
 //but my code can go to here, and the hint message will never show.
    if (ENOERR != __res && -EINTR != __res) {                   \
                 printf("%s: %d","cyg_io_read/timeout failed", __res);        \
    }                                                           \
    *(__r) = __res;                                             \
    untimeout(r_stamp);                                         \
    CYG_MACRO_END

the ecos documentation says that if cyg_io_get_config(io_handle,
CYG_IO_GET_CONFIG_SERIAL_ABORT, 0, &len) , the pending read will be
cancelled. but why cannot i get this result? Do i need to modify the
configuration of ecos or is there something wrong in my code? Please
help me.
Thanks in advance.

2009/9/28 Jonathan Larmour <jifl@jifvik.org>:
> wb ning wrote:
>>
>> Hi, everyone:
>>    I think it's a common question, but i can't find the answer. I
>> think block read/write of serial port need a overtime, if time exceeds
>> that, i can made my program don't
>> wait any longer, if i can't set overtime, maybe i send a command and
>> wait for response, but when some error occurs and the reponse is lost,
>> my thread will wait forever.
>>
>> Do anyone have find how to send overtime to block read/write? Please help
>> me.
>
> By overtime, I assume you mean a timeout. You can use a kernel alarm and
> from the alarm callback (after the timeout) use the
> CYG_IO_GET_CONFIG_SERIAL_ABORT config key with cyg_io_get_config(). Look at
> the eCos documentation for how to use kernel alarms, and
> cyg_io_get_config().
>
> Alternatively don't forget that with the file I/O package, you can use
> select() with serial drivers (e.g. if opened as filename "/dev/ser0").
>
> Jifl
> --
> --["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] how to set overtime to serial port block read/write?
  2009-10-07  2:44   ` wb ning
@ 2009-10-07  3:17     ` Jonathan Larmour
       [not found]       ` <44185a820910070151l673d3ab9r7f68c7adef7cb3ed@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Larmour @ 2009-10-07  3:17 UTC (permalink / raw)
  To: wb ning; +Cc: ecos-discuss

wb ning wrote:
> I use cyg_io_get_config(io_handle, CYG_IO_GET_CONFIG_SERIAL_ABORT, 0,
> &len) as you said. The return code of this function is 0, but seems my
> cyg_io_read() seems still block there. I cannot find where the mistake
> is, i used the test file at $ECOS_REPOSITORY/io/serial/v3_0/tests/.
> And my code is like this:

Your code looks ok to me. Have you been able to debug with GDB and find 
out where the thread doing the read has stopped? A backtrace would be very 
useful.

Jifl
-- 
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] how to set overtime to serial port block read/write?
       [not found]       ` <44185a820910070151l673d3ab9r7f68c7adef7cb3ed@mail.gmail.com>
@ 2009-10-07 19:27         ` Jonathan Larmour
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Larmour @ 2009-10-07 19:27 UTC (permalink / raw)
  To: wb ning; +Cc: eCos discussion

[Please keep things off the list for the benefit of anyone searching the 
mailing list archives to the solution for a problem like this]
wb ning wrote:
> Thanks to Jonathan Larmour. I found the problem by debugging the ecos
> sourcecode. The reason is that i have set the  "Buffer size for At91
> serial" to 0. If i set the buffer size to a non-zero value, i will got
> the right result. In the ecos sourcecode serial_get_config() has
> following statements:
>     case CYG_IO_GET_CONFIG_SERIAL_ABORT:
>         // Abort any outstanding I/O, including blocked reads
>         // Caution - assumed to be called from 'timeout' (i.e. DSR) code
>         if (in_cbuf->len != 0) {
>             in_cbuf->abort = true;
>             cyg_drv_cond_broadcast(&in_cbuf->wait);
>         }
>         if (out_cbuf->len != 0) {
>             out_cbuf->abort = true;
>             cyg_drv_cond_broadcast(&out_cbuf->wait);
>         }
>         break;
> So i will not pass the if statement, i don't know why shoud so this
> judge, if i set serial buffer to 0, i can't use the timeout function,
> and if i don't set serial buffer to 0,  my application may have some
> trouble. Are there have another timeout version for serial buffer 0
> size?

A serial buffer size of 0 means to poll. That's because there's no buffer 
space whatsoever to store data received by an interrupt. This is handled 
specially in the serial code, and doesn't check for aborts, which is 
probably a bug - please report this to bugzilla at 
http://bugs.ecos.sourceare.org/

Theoretically, all you need to do instead is set the buffer size to 1.

In practice, for the AT91, that may be quite unreliable as it needs more 
extensive use of buffering than normal UARTs due to the hardware 
properties - it uses DMA. You're likely to get dropped characters at 
anything other than very slow line speeds.

Jifl
-- 
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

end of thread, other threads:[~2009-10-07 19:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-26  7:58 [ECOS] how to set overtime to serial port block read/write? wb ning
2009-09-27 21:55 ` Jonathan Larmour
2009-09-28  6:42   ` wb ning
2009-10-07  2:44   ` wb ning
2009-10-07  3:17     ` Jonathan Larmour
     [not found]       ` <44185a820910070151l673d3ab9r7f68c7adef7cb3ed@mail.gmail.com>
2009-10-07 19:27         ` Jonathan Larmour

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).