Auto-initialization

Auto initialize modules.

This feature can be enabled in any application by adding the auto_init module to the application’s Makefile:

1
USEMODULE += auto_init

auto_init initializes any included module that provides auto-initialization capabilities. This concerns first any other included module that does not require a parameter in its init function, i.e. if the init prototype looks like this: void MODULE_init(void). Most timer modules or simple drivers can be initialized by auto_init. The modules will be initialized in the context of the main thread right before the main function gets called. Be aware that most modules expect to be initialized only once, so do not call a module’s init function when using auto_init unless you know what you’re doing.

More complex device drivers, for example SAUL drivers or network device drivers, can also be initialized automatically using the auto_init module. To do so, each driver implementation must provide default initialization parameters in the DRIVER_params.h file. These parameters can be overriden from the application code in several ways (examples with the BMP180 temperature and pressure sensor oversampling parameter BMP180_PARAM_OVERSAMPLING):

  • by passing them via the CFLAGS variable on the build command line:

1
CFLAGS=-DBMP180_PARAM_OVERSAMPLING=1 USEMODULE=bmp180 make BOARD=arduino-zero -C examples/default

  • by setting the CFLAGS variable in the application Makefile:

1
CFLAGS += -DBMP180_PARAM_OVERSAMPLING=1

  • by copying the bmp180_params.h header to the application directory and editing it there with the desired values. This file is be included first and thus the one from the driver implementation is skipped.

From low-level CPU peripheral, the default initialization parameters are defined in each board configuration that provides them.