Difference between revisions of "Zephyr device driver model"
From Wiki at Neela Nurseries
m |
|||
Line 4: | Line 4: | ||
<ul> | <ul> | ||
<i> | <i> | ||
− | Driver Data Structures | + | <b>Driver Data Structures</b> |
The device initialization macros populate some data structures at build time which are split into read-only and runtime-mutable parts. At a high level we have: | The device initialization macros populate some data structures at build time which are split into read-only and runtime-mutable parts. At a high level we have: | ||
− | + | <pre> | |
struct device { | struct device { | ||
const char *name; | const char *name; | ||
Line 13: | Line 13: | ||
const void *api; | const void *api; | ||
void * const data; | void * const data; | ||
− | }; | + | };</pre> |
</i> | </i> | ||
</ul> | </ul> |
Revision as of 05:37, 13 August 2021
Excerpt from Zephyr project drivers documentation:
-
Driver Data Structures
The device initialization macros populate some data structures at build time which are split into read-only and runtime-mutable parts. At a high level we have:
struct device { const char *name; const void *config; const void *api; void * const data; };
Excerpt from file ~/ncs/zephyr/include/drivers/sensor.h
:
382 /** 383 * @brief Set an attribute for a sensor 384 * 385 * @param dev Pointer to the sensor device 386 * @param chan The channel the attribute belongs to, if any. Some 387 * attributes may only be set for all channels of a device, depending on 388 * device capabilities. 389 * @param attr The attribute to set 390 * @param val The value to set the attribute to 391 * 392 * @return 0 if successful, negative errno code if failure. 393 */ 394 __syscall int sensor_attr_set(const struct device *dev, 395 enum sensor_channel chan, 396 enum sensor_attribute attr, 397 const struct sensor_value *val); 398 399 static inline int z_impl_sensor_attr_set(const struct device *dev, 400 enum sensor_channel chan, 401 enum sensor_attribute attr, 402 const struct sensor_value *val) 403 { 404 const struct sensor_driver_api *api = 405 (const struct sensor_driver_api *)dev->api; 406 407 if (api->attr_set == NULL) { 408 return -ENOSYS; 409 } 410 411 return api->attr_set(dev, chan, attr, val); 412 } 413