Appearance
Sysconfig
The sysconfig is a c-macro based configuration extension for a quick setup and configuration of the application's MCU peripherals and external devices. It takes over device initialization and makes all hardware easily available to Coldwave's embedded peripheral APIs.
To get started, just create a C source-file in your project, for simplicity call it sysconf.c
The sysconf file will need to include the OS-Include sysconfig.h
and consist of three main delcarative sections:
- declaration of the driver package(s) you intend to use
- (optional) declaration of driver specific (non-standard) init-parameters you want to pass to the driver
- declaration of the device(s) that should be created
A very basic sysconf that just creates a single UART, in this example based on a Silicon Labs Series 2 Chip, could look like this:
C
#include <sysconfig.h>
// Declare EFR32 Series2 UART Driver
sysconf_use_driver(euart_gecko)
// Create a Device "eusart1"
sysconf_create_device("silabs-gecko-euart", eusart1, 0x500A0000UL ,
sysconf_set_int_param (gpio_rx, 206),
sysconf_set_int_param (gpio_tx, 205),
sysconf_set_int_param (gpio_rts, 204),
sysconf_set_int_param (gpio_cts, 203))
Extending this example to use the UART for interfacing with a Quectel BG77 cellular modem would look like this:
C
#include <sysconfig.h>
// Declare EFR32 MG UART Driver
sysconf_use_driver(euart_gecko)
sysconf_use_driver(quectel_bg77_gsmmodem)
// Declare BG77 Modem Driver's special parameters
sysconf_declare_param(quectel_bg77_pwrkey_gpio)
// Create a Device "eusart1"
sysconf_create_device("silabs-gecko-euart", eusart1, 0x500A0000UL ,
sysconf_set_int_param (gpio_rx, 206),
sysconf_set_int_param (gpio_tx, 205),
sysconf_set_int_param (gpio_rts, 204),
sysconf_set_int_param (gpio_cts, 203))
sysconf_create_device("quectel-bg77", modem0, 0x0,
sysconf_set_parent_dev (eusart1),
sysconf_set_int_param (gpio_dcd, 201),
sysconf_set_int_param (gpio_dtr, 207),
sysconf_set_int_param (gpio_ri, 200),
sysconf_set_int_param (quectel_bg77_pwrkey_gpio, 208),
sysconf_set_int_param (gpio_status, 202))
Driver linkage
If you intend to use a driver, some additional object code needs to be added to the build. To inform the linker that it needs to include that code, you declare sysconf_use_driver
with the driver package's iD. This DRV_ID can be retrieved from the list of available drivers
c
sysconf_use_driver (DRV_ID)
Driver parameters
All the "standard" configuration and initialization paramters for a driver are listed in this documentation alongside the specific peripheral API.
In some cases, drivers can expose parameters that are only meaningful for a specific device, as in the above example a special GPIO for a certain modem device. Such parameters need to be declared in the sysconf to make them available for the driver.
c
sysconf_declare_param (PARAM_ID)
Device creation
Each peripheral device that requires a driver needs to be "created" with sysconf_create_device
with the driver name, followed by a device handle (a string) and a memory mapped register base for the device, that you will be using to refer to the device in your application.
c
sysconf_create_device (DRIVER_NAME, DEVICE_HANDLE, ...)
In the example above, we create a silabs-gecko-euart
device (which is provided by the previously linked driver eusart_gecko
.
We want to access this device in calls to open()
by the name "eusart1" (this should be something meaningful, but You are completely free to chose any name here, jas long as it does not exceed 32 characters).
The memory mapped register-base ot the eusart1 on the example-device is 0x500A0000UL
, the value was taken from the device datasheet.
Last not least we configure the mandatory parameters for the device. In case of a U(S)ART driver, they are the TX and RX gpios.
c
sysconf_create_device("silabs-gecko-euart", eusart1, 0x500A0000UL ,
sysconf_set_int_param (gpio_rx, 206),
sysconf_set_int_param (gpio_tx, 205))
Device parameter-list
When adding parameters to a device declaration, there are three different types: Integers, Strings and Parent Devices (whereas of the latter there obviously can be only one per device).
The macros for the respective parameter-types are as follows:
c
sysconf_set_int_param (PARAM_ID, int)
c
sysconf_set_str_param (PARAM_ID, const char*)
c
sysconf_set_parent_dev (PARAM_ID, void*)
the parent device always has to be referred to by its device handle, i.e. the paremeter denoted as "void*" must be the parents user-defined name ("eusart1", e.g.).