You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Oleg Evseev <ev...@gmail.com> on 2020/01/15 21:01:38 UTC

Can't make work shared file for CAN

Hi!

When I use usual file descriptor for can device:
file_open(&CANmodule->file, "/dev/can0", O_RDWR);
everything works, thread blocks if further read() and, when can message
receive, returns correct nbytes.

When I open can0 with
file_open(&file, "/dev/can0", O_RDWR);

it opens correctly and file_ioctl seems to work. But file_read from &file
do not block and return immediately same nbytes as requested with some
garbage in data. But there is no data on CAN bus. Polling (of course with
POLLFILE mask) also do not get blocked and return POLLIN event immediately.

Doing file_detach() as describe in
https://www.nuttx.org/doku.php?id=wiki:nxinternal:detachedfds leads to the
same result.

Any thoughts?

Thanks.

--
With regards,
Oleg Evseev

Re: Can't make work shared file for CAN

Posted by Oleg Evseev <ev...@gmail.com>.
Hi Gregory,

I found the problem. Made an issue:
https://github.com/apache/incubator-nuttx/issues/111

чт, 16 янв. 2020 г. в 00:31, Gregory Nutt <sp...@gmail.com>:

>
> > But file_read on file pointer doesn't work in the same way as read on
> file
> > descriptor, even if it is in the same thread - right after file_open!
>
> That would be surprising because read() just calls file_read(). I would
> expect the behaviors to be the same.
>
> If there is a semaphore locking issue, I would first be suspicious of
> drivers/can/can.c.
>
> Did you try enabling CAN debug.  Perhaps, if you are lucky, it will show
> something of interest.
>
>

Re: Can't make work shared file for CAN

Posted by Gregory Nutt <sp...@gmail.com>.
> But file_read on file pointer doesn't work in the same way as read on file
> descriptor, even if it is in the same thread - right after file_open!

That would be surprising because read() just calls file_read(). I would 
expect the behaviors to be the same.

If there is a semaphore locking issue, I would first be suspicious of 
drivers/can/can.c.

Did you try enabling CAN debug.  Perhaps, if you are lucky, it will show 
something of interest.


Re: Can't make work shared file for CAN

Posted by Oleg Evseev <ev...@gmail.com>.
Hi!

Is it really matters? I think the issue is more about file descriptors,
file pointers and so on.
CAN is configured with extended ID. Yes, I did use CAN app from examples,
it works.
Implementation in my own app also works fine if I use file descriptor when
opened /dev/can0. In different threads of one  task group - no problems.

Now I want to also send messages from another thread from different task
group, but  file descriptors cannot be used by different tasks. So I'm
trying to use internal OS interface from
https://www.nuttx.org/doku.php?id=wiki:nxinternal:detachedfds

But file_read on file pointer doesn't work in the same way as read on file
descriptor, even if it is in the same thread - right after file_open!

чт, 16 янв. 2020 г. в 00:11, Disruptive Solutions <
disruptivesolutionsnl@gmail.com>:

> Oleg: do you use an extended ID or standard ID? And do you use the CAN app
> from examples?
>
> Verstuurd vanaf mijn iPhone
>
> > Op 15 jan. 2020 om 22:02 heeft Oleg Evseev <ev...@gmail.com> het
> volgende geschreven:
> >
> > Hi!
> >
> > When I use usual file descriptor for can device:
> > file_open(&CANmodule->file, "/dev/can0", O_RDWR);
> > everything works, thread blocks if further read() and, when can message
> > receive, returns correct nbytes.
> >
> > When I open can0 with
> > file_open(&file, "/dev/can0", O_RDWR);
> >
> > it opens correctly and file_ioctl seems to work. But file_read from &file
> > do not block and return immediately same nbytes as requested with some
> > garbage in data. But there is no data on CAN bus. Polling (of course with
> > POLLFILE mask) also do not get blocked and return POLLIN event
> immediately.
> >
> > Doing file_detach() as describe in
> > https://www.nuttx.org/doku.php?id=wiki:nxinternal:detachedfds leads to
> the
> > same result.
> >
> > Any thoughts?
> >
> > Thanks.
> >
> > --
> > With regards,
> > Oleg Evseev
>

Re: Can't make work shared file for CAN

Posted by Disruptive Solutions <di...@gmail.com>.
Oleg: do you use an extended ID or standard ID? And do you use the CAN app from examples?

Verstuurd vanaf mijn iPhone

> Op 15 jan. 2020 om 22:02 heeft Oleg Evseev <ev...@gmail.com> het volgende geschreven:
> 
> Hi!
> 
> When I use usual file descriptor for can device:
> file_open(&CANmodule->file, "/dev/can0", O_RDWR);
> everything works, thread blocks if further read() and, when can message
> receive, returns correct nbytes.
> 
> When I open can0 with
> file_open(&file, "/dev/can0", O_RDWR);
> 
> it opens correctly and file_ioctl seems to work. But file_read from &file
> do not block and return immediately same nbytes as requested with some
> garbage in data. But there is no data on CAN bus. Polling (of course with
> POLLFILE mask) also do not get blocked and return POLLIN event immediately.
> 
> Doing file_detach() as describe in
> https://www.nuttx.org/doku.php?id=wiki:nxinternal:detachedfds leads to the
> same result.
> 
> Any thoughts?
> 
> Thanks.
> 
> --
> With regards,
> Oleg Evseev