Why do drivers copy their params to RAM?

Hi,

I've noticed drivers in RIOT will usually keep a copy of their configuration parameters in RAM:

typedef struct {     riot_driver_params_t params; } riot_driver_t;

void riot_driver_setup(riot_driver_t *dev,                        const riot_driver_params_t *params) {     dev->params = *params; }

Why is it done this way instead of keeping a pointer to the location in ROM?

typedef struct {     const riot_driver_params_t *params; } riot_driver_t;

void riot_driver_setup(riot_driver_t *dev,                        const riot_driver_params_t *params) {     dev->params = params; }

The only reason I can think of is that accessing RAM is faster than ROM on Flash - or am I missing something?

Best, Benjamin

Hej Benjamin,

you got it right, it is about additional overhead. At least in the drivers that I designed, I always look at the specific parameters and judge them on their importance. If used only during initialization, I tend to leave them in ROM. But if used constantly during run-time, I copy them into RAM to reduce the ROM overhead. Often a dual approach makes sense: keep the static config in ROM and only copy the often used fields into the device descriptor, e.g. the SPI/I2C bus and similar...

So as I see it, there is no right or wrong, but it always depends :slight_smile:

Cheers, Hauke