요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=============================
Industrial IIO device buffers
=============================
1. Overview
===========
The Industrial I/O core offers a way for continuous data capture based on a
trigger source. Multiple data channels can be read at once from
``/dev/iio:deviceX`` character device node, thus reducing the CPU load.
Devices with buffer support feature an additional sub-directory in the
``/sys/bus/iio/devices/iio:deviceX/`` directory hierarchy, called bufferY, where
Y defaults to 0, for devices with a single buffer.
2. Buffer attributes
====================
An IIO buffer has an associated attributes directory under
``/sys/bus/iio/iio:deviceX/bufferY/``. The attributes are described below.
``length``
----------
Read / Write attribute which states the total number of data samples (capacity)
that can be stored by the buffer.
``enable``
----------
Read / Write attribute which starts / stops the buffer capture. This file should
be written last, after length and selection of scan elements. Writing a non-zero
value may result in an error, such as EINVAL, if, for example, an unsupported
combination of channels is given.
``watermark``
-------------
Read / Write positive integer attribute specifying the maximum number of scan
elements to wait for.
Poll will block until the watermark is reached.
Blocking read will wait until the minimum between the requested read amount or
the low watermark is available.
Non-blocking read will retrieve the available samples from the buffer even if
there are less samples than the watermark level. This allows the application to
block on poll with a timeout and read the available samples after the timeout
expires and thus have a maximum delay guarantee.
Data available
--------------
Read-only attribute indicating the bytes of data available in the buffer. In the
case of an output buffer, this indicates the amount of empty space available to
write data to. In the case of an input buffer, this indicates the amount of data
available for reading.
Scan elements
-------------
The meta information associated with a channel data placed in a buffer is called
a scan element. The scan elements attributes are presented below.
**_en**
Read / Write attribute used for enabling a channel. If and only if its value
is non-zero, then a triggered capture will contain data samples for this
channel.
**_index**
Read-only unsigned integer attribute specifying the position of the channel in
the buffer. Note these are not dependent on what is enabled and may not be
contiguous. Thus for userspace to establish the full layout these must be used
in conjunction with all _en attributes to establish which channels are present,
and the relevant _type attributes to establish the data storage format.
**_type**
Read-only attribute containing the description of the scan element data storage
within the buffer and hence the form in which it is read from userspace. Format
is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift], where:
- **be** or **le** specifies big or little-endian.
- **s** or **u** specifies if signed (2's complement) or unsigned.
- **bits** is the number of valid data bits.
- **storagebits** is the number of bits (after padding) that it occupies in the
buffer.
- **repeat** specifies the number of bits/storagebits repetitions. When the
repeat element is 0 or 1, then the repeat value is omitted.
- **shift** if specified, is the shift that needs to be applied prior to
masking out unused bits.
For example, a driver for a 3-axis accelerometer with 12-bit resolution where
data is stored in two 8-bit registers is as follows::
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
|D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06)
+---+---+---+---+---+---+---+---+
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
|D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07)
+---+---+---+---+---+---+---+---+
will have the following scan element type for each axis:
.. code-block:: bash
$ cat /sys/bus/iio/devices/iio:device0/buffer0/in_accel_y_type
le:s12/16>>4
A userspace application will interpret data samples read from the buffer as
two-byte little-endian signed data, that needs a 4 bits right shift before
masking out the 12 valid bits of data.
It is also worth mentioning that the data in the buffer will be naturally
aligned, so the userspace application has to handle the buffers accordingly.
Take for example, a driver with four channels with the following description:
- channel0: index: 0, type: be:u16/16>>0
- channel1: index: 1, type: be:u32/32>>0
- channel2: index: 2, type: be:u32/32>>0
- channel3: index: 3, type: be:u64/64>>0
If all channels are enabled, the data will be aligned in the buffer as follows::
0-1 2 3 4-7 8-11 12 13 14 15 16-23 -> buffer byte number
+-----+---+---+-----+-----+---+---+---+---+-----+
|CHN_0|PAD|PAD|CHN_1|CHN_2|PAD|PAD|PAD|PAD|CHN_3| -> buffer content
+-----+---+---+-----+-----+---+---+---+---+-----+
If only channel0 and channel3 are enabled, the data will be aligned in the
buffer as follows::
0-1 2 3 4 5 6 7 8-15 -> buffer byte number
+-----+---+---+---+---+---+---+-----+
|CHN_0|PAD|PAD|PAD|PAD|PAD|PAD|CHN_3| -> buffer content
+-----+---+---+---+---+---+---+-----+
Typically the buffered data is found in raw format (unscaled with no offset
applied), however there are corner cases in which the buffered data may be found
in a processed form. Please note that these corner cases are not addressed by
this documentation.
Please see Documentation/ABI/testing/sysfs-bus-iio for a complete
description of the attributes.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Trigger 기반 연속 캡처와 장치 경로
1-17이 문서는 GPL-2.0 라이선스가 적용되는 Industrial IIO 장치 버퍼 설명서입니다.
Industrial I/O core는 trigger source를 기반으로 데이터를 연속 캡처하는 방법을 제공합니다. 여러 데이터 채널을 `/dev/iio:deviceX` 문자 장치 노드에서 한 번에 읽어 CPU 부하를 줄일 수 있습니다.
버퍼를 지원하는 장치에는 `/sys/bus/iio/devices/iio:deviceX/` 계층 아래에 `bufferY`라는 추가 하위 디렉터리가 있습니다. 버퍼가 하나인 장치에서 Y의 기본값은 0입니다.
Trigger 발생에서 사용자 공간 다중 채널 읽기까지의 흐름입니다.
Sysfs 설정 경로와 문자 장치 데이터 경로를 구분합니다.
.. SPDX-License-Identifier: GPL-2.0
=============================
Industrial IIO device buffers
=============================
1. Overview
===========
The Industrial I/O core offers a way for continuous data capture based on a
trigger source. Multiple data channels can be read at once from
``/dev/iio:deviceX`` character device node, thus reducing the CPU load.
Devices with buffer support feature an additional sub-directory in the
``/sys/bus/iio/devices/iio:deviceX/`` directory hierarchy, called bufferY, where
Y defaults to 0, for devices with a single buffer.
Length·enable·watermark·data available
18-60IIO 버퍼에는 원문이 제시한 `/sys/bus/iio/iio:deviceX/bufferY/` 아래에 연관된 속성 디렉터리가 있습니다.
용량·캡처·대기·가용량 속성의 접근 방식과 의미입니다.
`length`는 버퍼에 저장할 수 있는 전체 데이터 샘플 수인 용량을 나타냅니다.
`enable`은 버퍼 캡처를 시작하거나 중지합니다. `length`와 scan element 선택을 끝낸 뒤 마지막에 써야 합니다. 지원하지 않는 채널 조합을 지정한 경우처럼 0이 아닌 값을 쓰면 `EINVAL` 같은 오류가 발생할 수 있습니다.
`watermark`는 기다릴 scan element의 최대 수를 지정하는 양의 정수입니다. `poll`은 watermark에 도달할 때까지 차단됩니다.
Blocking read는 요청한 읽기 양과 low watermark 가운데 더 작은 양이 준비될 때까지 기다립니다.
Non-blocking read는 watermark보다 샘플이 적어도 버퍼에서 사용 가능한 샘플을 가져옵니다. 따라서 응용 프로그램은 timeout을 둔 `poll`에서 대기하고 timeout 뒤 사용 가능한 샘플을 읽어 최대 지연을 보장할 수 있습니다.
Data available은 버퍼에서 사용 가능한 데이터 byte 수를 나타내는 read-only 속성입니다. 출력 버퍼에서는 데이터를 쓸 수 있는 빈 공간의 양을, 입력 버퍼에서는 읽을 수 있는 데이터의 양을 나타냅니다.
`enable`을 마지막에 써야 하는 설정 순서입니다.
Poll과 두 read 모드의 대기 조건을 비교합니다.
2. Buffer attributes
====================
An IIO buffer has an associated attributes directory under
``/sys/bus/iio/iio:deviceX/bufferY/``. The attributes are described below.
``length``
----------
Read / Write attribute which states the total number of data samples (capacity)
that can be stored by the buffer.
``enable``
----------
Read / Write attribute which starts / stops the buffer capture. This file should
be written last, after length and selection of scan elements. Writing a non-zero
value may result in an error, such as EINVAL, if, for example, an unsupported
combination of channels is given.
``watermark``
-------------
Read / Write positive integer attribute specifying the maximum number of scan
elements to wait for.
Poll will block until the watermark is reached.
Blocking read will wait until the minimum between the requested read amount or
the low watermark is available.
Non-blocking read will retrieve the available samples from the buffer even if
there are less samples than the watermark level. This allows the application to
block on poll with a timeout and read the available samples after the timeout
expires and thus have a maximum delay guarantee.
Data available
--------------
Read-only attribute indicating the bytes of data available in the buffer. In the
case of an output buffer, this indicates the amount of empty space available to
write data to. In the case of an input buffer, this indicates the amount of data
available for reading.
Scan element 선택·순서·저장 형식
61-97버퍼에 놓이는 채널 데이터와 연관된 메타데이터를 scan element라고 합니다.
채널 포함 여부, 위치, 저장 형식을 결정하는 세 속성입니다.
`_en` 값이 0이 아닐 때에만 triggered capture에 해당 채널의 데이터 샘플이 포함됩니다.
`_index`는 활성화 여부와 무관하고 연속적이지 않을 수 있습니다. 사용자 공간이 전체 layout을 정하려면 모든 `_en` 속성으로 존재하는 채널을 판별하고 관련 `_type` 속성으로 저장 형식을 판별하면서 `_index`를 함께 사용해야 합니다.
`_type`의 형식은 `[be|le]:[s|u]bits/storagebits[Xrepeat][>>shift]`입니다.
형식 문자열의 각 구성요소를 원문 정의대로 풀이합니다.
세 scan 속성을 결합해 버퍼 레코드를 해석합니다.
Scan elements
-------------
The meta information associated with a channel data placed in a buffer is called
a scan element. The scan elements attributes are presented below.
**_en**
Read / Write attribute used for enabling a channel. If and only if its value
is non-zero, then a triggered capture will contain data samples for this
channel.
**_index**
Read-only unsigned integer attribute specifying the position of the channel in
the buffer. Note these are not dependent on what is enabled and may not be
contiguous. Thus for userspace to establish the full layout these must be used
in conjunction with all _en attributes to establish which channels are present,
and the relevant _type attributes to establish the data storage format.
**_type**
Read-only attribute containing the description of the scan element data storage
within the buffer and hence the form in which it is read from userspace. Format
is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift], where:
- **be** or **le** specifies big or little-endian.
- **s** or **u** specifies if signed (2's complement) or unsigned.
- **bits** is the number of valid data bits.
- **storagebits** is the number of bits (after padding) that it occupies in the
buffer.
- **repeat** specifies the number of bits/storagebits repetitions. When the
repeat element is 0 or 1, then the repeat value is omitted.
- **shift** if specified, is the shift that needs to be applied prior to
masking out unused bits.
12비트 가속도 샘플 저장 예제
98-124예제는 12비트 해상도의 3축 가속도계가 데이터를 두 개의 8비트 레지스터에 저장하는 경우입니다.
원문의 LOW/HIGH byte ASCII 비트 그림을 동일한 bit 위치 표로 재구성했습니다.
각 축의 scan element type은 `le:s12/16>>4`입니다.
$ cat /sys/bus/iio/devices/iio:device0/buffer0/in_accel_y_type
le:s12/16>>4
사용자 공간 응용 프로그램은 버퍼에서 읽은 샘플을 2바이트 little-endian signed 데이터로 해석해야 합니다. 사용하지 않는 bit를 mask해 12개의 유효 데이터 bit를 얻기 전에 4비트 right shift를 적용합니다.
두 레지스터의 raw bytes에서 12비트 signed 값을 복원하는 순서입니다.
버퍼 데이터는 자연 정렬되므로 사용자 공간 응용 프로그램은 그에 맞게 버퍼를 처리해야 합니다.
For example, a driver for a 3-axis accelerometer with 12-bit resolution where
data is stored in two 8-bit registers is as follows::
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
|D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06)
+---+---+---+---+---+---+---+---+
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
|D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07)
+---+---+---+---+---+---+---+---+
will have the following scan element type for each axis:
.. code-block:: bash
$ cat /sys/bus/iio/devices/iio:device0/buffer0/in_accel_y_type
le:s12/16>>4
A userspace application will interpret data samples read from the buffer as
two-byte little-endian signed data, that needs a 4 bits right shift before
masking out the 12 valid bits of data.
It is also worth mentioning that the data in the buffer will be naturally
aligned, so the userspace application has to handle the buffers accordingly.
다중 채널 자연 정렬과 raw 데이터
125-152정렬 예제의 네 채널은 channel0 `index: 0, type: be:u16/16>>0`, channel1 `index: 1, type: be:u32/32>>0`, channel2 `index: 2, type: be:u32/32>>0`, channel3 `index: 3, type: be:u64/64>>0`입니다.
자연 정렬 예제에 쓰이는 index와 type입니다.
원문의 0..23 byte ASCII 배치를 범위별로 재구성했습니다.
모든 채널을 활성화하면 channel0 뒤와 channel3 앞에 자연 정렬을 위한 padding이 들어가 전체 레코드가 24바이트가 됩니다.
원문의 0..15 byte ASCII 배치를 범위별로 재구성했습니다.
Channel0과 channel3만 활성화하면 2-7번 byte가 padding이 되어 channel3이 8번 byte에서 시작하며 전체 레코드는 16바이트입니다.
활성 채널 집합에 따라 padding이 달라지는 과정입니다.
일반적으로 버퍼 데이터는 scale이나 offset을 적용하지 않은 raw 형식입니다. 다만 일부 예외에서는 처리된 형식으로 들어올 수 있으며 이 문서는 그런 예외를 다루지 않습니다.
속성 전체 설명은 `Documentation/ABI/testing/sysfs-bus-iio`를 참고합니다.
Take for example, a driver with four channels with the following description:
- channel0: index: 0, type: be:u16/16>>0
- channel1: index: 1, type: be:u32/32>>0
- channel2: index: 2, type: be:u32/32>>0
- channel3: index: 3, type: be:u64/64>>0
If all channels are enabled, the data will be aligned in the buffer as follows::
0-1 2 3 4-7 8-11 12 13 14 15 16-23 -> buffer byte number
+-----+---+---+-----+-----+---+---+---+---+-----+
|CHN_0|PAD|PAD|CHN_1|CHN_2|PAD|PAD|PAD|PAD|CHN_3| -> buffer content
+-----+---+---+-----+-----+---+---+---+---+-----+
If only channel0 and channel3 are enabled, the data will be aligned in the
buffer as follows::
0-1 2 3 4 5 6 7 8-15 -> buffer byte number
+-----+---+---+---+---+---+---+-----+
|CHN_0|PAD|PAD|PAD|PAD|PAD|PAD|CHN_3| -> buffer content
+-----+---+---+---+---+---+---+-----+
Typically the buffered data is found in raw format (unscaled with no offset
applied), however there are corner cases in which the buffered data may be found
in a processed form. Please note that these corner cases are not addressed by
this documentation.
Please see Documentation/ABI/testing/sysfs-bus-iio for a complete
description of the attributes.
요약·해설
iio_devbuf.rst:1-152IIO device buffer는 trigger 기반 다중 채널 캡처를 문자 장치로 제공합니다. 사용자 공간은 `_en`, `_index`, `_type`을 결합해 record layout을 만들고 endian·sign·shift·mask와 자연 정렬 padding을 반영해 샘플을 해석해야 합니다.
원문 분량과 핵심 인터페이스를 요약합니다.
구성과 데이터 처리 순서를 압축합니다.