Skip to content

drivers/cc110x: Adapt cc110x netdev impl to changed rcv event handling#2177

Closed
fnack wants to merge 5 commits intoRIOT-OS:masterfrom
fnack:cc110x_rcv
Closed

drivers/cc110x: Adapt cc110x netdev impl to changed rcv event handling#2177
fnack wants to merge 5 commits intoRIOT-OS:masterfrom
fnack:cc110x_rcv

Conversation

@fnack
Copy link
Copy Markdown
Member

@fnack fnack commented Dec 10, 2014

This PR adapts the CC110X netdev implementation to the updated receive event handling sequence for netdev (see description).

On packet reception, in the interrupt routine the packet is read from the CC110X and stored in the device driver's RX-Buffer. The event handler thread is notified of the receive event with a msg and the interrupt routine is left. The event handler thread then calls _cc110x_event with the fitting event type. In the event function the packet is read from the device driver's RX-Buffer and the registered callback is executed. This sequence is needed to make sure that the callback execution is taking place in the event handler thread.

The PR is depending on #2163.

@fnack fnack added Area: drivers Area: Device drivers State: waiting for other PR State: The PR requires another PR to be merged first Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. labels Dec 10, 2014
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you ignore this oO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly didn't know what to do with it. Simply check it with

if (dev != &cc110x_dev) {
    return;
}

???

That's why I walked the easy way and did exactly the same you did in #1733 ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that, given that your it is the first driver post-introduction of netdev, your driver might support multiple instances of netdev. #1733 is just a wrapper for the old driver architecture (because I was lazy, yes ^^).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't really understood yet what the benefits of having multiple netdev "instances" are? Could you explain this with a proper use-case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine a board with two cc110x interfaces on different frequencies or channels.

@fnack
Copy link
Copy Markdown
Member Author

fnack commented Dec 10, 2014

I took a slightly different approach than you (@authmillenon) did in #1733. I read the received packet already in the interrupt routine (as it was done before with the transceiver module) and afterwards notify the event handling thread. I think this is a better approach than to completely rely on the event handling thread for receiving the packet from the device (we cannot be sure that the event handling thread is the one taking over after the interrupt routine and the packet might get lost).

This is something that should also be discussed with @haukepetersen (and maybe @thomaseichinger) because it looks like it differs from your basic flow description. Nevertheless, I think the slightly longer interrupt routine is justified by the gain of certainty that the packet is read from the device timely.

@LudwigKnuepfer
Copy link
Copy Markdown
Member

@fnack how large are the packets / how large is the overhead?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 11, 2014

I'm not quite sure, but instinctively I would say that with this kind of implementation you would risk to be easily DoS'd since you basically would never leave the ISR when you are flooded. I think the risk of not being able to respond outweighs the risk of loosing data because the OS was not fast enough. Making sure everything is received that should be is the task of the Link Layer (aka MAC Layer sometimes in our lingo) or the Transport Layer, but should never be the task of the driver (except the SoC offers some kind of congestion/packet loss control, of course, which is not the case for the cc1100 iirc).

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 11, 2014

+ You also loose data if you are in the ISR too long, because it can't react if it's working.

@LudwigKnuepfer
Copy link
Copy Markdown
Member

Why wouldn't it leave the ISR?
If it only reads one packet, and returns to user space then, this should not happen.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 11, 2014

Scenario (copy in ISR):
RX -> copy -> RX -> copy -> RX -> copy …
vs. (copy in thread, notified by ISR)
RX -> notify -> co -> RX -> notify -> py -> do st -> RX -> notify -> uff -> copy -> do stuff -> copy -> do stuff.

@thomaseichinger
Copy link
Copy Markdown
Member

@fnack I'm undecided on this as different hardware provides different features.

  • at86rf2xx provides an option to drop all packets while the one in the RXFIFO isn't read. (not deployed)
  • cc2420 has 128 bytes RXFIFO and fills it up. A discussion about the handling was in boards: Fix CC2420 RXFIFO overflow #1304. In either case (read in ISR or not) you can easily DoS this by sending many small packets.

I didn't really look into cc1100's features yet.

@authmillenon

RX -> notify -> co -> RX -> notify -> py -> do st -> RX -> notify -> uff -> copy -> do stuff -> copy -> do stuff

For this to work, at least for the cc2420, you'd have to disable radio interrupts, else, as mentioned above, when firing with minimal sized packets the notified thread could be outperformed by the number of interrupts. (And to assure the received data is valid)

To sum up, in either case we could/will loose data but, although currently implemented differently for rf2xx, I tend to support the notify strategy since in the not "evil" case we can react to other events more promptly.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 11, 2014

(And to assure the received data is valid)

To assess that is also the job of an upper layer IMHO.

@thomaseichinger
Copy link
Copy Markdown
Member

(And to assure the received data is valid)

To assess that is also the job of an upper layer IMHO.

Also yes, the radio driver should assure to receive valid and complete 15.4 packets.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Dec 11, 2014

The cc1100 is not a 15.4 transceiver ;-)

@thomaseichinger
Copy link
Copy Markdown
Member

@authmillenon Yes, came to my mind as I pressed the button. As stated above I'm not familiar with this device but shouldn't it still do some CRC checking etc?

@fnack
Copy link
Copy Markdown
Member Author

fnack commented Dec 11, 2014

Yes, the CC110x does CRC checking.

@fnack
Copy link
Copy Markdown
Member Author

fnack commented Dec 13, 2014

I thought about it again and in some cases multiple interrupts are preferable/needed to handle packet reception from the device (for example when the packet length exceeds the CCxxxx's RXFIFO). In these cases handling the reception in the link layer thread using notifications with different event-types is probably the better approach. I think I'll adapt my implementation, but nonetheless I'd really like to hear @haukepetersen's opinion on this topic as well.

@haukepetersen
Copy link
Copy Markdown
Contributor

I have the same opinion: the (time consuming) data transfers should be done in the thread context. This way no other function with time critical operations will be disturbed by this long running interrupt. So the way I would imagine this is:

  1. data arrives at the radio device
  2. radio triggers external interrupt
  3. in the RX ISR: send message to thread
  4. thread is woken up/receives message from RX ISR
  5. thread runs event(xx) call
  6. event call takes care of the data transfer from the radio to the packet buffer

In case there are different events to be handled (receptions of data on multiple FIFOs...), the argument of the event callback can be used to tell the driver what to do.

@fnack
Copy link
Copy Markdown
Member Author

fnack commented Dec 30, 2014

I'll close this PR in favor of #2237 and because it was based on the old objectives from #2163.

@fnack fnack closed this Dec 30, 2014
@fnack fnack deleted the cc110x_rcv branch January 9, 2015 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. State: waiting for other PR State: The PR requires another PR to be merged first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants