Difference between revisions of "Zephyr drivers"

From Wiki at Neela Nurseries
Jump to: navigation, search
m (Zephyr device tree macros used to obtain node identifiers)
m (Device Tree versus Kconfig)
Line 42: Line 42:
  
 
On a somewhat unrelated note, Zephyr device tree macros used to obtain node identifiers:  https://docs.zephyrproject.org/latest/build/dts/api-usage.html#node-identifiers
 
On a somewhat unrelated note, Zephyr device tree macros used to obtain node identifiers:  https://docs.zephyrproject.org/latest/build/dts/api-usage.html#node-identifiers
 +
 +
*  https://docs.zephyrproject.org/latest/build/dts/dt-vs-kconfig.html  Device Tree versus Kconfig
  
 
<!-- comentario -->
 
<!-- comentario -->

Revision as of 23:19, 15 November 2022

^ OVERVIEW

2022 Q4 notes on Zephyr RTOS drivers, driver frameworks and driver design. Current projects include work to extend KX132-1211 Zephyr out-of-tree driver, plus work to craft an IIS2DH driver which supports in Zephyr RTOS context both I2C and SPI bus connections for this sensor.


^ Example Zephyr drivers

Example apps here offer varying amounts of insight into Zephyr RTOS' framework(s) for device driver development. Of particular interest 2022 Q4 are the ways in which developers use Zephyr device tree macros to obtain pointers to devices, in their mostly C based code, at compile time. Though not fully explained in Zephyr's extensive documentation it appears that device pointers which can be correctly passed to and used with API function device_is_ready() and macro DEVICE_DT_GET() involve pairings of macros, which must be expanded prior to these calls in order to compile correctly.


^ Zephyr Kernel Level Device Support

Interesting code excerpt from `zephy/kernel/device.c`, this following routine is the implementation behind a wrapper like function `device_is_read()`. But this routine, and sensibly so, doesn't say anything about how a given device is initialized. It only looks at two data members of a device instance data structure:

150 
151 bool z_device_is_ready(const struct device *dev)
152 {
153         /*
154          * if an invalid device pointer is passed as argument, this call
155          * reports the `device` as not ready for usage.
156          */
157         if (dev == NULL) {
158                 return false;
159         }
160 
161         return dev->state->initialized && (dev->state->init_res == 0U);
162 }
163 

On a somewhat unrelated note, Zephyr device tree macros used to obtain node identifiers: https://docs.zephyrproject.org/latest/build/dts/api-usage.html#node-identifiers


^ Understanding Zephyr SPI API

To make use of Zephyr API for SPI bus, we must in part understand how each of the three parameters passed to spi_read() and spi_write() are defined. Further, when we have a sensor with which we communicate in our Zephyr based app we need to understand how parts of this sensor's data structures in the firmware relate to the SPI bus to which the sensor is connected. Our sensor driver's code which talks with the sensor via SPI must pass certain SPI bus related pointers to Zephyr's SPI Application Programmers' Interface.

Another important SPI defining resource in Zephyr RTOS is the header file spi.h#L379. This file defines the small data structure named `spi_dt_spec`. It gives us the data member names for a SPI bus peripheral, as Zephyr sees them.


^ LPC55S69 flexcomm2 and hs_lspi pins conflict

zephyr/boards/arm/lpcxpresso55s69/lpcxpresso55s69-pinctrl.dtsi lines 21 - 28