-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
network: make auto_init_ng_netif less board-dependant #2901
Conversation
/** | ||
* @name AT86RF231 configuration | ||
*/ | ||
static const at86rf2xx_params_t at86rf2xx_params[] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
Can we find a solution that has less code duplication AND does not need any arrays stored in memory? |
@authmillenon Where does this store arrays in memory? Only the device structs are stored in memory, but they have to. |
AT86RF231_SLEEP, | ||
AT86RF231_SPI_CLK, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@authmillenon Where does this store arrays in memory?
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This get's optimized out.
Yes but not for the whole run-time as global constants IMHO. |
They are driver-specific state variables. If they get stored in memory, that's how the driver has been implemented. |
Have look at this example: #include <stdio.h>
#define ARRAY_SIZE (2)
struct test {
int one;
int two;
};
const struct test t_array[] = {
{ 1, 2 },
{ 2, 3 },
};
void output(const struct test *t, size_t t_size) {
for (int i = 0; i < t_size; i++) {
printf("one: %d; two: %d\n", t[i].one, t[i].two);
}
}
int main(int argc, char **argv) {
output(t_array, ARRAY_SIZE);
}
vs. #include <stdio.h>
#define ARRAY_SIZE (2)
struct test {
int one;
int two;
};
#define ARRAY (struct test[]){ \
{ 1, 2 }, \
{ 2, 3 }, \
}
void output(const struct test *t, size_t t_size) {
for (int i = 0; i < t_size; i++) {
printf("one: %d; two: %d\n", t[i].one, t[i].two);
}
}
int main(int argc, char **argv) {
output(ARRAY, ARRAY_SIZE);
}
|
Interesting… I'm a little bit surprised, that the text section is shrinking... not the bss section oO Compiler was |
However, the current device init-functions do not allow for that currently. But since you introduce this structs anyways, we can save parameters and just define them with your |
You are however propably right about the optimization when I look at the bss section ;-) |
@authmillenon gcc compiles like this: (main.c is the const array example, main2.c the second with [kaspar@localhost hello-world]$ gcc -std=c99 main.c -Os -o main [kaspar@localhost hello-world]$ gcc -std=c99 main2.c -Os -o main2 [kaspar@localhost hello-world]$ size main text data bss dec hex filename 1360 560 8 1928 788 main [kaspar@localhost hello-world]$ size main2 text data bss dec hex filename 1366 560 8 1934 78e main2 [kaspar@localhost hello-world]$ |
static void start_nomac(char *stack, int stack_size, ng_netdev_t *device, const char* name) { | ||
/* starting NOMAC */ | ||
DEBUG("Start NOMAC layer for dev %s\n", name); | ||
ng_nomac_init(stack, stack_size, MAC_PRIO, name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if other MAC layers than nomac
want to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uff. All the configurability, all the time.
Either #define AT86RF2XX_MAC NOMAC
or another field in *_params
, then a switch(...) over it. The first would be global for all devices of one type, the second would allow for two devices with different MAC layers.
Let's cross that bridge as soon as we have a) a second MAC layer, b) a use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we need a mapping from MAC to device somewhere. I think it's safe to neglect the case of multiple radios of the same type with different MAC protocols for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it must be possible for a board, to specify the MAC layer that should be used, e.g. BOARD A, driver A, MAC A - BOARD B, driver A, MAC B... That is something, that we will see in the foreseeable future...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even for the same board this is required.
well, that could be a next step. |
So you approve the concept? @haukepetersen what do you think? |
Only problem laying still around is #2901 (comment) |
Easy to solve as soon as there's a second option for the MAC layer. |
I'd prefer to see your solution now :-). |
It's already in there and works with all available MAC layers. :-) |
No seriously? How do you propose to work with multiple MAC layers? Let's say the user wants |
in e.g., xbee_params.h: static const netlayer_nr_typt_t xbee_mac_layers[XBEE_NUM] = { MAC_LAYER_NOMAC, MAC_LAYER_802154 } in auto_init_ng_netif.c: maclayer_start_functions[xbee_mac_layers[i]](xbee_dev); |
But anyhow, I'd rather go for selecting a sane standard MAC layer and not use auto_init for the special cases. Choice is good but not if it complicates 99% of the use cases. |
#include "net/ng_nomac.h" | ||
#include "net/ng_netbase.h" | ||
|
||
#define ENABLE_DEBUG 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(0)
Should I squash this? |
@OlegHahm did you retry the xbee test? |
I just did. Builds without problem on my system. Pleas squash. |
f1bbc67
to
481a5b8
Compare
|
@haukepetersen ping |
Please rebase and add ACK then. Let's get this merged. |
I already prepared a new PR to adapt |
Cool! 👍 |
481a5b8
to
fa4bdd9
Compare
I fixed the problem differently: the auto_init_* functions where called whenever a radio module was selected, but the auto_init_ng_module wasn't linked in. Fixed. Pls have a quick look, then I'll squash. |
Had a quick look. I'm fine. Go squashing. |
fa4bdd9
to
8e1370b
Compare
The last commit doesn't squash easily, so I just fixed the commit message. |
@kaspar030 @OlegHahm I think Travis had an unrelated error. Could someone kick Travis? |
So this was ACKed? travis is happy... |
I say ACK and as far as I understood @haukepetersen, he doesn't NACK. |
allright, then GO. |
network: make auto_init_ng_netif less board-dependant
🍻 🎈 🎊 |
PR for #2900, IMHO improves #2891.
This is work in progress, let's please discuss the concept.I've adapted ng_at86rf2xx and xbee
but only the iot-lab_M3 node.Couldn't test xbee for lack of device.