[U-Boot] [Question of dm serial] Is pending handler optional?

Hi Simon,
I have questions of driver model serial.
The comment block in include/serial.h states .pending is optional
---------------------------->8------------------------------- * pending() - Check if input/output characters are waiting * * This can be used to return an indication of the number of waiting * characters if the driver knows this (e.g. by looking at the FIFO * level). It is acceptable to return 1 if an indeterminant number * of characters is waiting. * * This method is optional. ----------------------------8<-------------------------------
When I was testing my driver model conversion patch, I noticed ctrlc() function would not work without .pending handler.
The function ctrlc() calls tstc() and if it returns non-zero value, it also calls getc().
If .pending handler is not implemented, tstc() function always return 1, even if no input character is available in UART FIFO; As a result, getc() function will get stuck in
do { err = ops->getc(cur_dev); } while (err == -EAGAIN);
loop.
For example, "help" command does not work.
So, .pending is mandatory, isn't it?
One more question.
The comment says .pending is: Check if input/output characters are waiting
Should .pending check output buffer? or input only?

Hi Masahiro,
On 23 October 2014 09:29, Masahiro YAMADA yamada.m@jp.panasonic.com wrote:
Hi Simon,
I have questions of driver model serial.
The comment block in include/serial.h states .pending is optional
---------------------------->8-------------------------------
- pending() - Check if input/output characters are waiting
- This can be used to return an indication of the number of waiting
- characters if the driver knows this (e.g. by looking at the FIFO
- level). It is acceptable to return 1 if an indeterminant number
- of characters is waiting.
- This method is optional.
----------------------------8<-------------------------------
When I was testing my driver model conversion patch, I noticed ctrlc() function would not work without .pending handler.
The function ctrlc() calls tstc() and if it returns non-zero value, it also calls getc().
If .pending handler is not implemented, tstc() function always return 1, even if no input character is available in UART FIFO; As a result, getc() function will get stuck in
do { err = ops->getc(cur_dev); } while (err == -EAGAIN);
loop.
For example, "help" command does not work.
So, .pending is mandatory, isn't it?
One more question.
The comment says .pending is: Check if input/output characters are waiting
Should .pending check output buffer? or input only?
Yes it is actually mandatory, since we really don't want drivers to block in their getc()/putc() methods.
Output character check is required so we can implement flush. E.g. when we change the baud rate we should flush first.
Regards, Simon

Hi Simon,
2014-10-24 3:34 GMT+09:00 Simon Glass sjg@chromium.org:
Yes it is actually mandatory, since we really don't want drivers to block in their getc()/putc() methods.
If so, could you update this comment block, please?
I think the comment "This method is optional" is misleading.
Output character check is required so we can implement flush. E.g. when we change the baud rate we should flush first.
OK, I will implement this way; .handler returns 0 input and output FIFO are both empty, returns 1 otherwise. Is this correct? (My hardware cannot know how many characters are available in the FIFO.)

Hi Masahiro,
On 23 October 2014 13:10, Masahiro YAMADA yamada.m@jp.panasonic.com wrote:
Hi Simon,
2014-10-24 3:34 GMT+09:00 Simon Glass sjg@chromium.org:
Yes it is actually mandatory, since we really don't want drivers to block in their getc()/putc() methods.
If so, could you update this comment block, please?
OK
I think the comment "This method is optional" is misleading.
Output character check is required so we can implement flush. E.g. when we change the baud rate we should flush first.
OK, I will implement this way; .handler returns 0 input and output FIFO are both empty, returns 1 otherwise. Is this correct? (My hardware cannot know how many characters are available in the FIFO.)
Well in one case (input=true) it should check the input and in the other the output.
Regards, Simon
participants (2)
-
Masahiro YAMADA
-
Simon Glass