This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Problem with SCANF function
Jonathan Larmour-2 wrote:
>
> On 12/03/10 13:59, bkankur wrote:
>>
>> Dear Friends,
>>
>> I am using polling based serial driver by specifying buffer
>> size(cbuf->len)
>> to zero through configuration tool.
>> When I call scanf function from application layer, I found that it is
>> calling serial_read function from file
>> packages\io\serial\current\src\common\serial.c.
>>
>> For given function, static Cyg_ErrNo serial_read(cyg_io_handle_t handle,
>> void *_buf, cyg_uint32 *len)
>> I printed the argument values and found that *len=-1, which makes "while
>> (size++ < *len) " condition true always and my program gets stuck there.
>
> That certainly doesn't seem right. *len should not be -1 while in the loop
> in serial_read (presumably that's the loop you mean). That would imply
> it's been called with *len==-1. But the libc stream support should be
> using a positive integer of at least 1. (refill_read_buffer() in
> stream.cxx is the key here.)
>
> Just in case, you may want to increase your stack sizes in case
> something's getting scribbled on due to stack overflow.
>
>> I did similar thing for serial_write and I got *len value correct when I
>> call Printf function from user application.
>>
>> I try to debug the /libc/sdio/current/src/input/scanf.cxx, but I couldn't
>> understand it. Can anyone please guide me where to look at for the error,
>> in
>> my case *len = -1 which should be greater than 1 ?
>
> Double check what the value of *len is at the entry to serial_read. You
> can also try stepping through
> Cyg_StdioStream::refill_read_buffer() to see what it's calling it with.
> Jifl
>
Dear Jonathan,
Thank you for your response.
You are true, I found the problem in refill_read_buffer() function. As I
dont have JTAG or debugger, I try to debug on my own and found the problem
at statement "len = io_buf.get_buffer_addr_to_write( (cyg_uint8**)&buffer
)".
A strange thing happens, when I modified the code as below, still, I got the
len = -1, as shown in the output.
len = io_buf.get_buffer_addr_to_write( (cyg_uint8**)&buffer );
if(len <= 0)
len = 10;
Complete: serial_read with debug statment can be found at
http://pastebin.com/xQsTG4Wj
Complete: refill_read_buffer with debug statement can be found at
http://pastebin.com/mijXBAqY
Program Output:
under serial_read
Before While size 0 len -1
size 1 len -1
polling base 1 4
size 2 len -1
polling base 2 5
Kindly let me know if you need further information.
Thank you,
Have a Good Day,
Ankur
--
View this message in context: http://old.nabble.com/Problem-with-SCANF-function-tp27874746p27887562.html
Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss