This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: how to set overtime to serial port block read/write?
- From: wb ning <helloningwb at gmail dot com>
- To: Jonathan Larmour <jifl at jifvik dot org>
- Cc: ecos-discuss at ecos dot sourceware dot org
- Date: Wed, 7 Oct 2009 10:44:15 +0800
- Subject: Re: [ECOS] how to set overtime to serial port block read/write?
- References: <44185a820909260058k6f820a1aheb6f37b2e4e868fc@mail.gmail.com> <4ABFDF2D.6070709@jifvik.org>
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