Part 1
요약·해설
Application 사용법과 driver의 MUST·SHOULD·MAY 계약을 한 페이지에서 정리합니다.
Fetch and Get
Read and Decode
MUST · SHOULD · MAY
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
745BC256331E47BAC766F067EBD258165B07CB50A1C760A7AF20483FA6AE96E5
.. _sensor:
Sensors
#######
The sensor driver API provides functionality to uniformly read, configure,
and setup event handling for devices that take real world measurements in
meaningful units.
Sensors range from very simple temperature-reading devices that must be polled
with a fixed scale to complex devices taking in readings from multitudes of
sensors and themselves producing new inferred sensor data such as step counts,
presence detection, orientation, and more.
Supporting this wide breadth of devices is a demanding task and the sensor API
attempts to provide a uniform interface to them.
.. _sensor-using:
Using Sensors
*************
Using sensors from an application there are some APIs and terms that are helpful
to understand. Sensors in Zephyr are composed of :ref:`sensor-channel`,
:ref:`sensor-attribute`, and :ref:`sensor-trigger`. Attributes and triggers may
be device or channel specific.
.. note::
Getting samples from sensors using the sensor API today can be done in one of
two ways. A stable and long-lived API :ref:`sensor-fetch-and-get`, or a newer
but rapidly stabilizing API :ref:`sensor-read-and-decode`. It's expected that
in the near future :ref:`sensor-fetch-and-get` will be deprecated in favor of
:ref:`sensor-read-and-decode`. Triggers are handled entirely differently for
:ref:`sensor-fetch-and-get` or :ref:`sensor-read-and-decode` and the
differences are noted in each of those sections.
.. toctree::
:maxdepth: 1
attributes.rst
channels.rst
triggers.rst
power_management.rst
device_tree.rst
fetch_and_get.rst
read_and_decode.rst
.. _sensor-implementing:
Implementing Sensor Drivers
***************************
.. note::
Implementing the driver side of the sensor API requires an understanding how
the sensor APIs are used. Please read through :ref:`sensor-using` first!
Implementing Attributes
=======================
* SHOULD implement attribute setting in a blocking manner.
* SHOULD provide the ability to get and set channel scale if supported by the
device.
* SHOULD provide the ability to get and set channel sampling rate if supported
by the device.
Implementing Fetch and Get
==========================
* SHOULD implement :c:type:`sensor_sample_fetch_t` as a blocking call that
stashes the specified channels (or all sensor channels) as driver instance
data.
* SHOULD implement :c:type:`sensor_channel_get_t` without side effects
manipulating driver state returning stashed sensor readings.
* SHOULD implement :c:type:`sensor_trigger_set_t` storing the address of the
:c:struct:`sensor_trigger` rather than copying the contents. This is so
:c:macro:`CONTAINER_OF` may be used for trigger callback context.
Implementing Read and Decode
============================
* MUST implement :c:type:`sensor_submit_t` as a non-blocking call.
* SHOULD implement :c:type:`sensor_submit_t` using :ref:`rtio` to do non-blocking bus transfers if possible.
* MAY implement :c:type:`sensor_submit_t` using a work queue if
:ref:`rtio` is unsupported by the bus.
* SHOULD implement :c:type:`sensor_submit_t` checking the :c:struct:`rtio_sqe`
is of type :c:enum:`RTIO_SQE_RX` (read request).
* SHOULD implement :c:type:`sensor_submit_t` checking all requested channels
supported or respond with an error if not.
* SHOULD implement :c:type:`sensor_submit_t` checking the provided buffer
is large enough for the requested channels.
* SHOULD implement :c:type:`sensor_submit_t` in a way that directly reads into
the provided buffer avoiding copying of any kind, with few exceptions.
* MUST implement :c:struct:`sensor_decoder_api` with pure stateless functions. All state needed to convert the raw sensor readings into
fixed point SI united values must be in the provided buffer.
* MUST implement :c:type:`sensor_get_decoder_t` returning the
:c:struct:`sensor_decoder_api` for that device type.
.. _sensor-api-reference:
API Reference
***************
.. doxygengroup:: sensor_interface
.. doxygengroup:: sensor_emulator_backend
Part 3
한국어 전문 번역
Sensor driver API는 real-world measurement를 meaningful unit으로 생성하는 device를 일관된 방식으로 읽고 구성하며 event handling을 설정하는 기능을 제공합니다.
Sensor는 fixed scale로 polling해야 하는 단순한 temperature device부터, 수많은 sensor reading을 받아 step count·presence detection·orientation 같은 새로운 inferred sensor data를 만드는 복잡한 device까지 다양합니다.
이처럼 폭넓은 device를 지원하는 일은 까다로우며 sensor API는 이들에게 uniform interface를 제공하려 합니다.
Using Sensors
Application에서 sensor를 사용할 때 이해하면 좋은 API와 용어가 있습니다. Zephyr sensor는 Sensor Channel, Sensor Attribute, Sensor Trigger로 구성됩니다. Attribute와 trigger는 device-specific 또는 channel-specific일 수 있습니다.
- Sensor Attributes (
attributes.rst) - Sensor Channels (
channels.rst) - Sensor Triggers (
triggers.rst) - Power Management (
power_management.rst) - Device Tree (
device_tree.rst) - Fetch and Get (
fetch_and_get.rst) - Read and Decode (
read_and_decode.rst)
Implementing Sensor Drivers
Implementing Attributes
- SHOULD: Attribute 설정을 blocking 방식으로 구현합니다.
- SHOULD: Device가 지원한다면 channel scale get/set을 제공합니다.
- SHOULD: Device가 지원한다면 channel sampling rate get/set을 제공합니다.
Implementing Fetch and Get
- SHOULD:
sensor_sample_fetch_t를 지정한 channel 또는 모든 sensor channel을 driver instance data에 저장하는 blocking call로 구현합니다. - SHOULD:
sensor_channel_get_t는 driver state를 조작하는 side effect 없이 저장된 sensor reading을 반환하도록 구현합니다. - SHOULD:
sensor_trigger_set_t가sensor_trigger내용을 복사하지 않고 address를 저장하도록 구현합니다. 그래야 trigger callback context에CONTAINER_OF를 사용할 수 있습니다.
Implementing Read and Decode
- MUST:
sensor_submit_t를 non-blocking call로 구현합니다. - SHOULD: 가능하면 RTIO를 사용해 non-blocking bus transfer를 수행합니다.
- MAY: Bus가 RTIO를 지원하지 않으면 work queue로
sensor_submit_t를 구현할 수 있습니다. - SHOULD:
rtio_sqe가 read request인RTIO_SQE_RXtype인지 확인합니다. - SHOULD: 요청한 모든 channel을 지원하는지 확인하고 그렇지 않으면 error로 응답합니다.
- SHOULD: 제공된 buffer가 요청 channel에 충분히 큰지 확인합니다.
- SHOULD: 일부 예외를 제외하고 복사 없이 제공된 buffer로 직접 읽도록 구현합니다.
- MUST:
sensor_decoder_api를 pure stateless function으로 구현합니다. Raw sensor reading을 fixed-point SI unit 값으로 변환하는 데 필요한 모든 state가 제공된 buffer에 있어야 합니다. - MUST:
sensor_get_decoder_t가 해당 device type의sensor_decoder_api를 반환하도록 구현합니다.
API Reference
sensor_interface와 sensor_emulator_backend Doxygen group이 sensor interface와 emulator backend의 공식 API reference를 제공합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.