Zephyr . Iterable Section API
소스파일에서 STRUCT_SECTION_ITERABLE() 매크로 이용하여 구조체를 등록(Zephyr 관리하는 Iterable Section 체계로 등록한다는 의미) 하겠다고 선언 해두면 빌드 단계에서 지정한 ( _iterable.구조체이름.static.데이터 ) 곳에 모든 구조체들이 모아지게 된다.
STRUCT_SECTION_FOREACH() 로 호출하면 등록한 모든 구조체 순회 가능하다.
여러 파일에서 구조체 등록가능하며, 프로젝트에 해당파일을 포함시키면 자동으로 구조체 등록되고 해당파일 제외하면 자동으로 구조체 제외된다.
Zephyr Iterable Section 문서
https://docs.zephyrproject.org/latest/kernel/iterable_sections/index.html
Iterable Sections — Zephyr Project Documentation
Note The linker is going to place the entries sorted by name, so the example above would visit d1, d2 and d3 in that order, regardless of how they were defined in the code.
docs.zephyrproject.org
https://docs.zephyrproject.org/latest/doxygen/html/group__iterable__section__apis.html
Zephyr API Documentation: Iterable Sections APIs
Iterable Sections APIs. More... #define ITERABLE_SECTION_ROM(struct_type, subalign) Define a read-only iterable section output. #define ITERABLE_SECTION_ROM_NUMERIC(struct_type, subalign) Define a read-only iterable section output, sorted numerically
docs.zephyrproject.org
Iterable Section 활용 장점 - 플러그인 구조
- 새로운 통신 규격이 필요하면 spec_new3.c 파일을 프로젝트 폴더에 집어넣고 빌드(CMake 등록)하면 자동으로 시스템에 구조체 주입. 여기서 구조체란 spec_new3.c 에서 STRUCT_SECTION_ITERABLE() 로 등록한 것
- 반대로 어떤 규격을 이번 빌드에서 빼고 싶다면, 메인 소스코드를 건드릴 필요 없이 spec_new3.c 파일을 빌드 대상에서 제외하면 자동 비적용이 달성된다.
- 즉, 수신 엔진 코드는 가만히 두고 규격 파일 배치만으로 해당 기능을 켜고 끄는 '플러그인 형태'의 아키텍처 달성가능.
STRUCT_SECTION_ITERABLE
- iterable section 에 신규 요소 정의
#define STRUCT_SECTION_ITERABLE (struct_type, varname)
#include <zephyr/sys/iterable_sections.h>
인자. struct_type
- 용도: 메모리 섹션에 저장할 데이터의 '구조체 타입' 지정.
- 내부 동작 :
Zephyr 내부에서 이 인자는 메모리 구역(Section)의 이름을 자동으로 생성하는 힌트로 사용.- 예를 들어 struct_type에 type_frame_parser를 넣으면, 매크로 내부적으로 "_iterable.type_frame_parser.static.데이터" 같은 고유한 섹션 이름을 만든다.
- 링커는 이 이름을 보고 "타입 이름이 같은 구조체들만 골라 한 줄로 모아준다."
- 비유: 같은 종류의 서류들을 모아두는 "서류철의 이름표"
인자 varname
- 용도: 실제로 메모리에 생성되어 데이터가 채워질 '개별 변수(Instance)의 고유한 이름'
- 내부 동작:
이 인자는 코드 상에서 일반적인 변수 선언 문법(struct struct_type var_name = { ... };)으로 그대로 치환. - 비유: 서류철 안에 들어가는 "개별 서류 한 장 한 장의 제목".
// 구조체 정의.
typedef struct {
const char *frame_name;
bool is_enabled;
void (*unpack)(const uint8_t *packet, uint16_t length);
} type_frmae_parser;
// [선언 예시]
STRUCT_SECTION_ITERABLE(type_frmae_parser, parser_myframe_1) = {
.frame_name = "Name_1",
.is_enabled = true,
.unpack = unpack_myframe_1
};
연관
Zephyr (제퍼) . RTOS . 경량
Zephyr (제퍼)- 경량 RTOS . nRF52840 ( ARM Cortex M4F, 1MByte flash, 256kbyte ram. 64MHz )급에서도 활용 가능. - 라이센스 : 오픈소스- 관리주체 : 리눅스재단 하위 별도 프로젝트 팀. - - 제퍼운영체제는 리눅스 커
igotit.tistory.com
첫 등록 : 2026.08.08
최종 수정 :
단축 주소 : https://igotit.tistory.com/6756
'임베디드.일렉트로닉스' 카테고리의 다른 글
| Zephyr . nanopb . 임베디드 프로토 버퍼 (0) | 2026.08.25 |
|---|---|
| LuckFox Pico Linux 보드 . 초저가 초소형 저전력 (0) | 2026.07.29 |
| LED . 1300nm (0) | 2026.07.22 |
| LED . 1550nm (0) | 2026.07.22 |
| LED . 1650nm (0) | 2026.07.22 |
댓글