Kaspar,

Thanks for this! Very clever to put a pointer to a second struct to keep the 
flexibility without forcing the user to know it.

I'm trying to understand a few things.  In the <radio>_setup command, how 
should I copy the default value struct into the overall params if the 
radio_params pointer member is const.  Should I use memcpy? Or should I create 
a new struct on the stack and initialize it with the correct pointer before 
copying it to the dev->params?

Also, I'm trying to understand how to achieve your comment: "In the default 
case, all parameters end up in flash."

Thanks Again!
-Anthony
[photo]
Anthony Merlino
CTO & Co-founder, Verge Aero
(609)-319-1399 [tel:(609)-319-1399]
On 2/20/2017 3:18:20 PM, Kaspar Schleiser <kas...@schleiser.de> wrote:
Hi Anthony,

On 02/14/2017 03:56 PM, Anthony Merlino wrote:
> I am in the process of writing a radio driver for a device I'm working
> with. The device is highly configurable and I am trying to identify the
> best strategy for exposing some of the configuration to the user. For
> example, the data rate, channel, preamble length, etc. can be changed to
> configure the radio.
> 1. Put all configurable parameters in _params_t held in the
> device descriptor. I don't like this option since the user basically
> needs to worry about all of them even if they want to just use them as
> default. Plus it's more stored data that doesn't necessarily need to be
> stored.

Some parameters might make sense to have them runtime user configurable,
e.g., the channel used. Probably for most of them there's a netapi
option. If not, it might make sense to just add it.

IMHO, for everything that doesn't need to be changed much, e.g. general
radio parameters like preable length, should end up in _params_t.
The usual way here is to have the initialization function read that
struct as const parameter, so it can be put to flash (but doesn't have
to be).

If you'd like to seperate the device specific parameters (e.g., SPI,
gpi-pins) from the radio configuration, you can nest the parameter structs:

typedef struct {
spi_t spi;
...
const _radio_params_t *radio_params;
};

Then define a default set of radio_params_t with the most sensible
default values.

Make your initialization function use that default if the radio_params
field equals NULL.

That way, e.g. in the board config, it is possible to just do

const _params_t whatever = {
.spi = SPI;
};

Leaving out radio_params implicitly zeroes it.

This way you'll get sensible defaults, but a way to override them, even
at runtime. In the default case, all parameters end up in flash.

Kaspar
_______________________________________________
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel
_______________________________________________
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel

Reply via email to