Devicetree output
The following section present the content of a C coded version of the devicetree
Devices instances definition
A hardware peripheral is visible from the SDK as a pi_device_t object. Such object has three pointers :
a configuration structure pointer
a data structure pointer
an api structure pointer
Based on the devicetree source file content, outputed C files must provide :
a definition of the configuration structure
a declaration of the data structure (it will be fullfilled by the device itself at run time)
a definition of the device itself with adequate pointers including the device api which is defined inside the device driver.
Note
All of this structures has a name convention.
Type |
Name convention |
---|---|
Device name |
DEVICENAME_dev |
Data type |
pi_DEVICENAME_data_t |
Data name |
pi_DEVICENAME_data |
Config type |
pi_DEVICENAME_conf_t |
Config name |
pi_DEVICENAME_conf |
Api name |
DEVICENAME_api |
Note
There is no convention about a device’s api type because it is cast into the generic api type pi_device_api_t
Here is an example of how a device is outputed.
sys
{
device_name = "mx25u51245g";
device_type = "flash";
device_board = "gap9mod_v1_0_b";
device_driver = "bsp/flash/mx25u51245g.h";
};
conf
{
spi_itf = <0>;
spi_cs = <0>;
size = <0x00800000>;
sector_size = <4096>;
xip_en = <0>;
baudrate = <0>;
};
pi_mx25u51245g_conf_t mx25u51245g_conf = {
.baudrate = DT_MX25U51245G_BAUDRATE,
.xip_en = DT_MX25U51245G_XIP_EN,
.sector_size = DT_MX25U51245G_SECTOR_SIZE,
.size = DT_MX25U51245G_SIZE,
.spi_cs = DT_MX25U51245G_SPI_CS,
.spi_itf = DT_MX25U51245G_SPI_ITF,
};
pi_mx25u51245g_data_t mx25u51245g_data;
pi_device_t mx25u51245g_dev = {
.config = &mx25u51245g_conf,
.data = &mx25u51245g_data,
.api = (pi_device_api_t*)&mx25u51245g_api
};
Device API
For each outputed device, an enum is added to the pi_device_enum type. This enum type represent all devices a user can open and close in his application. If an application require only a flash device, the enum list will have only one member.
Here is an example about an application thta only use a mx25u51245g flash device
typedef enum {
PI_FLASH_MX25U51245G,
PI_FLASH_DEFAULT,
}pi_device_e;
Note
Here, a PI_FLASH_DEFAULT is also defined in the list thanks to the default driver mechanism. Please check Default driver section in Interaction with Kconfig page for more explanations. This is for applications that support multiple devices from a same type and use an abstracted API.
Devices outputed from the devicetree can be opened with the following function:
pi_err_t pi_open(pi_device_e device_enum, pi_device_t** device_ptr)
Devices are closed with the following API using the same enum list:
pi_err_t pi_close(pi_device_e device_enum);
Automatic pad configuration
The devicetree aims to facilitate the pad configuration by automate the configuration of pads registers.
A pad is detected in device nodes if it has the following syntax :
GAP9_PADMUX(<pad_id>, <pad_af>, <pad_muxgroup>)
For each identified pad, a define will be outputed. The define’s value is obtained from the pi_pad_e enum list.
Here is an example with the mx25u51245g device, connected on the GAP9 Hyperbus0 interface :
pads
{
ckn = "GAP9_PADMUX(0, 0,-1)";
ck = "GAP9_PADMUX(1, 0,-1)";
dq0 = "GAP9_PADMUX(2, 0,-1)";
dq1 = "GAP9_PADMUX(3, 0,-1)";
dq2 = "GAP9_PADMUX(4, 0,-1)";
dq3 = "GAP9_PADMUX(5, 0,-1)";
dq4 = "GAP9_PADMUX(6, 0,-1)";
dq5 = "GAP9_PADMUX(7, 0,-1)";
dq6 = "GAP9_PADMUX(8, 0,-1)";
dq7 = "GAP9_PADMUX(9, 0,-1)";
sn0 = "GAP9_PADMUX(10,0,-1)";
csn1 = "GAP9_PADMUX(11,0,-1)";
rwds = "GAP9_PADMUX(12,0,-1)";
};
#define PADFUN0_INIT 0x54000000
#define PADFUN1_INIT 0x55555555
#define PADFUN2_INIT 0x55555555
#define PADFUN3_INIT 0x55555555
#define PADFUN4_INIT 0x55555555
#define PADFUN5_INIT 0x55555555
#define PAD_MX25U51245G_RWDS PI_PAD_012
#define PAD_MX25U51245G_CSN1 PI_PAD_011
#define PAD_MX25U51245G_SN0 PI_PAD_010
#define PAD_MX25U51245G_DQ7 PI_PAD_009
#define PAD_MX25U51245G_DQ6 PI_PAD_008
#define PAD_MX25U51245G_DQ5 PI_PAD_007
#define PAD_MX25U51245G_DQ4 PI_PAD_006
#define PAD_MX25U51245G_DQ3 PI_PAD_005
#define PAD_MX25U51245G_DQ2 PI_PAD_004
#define PAD_MX25U51245G_DQ1 PI_PAD_003
#define PAD_MX25U51245G_DQ0 PI_PAD_002
#define PAD_MX25U51245G_CK PI_PAD_001
#define PAD_MX25U51245G_CKN PI_PAD_000
Note
As a default value, a pad is set to its alternate 1 meaning GPIO.