Skip to content

netdev: add event handler thread as member of netdev_t#2163

Closed
miri64 wants to merge 7 commits intoRIOT-OS:masterfrom
miri64:netdev/api/driver-set_event_handler
Closed

netdev: add event handler thread as member of netdev_t#2163
miri64 wants to merge 7 commits intoRIOT-OS:masterfrom
miri64:netdev/api/driver-set_event_handler

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Dec 8, 2014

To send NETDEV_MSG_EVENT_TYPE a target PID (event handler) has to be known. This API extension allows to set one.

Functionality for existing drivers will follow in separate PRs.

@miri64 miri64 added Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Area: network Area: Networking Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Dec 8, 2014
@miri64 miri64 added this to the Release 2014.12 milestone Dec 8, 2014
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 8, 2014

@fnack @thomaseichinger can you port this for your driver implementations?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 8, 2014

(if you need a guideline: see #1733)

@phiros
Copy link
Copy Markdown
Member

phiros commented Dec 10, 2014

kicked travis

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.

Shouldn't this be done earlier in the main sequence? At this point the sender's packet might have been received already, or am I wrong?

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.

Since the test script starts the receiver first anyways I don't think that this is an issue.

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.

Okay, I didn't look thoroughly through the script ;)

@fnack
Copy link
Copy Markdown
Member

fnack commented Dec 10, 2014

I adapted the cc110x driver implementation (see #2177).

@haukepetersen
Copy link
Copy Markdown
Contributor

I don't quite understand why this additional function is needed. I think just makes the interface bulkier without any benefit as I don't see any need for changing the event handler PID at after initialization.

I would suggest to call a simple thread_getpid() in the netdev::init() function and save the PID to the device descriptor. This works as we expect the init function to be called in the thread context of the drivers/MAC layers thread.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 15, 2014

You are completely right, this would simplify a lot :/. Also in that the event handler PID is more a device dependent option than a driver dependent. I'm not quite sure though, if netdev::init() is always able to be called from the thread context of the MAC layer or if the need to change it could arise.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 15, 2014

After digging a little bit through existing driver code (and porting for this change here), I realized, that a context value (to identify the position in the device internal buffer e.g.) for the IPC call by the driver and as argument for the netdev::driver::event() function might be beneficial for some hardware. What do you think, @haukepetersen?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 15, 2014

I would suggest to call a simple thread_getpid() in the netdev::init() function and save the PID to the device descriptor. This works as we expect the init function to be called in the thread context of the drivers/MAC layers thread.

Another open implementation detail that remains is: how does the driver identify the device of which event handler it needs to notify. Usually the devices are allocated outside of the context of the driver and the driver thus usually does not have any (hardware interface -> event handler PID)-mapping context available.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 15, 2014

(I'm aware that this problem is not solved with this PR either ;-))

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 15, 2014

[@haukepetersen we discussed this in RL, but can you give us a pointer to the interrupt argument in the current master/one of your PRs]

@haukepetersen
Copy link
Copy Markdown
Contributor

About the device/driver interfaces and hw interface -> handler PID mapping: I do not understand the question.
We have a 1-to-1 mapping between device driver and MAC layer. Both are run in the same thread, namely the MAC layer thread. This thread's PID is saved in the device descriptor. This device descriptor is passed as argument to the connected interrupt routines.
--> The ISRs know the PID of the MAC layer thread and therefore know which thread to message.

@haukepetersen
Copy link
Copy Markdown
Contributor

About the argument for the event() call: I don't think it's necessary. All scenarios should be able to be implemented just using the one existing parameter of the event() call.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 16, 2014

This thread's PID is saved in the device descriptor. This device descriptor is passed as argument to the connected interrupt routines.

@haukepetersen that was exactly what you told me in but can you show me how to do this?

@haukepetersen
Copy link
Copy Markdown
Contributor

I can try :-)

say you have

typedef struct{
    kernel_pid_t pid;
    spi_t spi;
    gpio_t rx_int_pin;
    gpio_t cs;
    netdev_t driver;
} at86xx_t;

at86xx_t dev;

as the device descriptor for an imaginable device. During initialization of your driver you call

gpio_init_int(dev.rx_int_pin, GPIO_NOPULL, GPIO_FALLING, cb, &dev);

to initialize your external interrupt line that the radio device pulls low in case new data arrives. In the callback, that is called in the interrupt routine, you do something like

void cb(void *arg)
{
    at86xx_t *dev = (at86xx_t *)arg;
    msg_t msg;
    msg.type = NETDEV_MSG_EVENT_TYPE;  // don't remember what we called the type...
    mst.content.value = YOUR_CODE_HERE;
    msg_send_int(&msg, dev->pid);
}

Now in the event loop of the MAC thread you receive this message trigger the event call

...
case NETDEV_MSG_EVENT_TYPE:
    dev->driver.event(msg.content.value);
    break;
....

finally the event function is called in the context of the MAC thread

void event(int type)
{
    switch (type) {
        case YOUR_CODE_HERE:
            // transfer data, reset status, do whatever is appropriate... e.g.
            gpio_clear(dev.cs);
            spi_transfer_bytes(dev.spi, NULL, &buf, 123);
            gpio_set(dev.cs);
        break;
    }
}

Is this what you meant?

@OlegHahm OlegHahm modified the milestones: Release NEXT MAJOR, Release 2014.12 Dec 18, 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.

This initializer needs to be fixed, too.

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.

Addressed

fnack pushed a commit to fnack/RIOT that referenced this pull request Jan 3, 2015
fnack pushed a commit to fnack/RIOT that referenced this pull request Jan 5, 2015
fnack pushed a commit to fnack/RIOT that referenced this pull request Jan 5, 2015
@fnack
Copy link
Copy Markdown
Member

fnack commented Jan 6, 2015

@OlegHahm: I don't want to add a HACK n ACK candidate label unauthorized (especially as I am not taking part in the event) but I'd vote to take this PR into consideration. A lot of other PRs (#1968, #2164, #2166, #2237, ...) are depending on it, so it would be great to see this merged anytime soon!

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Jan 6, 2015

Seems valid to me. I wasn't tracking this PR after #2163 (comment).

@OlegHahm OlegHahm added the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Jan 6, 2015
fnack pushed a commit to fnack/RIOT that referenced this pull request Jan 13, 2015
fnack pushed a commit to fnack/RIOT that referenced this pull request Jan 13, 2015
@fnack
Copy link
Copy Markdown
Member

fnack commented Jan 29, 2015

Ping @authmillenon, @haukepetersen . What's the status of this PR? A lot of other PR's seem to rely on this one to be merged.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 29, 2015

@fnack this is still on the table, but netdev itself will see some major changes (see #2297), too. Also we kind of set the whole network stack implementation more or less on hold until the Network Stack Task Force Workshop next week, in hopes that we get a [more] stable model from this.

@fnack
Copy link
Copy Markdown
Member

fnack commented Jan 29, 2015

Okay, I don't like it but I guess I have to accept it. From my point of view, the restructuring of netdev will probably take a lot of time and meanwhile this PR could simplify using the current master branch.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 29, 2015

That's up to the reviewers of this and the follow-up PRs ;-)

@haukepetersen
Copy link
Copy Markdown
Contributor

@fnack, I would not build on this PR yet, in my opinion is still subject to change (see #2297 for a first draft)...

@OlegHahm OlegHahm modified the milestones: Release NEXT MAJOR, Network Stack Task Force Feb 6, 2015
@OlegHahm OlegHahm added NSTF and removed NSTF labels Feb 6, 2015
@miri64 miri64 modified the milestone: Network Stack Task Force Feb 8, 2015
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Feb 8, 2015

Closed in favor for #2398

@miri64 miri64 closed this Feb 8, 2015
@miri64 miri64 deleted the netdev/api/driver-set_event_handler branch February 8, 2015 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants